1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
59 u32 subscr_ref;
60 u32 link_subscriptions;
61 struct list_head link_subscribers;
62};
63
64static struct manager mng = { 0};
65
66static DEFINE_SPINLOCK(config_lock);
67
68static const void *req_tlv_area;
69static int req_tlv_space;
70static int rep_headroom;
71
72
73void tipc_cfg_link_event(u32 addr, char *name, int up)
74{
75
76}
77
78
79struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
80{
81 struct sk_buff *buf;
82
83 buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
84 if (buf)
85 skb_reserve(buf, rep_headroom);
86 return buf;
87}
88
89int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
90 void *tlv_data, int tlv_data_size)
91{
92 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
93 int new_tlv_space = TLV_SPACE(tlv_data_size);
94
95 if (skb_tailroom(buf) < new_tlv_space) {
96 dbg("tipc_cfg_append_tlv unable to append TLV\n");
97 return 0;
98 }
99 skb_put(buf, new_tlv_space);
100 tlv->tlv_type = htons(tlv_type);
101 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
102 if (tlv_data_size && tlv_data)
103 memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
104 return 1;
105}
106
107struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
108{
109 struct sk_buff *buf;
110 __be32 value_net;
111
112 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
113 if (buf) {
114 value_net = htonl(value);
115 tipc_cfg_append_tlv(buf, tlv_type, &value_net,
116 sizeof(value_net));
117 }
118 return buf;
119}
120
121struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
122{
123 struct sk_buff *buf;
124 int string_len = strlen(string) + 1;
125
126 buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
127 if (buf)
128 tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
129 return buf;
130}
131
132
133
134
135#if 0
136
137
138
139int tipc_cfg_cmd(const struct tipc_cmd_msg * msg,
140 char *data,
141 u32 sz,
142 u32 *ret_size,
143 struct tipc_portid *orig)
144{
145 int rv = -EINVAL;
146 u32 cmd = msg->cmd;
147
148 *ret_size = 0;
149 switch (cmd) {
150 case TIPC_REMOVE_LINK:
151 case TIPC_CMD_BLOCK_LINK:
152 case TIPC_CMD_UNBLOCK_LINK:
153 if (!cfg_check_connection(orig))
154 rv = link_control(msg->argv.link_name, msg->cmd, 0);
155 break;
156 case TIPC_ESTABLISH:
157 {
158 int connected;
159
160 tipc_isconnected(mng.conn_port_ref, &connected);
161 if (connected || !orig) {
162 rv = TIPC_FAILURE;
163 break;
164 }
165 rv = tipc_connect2port(mng.conn_port_ref, orig);
166 if (rv == TIPC_OK)
167 orig = 0;
168 break;
169 }
170 case TIPC_GET_PEER_ADDRESS:
171 *ret_size = link_peer_addr(msg->argv.link_name, data, sz);
172 break;
173 case TIPC_GET_ROUTES:
174 rv = TIPC_OK;
175 break;
176 default: {}
177 }
178 if (*ret_size)
179 rv = TIPC_OK;
180 return rv;
181}
182
183static void cfg_cmd_event(struct tipc_cmd_msg *msg,
184 char *data,
185 u32 sz,
186 struct tipc_portid const *orig)
187{
188 int rv = -EINVAL;
189 struct tipc_cmd_result_msg rmsg;
190 struct iovec msg_sect[2];
191 int *arg;
192
193 msg->cmd = ntohl(msg->cmd);
194
195 cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect,
196 data, 0);
197 if (ntohl(msg->magic) != TIPC_MAGIC)
198 goto exit;
199
200 switch (msg->cmd) {
201 case TIPC_CREATE_LINK:
202 if (!cfg_check_connection(orig))
203 rv = disc_create_link(&msg->argv.create_link);
204 break;
205 case TIPC_LINK_SUBSCRIBE:
206 {
207 struct subscr_data *sub;
208
209 if (mng.link_subscriptions > 64)
210 break;
211 sub = kmalloc(sizeof(*sub),
212 GFP_ATOMIC);
213 if (sub == NULL) {
214 warn("Memory squeeze; dropped remote link subscription\n");
215 break;
216 }
217 INIT_LIST_HEAD(&sub->subd_list);
218 tipc_createport(mng.user_ref,
219 (void *)sub,
220 TIPC_HIGH_IMPORTANCE,
221 0,
222 0,
223 (tipc_conn_shutdown_event)cfg_linksubscr_cancel,
224 0,
225 0,
226 (tipc_conn_msg_event)cfg_linksubscr_cancel,
227 0,
228 &sub->port_ref);
229 if (!sub->port_ref) {
230 kfree(sub);
231 break;
232 }
233 memcpy(sub->usr_handle,msg->usr_handle,
234 sizeof(sub->usr_handle));
235 sub->domain = msg->argv.domain;
236 list_add_tail(&sub->subd_list, &mng.link_subscribers);
237 tipc_connect2port(sub->port_ref, orig);
238 rmsg.retval = TIPC_OK;
239 tipc_send(sub->port_ref, 2u, msg_sect);
240 mng.link_subscriptions++;
241 return;
242 }
243 default:
244 rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig);
245 }
246 exit:
247 rmsg.result_len = htonl(msg_sect[1].iov_len);
248 rmsg.retval = htonl(rv);
249 tipc_cfg_respond(msg_sect, 2u, orig);
250}
251#endif
252
253static struct sk_buff *cfg_enable_bearer(void)
254{
255 struct tipc_bearer_config *args;
256
257 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
258 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
259
260 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
261 if (tipc_enable_bearer(args->name,
262 ntohl(args->detect_scope),
263 ntohl(args->priority)))
264 return tipc_cfg_reply_error_string("unable to enable bearer");
265
266 return tipc_cfg_reply_none();
267}
268
269static struct sk_buff *cfg_disable_bearer(void)
270{
271 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
272 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
273
274 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
275 return tipc_cfg_reply_error_string("unable to disable bearer");
276
277 return tipc_cfg_reply_none();
278}
279
280static struct sk_buff *cfg_set_own_addr(void)
281{
282 u32 addr;
283
284 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
285 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
286
287 addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
288 if (addr == tipc_own_addr)
289 return tipc_cfg_reply_none();
290 if (!tipc_addr_node_valid(addr))
291 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
292 " (node address)");
293 if (tipc_mode == TIPC_NET_MODE)
294 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
295 " (cannot change node address once assigned)");
296
297
298
299
300
301
302
303
304
305
306
307 spin_unlock_bh(&config_lock);
308 tipc_core_start_net(addr);
309 spin_lock_bh(&config_lock);
310 return tipc_cfg_reply_none();
311}
312
313static struct sk_buff *cfg_set_remote_mng(void)
314{
315 u32 value;
316
317 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
318 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
319
320 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
321 tipc_remote_management = (value != 0);
322 return tipc_cfg_reply_none();
323}
324
325static struct sk_buff *cfg_set_max_publications(void)
326{
327 u32 value;
328
329 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
330 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
331
332 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
333 if (value != delimit(value, 1, 65535))
334 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
335 " (max publications must be 1-65535)");
336 tipc_max_publications = value;
337 return tipc_cfg_reply_none();
338}
339
340static struct sk_buff *cfg_set_max_subscriptions(void)
341{
342 u32 value;
343
344 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
345 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
346
347 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
348 if (value != delimit(value, 1, 65535))
349 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
350 " (max subscriptions must be 1-65535");
351 tipc_max_subscriptions = value;
352 return tipc_cfg_reply_none();
353}
354
355static struct sk_buff *cfg_set_max_ports(void)
356{
357 u32 value;
358
359 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
360 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
361 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
362 if (value == tipc_max_ports)
363 return tipc_cfg_reply_none();
364 if (value != delimit(value, 127, 65535))
365 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
366 " (max ports must be 127-65535)");
367 if (tipc_mode != TIPC_NOT_RUNNING)
368 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
369 " (cannot change max ports while TIPC is active)");
370 tipc_max_ports = value;
371 return tipc_cfg_reply_none();
372}
373
374static struct sk_buff *cfg_set_max_zones(void)
375{
376 u32 value;
377
378 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
379 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
380 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
381 if (value == tipc_max_zones)
382 return tipc_cfg_reply_none();
383 if (value != delimit(value, 1, 255))
384 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
385 " (max zones must be 1-255)");
386 if (tipc_mode == TIPC_NET_MODE)
387 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
388 " (cannot change max zones once TIPC has joined a network)");
389 tipc_max_zones = value;
390 return tipc_cfg_reply_none();
391}
392
393static struct sk_buff *cfg_set_max_clusters(void)
394{
395 u32 value;
396
397 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
398 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
399 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
400 if (value != delimit(value, 1, 1))
401 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
402 " (max clusters fixed at 1)");
403 return tipc_cfg_reply_none();
404}
405
406static struct sk_buff *cfg_set_max_nodes(void)
407{
408 u32 value;
409
410 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
411 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
412 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
413 if (value == tipc_max_nodes)
414 return tipc_cfg_reply_none();
415 if (value != delimit(value, 8, 2047))
416 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
417 " (max nodes must be 8-2047)");
418 if (tipc_mode == TIPC_NET_MODE)
419 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
420 " (cannot change max nodes once TIPC has joined a network)");
421 tipc_max_nodes = value;
422 return tipc_cfg_reply_none();
423}
424
425static struct sk_buff *cfg_set_max_slaves(void)
426{
427 u32 value;
428
429 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
430 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
431 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
432 if (value != 0)
433 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
434 " (max secondary nodes fixed at 0)");
435 return tipc_cfg_reply_none();
436}
437
438static struct sk_buff *cfg_set_netid(void)
439{
440 u32 value;
441
442 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
443 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
444 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
445 if (value == tipc_net_id)
446 return tipc_cfg_reply_none();
447 if (value != delimit(value, 1, 9999))
448 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
449 " (network id must be 1-9999)");
450 if (tipc_mode == TIPC_NET_MODE)
451 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
452 " (cannot change network id once TIPC has joined a network)");
453 tipc_net_id = value;
454 return tipc_cfg_reply_none();
455}
456
457struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
458 int request_space, int reply_headroom)
459{
460 struct sk_buff *rep_tlv_buf;
461
462 spin_lock_bh(&config_lock);
463
464
465
466 req_tlv_area = request_area;
467 req_tlv_space = request_space;
468 rep_headroom = reply_headroom;
469
470
471
472 if (likely(orig_node == tipc_own_addr)) {
473
474 } else if (cmd >= 0x8000) {
475 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
476 " (cannot be done remotely)");
477 goto exit;
478 } else if (!tipc_remote_management) {
479 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
480 goto exit;
481 }
482 else if (cmd >= 0x4000) {
483 u32 domain = 0;
484
485 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
486 (domain != orig_node)) {
487 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
488 goto exit;
489 }
490 }
491
492
493
494 switch (cmd) {
495 case TIPC_CMD_NOOP:
496 rep_tlv_buf = tipc_cfg_reply_none();
497 break;
498 case TIPC_CMD_GET_NODES:
499 rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
500 break;
501 case TIPC_CMD_GET_LINKS:
502 rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
503 break;
504 case TIPC_CMD_SHOW_LINK_STATS:
505 rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
506 break;
507 case TIPC_CMD_RESET_LINK_STATS:
508 rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
509 break;
510 case TIPC_CMD_SHOW_NAME_TABLE:
511 rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
512 break;
513 case TIPC_CMD_GET_BEARER_NAMES:
514 rep_tlv_buf = tipc_bearer_get_names();
515 break;
516 case TIPC_CMD_GET_MEDIA_NAMES:
517 rep_tlv_buf = tipc_media_get_names();
518 break;
519 case TIPC_CMD_SHOW_PORTS:
520 rep_tlv_buf = tipc_port_get_ports();
521 break;
522#if 0
523 case TIPC_CMD_SHOW_PORT_STATS:
524 rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
525 break;
526 case TIPC_CMD_RESET_PORT_STATS:
527 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
528 break;
529#endif
530 case TIPC_CMD_SET_LOG_SIZE:
531 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
532 break;
533 case TIPC_CMD_DUMP_LOG:
534 rep_tlv_buf = tipc_log_dump();
535 break;
536 case TIPC_CMD_SET_LINK_TOL:
537 case TIPC_CMD_SET_LINK_PRI:
538 case TIPC_CMD_SET_LINK_WINDOW:
539 rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
540 break;
541 case TIPC_CMD_ENABLE_BEARER:
542 rep_tlv_buf = cfg_enable_bearer();
543 break;
544 case TIPC_CMD_DISABLE_BEARER:
545 rep_tlv_buf = cfg_disable_bearer();
546 break;
547 case TIPC_CMD_SET_NODE_ADDR:
548 rep_tlv_buf = cfg_set_own_addr();
549 break;
550 case TIPC_CMD_SET_REMOTE_MNG:
551 rep_tlv_buf = cfg_set_remote_mng();
552 break;
553 case TIPC_CMD_SET_MAX_PORTS:
554 rep_tlv_buf = cfg_set_max_ports();
555 break;
556 case TIPC_CMD_SET_MAX_PUBL:
557 rep_tlv_buf = cfg_set_max_publications();
558 break;
559 case TIPC_CMD_SET_MAX_SUBSCR:
560 rep_tlv_buf = cfg_set_max_subscriptions();
561 break;
562 case TIPC_CMD_SET_MAX_ZONES:
563 rep_tlv_buf = cfg_set_max_zones();
564 break;
565 case TIPC_CMD_SET_MAX_CLUSTERS:
566 rep_tlv_buf = cfg_set_max_clusters();
567 break;
568 case TIPC_CMD_SET_MAX_NODES:
569 rep_tlv_buf = cfg_set_max_nodes();
570 break;
571 case TIPC_CMD_SET_MAX_SLAVES:
572 rep_tlv_buf = cfg_set_max_slaves();
573 break;
574 case TIPC_CMD_SET_NETID:
575 rep_tlv_buf = cfg_set_netid();
576 break;
577 case TIPC_CMD_GET_REMOTE_MNG:
578 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
579 break;
580 case TIPC_CMD_GET_MAX_PORTS:
581 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
582 break;
583 case TIPC_CMD_GET_MAX_PUBL:
584 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
585 break;
586 case TIPC_CMD_GET_MAX_SUBSCR:
587 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
588 break;
589 case TIPC_CMD_GET_MAX_ZONES:
590 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
591 break;
592 case TIPC_CMD_GET_MAX_CLUSTERS:
593 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
594 break;
595 case TIPC_CMD_GET_MAX_NODES:
596 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
597 break;
598 case TIPC_CMD_GET_MAX_SLAVES:
599 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
600 break;
601 case TIPC_CMD_GET_NETID:
602 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
603 break;
604 case TIPC_CMD_NOT_NET_ADMIN:
605 rep_tlv_buf =
606 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
607 break;
608 default:
609 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
610 " (unknown command)");
611 break;
612 }
613
614
615exit:
616 spin_unlock_bh(&config_lock);
617 return rep_tlv_buf;
618}
619
620static void cfg_named_msg_event(void *userdata,
621 u32 port_ref,
622 struct sk_buff **buf,
623 const unchar *msg,
624 u32 size,
625 u32 importance,
626 struct tipc_portid const *orig,
627 struct tipc_name_seq const *dest)
628{
629 struct tipc_cfg_msg_hdr *req_hdr;
630 struct tipc_cfg_msg_hdr *rep_hdr;
631 struct sk_buff *rep_buf;
632
633
634
635 req_hdr = (struct tipc_cfg_msg_hdr *)msg;
636 if ((size < sizeof(*req_hdr)) ||
637 (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
638 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
639 warn("Invalid configuration message discarded\n");
640 return;
641 }
642
643
644
645 rep_buf = tipc_cfg_do_cmd(orig->node,
646 ntohs(req_hdr->tcm_type),
647 msg + sizeof(*req_hdr),
648 size - sizeof(*req_hdr),
649 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
650 if (rep_buf) {
651 skb_push(rep_buf, sizeof(*rep_hdr));
652 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
653 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
654 rep_hdr->tcm_len = htonl(rep_buf->len);
655 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
656 } else {
657 rep_buf = *buf;
658 *buf = NULL;
659 }
660
661
662 tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
663}
664
665int tipc_cfg_init(void)
666{
667 struct tipc_name_seq seq;
668 int res;
669
670 memset(&mng, 0, sizeof(mng));
671 INIT_LIST_HEAD(&mng.link_subscribers);
672
673 res = tipc_attach(&mng.user_ref, NULL, NULL);
674 if (res)
675 goto failed;
676
677 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
678 NULL, NULL, NULL,
679 NULL, cfg_named_msg_event, NULL,
680 NULL, &mng.port_ref);
681 if (res)
682 goto failed;
683
684 seq.type = TIPC_CFG_SRV;
685 seq.lower = seq.upper = tipc_own_addr;
686 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
687 if (res)
688 goto failed;
689
690 return 0;
691
692failed:
693 err("Unable to create configuration service\n");
694 tipc_detach(mng.user_ref);
695 mng.user_ref = 0;
696 return res;
697}
698
699void tipc_cfg_stop(void)
700{
701 if (mng.user_ref) {
702 tipc_detach(mng.user_ref);
703 mng.user_ref = 0;
704 }
705}
706