[PATCH] libata won't build on SUN4
[linux-2.6.22.y-op.git] / net / tipc / config.c
blob285e1bc2d8808502f53e952eed76a1dd72308534
1 /*
2 * net/tipc/config.c: TIPC configuration management code
3 *
4 * Copyright (c) 2002-2006, Ericsson AB
5 * Copyright (c) 2004-2005, Wind River Systems
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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
34 * POSSIBILITY OF SUCH DAMAGE.
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"
49 struct subscr_data {
50 char usr_handle[8];
51 u32 domain;
52 u32 port_ref;
53 struct list_head subd_list;
56 struct manager {
57 u32 user_ref;
58 u32 port_ref;
59 u32 subscr_ref;
60 u32 link_subscriptions;
61 struct list_head link_subscribers;
64 static struct manager mng = { 0};
66 static DEFINE_SPINLOCK(config_lock);
68 static const void *req_tlv_area; /* request message TLV area */
69 static int req_tlv_space; /* request message TLV area size */
70 static int rep_headroom; /* reply message headroom to use */
73 void tipc_cfg_link_event(u32 addr, char *name, int up)
75 /* TIPC DOESN'T HANDLE LINK EVENT SUBSCRIPTIONS AT THE MOMENT */
79 struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
81 struct sk_buff *buf;
83 buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
84 if (buf)
85 skb_reserve(buf, rep_headroom);
86 return buf;
89 int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
90 void *tlv_data, int tlv_data_size)
92 struct tlv_desc *tlv = (struct tlv_desc *)buf->tail;
93 int new_tlv_space = TLV_SPACE(tlv_data_size);
95 if (skb_tailroom(buf) < new_tlv_space) {
96 dbg("tipc_cfg_append_tlv unable to append TLV\n");
97 return 0;
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;
107 struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
109 struct sk_buff *buf;
110 u32 value_net;
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));
118 return buf;
121 struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
123 struct sk_buff *buf;
124 int string_len = strlen(string) + 1;
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;
135 #if 0
137 /* Now obsolete code for handling commands not yet implemented the new way */
139 int tipc_cfg_cmd(const struct tipc_cmd_msg * msg,
140 char *data,
141 u32 sz,
142 u32 *ret_size,
143 struct tipc_portid *orig)
145 int rv = -EINVAL;
146 u32 cmd = msg->cmd;
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:
158 int connected;
160 tipc_isconnected(mng.conn_port_ref, &connected);
161 if (connected || !orig) {
162 rv = TIPC_FAILURE;
163 break;
165 rv = tipc_connect2port(mng.conn_port_ref, orig);
166 if (rv == TIPC_OK)
167 orig = 0;
168 break;
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: {}
178 if (*ret_size)
179 rv = TIPC_OK;
180 return rv;
183 static void cfg_cmd_event(struct tipc_cmd_msg *msg,
184 char *data,
185 u32 sz,
186 struct tipc_portid const *orig)
188 int rv = -EINVAL;
189 struct tipc_cmd_result_msg rmsg;
190 struct iovec msg_sect[2];
191 int *arg;
193 msg->cmd = ntohl(msg->cmd);
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;
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:
207 struct subscr_data *sub;
209 if (mng.link_subscriptions > 64)
210 break;
211 sub = (struct subscr_data *)kmalloc(sizeof(*sub),
212 GFP_ATOMIC);
213 if (sub == NULL) {
214 warn("Memory squeeze; dropped remote link subscription\n");
215 break;
217 INIT_LIST_HEAD(&sub->subd_list);
218 tipc_createport(mng.user_ref,
219 (void *)sub,
220 TIPC_HIGH_IMPORTANCE,
223 (tipc_conn_shutdown_event)cfg_linksubscr_cancel,
226 (tipc_conn_msg_event)cfg_linksubscr_cancel,
228 &sub->port_ref);
229 if (!sub->port_ref) {
230 kfree(sub);
231 break;
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;
243 default:
244 rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig);
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);
251 #endif
253 static struct sk_buff *cfg_enable_bearer(void)
255 struct tipc_bearer_config *args;
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);
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");
266 return tipc_cfg_reply_none();
269 static struct sk_buff *cfg_disable_bearer(void)
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);
274 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
275 return tipc_cfg_reply_error_string("unable to disable bearer");
277 return tipc_cfg_reply_none();
280 static struct sk_buff *cfg_set_own_addr(void)
282 u32 addr;
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);
287 addr = *(u32 *)TLV_DATA(req_tlv_area);
288 addr = ntohl(addr);
289 if (addr == tipc_own_addr)
290 return tipc_cfg_reply_none();
291 if (!tipc_addr_node_valid(addr))
292 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
293 " (node address)");
294 if (tipc_mode == TIPC_NET_MODE)
295 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
296 " (cannot change node address once assigned)");
297 tipc_own_addr = addr;
300 * Must release all spinlocks before calling start_net() because
301 * Linux version of TIPC calls eth_media_start() which calls
302 * register_netdevice_notifier() which may block!
304 * Temporarily releasing the lock should be harmless for non-Linux TIPC,
305 * but Linux version of eth_media_start() should really be reworked
306 * so that it can be called with spinlocks held.
309 spin_unlock_bh(&config_lock);
310 tipc_core_start_net();
311 spin_lock_bh(&config_lock);
312 return tipc_cfg_reply_none();
315 static struct sk_buff *cfg_set_remote_mng(void)
317 u32 value;
319 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
320 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
322 value = *(u32 *)TLV_DATA(req_tlv_area);
323 value = ntohl(value);
324 tipc_remote_management = (value != 0);
325 return tipc_cfg_reply_none();
328 static struct sk_buff *cfg_set_max_publications(void)
330 u32 value;
332 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
333 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
335 value = *(u32 *)TLV_DATA(req_tlv_area);
336 value = ntohl(value);
337 if (value != delimit(value, 1, 65535))
338 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
339 " (max publications must be 1-65535)");
340 tipc_max_publications = value;
341 return tipc_cfg_reply_none();
344 static struct sk_buff *cfg_set_max_subscriptions(void)
346 u32 value;
348 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
349 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
351 value = *(u32 *)TLV_DATA(req_tlv_area);
352 value = ntohl(value);
353 if (value != delimit(value, 1, 65535))
354 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
355 " (max subscriptions must be 1-65535");
356 tipc_max_subscriptions = value;
357 return tipc_cfg_reply_none();
360 static struct sk_buff *cfg_set_max_ports(void)
362 u32 value;
364 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
365 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
366 value = *(u32 *)TLV_DATA(req_tlv_area);
367 value = ntohl(value);
368 if (value == tipc_max_ports)
369 return tipc_cfg_reply_none();
370 if (value != delimit(value, 127, 65535))
371 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
372 " (max ports must be 127-65535)");
373 if (tipc_mode != TIPC_NOT_RUNNING)
374 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
375 " (cannot change max ports while TIPC is active)");
376 tipc_max_ports = value;
377 return tipc_cfg_reply_none();
380 static struct sk_buff *cfg_set_max_zones(void)
382 u32 value;
384 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
385 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
386 value = *(u32 *)TLV_DATA(req_tlv_area);
387 value = ntohl(value);
388 if (value == tipc_max_zones)
389 return tipc_cfg_reply_none();
390 if (value != delimit(value, 1, 255))
391 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
392 " (max zones must be 1-255)");
393 if (tipc_mode == TIPC_NET_MODE)
394 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
395 " (cannot change max zones once TIPC has joined a network)");
396 tipc_max_zones = value;
397 return tipc_cfg_reply_none();
400 static struct sk_buff *cfg_set_max_clusters(void)
402 u32 value;
404 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
405 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
406 value = *(u32 *)TLV_DATA(req_tlv_area);
407 value = ntohl(value);
408 if (value != delimit(value, 1, 1))
409 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
410 " (max clusters fixed at 1)");
411 return tipc_cfg_reply_none();
414 static struct sk_buff *cfg_set_max_nodes(void)
416 u32 value;
418 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
419 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
420 value = *(u32 *)TLV_DATA(req_tlv_area);
421 value = ntohl(value);
422 if (value == tipc_max_nodes)
423 return tipc_cfg_reply_none();
424 if (value != delimit(value, 8, 2047))
425 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
426 " (max nodes must be 8-2047)");
427 if (tipc_mode == TIPC_NET_MODE)
428 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
429 " (cannot change max nodes once TIPC has joined a network)");
430 tipc_max_nodes = value;
431 return tipc_cfg_reply_none();
434 static struct sk_buff *cfg_set_max_slaves(void)
436 u32 value;
438 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
439 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
440 value = *(u32 *)TLV_DATA(req_tlv_area);
441 value = ntohl(value);
442 if (value != 0)
443 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
444 " (max secondary nodes fixed at 0)");
445 return tipc_cfg_reply_none();
448 static struct sk_buff *cfg_set_netid(void)
450 u32 value;
452 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
453 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
454 value = *(u32 *)TLV_DATA(req_tlv_area);
455 value = ntohl(value);
456 if (value == tipc_net_id)
457 return tipc_cfg_reply_none();
458 if (value != delimit(value, 1, 9999))
459 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
460 " (network id must be 1-9999)");
461 if (tipc_mode == TIPC_NET_MODE)
462 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
463 " (cannot change network id once TIPC has joined a network)");
464 tipc_net_id = value;
465 return tipc_cfg_reply_none();
468 struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
469 int request_space, int reply_headroom)
471 struct sk_buff *rep_tlv_buf;
473 spin_lock_bh(&config_lock);
475 /* Save request and reply details in a well-known location */
477 req_tlv_area = request_area;
478 req_tlv_space = request_space;
479 rep_headroom = reply_headroom;
481 /* Check command authorization */
483 if (likely(orig_node == tipc_own_addr)) {
484 /* command is permitted */
485 } else if (cmd >= 0x8000) {
486 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
487 " (cannot be done remotely)");
488 goto exit;
489 } else if (!tipc_remote_management) {
490 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
491 goto exit;
493 else if (cmd >= 0x4000) {
494 u32 domain = 0;
496 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
497 (domain != orig_node)) {
498 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
499 goto exit;
503 /* Call appropriate processing routine */
505 switch (cmd) {
506 case TIPC_CMD_NOOP:
507 rep_tlv_buf = tipc_cfg_reply_none();
508 break;
509 case TIPC_CMD_GET_NODES:
510 rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
511 break;
512 case TIPC_CMD_GET_LINKS:
513 rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
514 break;
515 case TIPC_CMD_SHOW_LINK_STATS:
516 rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
517 break;
518 case TIPC_CMD_RESET_LINK_STATS:
519 rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
520 break;
521 case TIPC_CMD_SHOW_NAME_TABLE:
522 rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
523 break;
524 case TIPC_CMD_GET_BEARER_NAMES:
525 rep_tlv_buf = tipc_bearer_get_names();
526 break;
527 case TIPC_CMD_GET_MEDIA_NAMES:
528 rep_tlv_buf = tipc_media_get_names();
529 break;
530 case TIPC_CMD_SHOW_PORTS:
531 rep_tlv_buf = tipc_port_get_ports();
532 break;
533 #if 0
534 case TIPC_CMD_SHOW_PORT_STATS:
535 rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
536 break;
537 case TIPC_CMD_RESET_PORT_STATS:
538 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
539 break;
540 #endif
541 case TIPC_CMD_SET_LOG_SIZE:
542 rep_tlv_buf = tipc_log_resize(req_tlv_area, req_tlv_space);
543 break;
544 case TIPC_CMD_DUMP_LOG:
545 rep_tlv_buf = tipc_log_dump();
546 break;
547 case TIPC_CMD_SET_LINK_TOL:
548 case TIPC_CMD_SET_LINK_PRI:
549 case TIPC_CMD_SET_LINK_WINDOW:
550 rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
551 break;
552 case TIPC_CMD_ENABLE_BEARER:
553 rep_tlv_buf = cfg_enable_bearer();
554 break;
555 case TIPC_CMD_DISABLE_BEARER:
556 rep_tlv_buf = cfg_disable_bearer();
557 break;
558 case TIPC_CMD_SET_NODE_ADDR:
559 rep_tlv_buf = cfg_set_own_addr();
560 break;
561 case TIPC_CMD_SET_REMOTE_MNG:
562 rep_tlv_buf = cfg_set_remote_mng();
563 break;
564 case TIPC_CMD_SET_MAX_PORTS:
565 rep_tlv_buf = cfg_set_max_ports();
566 break;
567 case TIPC_CMD_SET_MAX_PUBL:
568 rep_tlv_buf = cfg_set_max_publications();
569 break;
570 case TIPC_CMD_SET_MAX_SUBSCR:
571 rep_tlv_buf = cfg_set_max_subscriptions();
572 break;
573 case TIPC_CMD_SET_MAX_ZONES:
574 rep_tlv_buf = cfg_set_max_zones();
575 break;
576 case TIPC_CMD_SET_MAX_CLUSTERS:
577 rep_tlv_buf = cfg_set_max_clusters();
578 break;
579 case TIPC_CMD_SET_MAX_NODES:
580 rep_tlv_buf = cfg_set_max_nodes();
581 break;
582 case TIPC_CMD_SET_MAX_SLAVES:
583 rep_tlv_buf = cfg_set_max_slaves();
584 break;
585 case TIPC_CMD_SET_NETID:
586 rep_tlv_buf = cfg_set_netid();
587 break;
588 case TIPC_CMD_GET_REMOTE_MNG:
589 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
590 break;
591 case TIPC_CMD_GET_MAX_PORTS:
592 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
593 break;
594 case TIPC_CMD_GET_MAX_PUBL:
595 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
596 break;
597 case TIPC_CMD_GET_MAX_SUBSCR:
598 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
599 break;
600 case TIPC_CMD_GET_MAX_ZONES:
601 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
602 break;
603 case TIPC_CMD_GET_MAX_CLUSTERS:
604 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
605 break;
606 case TIPC_CMD_GET_MAX_NODES:
607 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
608 break;
609 case TIPC_CMD_GET_MAX_SLAVES:
610 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
611 break;
612 case TIPC_CMD_GET_NETID:
613 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
614 break;
615 default:
616 rep_tlv_buf = NULL;
617 break;
620 /* Return reply buffer */
621 exit:
622 spin_unlock_bh(&config_lock);
623 return rep_tlv_buf;
626 static void cfg_named_msg_event(void *userdata,
627 u32 port_ref,
628 struct sk_buff **buf,
629 const unchar *msg,
630 u32 size,
631 u32 importance,
632 struct tipc_portid const *orig,
633 struct tipc_name_seq const *dest)
635 struct tipc_cfg_msg_hdr *req_hdr;
636 struct tipc_cfg_msg_hdr *rep_hdr;
637 struct sk_buff *rep_buf;
639 /* Validate configuration message header (ignore invalid message) */
641 req_hdr = (struct tipc_cfg_msg_hdr *)msg;
642 if ((size < sizeof(*req_hdr)) ||
643 (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
644 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
645 warn("Invalid configuration message discarded\n");
646 return;
649 /* Generate reply for request (if can't, return request) */
651 rep_buf = tipc_cfg_do_cmd(orig->node,
652 ntohs(req_hdr->tcm_type),
653 msg + sizeof(*req_hdr),
654 size - sizeof(*req_hdr),
655 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
656 if (rep_buf) {
657 skb_push(rep_buf, sizeof(*rep_hdr));
658 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
659 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
660 rep_hdr->tcm_len = htonl(rep_buf->len);
661 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
662 } else {
663 rep_buf = *buf;
664 *buf = NULL;
667 /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
668 tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
671 int tipc_cfg_init(void)
673 struct tipc_name_seq seq;
674 int res;
676 memset(&mng, 0, sizeof(mng));
677 INIT_LIST_HEAD(&mng.link_subscribers);
679 res = tipc_attach(&mng.user_ref, NULL, NULL);
680 if (res)
681 goto failed;
683 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
684 NULL, NULL, NULL,
685 NULL, cfg_named_msg_event, NULL,
686 NULL, &mng.port_ref);
687 if (res)
688 goto failed;
690 seq.type = TIPC_CFG_SRV;
691 seq.lower = seq.upper = tipc_own_addr;
692 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
693 if (res)
694 goto failed;
696 return 0;
698 failed:
699 err("Unable to create configuration service\n");
700 tipc_detach(mng.user_ref);
701 mng.user_ref = 0;
702 return res;
705 void tipc_cfg_stop(void)
707 if (mng.user_ref) {
708 tipc_detach(mng.user_ref);
709 mng.user_ref = 0;