blob: 9e55cf8caec70a5586f6a7d6d4c66ad265937523 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/config.c: TIPC configuration management code
3 *
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2004-2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
7 * All rights reserved.
8 *
Per Liden9ea1fd32006-01-11 13:30:43 +01009 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +010010 * modification, are permitted provided that the following conditions are met:
11 *
Per Liden9ea1fd32006-01-11 13:30:43 +010012 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
Per Lidenb97bf3f2006-01-02 19:04:38 +010020 *
Per Liden9ea1fd32006-01-11 13:30:43 +010021 * Alternatively, this software may be distributed under the terms of the
22 * GNU General Public License ("GPL") version 2 as published by the Free
23 * Software Foundation.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Per Lidenb97bf3f2006-01-02 19:04:38 +010035 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include "core.h"
39#include "dbg.h"
40#include "bearer.h"
41#include "port.h"
42#include "link.h"
43#include "zone.h"
44#include "addr.h"
45#include "name_table.h"
46#include "node.h"
47#include "config.h"
48#include "discover.h"
49
50struct subscr_data {
51 char usr_handle[8];
52 u32 domain;
53 u32 port_ref;
54 struct list_head subd_list;
55};
56
57struct manager {
58 u32 user_ref;
59 u32 port_ref;
60 u32 subscr_ref;
61 u32 link_subscriptions;
62 struct list_head link_subscribers;
63};
64
65static struct manager mng = { 0};
66
67static spinlock_t config_lock = SPIN_LOCK_UNLOCKED;
68
69static const void *req_tlv_area; /* request message TLV area */
70static int req_tlv_space; /* request message TLV area size */
71static int rep_headroom; /* reply message headroom to use */
72
73
74void cfg_link_event(u32 addr, char *name, int up)
75{
76 /* TIPC DOESN'T HANDLE LINK EVENT SUBSCRIPTIONS AT THE MOMENT */
77}
78
79
80struct sk_buff *cfg_reply_alloc(int payload_size)
81{
82 struct sk_buff *buf;
83
84 buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
85 if (buf)
86 skb_reserve(buf, rep_headroom);
87 return buf;
88}
89
90int cfg_append_tlv(struct sk_buff *buf, int tlv_type,
91 void *tlv_data, int tlv_data_size)
92{
93 struct tlv_desc *tlv = (struct tlv_desc *)buf->tail;
94 int new_tlv_space = TLV_SPACE(tlv_data_size);
95
96 if (skb_tailroom(buf) < new_tlv_space) {
97 dbg("cfg_append_tlv unable to append TLV\n");
98 return 0;
99 }
100 skb_put(buf, new_tlv_space);
101 tlv->tlv_type = htons(tlv_type);
102 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
103 if (tlv_data_size && tlv_data)
104 memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
105 return 1;
106}
107
108struct sk_buff *cfg_reply_unsigned_type(u16 tlv_type, u32 value)
109{
110 struct sk_buff *buf;
111 u32 value_net;
112
113 buf = cfg_reply_alloc(TLV_SPACE(sizeof(value)));
114 if (buf) {
115 value_net = htonl(value);
116 cfg_append_tlv(buf, tlv_type, &value_net,
117 sizeof(value_net));
118 }
119 return buf;
120}
121
122struct sk_buff *cfg_reply_string_type(u16 tlv_type, char *string)
123{
124 struct sk_buff *buf;
125 int string_len = strlen(string) + 1;
126
127 buf = cfg_reply_alloc(TLV_SPACE(string_len));
128 if (buf)
129 cfg_append_tlv(buf, tlv_type, string, string_len);
130 return buf;
131}
132
133
134
135
136#if 0
137
138/* Now obsolete code for handling commands not yet implemented the new way */
139
140int tipc_cfg_cmd(const struct tipc_cmd_msg * msg,
141 char *data,
142 u32 sz,
143 u32 *ret_size,
144 struct tipc_portid *orig)
145{
146 int rv = -EINVAL;
147 u32 cmd = msg->cmd;
148
149 *ret_size = 0;
150 switch (cmd) {
151 case TIPC_REMOVE_LINK:
152 case TIPC_CMD_BLOCK_LINK:
153 case TIPC_CMD_UNBLOCK_LINK:
154 if (!cfg_check_connection(orig))
155 rv = link_control(msg->argv.link_name, msg->cmd, 0);
156 break;
157 case TIPC_ESTABLISH:
158 {
159 int connected;
160
161 tipc_isconnected(mng.conn_port_ref, &connected);
162 if (connected || !orig) {
163 rv = TIPC_FAILURE;
164 break;
165 }
166 rv = tipc_connect2port(mng.conn_port_ref, orig);
167 if (rv == TIPC_OK)
168 orig = 0;
169 break;
170 }
171 case TIPC_GET_PEER_ADDRESS:
172 *ret_size = link_peer_addr(msg->argv.link_name, data, sz);
173 break;
174 case TIPC_GET_ROUTES:
175 rv = TIPC_OK;
176 break;
177 default: {}
178 }
179 if (*ret_size)
180 rv = TIPC_OK;
181 return rv;
182}
183
184static void cfg_cmd_event(struct tipc_cmd_msg *msg,
185 char *data,
186 u32 sz,
187 struct tipc_portid const *orig)
188{
189 int rv = -EINVAL;
190 struct tipc_cmd_result_msg rmsg;
191 struct iovec msg_sect[2];
192 int *arg;
193
194 msg->cmd = ntohl(msg->cmd);
195
196 cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect,
197 data, 0);
198 if (ntohl(msg->magic) != TIPC_MAGIC)
199 goto exit;
200
201 switch (msg->cmd) {
202 case TIPC_CREATE_LINK:
203 if (!cfg_check_connection(orig))
204 rv = disc_create_link(&msg->argv.create_link);
205 break;
206 case TIPC_LINK_SUBSCRIBE:
207 {
208 struct subscr_data *sub;
209
210 if (mng.link_subscriptions > 64)
211 break;
212 sub = (struct subscr_data *)kmalloc(sizeof(*sub),
213 GFP_ATOMIC);
214 if (sub == NULL) {
215 warn("Memory squeeze; dropped remote link subscription\n");
216 break;
217 }
218 INIT_LIST_HEAD(&sub->subd_list);
219 tipc_createport(mng.user_ref,
220 (void *)sub,
221 TIPC_HIGH_IMPORTANCE,
222 0,
223 0,
224 (tipc_conn_shutdown_event)cfg_linksubscr_cancel,
225 0,
226 0,
227 (tipc_conn_msg_event)cfg_linksubscr_cancel,
228 0,
229 &sub->port_ref);
230 if (!sub->port_ref) {
231 kfree(sub);
232 break;
233 }
234 memcpy(sub->usr_handle,msg->usr_handle,
235 sizeof(sub->usr_handle));
236 sub->domain = msg->argv.domain;
237 list_add_tail(&sub->subd_list, &mng.link_subscribers);
238 tipc_connect2port(sub->port_ref, orig);
239 rmsg.retval = TIPC_OK;
240 tipc_send(sub->port_ref, 2u, msg_sect);
241 mng.link_subscriptions++;
242 return;
243 }
244 default:
245 rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig);
246 }
247 exit:
248 rmsg.result_len = htonl(msg_sect[1].iov_len);
249 rmsg.retval = htonl(rv);
250 cfg_respond(msg_sect, 2u, orig);
251}
252#endif
253
254static struct sk_buff *cfg_enable_bearer(void)
255{
256 struct tipc_bearer_config *args;
257
258 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
259 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
260
261 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
262 if (tipc_enable_bearer(args->name,
263 ntohl(args->detect_scope),
264 ntohl(args->priority)))
265 return cfg_reply_error_string("unable to enable bearer");
266
267 return cfg_reply_none();
268}
269
270static struct sk_buff *cfg_disable_bearer(void)
271{
272 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
273 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
274
275 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
276 return cfg_reply_error_string("unable to disable bearer");
277
278 return cfg_reply_none();
279}
280
281static struct sk_buff *cfg_set_own_addr(void)
282{
283 u32 addr;
284
285 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
286 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
287
288 addr = *(u32 *)TLV_DATA(req_tlv_area);
289 addr = ntohl(addr);
290 if (addr == tipc_own_addr)
291 return cfg_reply_none();
292 if (!addr_node_valid(addr))
293 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
294 " (node address)");
295 if (tipc_own_addr)
296 return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
297 " (cannot change node address once assigned)");
298
299 spin_unlock_bh(&config_lock);
300 stop_net();
301 tipc_own_addr = addr;
302 start_net();
303 spin_lock_bh(&config_lock);
304 return cfg_reply_none();
305}
306
307static struct sk_buff *cfg_set_remote_mng(void)
308{
309 u32 value;
310
311 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
312 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
313
314 value = *(u32 *)TLV_DATA(req_tlv_area);
315 value = ntohl(value);
316 tipc_remote_management = (value != 0);
317 return cfg_reply_none();
318}
319
320static struct sk_buff *cfg_set_max_publications(void)
321{
322 u32 value;
323
324 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
325 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
326
327 value = *(u32 *)TLV_DATA(req_tlv_area);
328 value = ntohl(value);
329 if (value != delimit(value, 1, 65535))
330 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
331 " (max publications must be 1-65535)");
332 tipc_max_publications = value;
333 return cfg_reply_none();
334}
335
336static struct sk_buff *cfg_set_max_subscriptions(void)
337{
338 u32 value;
339
340 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
341 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
342
343 value = *(u32 *)TLV_DATA(req_tlv_area);
344 value = ntohl(value);
345 if (value != delimit(value, 1, 65535))
346 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
347 " (max subscriptions must be 1-65535");
348 tipc_max_subscriptions = value;
349 return cfg_reply_none();
350}
351
352static struct sk_buff *cfg_set_max_ports(void)
353{
354 int orig_mode;
355 u32 value;
356
357 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
358 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
359 value = *(u32 *)TLV_DATA(req_tlv_area);
360 value = ntohl(value);
361 if (value != delimit(value, 127, 65535))
362 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
363 " (max ports must be 127-65535)");
364
365 if (value == tipc_max_ports)
366 return cfg_reply_none();
367
368 if (atomic_read(&tipc_user_count) > 2)
369 return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
370 " (cannot change max ports while TIPC users exist)");
371
372 spin_unlock_bh(&config_lock);
373 orig_mode = tipc_get_mode();
374 if (orig_mode == TIPC_NET_MODE)
375 stop_net();
376 stop_core();
377 tipc_max_ports = value;
378 start_core();
379 if (orig_mode == TIPC_NET_MODE)
380 start_net();
381 spin_lock_bh(&config_lock);
382 return cfg_reply_none();
383}
384
385static struct sk_buff *set_net_max(int value, int *parameter)
386{
387 int orig_mode;
388
389 if (value != *parameter) {
390 orig_mode = tipc_get_mode();
391 if (orig_mode == TIPC_NET_MODE)
392 stop_net();
393 *parameter = value;
394 if (orig_mode == TIPC_NET_MODE)
395 start_net();
396 }
397
398 return cfg_reply_none();
399}
400
401static struct sk_buff *cfg_set_max_zones(void)
402{
403 u32 value;
404
405 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
406 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
407 value = *(u32 *)TLV_DATA(req_tlv_area);
408 value = ntohl(value);
409 if (value != delimit(value, 1, 255))
410 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
411 " (max zones must be 1-255)");
412 return set_net_max(value, &tipc_max_zones);
413}
414
415static struct sk_buff *cfg_set_max_clusters(void)
416{
417 u32 value;
418
419 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
420 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
421 value = *(u32 *)TLV_DATA(req_tlv_area);
422 value = ntohl(value);
423 if (value != 1)
424 return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
425 " (max clusters fixed at 1)");
426 return cfg_reply_none();
427}
428
429static struct sk_buff *cfg_set_max_nodes(void)
430{
431 u32 value;
432
433 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
434 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
435 value = *(u32 *)TLV_DATA(req_tlv_area);
436 value = ntohl(value);
437 if (value != delimit(value, 8, 2047))
438 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
439 " (max nodes must be 8-2047)");
440 return set_net_max(value, &tipc_max_nodes);
441}
442
443static struct sk_buff *cfg_set_max_slaves(void)
444{
445 u32 value;
446
447 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
448 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
449 value = *(u32 *)TLV_DATA(req_tlv_area);
450 value = ntohl(value);
451 if (value != 0)
452 return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
453 " (max secondary nodes fixed at 0)");
454 return cfg_reply_none();
455}
456
457static struct sk_buff *cfg_set_netid(void)
458{
459 u32 value;
460
461 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
462 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
463 value = *(u32 *)TLV_DATA(req_tlv_area);
464 value = ntohl(value);
465 if (value != delimit(value, 1, 9999))
466 return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
467 " (network id must be 1-9999)");
468
469 if (tipc_own_addr)
470 return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
471 " (cannot change network id once part of network)");
472
473 return set_net_max(value, &tipc_net_id);
474}
475
476struct sk_buff *cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
477 int request_space, int reply_headroom)
478{
479 struct sk_buff *rep_tlv_buf;
480
481 spin_lock_bh(&config_lock);
482
483 /* Save request and reply details in a well-known location */
484
485 req_tlv_area = request_area;
486 req_tlv_space = request_space;
487 rep_headroom = reply_headroom;
488
489 /* Check command authorization */
490
491 if (likely(orig_node == tipc_own_addr)) {
492 /* command is permitted */
493 } else if (cmd >= 0x8000) {
494 rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
495 " (cannot be done remotely)");
496 goto exit;
497 } else if (!tipc_remote_management) {
498 rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
499 goto exit;
500 }
501 else if (cmd >= 0x4000) {
502 u32 domain = 0;
503
504 if ((nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
505 (domain != orig_node)) {
506 rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
507 goto exit;
508 }
509 }
510
511 /* Call appropriate processing routine */
512
513 switch (cmd) {
514 case TIPC_CMD_NOOP:
515 rep_tlv_buf = cfg_reply_none();
516 break;
517 case TIPC_CMD_GET_NODES:
518 rep_tlv_buf = node_get_nodes(req_tlv_area, req_tlv_space);
519 break;
520 case TIPC_CMD_GET_LINKS:
521 rep_tlv_buf = node_get_links(req_tlv_area, req_tlv_space);
522 break;
523 case TIPC_CMD_SHOW_LINK_STATS:
524 rep_tlv_buf = link_cmd_show_stats(req_tlv_area, req_tlv_space);
525 break;
526 case TIPC_CMD_RESET_LINK_STATS:
527 rep_tlv_buf = link_cmd_reset_stats(req_tlv_area, req_tlv_space);
528 break;
529 case TIPC_CMD_SHOW_NAME_TABLE:
530 rep_tlv_buf = nametbl_get(req_tlv_area, req_tlv_space);
531 break;
532 case TIPC_CMD_GET_BEARER_NAMES:
533 rep_tlv_buf = bearer_get_names();
534 break;
535 case TIPC_CMD_GET_MEDIA_NAMES:
536 rep_tlv_buf = media_get_names();
537 break;
538 case TIPC_CMD_SHOW_PORTS:
539 rep_tlv_buf = port_get_ports();
540 break;
541#if 0
542 case TIPC_CMD_SHOW_PORT_STATS:
543 rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
544 break;
545 case TIPC_CMD_RESET_PORT_STATS:
546 rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
547 break;
548#endif
549 case TIPC_CMD_SET_LOG_SIZE:
550 rep_tlv_buf = log_resize(req_tlv_area, req_tlv_space);
551 break;
552 case TIPC_CMD_DUMP_LOG:
553 rep_tlv_buf = log_dump();
554 break;
555 case TIPC_CMD_SET_LINK_TOL:
556 case TIPC_CMD_SET_LINK_PRI:
557 case TIPC_CMD_SET_LINK_WINDOW:
558 rep_tlv_buf = link_cmd_config(req_tlv_area, req_tlv_space, cmd);
559 break;
560 case TIPC_CMD_ENABLE_BEARER:
561 rep_tlv_buf = cfg_enable_bearer();
562 break;
563 case TIPC_CMD_DISABLE_BEARER:
564 rep_tlv_buf = cfg_disable_bearer();
565 break;
566 case TIPC_CMD_SET_NODE_ADDR:
567 rep_tlv_buf = cfg_set_own_addr();
568 break;
569 case TIPC_CMD_SET_REMOTE_MNG:
570 rep_tlv_buf = cfg_set_remote_mng();
571 break;
572 case TIPC_CMD_SET_MAX_PORTS:
573 rep_tlv_buf = cfg_set_max_ports();
574 break;
575 case TIPC_CMD_SET_MAX_PUBL:
576 rep_tlv_buf = cfg_set_max_publications();
577 break;
578 case TIPC_CMD_SET_MAX_SUBSCR:
579 rep_tlv_buf = cfg_set_max_subscriptions();
580 break;
581 case TIPC_CMD_SET_MAX_ZONES:
582 rep_tlv_buf = cfg_set_max_zones();
583 break;
584 case TIPC_CMD_SET_MAX_CLUSTERS:
585 rep_tlv_buf = cfg_set_max_clusters();
586 break;
587 case TIPC_CMD_SET_MAX_NODES:
588 rep_tlv_buf = cfg_set_max_nodes();
589 break;
590 case TIPC_CMD_SET_MAX_SLAVES:
591 rep_tlv_buf = cfg_set_max_slaves();
592 break;
593 case TIPC_CMD_SET_NETID:
594 rep_tlv_buf = cfg_set_netid();
595 break;
596 case TIPC_CMD_GET_REMOTE_MNG:
597 rep_tlv_buf = cfg_reply_unsigned(tipc_remote_management);
598 break;
599 case TIPC_CMD_GET_MAX_PORTS:
600 rep_tlv_buf = cfg_reply_unsigned(tipc_max_ports);
601 break;
602 case TIPC_CMD_GET_MAX_PUBL:
603 rep_tlv_buf = cfg_reply_unsigned(tipc_max_publications);
604 break;
605 case TIPC_CMD_GET_MAX_SUBSCR:
606 rep_tlv_buf = cfg_reply_unsigned(tipc_max_subscriptions);
607 break;
608 case TIPC_CMD_GET_MAX_ZONES:
609 rep_tlv_buf = cfg_reply_unsigned(tipc_max_zones);
610 break;
611 case TIPC_CMD_GET_MAX_CLUSTERS:
612 rep_tlv_buf = cfg_reply_unsigned(tipc_max_clusters);
613 break;
614 case TIPC_CMD_GET_MAX_NODES:
615 rep_tlv_buf = cfg_reply_unsigned(tipc_max_nodes);
616 break;
617 case TIPC_CMD_GET_MAX_SLAVES:
618 rep_tlv_buf = cfg_reply_unsigned(tipc_max_slaves);
619 break;
620 case TIPC_CMD_GET_NETID:
621 rep_tlv_buf = cfg_reply_unsigned(tipc_net_id);
622 break;
623 default:
624 rep_tlv_buf = NULL;
625 break;
626 }
627
628 /* Return reply buffer */
629exit:
630 spin_unlock_bh(&config_lock);
631 return rep_tlv_buf;
632}
633
634static void cfg_named_msg_event(void *userdata,
635 u32 port_ref,
636 struct sk_buff **buf,
637 const unchar *msg,
638 u32 size,
639 u32 importance,
640 struct tipc_portid const *orig,
641 struct tipc_name_seq const *dest)
642{
643 struct tipc_cfg_msg_hdr *req_hdr;
644 struct tipc_cfg_msg_hdr *rep_hdr;
645 struct sk_buff *rep_buf;
646
647 /* Validate configuration message header (ignore invalid message) */
648
649 req_hdr = (struct tipc_cfg_msg_hdr *)msg;
650 if ((size < sizeof(*req_hdr)) ||
651 (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
652 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
653 warn("discarded invalid configuration message\n");
654 return;
655 }
656
657 /* Generate reply for request (if can't, return request) */
658
659 rep_buf = cfg_do_cmd(orig->node,
660 ntohs(req_hdr->tcm_type),
661 msg + sizeof(*req_hdr),
662 size - sizeof(*req_hdr),
663 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
664 if (rep_buf) {
665 skb_push(rep_buf, sizeof(*rep_hdr));
666 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
667 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
668 rep_hdr->tcm_len = htonl(rep_buf->len);
669 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
670 } else {
671 rep_buf = *buf;
672 *buf = NULL;
673 }
674
675 /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
676 tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
677}
678
679int cfg_init(void)
680{
681 struct tipc_name_seq seq;
682 int res;
683
684 memset(&mng, 0, sizeof(mng));
685 INIT_LIST_HEAD(&mng.link_subscribers);
686
687 res = tipc_attach(&mng.user_ref, 0, 0);
688 if (res)
689 goto failed;
690
691 res = tipc_createport(mng.user_ref, 0, TIPC_CRITICAL_IMPORTANCE,
692 NULL, NULL, NULL,
693 NULL, cfg_named_msg_event, NULL,
694 NULL, &mng.port_ref);
695 if (res)
696 goto failed;
697
698 seq.type = TIPC_CFG_SRV;
699 seq.lower = seq.upper = tipc_own_addr;
700 res = nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
701 if (res)
702 goto failed;
703
704 return 0;
705
706failed:
707 err("Unable to create configuration service\n");
708 tipc_detach(mng.user_ref);
709 mng.user_ref = 0;
710 return res;
711}
712
713void cfg_stop(void)
714{
715 if (mng.user_ref) {
716 tipc_detach(mng.user_ref);
717 mng.user_ref = 0;
718 }
719}