]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/tipc/config.c
tipc: cleanup function namespace
[net-next-2.6.git] / net / tipc / config.c
CommitLineData
b97bf3fd
PL
1/*
2 * net/tipc/config.c: TIPC configuration management code
c4307285 3 *
593a5f22 4 * Copyright (c) 2002-2006, Ericsson AB
59f0c452 5 * Copyright (c) 2004-2007, Wind River Systems
b97bf3fd
PL
6 * All rights reserved.
7 *
9ea1fd3c 8 * Redistribution and use in source and binary forms, with or without
b97bf3fd
PL
9 * modification, are permitted provided that the following conditions are met:
10 *
9ea1fd3c
PL
11 * 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.
b97bf3fd 19 *
9ea1fd3c
PL
20 * 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
b97bf3fd
PL
34 * 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;
b97bf3fd
PL
59};
60
61static struct manager mng = { 0};
62
34af946a 63static DEFINE_SPINLOCK(config_lock);
b97bf3fd
PL
64
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
4323add6 70struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
b97bf3fd
PL
71{
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
c4307285 80int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
4323add6 81 void *tlv_data, int tlv_data_size)
b97bf3fd 82{
27a884dc 83 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
b97bf3fd
PL
84 int new_tlv_space = TLV_SPACE(tlv_data_size);
85
86 if (skb_tailroom(buf) < new_tlv_space) {
4323add6 87 dbg("tipc_cfg_append_tlv unable to append TLV\n");
b97bf3fd
PL
88 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
31e3c3f6 98static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
b97bf3fd
PL
99{
100 struct sk_buff *buf;
3e6c8cd5 101 __be32 value_net;
b97bf3fd 102
4323add6 103 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
b97bf3fd
PL
104 if (buf) {
105 value_net = htonl(value);
c4307285 106 tipc_cfg_append_tlv(buf, tlv_type, &value_net,
4323add6 107 sizeof(value_net));
b97bf3fd
PL
108 }
109 return buf;
110}
111
31e3c3f6 112static struct sk_buff *tipc_cfg_reply_unsigned(u32 value)
113{
114 return tipc_cfg_reply_unsigned_type(TIPC_TLV_UNSIGNED, value);
115}
116
4323add6 117struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
b97bf3fd
PL
118{
119 struct sk_buff *buf;
120 int string_len = strlen(string) + 1;
121
4323add6 122 buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
b97bf3fd 123 if (buf)
4323add6 124 tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
b97bf3fd
PL
125 return buf;
126}
127
107e7be6
AS
128#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
b97bf3fd
PL
163static 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))
4323add6 168 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd
PL
169
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)))
4323add6 174 return tipc_cfg_reply_error_string("unable to enable bearer");
b97bf3fd 175
4323add6 176 return tipc_cfg_reply_none();
b97bf3fd
PL
177}
178
179static struct sk_buff *cfg_disable_bearer(void)
180{
181 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
4323add6 182 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd
PL
183
184 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
4323add6 185 return tipc_cfg_reply_error_string("unable to disable bearer");
b97bf3fd 186
4323add6 187 return tipc_cfg_reply_none();
b97bf3fd
PL
188}
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))
4323add6 195 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd 196
3e6c8cd5 197 addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
b97bf3fd 198 if (addr == tipc_own_addr)
4323add6
PL
199 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)");
e100ae92 203 if (tipc_mode == TIPC_NET_MODE)
4323add6
PL
204 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
205 " (cannot change node address once assigned)");
e100ae92 206
c4307285 207 /*
e100ae92
AS
208 * 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 */
b97bf3fd
PL
216
217 spin_unlock_bh(&config_lock);
03194379 218 tipc_core_start_net(addr);
b97bf3fd 219 spin_lock_bh(&config_lock);
4323add6 220 return tipc_cfg_reply_none();
b97bf3fd
PL
221}
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))
4323add6 228 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd 229
3e6c8cd5 230 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
b97bf3fd 231 tipc_remote_management = (value != 0);
4323add6 232 return tipc_cfg_reply_none();
b97bf3fd
PL
233}
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))
4323add6 240 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd 241
3e6c8cd5 242 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
b97bf3fd 243 if (value != delimit(value, 1, 65535))
4323add6
PL
244 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
245 " (max publications must be 1-65535)");
b97bf3fd 246 tipc_max_publications = value;
4323add6 247 return tipc_cfg_reply_none();
b97bf3fd
PL
248}
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))
4323add6 255 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd 256
3e6c8cd5 257 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
b97bf3fd 258 if (value != delimit(value, 1, 65535))
4323add6
PL
259 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
260 " (max subscriptions must be 1-65535");
b97bf3fd 261 tipc_max_subscriptions = value;
4323add6 262 return tipc_cfg_reply_none();
b97bf3fd
PL
263}
264
265static struct sk_buff *cfg_set_max_ports(void)
266{
b97bf3fd
PL
267 u32 value;
268
269 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
4323add6 270 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
3e6c8cd5 271 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
e100ae92
AS
272 if (value == tipc_max_ports)
273 return tipc_cfg_reply_none();
b97bf3fd 274 if (value != delimit(value, 127, 65535))
4323add6
PL
275 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
276 " (max ports must be 127-65535)");
e100ae92 277 if (tipc_mode != TIPC_NOT_RUNNING)
4323add6 278 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
e100ae92 279 " (cannot change max ports while TIPC is active)");
b97bf3fd 280 tipc_max_ports = value;
4323add6 281 return tipc_cfg_reply_none();
b97bf3fd
PL
282}
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))
4323add6 289 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
3e6c8cd5 290 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
e100ae92
AS
291 if (value == tipc_max_zones)
292 return tipc_cfg_reply_none();
b97bf3fd 293 if (value != delimit(value, 1, 255))
4323add6
PL
294 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
295 " (max zones must be 1-255)");
e100ae92
AS
296 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();
b97bf3fd
PL
301}
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))
4323add6 308 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
3e6c8cd5 309 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
e100ae92
AS
310 if (value != delimit(value, 1, 1))
311 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
4323add6
PL
312 " (max clusters fixed at 1)");
313 return tipc_cfg_reply_none();
b97bf3fd
PL
314}
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))
4323add6 321 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
3e6c8cd5 322 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
e100ae92
AS
323 if (value == tipc_max_nodes)
324 return tipc_cfg_reply_none();
b97bf3fd 325 if (value != delimit(value, 8, 2047))
4323add6
PL
326 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
327 " (max nodes must be 8-2047)");
e100ae92
AS
328 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();
b97bf3fd
PL
333}
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))
4323add6 340 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
3e6c8cd5 341 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
b97bf3fd 342 if (value != 0)
4323add6
PL
343 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
344 " (max secondary nodes fixed at 0)");
345 return tipc_cfg_reply_none();
b97bf3fd
PL
346}
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))
4323add6 353 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
3e6c8cd5 354 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
e100ae92
AS
355 if (value == tipc_net_id)
356 return tipc_cfg_reply_none();
b97bf3fd 357 if (value != delimit(value, 1, 9999))
4323add6
PL
358 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
359 " (network id must be 1-9999)");
e100ae92 360 if (tipc_mode == TIPC_NET_MODE)
4323add6 361 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
e100ae92
AS
362 " (cannot change network id once TIPC has joined a network)");
363 tipc_net_id = value;
364 return tipc_cfg_reply_none();
b97bf3fd
PL
365}
366
4323add6
PL
367struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
368 int request_space, int reply_headroom)
b97bf3fd
PL
369{
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) {
4323add6
PL
385 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
386 " (cannot be done remotely)");
b97bf3fd
PL
387 goto exit;
388 } else if (!tipc_remote_management) {
4323add6 389 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
b97bf3fd
PL
390 goto exit;
391 }
392 else if (cmd >= 0x4000) {
393 u32 domain = 0;
394
4323add6 395 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
b97bf3fd 396 (domain != orig_node)) {
4323add6 397 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
b97bf3fd
PL
398 goto exit;
399 }
400 }
401
402 /* Call appropriate processing routine */
403
404 switch (cmd) {
405 case TIPC_CMD_NOOP:
4323add6 406 rep_tlv_buf = tipc_cfg_reply_none();
b97bf3fd
PL
407 break;
408 case TIPC_CMD_GET_NODES:
4323add6 409 rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
b97bf3fd
PL
410 break;
411 case TIPC_CMD_GET_LINKS:
4323add6 412 rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
b97bf3fd
PL
413 break;
414 case TIPC_CMD_SHOW_LINK_STATS:
4323add6 415 rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
b97bf3fd
PL
416 break;
417 case TIPC_CMD_RESET_LINK_STATS:
4323add6 418 rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
b97bf3fd
PL
419 break;
420 case TIPC_CMD_SHOW_NAME_TABLE:
4323add6 421 rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
b97bf3fd
PL
422 break;
423 case TIPC_CMD_GET_BEARER_NAMES:
4323add6 424 rep_tlv_buf = tipc_bearer_get_names();
b97bf3fd
PL
425 break;
426 case TIPC_CMD_GET_MEDIA_NAMES:
4323add6 427 rep_tlv_buf = tipc_media_get_names();
b97bf3fd
PL
428 break;
429 case TIPC_CMD_SHOW_PORTS:
4323add6 430 rep_tlv_buf = tipc_port_get_ports();
b97bf3fd 431 break;
b97bf3fd 432 case TIPC_CMD_SET_LOG_SIZE:
025adbe8 433 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
b97bf3fd
PL
434 break;
435 case TIPC_CMD_DUMP_LOG:
4323add6 436 rep_tlv_buf = tipc_log_dump();
b97bf3fd 437 break;
107e7be6
AS
438 case TIPC_CMD_SHOW_STATS:
439 rep_tlv_buf = tipc_show_stats();
440 break;
b97bf3fd
PL
441 case TIPC_CMD_SET_LINK_TOL:
442 case TIPC_CMD_SET_LINK_PRI:
443 case TIPC_CMD_SET_LINK_WINDOW:
4323add6 444 rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
b97bf3fd
PL
445 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:
4323add6 483 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
b97bf3fd
PL
484 break;
485 case TIPC_CMD_GET_MAX_PORTS:
4323add6 486 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
b97bf3fd
PL
487 break;
488 case TIPC_CMD_GET_MAX_PUBL:
4323add6 489 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
b97bf3fd
PL
490 break;
491 case TIPC_CMD_GET_MAX_SUBSCR:
4323add6 492 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
b97bf3fd
PL
493 break;
494 case TIPC_CMD_GET_MAX_ZONES:
4323add6 495 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
b97bf3fd
PL
496 break;
497 case TIPC_CMD_GET_MAX_CLUSTERS:
4323add6 498 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
b97bf3fd
PL
499 break;
500 case TIPC_CMD_GET_MAX_NODES:
4323add6 501 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
b97bf3fd
PL
502 break;
503 case TIPC_CMD_GET_MAX_SLAVES:
4323add6 504 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
b97bf3fd
PL
505 break;
506 case TIPC_CMD_GET_NETID:
4323add6 507 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
b97bf3fd 508 break;
59f0c452
AS
509 case TIPC_CMD_NOT_NET_ADMIN:
510 rep_tlv_buf =
511 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
512 break;
b97bf3fd 513 default:
53cfd1e1
AS
514 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
515 " (unknown command)");
b97bf3fd
PL
516 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,
c4307285 530 u32 importance,
b97bf3fd
PL
531 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)) {
a10bd924 544 warn("Invalid configuration message discarded\n");
b97bf3fd
PL
545 return;
546 }
547
548 /* Generate reply for request (if can't, return request) */
549
4323add6 550 rep_buf = tipc_cfg_do_cmd(orig->node,
c4307285 551 ntohs(req_hdr->tcm_type),
4323add6
PL
552 msg + sizeof(*req_hdr),
553 size - sizeof(*req_hdr),
554 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
b97bf3fd
PL
555 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
4323add6 570int tipc_cfg_init(void)
b97bf3fd
PL
571{
572 struct tipc_name_seq seq;
573 int res;
574
1fc54d8f 575 res = tipc_attach(&mng.user_ref, NULL, NULL);
b97bf3fd
PL
576 if (res)
577 goto failed;
578
1fc54d8f 579 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
b97bf3fd
PL
580 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;
4323add6 588 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
b97bf3fd
PL
589 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
4323add6 601void tipc_cfg_stop(void)
b97bf3fd
PL
602{
603 if (mng.user_ref) {
604 tipc_detach(mng.user_ref);
605 mng.user_ref = 0;
606 }
607}