blob: 50a6133a3668f082daf5bb5f6e63a1b67191ab52 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/config.c: TIPC configuration management code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Per Liden593a5f22006-01-11 19:14:19 +01004 * Copyright (c) 2002-2006, Ericsson AB
Allan Stephens59f0c452008-05-21 14:52:30 -07005 * Copyright (c) 2004-2007, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01006 * All rights reserved.
7 *
Per Liden9ea1fd32006-01-11 13:30:43 +01008 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +01009 * modification, are permitted provided that the following conditions are met:
10 *
Per Liden9ea1fd32006-01-11 13:30:43 +010011 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the names of the copyright holders nor the names of its
17 * contributors may be used to endorse or promote products derived from
18 * this software without specific prior written permission.
Per Lidenb97bf3f2006-01-02 19:04:38 +010019 *
Per Liden9ea1fd32006-01-11 13:30:43 +010020 * Alternatively, this software may be distributed under the terms of the
21 * GNU General Public License ("GPL") version 2 as published by the Free
22 * Software Foundation.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Per Lidenb97bf3f2006-01-02 19:04:38 +010034 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "dbg.h"
39#include "bearer.h"
40#include "port.h"
41#include "link.h"
42#include "zone.h"
43#include "addr.h"
44#include "name_table.h"
45#include "node.h"
46#include "config.h"
47#include "discover.h"
48
49struct subscr_data {
50 char usr_handle[8];
51 u32 domain;
52 u32 port_ref;
53 struct list_head subd_list;
54};
55
56struct manager {
57 u32 user_ref;
58 u32 port_ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +010059};
60
61static struct manager mng = { 0};
62
Ingo Molnar34af9462006-06-27 02:53:55 -070063static DEFINE_SPINLOCK(config_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +010064
65static const void *req_tlv_area; /* request message TLV area */
66static int req_tlv_space; /* request message TLV area size */
67static int rep_headroom; /* reply message headroom to use */
68
69
Per Liden4323add2006-01-18 00:38:21 +010070struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +010071{
72 struct sk_buff *buf;
73
74 buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
75 if (buf)
76 skb_reserve(buf, rep_headroom);
77 return buf;
78}
79
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090080int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
Per Liden4323add2006-01-18 00:38:21 +010081 void *tlv_data, int tlv_data_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +010082{
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -070083 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +010084 int new_tlv_space = TLV_SPACE(tlv_data_size);
85
86 if (skb_tailroom(buf) < new_tlv_space) {
Per Liden4323add2006-01-18 00:38:21 +010087 dbg("tipc_cfg_append_tlv unable to append TLV\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +010088 return 0;
89 }
90 skb_put(buf, new_tlv_space);
91 tlv->tlv_type = htons(tlv_type);
92 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
93 if (tlv_data_size && tlv_data)
94 memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
95 return 1;
96}
97
stephen hemminger31e3c3f2010-10-13 13:20:35 +000098static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
Per Lidenb97bf3f2006-01-02 19:04:38 +010099{
100 struct sk_buff *buf;
Al Viro3e6c8cd2006-11-08 00:19:09 -0800101 __be32 value_net;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100102
Per Liden4323add2006-01-18 00:38:21 +0100103 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100104 if (buf) {
105 value_net = htonl(value);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900106 tipc_cfg_append_tlv(buf, tlv_type, &value_net,
Per Liden4323add2006-01-18 00:38:21 +0100107 sizeof(value_net));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108 }
109 return buf;
110}
111
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000112static struct sk_buff *tipc_cfg_reply_unsigned(u32 value)
113{
114 return tipc_cfg_reply_unsigned_type(TIPC_TLV_UNSIGNED, value);
115}
116
Per Liden4323add2006-01-18 00:38:21 +0100117struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100118{
119 struct sk_buff *buf;
120 int string_len = strlen(string) + 1;
121
Per Liden4323add2006-01-18 00:38:21 +0100122 buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100123 if (buf)
Per Liden4323add2006-01-18 00:38:21 +0100124 tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100125 return buf;
126}
127
Allan Stephens107e7be2010-05-11 14:30:08 +0000128#define MAX_STATS_INFO 2000
129
130static struct sk_buff *tipc_show_stats(void)
131{
132 struct sk_buff *buf;
133 struct tlv_desc *rep_tlv;
134 struct print_buf pb;
135 int str_len;
136 u32 value;
137
138 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
139 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
140
141 value = ntohl(*(u32 *)TLV_DATA(req_tlv_area));
142 if (value != 0)
143 return tipc_cfg_reply_error_string("unsupported argument");
144
145 buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_STATS_INFO));
146 if (buf == NULL)
147 return NULL;
148
149 rep_tlv = (struct tlv_desc *)buf->data;
150 tipc_printbuf_init(&pb, (char *)TLV_DATA(rep_tlv), MAX_STATS_INFO);
151
152 tipc_printf(&pb, "TIPC version " TIPC_MOD_VER "\n");
153
154 /* Use additional tipc_printf()'s to return more info ... */
155
156 str_len = tipc_printbuf_validate(&pb);
157 skb_put(buf, TLV_SPACE(str_len));
158 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
159
160 return buf;
161}
162
Per Lidenb97bf3f2006-01-02 19:04:38 +0100163static struct sk_buff *cfg_enable_bearer(void)
164{
165 struct tipc_bearer_config *args;
166
167 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +0100168 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100169
170 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
171 if (tipc_enable_bearer(args->name,
172 ntohl(args->detect_scope),
173 ntohl(args->priority)))
Per Liden4323add2006-01-18 00:38:21 +0100174 return tipc_cfg_reply_error_string("unable to enable bearer");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100175
Per Liden4323add2006-01-18 00:38:21 +0100176 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100177}
178
179static struct sk_buff *cfg_disable_bearer(void)
180{
181 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
Per Liden4323add2006-01-18 00:38:21 +0100182 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100183
184 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
Per Liden4323add2006-01-18 00:38:21 +0100185 return tipc_cfg_reply_error_string("unable to disable bearer");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100186
Per Liden4323add2006-01-18 00:38:21 +0100187 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100188}
189
190static struct sk_buff *cfg_set_own_addr(void)
191{
192 u32 addr;
193
194 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100195 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100196
Al Viro3e6c8cd2006-11-08 00:19:09 -0800197 addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100198 if (addr == tipc_own_addr)
Per Liden4323add2006-01-18 00:38:21 +0100199 return tipc_cfg_reply_none();
200 if (!tipc_addr_node_valid(addr))
201 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
202 " (node address)");
Allan Stephense100ae92006-06-25 23:51:08 -0700203 if (tipc_mode == TIPC_NET_MODE)
Per Liden4323add2006-01-18 00:38:21 +0100204 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
205 " (cannot change node address once assigned)");
Allan Stephense100ae92006-06-25 23:51:08 -0700206
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900207 /*
Allan Stephense100ae92006-06-25 23:51:08 -0700208 * Must release all spinlocks before calling start_net() because
209 * Linux version of TIPC calls eth_media_start() which calls
210 * register_netdevice_notifier() which may block!
211 *
212 * Temporarily releasing the lock should be harmless for non-Linux TIPC,
213 * but Linux version of eth_media_start() should really be reworked
214 * so that it can be called with spinlocks held.
215 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100216
217 spin_unlock_bh(&config_lock);
Allan Stephens03194372008-05-21 14:55:04 -0700218 tipc_core_start_net(addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100219 spin_lock_bh(&config_lock);
Per Liden4323add2006-01-18 00:38:21 +0100220 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221}
222
223static struct sk_buff *cfg_set_remote_mng(void)
224{
225 u32 value;
226
227 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100228 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100229
Al Viro3e6c8cd2006-11-08 00:19:09 -0800230 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100231 tipc_remote_management = (value != 0);
Per Liden4323add2006-01-18 00:38:21 +0100232 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100233}
234
235static struct sk_buff *cfg_set_max_publications(void)
236{
237 u32 value;
238
239 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100240 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100241
Al Viro3e6c8cd2006-11-08 00:19:09 -0800242 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100243 if (value != delimit(value, 1, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100244 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
245 " (max publications must be 1-65535)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100246 tipc_max_publications = value;
Per Liden4323add2006-01-18 00:38:21 +0100247 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100248}
249
250static struct sk_buff *cfg_set_max_subscriptions(void)
251{
252 u32 value;
253
254 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100255 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100256
Al Viro3e6c8cd2006-11-08 00:19:09 -0800257 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100258 if (value != delimit(value, 1, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100259 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
260 " (max subscriptions must be 1-65535");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100261 tipc_max_subscriptions = value;
Per Liden4323add2006-01-18 00:38:21 +0100262 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100263}
264
265static struct sk_buff *cfg_set_max_ports(void)
266{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100267 u32 value;
268
269 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100270 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800271 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700272 if (value == tipc_max_ports)
273 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100274 if (value != delimit(value, 127, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100275 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
276 " (max ports must be 127-65535)");
Allan Stephense100ae92006-06-25 23:51:08 -0700277 if (tipc_mode != TIPC_NOT_RUNNING)
Per Liden4323add2006-01-18 00:38:21 +0100278 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Allan Stephense100ae92006-06-25 23:51:08 -0700279 " (cannot change max ports while TIPC is active)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100280 tipc_max_ports = value;
Per Liden4323add2006-01-18 00:38:21 +0100281 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100282}
283
284static struct sk_buff *cfg_set_max_zones(void)
285{
286 u32 value;
287
288 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100289 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800290 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700291 if (value == tipc_max_zones)
292 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100293 if (value != delimit(value, 1, 255))
Per Liden4323add2006-01-18 00:38:21 +0100294 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
295 " (max zones must be 1-255)");
Allan Stephense100ae92006-06-25 23:51:08 -0700296 if (tipc_mode == TIPC_NET_MODE)
297 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
298 " (cannot change max zones once TIPC has joined a network)");
299 tipc_max_zones = value;
300 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100301}
302
303static struct sk_buff *cfg_set_max_clusters(void)
304{
305 u32 value;
306
307 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100308 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800309 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700310 if (value != delimit(value, 1, 1))
311 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
Per Liden4323add2006-01-18 00:38:21 +0100312 " (max clusters fixed at 1)");
313 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100314}
315
316static struct sk_buff *cfg_set_max_nodes(void)
317{
318 u32 value;
319
320 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100321 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800322 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700323 if (value == tipc_max_nodes)
324 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100325 if (value != delimit(value, 8, 2047))
Per Liden4323add2006-01-18 00:38:21 +0100326 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
327 " (max nodes must be 8-2047)");
Allan Stephense100ae92006-06-25 23:51:08 -0700328 if (tipc_mode == TIPC_NET_MODE)
329 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
330 " (cannot change max nodes once TIPC has joined a network)");
331 tipc_max_nodes = value;
332 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100333}
334
335static struct sk_buff *cfg_set_max_slaves(void)
336{
337 u32 value;
338
339 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100340 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800341 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100342 if (value != 0)
Per Liden4323add2006-01-18 00:38:21 +0100343 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
344 " (max secondary nodes fixed at 0)");
345 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100346}
347
348static struct sk_buff *cfg_set_netid(void)
349{
350 u32 value;
351
352 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100353 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800354 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700355 if (value == tipc_net_id)
356 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100357 if (value != delimit(value, 1, 9999))
Per Liden4323add2006-01-18 00:38:21 +0100358 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
359 " (network id must be 1-9999)");
Allan Stephense100ae92006-06-25 23:51:08 -0700360 if (tipc_mode == TIPC_NET_MODE)
Per Liden4323add2006-01-18 00:38:21 +0100361 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Allan Stephense100ae92006-06-25 23:51:08 -0700362 " (cannot change network id once TIPC has joined a network)");
363 tipc_net_id = value;
364 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100365}
366
Per Liden4323add2006-01-18 00:38:21 +0100367struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
368 int request_space, int reply_headroom)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100369{
370 struct sk_buff *rep_tlv_buf;
371
372 spin_lock_bh(&config_lock);
373
374 /* Save request and reply details in a well-known location */
375
376 req_tlv_area = request_area;
377 req_tlv_space = request_space;
378 rep_headroom = reply_headroom;
379
380 /* Check command authorization */
381
382 if (likely(orig_node == tipc_own_addr)) {
383 /* command is permitted */
384 } else if (cmd >= 0x8000) {
Per Liden4323add2006-01-18 00:38:21 +0100385 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
386 " (cannot be done remotely)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100387 goto exit;
388 } else if (!tipc_remote_management) {
Per Liden4323add2006-01-18 00:38:21 +0100389 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100390 goto exit;
391 }
392 else if (cmd >= 0x4000) {
393 u32 domain = 0;
394
Per Liden4323add2006-01-18 00:38:21 +0100395 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100396 (domain != orig_node)) {
Per Liden4323add2006-01-18 00:38:21 +0100397 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100398 goto exit;
399 }
400 }
401
402 /* Call appropriate processing routine */
403
404 switch (cmd) {
405 case TIPC_CMD_NOOP:
Per Liden4323add2006-01-18 00:38:21 +0100406 rep_tlv_buf = tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100407 break;
408 case TIPC_CMD_GET_NODES:
Per Liden4323add2006-01-18 00:38:21 +0100409 rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100410 break;
411 case TIPC_CMD_GET_LINKS:
Per Liden4323add2006-01-18 00:38:21 +0100412 rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100413 break;
414 case TIPC_CMD_SHOW_LINK_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100415 rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100416 break;
417 case TIPC_CMD_RESET_LINK_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100418 rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100419 break;
420 case TIPC_CMD_SHOW_NAME_TABLE:
Per Liden4323add2006-01-18 00:38:21 +0100421 rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100422 break;
423 case TIPC_CMD_GET_BEARER_NAMES:
Per Liden4323add2006-01-18 00:38:21 +0100424 rep_tlv_buf = tipc_bearer_get_names();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100425 break;
426 case TIPC_CMD_GET_MEDIA_NAMES:
Per Liden4323add2006-01-18 00:38:21 +0100427 rep_tlv_buf = tipc_media_get_names();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100428 break;
429 case TIPC_CMD_SHOW_PORTS:
Per Liden4323add2006-01-18 00:38:21 +0100430 rep_tlv_buf = tipc_port_get_ports();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100431 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100432 case TIPC_CMD_SET_LOG_SIZE:
Allan Stephens025adbe2008-05-05 01:20:04 -0700433 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100434 break;
435 case TIPC_CMD_DUMP_LOG:
Per Liden4323add2006-01-18 00:38:21 +0100436 rep_tlv_buf = tipc_log_dump();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100437 break;
Allan Stephens107e7be2010-05-11 14:30:08 +0000438 case TIPC_CMD_SHOW_STATS:
439 rep_tlv_buf = tipc_show_stats();
440 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100441 case TIPC_CMD_SET_LINK_TOL:
442 case TIPC_CMD_SET_LINK_PRI:
443 case TIPC_CMD_SET_LINK_WINDOW:
Per Liden4323add2006-01-18 00:38:21 +0100444 rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100445 break;
446 case TIPC_CMD_ENABLE_BEARER:
447 rep_tlv_buf = cfg_enable_bearer();
448 break;
449 case TIPC_CMD_DISABLE_BEARER:
450 rep_tlv_buf = cfg_disable_bearer();
451 break;
452 case TIPC_CMD_SET_NODE_ADDR:
453 rep_tlv_buf = cfg_set_own_addr();
454 break;
455 case TIPC_CMD_SET_REMOTE_MNG:
456 rep_tlv_buf = cfg_set_remote_mng();
457 break;
458 case TIPC_CMD_SET_MAX_PORTS:
459 rep_tlv_buf = cfg_set_max_ports();
460 break;
461 case TIPC_CMD_SET_MAX_PUBL:
462 rep_tlv_buf = cfg_set_max_publications();
463 break;
464 case TIPC_CMD_SET_MAX_SUBSCR:
465 rep_tlv_buf = cfg_set_max_subscriptions();
466 break;
467 case TIPC_CMD_SET_MAX_ZONES:
468 rep_tlv_buf = cfg_set_max_zones();
469 break;
470 case TIPC_CMD_SET_MAX_CLUSTERS:
471 rep_tlv_buf = cfg_set_max_clusters();
472 break;
473 case TIPC_CMD_SET_MAX_NODES:
474 rep_tlv_buf = cfg_set_max_nodes();
475 break;
476 case TIPC_CMD_SET_MAX_SLAVES:
477 rep_tlv_buf = cfg_set_max_slaves();
478 break;
479 case TIPC_CMD_SET_NETID:
480 rep_tlv_buf = cfg_set_netid();
481 break;
482 case TIPC_CMD_GET_REMOTE_MNG:
Per Liden4323add2006-01-18 00:38:21 +0100483 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100484 break;
485 case TIPC_CMD_GET_MAX_PORTS:
Per Liden4323add2006-01-18 00:38:21 +0100486 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100487 break;
488 case TIPC_CMD_GET_MAX_PUBL:
Per Liden4323add2006-01-18 00:38:21 +0100489 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100490 break;
491 case TIPC_CMD_GET_MAX_SUBSCR:
Per Liden4323add2006-01-18 00:38:21 +0100492 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100493 break;
494 case TIPC_CMD_GET_MAX_ZONES:
Per Liden4323add2006-01-18 00:38:21 +0100495 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100496 break;
497 case TIPC_CMD_GET_MAX_CLUSTERS:
Per Liden4323add2006-01-18 00:38:21 +0100498 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100499 break;
500 case TIPC_CMD_GET_MAX_NODES:
Per Liden4323add2006-01-18 00:38:21 +0100501 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100502 break;
503 case TIPC_CMD_GET_MAX_SLAVES:
Per Liden4323add2006-01-18 00:38:21 +0100504 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100505 break;
506 case TIPC_CMD_GET_NETID:
Per Liden4323add2006-01-18 00:38:21 +0100507 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100508 break;
Allan Stephens59f0c452008-05-21 14:52:30 -0700509 case TIPC_CMD_NOT_NET_ADMIN:
510 rep_tlv_buf =
511 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
512 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100513 default:
Allan Stephens53cfd1e2006-10-16 22:00:56 -0700514 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
515 " (unknown command)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100516 break;
517 }
518
519 /* Return reply buffer */
520exit:
521 spin_unlock_bh(&config_lock);
522 return rep_tlv_buf;
523}
524
525static void cfg_named_msg_event(void *userdata,
526 u32 port_ref,
527 struct sk_buff **buf,
528 const unchar *msg,
529 u32 size,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900530 u32 importance,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100531 struct tipc_portid const *orig,
532 struct tipc_name_seq const *dest)
533{
534 struct tipc_cfg_msg_hdr *req_hdr;
535 struct tipc_cfg_msg_hdr *rep_hdr;
536 struct sk_buff *rep_buf;
537
538 /* Validate configuration message header (ignore invalid message) */
539
540 req_hdr = (struct tipc_cfg_msg_hdr *)msg;
541 if ((size < sizeof(*req_hdr)) ||
542 (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
543 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700544 warn("Invalid configuration message discarded\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100545 return;
546 }
547
548 /* Generate reply for request (if can't, return request) */
549
Per Liden4323add2006-01-18 00:38:21 +0100550 rep_buf = tipc_cfg_do_cmd(orig->node,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900551 ntohs(req_hdr->tcm_type),
Per Liden4323add2006-01-18 00:38:21 +0100552 msg + sizeof(*req_hdr),
553 size - sizeof(*req_hdr),
554 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100555 if (rep_buf) {
556 skb_push(rep_buf, sizeof(*rep_hdr));
557 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
558 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
559 rep_hdr->tcm_len = htonl(rep_buf->len);
560 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
561 } else {
562 rep_buf = *buf;
563 *buf = NULL;
564 }
565
566 /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
567 tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
568}
569
Per Liden4323add2006-01-18 00:38:21 +0100570int tipc_cfg_init(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100571{
572 struct tipc_name_seq seq;
573 int res;
574
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800575 res = tipc_attach(&mng.user_ref, NULL, NULL);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100576 if (res)
577 goto failed;
578
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800579 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100580 NULL, NULL, NULL,
581 NULL, cfg_named_msg_event, NULL,
582 NULL, &mng.port_ref);
583 if (res)
584 goto failed;
585
586 seq.type = TIPC_CFG_SRV;
587 seq.lower = seq.upper = tipc_own_addr;
Per Liden4323add2006-01-18 00:38:21 +0100588 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100589 if (res)
590 goto failed;
591
592 return 0;
593
594failed:
595 err("Unable to create configuration service\n");
596 tipc_detach(mng.user_ref);
597 mng.user_ref = 0;
598 return res;
599}
600
Per Liden4323add2006-01-18 00:38:21 +0100601void tipc_cfg_stop(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100602{
603 if (mng.user_ref) {
604 tipc_detach(mng.user_ref);
605 mng.user_ref = 0;
606 }
607}