aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/config.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/config.c')
-rw-r--r--net/tipc/config.c297
1 files changed, 28 insertions, 269 deletions
diff --git a/net/tipc/config.c b/net/tipc/config.c
index 961d1b097146..b25a396b7e1e 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -2,7 +2,7 @@
2 * net/tipc/config.c: TIPC configuration management code 2 * net/tipc/config.c: TIPC configuration management code
3 * 3 *
4 * Copyright (c) 2002-2006, Ericsson AB 4 * Copyright (c) 2002-2006, Ericsson AB
5 * Copyright (c) 2004-2007, Wind River Systems 5 * Copyright (c) 2004-2007, 2010-2011, Wind River Systems
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
@@ -35,30 +35,11 @@
35 */ 35 */
36 36
37#include "core.h" 37#include "core.h"
38#include "dbg.h"
39#include "bearer.h"
40#include "port.h" 38#include "port.h"
41#include "link.h"
42#include "zone.h"
43#include "addr.h"
44#include "name_table.h" 39#include "name_table.h"
45#include "node.h"
46#include "config.h" 40#include "config.h"
47#include "discover.h"
48 41
49struct subscr_data { 42static u32 config_port_ref;
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};
60
61static struct manager mng = { 0};
62 43
63static DEFINE_SPINLOCK(config_lock); 44static DEFINE_SPINLOCK(config_lock);
64 45
@@ -83,10 +64,8 @@ int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
83 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf); 64 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
84 int new_tlv_space = TLV_SPACE(tlv_data_size); 65 int new_tlv_space = TLV_SPACE(tlv_data_size);
85 66
86 if (skb_tailroom(buf) < new_tlv_space) { 67 if (skb_tailroom(buf) < new_tlv_space)
87 dbg("tipc_cfg_append_tlv unable to append TLV\n");
88 return 0; 68 return 0;
89 }
90 skb_put(buf, new_tlv_space); 69 skb_put(buf, new_tlv_space);
91 tlv->tlv_type = htons(tlv_type); 70 tlv->tlv_type = htons(tlv_type);
92 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size)); 71 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
@@ -95,7 +74,7 @@ int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
95 return 1; 74 return 1;
96} 75}
97 76
98struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value) 77static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
99{ 78{
100 struct sk_buff *buf; 79 struct sk_buff *buf;
101 __be32 value_net; 80 __be32 value_net;
@@ -109,6 +88,11 @@ struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
109 return buf; 88 return buf;
110} 89}
111 90
91static struct sk_buff *tipc_cfg_reply_unsigned(u32 value)
92{
93 return tipc_cfg_reply_unsigned_type(TIPC_TLV_UNSIGNED, value);
94}
95
112struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string) 96struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
113{ 97{
114 struct sk_buff *buf; 98 struct sk_buff *buf;
@@ -120,139 +104,6 @@ struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
120 return buf; 104 return buf;
121} 105}
122 106
123
124#if 0
125
126/* Now obsolete code for handling commands not yet implemented the new way */
127
128/*
129 * Some of this code assumed that the manager structure contains two added
130 * fields:
131 * u32 link_subscriptions;
132 * struct list_head link_subscribers;
133 * which are currently not present. These fields may need to be re-introduced
134 * if and when support for link subscriptions is added.
135 */
136
137void tipc_cfg_link_event(u32 addr, char *name, int up)
138{
139 /* TIPC DOESN'T HANDLE LINK EVENT SUBSCRIPTIONS AT THE MOMENT */
140}
141
142int tipc_cfg_cmd(const struct tipc_cmd_msg * msg,
143 char *data,
144 u32 sz,
145 u32 *ret_size,
146 struct tipc_portid *orig)
147{
148 int rv = -EINVAL;
149 u32 cmd = msg->cmd;
150
151 *ret_size = 0;
152 switch (cmd) {
153 case TIPC_REMOVE_LINK:
154 case TIPC_CMD_BLOCK_LINK:
155 case TIPC_CMD_UNBLOCK_LINK:
156 if (!cfg_check_connection(orig))
157 rv = link_control(msg->argv.link_name, msg->cmd, 0);
158 break;
159 case TIPC_ESTABLISH:
160 {
161 int connected;
162
163 tipc_isconnected(mng.conn_port_ref, &connected);
164 if (connected || !orig) {
165 rv = TIPC_FAILURE;
166 break;
167 }
168 rv = tipc_connect2port(mng.conn_port_ref, orig);
169 if (rv == TIPC_OK)
170 orig = 0;
171 break;
172 }
173 case TIPC_GET_PEER_ADDRESS:
174 *ret_size = link_peer_addr(msg->argv.link_name, data, sz);
175 break;
176 case TIPC_GET_ROUTES:
177 rv = TIPC_OK;
178 break;
179 default: {}
180 }
181 if (*ret_size)
182 rv = TIPC_OK;
183 return rv;
184}
185
186static void cfg_cmd_event(struct tipc_cmd_msg *msg,
187 char *data,
188 u32 sz,
189 struct tipc_portid const *orig)
190{
191 int rv = -EINVAL;
192 struct tipc_cmd_result_msg rmsg;
193 struct iovec msg_sect[2];
194 int *arg;
195
196 msg->cmd = ntohl(msg->cmd);
197
198 cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect,
199 data, 0);
200 if (ntohl(msg->magic) != TIPC_MAGIC)
201 goto exit;
202
203 switch (msg->cmd) {
204 case TIPC_CREATE_LINK:
205 if (!cfg_check_connection(orig))
206 rv = disc_create_link(&msg->argv.create_link);
207 break;
208 case TIPC_LINK_SUBSCRIBE:
209 {
210 struct subscr_data *sub;
211
212 if (mng.link_subscriptions > 64)
213 break;
214 sub = kmalloc(sizeof(*sub),
215 GFP_ATOMIC);
216 if (sub == NULL) {
217 warn("Memory squeeze; dropped remote link subscription\n");
218 break;
219 }
220 INIT_LIST_HEAD(&sub->subd_list);
221 tipc_createport(mng.user_ref,
222 (void *)sub,
223 TIPC_HIGH_IMPORTANCE,
224 0,
225 0,
226 (tipc_conn_shutdown_event)cfg_linksubscr_cancel,
227 0,
228 0,
229 (tipc_conn_msg_event)cfg_linksubscr_cancel,
230 0,
231 &sub->port_ref);
232 if (!sub->port_ref) {
233 kfree(sub);
234 break;
235 }
236 memcpy(sub->usr_handle,msg->usr_handle,
237 sizeof(sub->usr_handle));
238 sub->domain = msg->argv.domain;
239 list_add_tail(&sub->subd_list, &mng.link_subscribers);
240 tipc_connect2port(sub->port_ref, orig);
241 rmsg.retval = TIPC_OK;
242 tipc_send(sub->port_ref, 2u, msg_sect);
243 mng.link_subscriptions++;
244 return;
245 }
246 default:
247 rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig);
248 }
249exit:
250 rmsg.result_len = htonl(msg_sect[1].iov_len);
251 rmsg.retval = htonl(rv);
252 tipc_cfg_respond(msg_sect, 2u, orig);
253}
254#endif
255
256#define MAX_STATS_INFO 2000 107#define MAX_STATS_INFO 2000
257 108
258static struct sk_buff *tipc_show_stats(void) 109static struct sk_buff *tipc_show_stats(void)
@@ -297,7 +148,7 @@ static struct sk_buff *cfg_enable_bearer(void)
297 148
298 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area); 149 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
299 if (tipc_enable_bearer(args->name, 150 if (tipc_enable_bearer(args->name,
300 ntohl(args->detect_scope), 151 ntohl(args->disc_domain),
301 ntohl(args->priority))) 152 ntohl(args->priority)))
302 return tipc_cfg_reply_error_string("unable to enable bearer"); 153 return tipc_cfg_reply_error_string("unable to enable bearer");
303 154
@@ -409,70 +260,6 @@ static struct sk_buff *cfg_set_max_ports(void)
409 return tipc_cfg_reply_none(); 260 return tipc_cfg_reply_none();
410} 261}
411 262
412static struct sk_buff *cfg_set_max_zones(void)
413{
414 u32 value;
415
416 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
417 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
418 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
419 if (value == tipc_max_zones)
420 return tipc_cfg_reply_none();
421 if (value != delimit(value, 1, 255))
422 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
423 " (max zones must be 1-255)");
424 if (tipc_mode == TIPC_NET_MODE)
425 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
426 " (cannot change max zones once TIPC has joined a network)");
427 tipc_max_zones = value;
428 return tipc_cfg_reply_none();
429}
430
431static struct sk_buff *cfg_set_max_clusters(void)
432{
433 u32 value;
434
435 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
436 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
437 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
438 if (value != delimit(value, 1, 1))
439 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
440 " (max clusters fixed at 1)");
441 return tipc_cfg_reply_none();
442}
443
444static struct sk_buff *cfg_set_max_nodes(void)
445{
446 u32 value;
447
448 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
449 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
450 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
451 if (value == tipc_max_nodes)
452 return tipc_cfg_reply_none();
453 if (value != delimit(value, 8, 2047))
454 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
455 " (max nodes must be 8-2047)");
456 if (tipc_mode == TIPC_NET_MODE)
457 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
458 " (cannot change max nodes once TIPC has joined a network)");
459 tipc_max_nodes = value;
460 return tipc_cfg_reply_none();
461}
462
463static struct sk_buff *cfg_set_max_slaves(void)
464{
465 u32 value;
466
467 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
468 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
469 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
470 if (value != 0)
471 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
472 " (max secondary nodes fixed at 0)");
473 return tipc_cfg_reply_none();
474}
475
476static struct sk_buff *cfg_set_netid(void) 263static struct sk_buff *cfg_set_netid(void)
477{ 264{
478 u32 value; 265 u32 value;
@@ -516,8 +303,7 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
516 } else if (!tipc_remote_management) { 303 } else if (!tipc_remote_management) {
517 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE); 304 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
518 goto exit; 305 goto exit;
519 } 306 } else if (cmd >= 0x4000) {
520 else if (cmd >= 0x4000) {
521 u32 domain = 0; 307 u32 domain = 0;
522 308
523 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) || 309 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
@@ -557,14 +343,6 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
557 case TIPC_CMD_SHOW_PORTS: 343 case TIPC_CMD_SHOW_PORTS:
558 rep_tlv_buf = tipc_port_get_ports(); 344 rep_tlv_buf = tipc_port_get_ports();
559 break; 345 break;
560#if 0
561 case TIPC_CMD_SHOW_PORT_STATS:
562 rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
563 break;
564 case TIPC_CMD_RESET_PORT_STATS:
565 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
566 break;
567#endif
568 case TIPC_CMD_SET_LOG_SIZE: 346 case TIPC_CMD_SET_LOG_SIZE:
569 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space); 347 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
570 break; 348 break;
@@ -600,18 +378,6 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
600 case TIPC_CMD_SET_MAX_SUBSCR: 378 case TIPC_CMD_SET_MAX_SUBSCR:
601 rep_tlv_buf = cfg_set_max_subscriptions(); 379 rep_tlv_buf = cfg_set_max_subscriptions();
602 break; 380 break;
603 case TIPC_CMD_SET_MAX_ZONES:
604 rep_tlv_buf = cfg_set_max_zones();
605 break;
606 case TIPC_CMD_SET_MAX_CLUSTERS:
607 rep_tlv_buf = cfg_set_max_clusters();
608 break;
609 case TIPC_CMD_SET_MAX_NODES:
610 rep_tlv_buf = cfg_set_max_nodes();
611 break;
612 case TIPC_CMD_SET_MAX_SLAVES:
613 rep_tlv_buf = cfg_set_max_slaves();
614 break;
615 case TIPC_CMD_SET_NETID: 381 case TIPC_CMD_SET_NETID:
616 rep_tlv_buf = cfg_set_netid(); 382 rep_tlv_buf = cfg_set_netid();
617 break; 383 break;
@@ -627,18 +393,6 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
627 case TIPC_CMD_GET_MAX_SUBSCR: 393 case TIPC_CMD_GET_MAX_SUBSCR:
628 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions); 394 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
629 break; 395 break;
630 case TIPC_CMD_GET_MAX_ZONES:
631 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
632 break;
633 case TIPC_CMD_GET_MAX_CLUSTERS:
634 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
635 break;
636 case TIPC_CMD_GET_MAX_NODES:
637 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
638 break;
639 case TIPC_CMD_GET_MAX_SLAVES:
640 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
641 break;
642 case TIPC_CMD_GET_NETID: 396 case TIPC_CMD_GET_NETID:
643 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id); 397 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
644 break; 398 break;
@@ -646,6 +400,17 @@ struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area
646 rep_tlv_buf = 400 rep_tlv_buf =
647 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN); 401 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
648 break; 402 break;
403 case TIPC_CMD_SET_MAX_ZONES:
404 case TIPC_CMD_GET_MAX_ZONES:
405 case TIPC_CMD_SET_MAX_SLAVES:
406 case TIPC_CMD_GET_MAX_SLAVES:
407 case TIPC_CMD_SET_MAX_CLUSTERS:
408 case TIPC_CMD_GET_MAX_CLUSTERS:
409 case TIPC_CMD_SET_MAX_NODES:
410 case TIPC_CMD_GET_MAX_NODES:
411 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
412 " (obsolete command)");
413 break;
649 default: 414 default:
650 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED 415 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
651 " (unknown command)"); 416 " (unknown command)");
@@ -708,20 +473,16 @@ int tipc_cfg_init(void)
708 struct tipc_name_seq seq; 473 struct tipc_name_seq seq;
709 int res; 474 int res;
710 475
711 res = tipc_attach(&mng.user_ref, NULL, NULL); 476 res = tipc_createport(NULL, TIPC_CRITICAL_IMPORTANCE,
712 if (res)
713 goto failed;
714
715 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
716 NULL, NULL, NULL, 477 NULL, NULL, NULL,
717 NULL, cfg_named_msg_event, NULL, 478 NULL, cfg_named_msg_event, NULL,
718 NULL, &mng.port_ref); 479 NULL, &config_port_ref);
719 if (res) 480 if (res)
720 goto failed; 481 goto failed;
721 482
722 seq.type = TIPC_CFG_SRV; 483 seq.type = TIPC_CFG_SRV;
723 seq.lower = seq.upper = tipc_own_addr; 484 seq.lower = seq.upper = tipc_own_addr;
724 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq); 485 res = tipc_nametbl_publish_rsv(config_port_ref, TIPC_ZONE_SCOPE, &seq);
725 if (res) 486 if (res)
726 goto failed; 487 goto failed;
727 488
@@ -729,15 +490,13 @@ int tipc_cfg_init(void)
729 490
730failed: 491failed:
731 err("Unable to create configuration service\n"); 492 err("Unable to create configuration service\n");
732 tipc_detach(mng.user_ref);
733 mng.user_ref = 0;
734 return res; 493 return res;
735} 494}
736 495
737void tipc_cfg_stop(void) 496void tipc_cfg_stop(void)
738{ 497{
739 if (mng.user_ref) { 498 if (config_port_ref) {
740 tipc_detach(mng.user_ref); 499 tipc_deleteport(config_port_ref);
741 mng.user_ref = 0; 500 config_port_ref = 0;
742 } 501 }
743} 502}