blob: 7370241412cbf1429d153672495c1d604dd24a62 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/config.c: TIPC configuration management code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Per Liden593a5f22006-01-11 19:14:19 +01004 * Copyright (c) 2002-2006, Ericsson AB
Allan Stephens59f0c452008-05-21 14:52:30 -07005 * Copyright (c) 2004-2007, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01006 * All rights reserved.
7 *
Per Liden9ea1fd32006-01-11 13:30:43 +01008 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +01009 * modification, are permitted provided that the following conditions are met:
10 *
Per Liden9ea1fd32006-01-11 13:30:43 +010011 * 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.
Per Lidenb97bf3f2006-01-02 19:04:38 +010019 *
Per Liden9ea1fd32006-01-11 13:30:43 +010020 * 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
Per Lidenb97bf3f2006-01-02 19:04:38 +010034 * 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;
Per Lidenb97bf3f2006-01-02 19:04:38 +010059};
60
61static struct manager mng = { 0};
62
Ingo Molnar34af9462006-06-27 02:53:55 -070063static DEFINE_SPINLOCK(config_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +010064
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
Per Liden4323add2006-01-18 00:38:21 +010070struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +010071{
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
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090080int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
Per Liden4323add2006-01-18 00:38:21 +010081 void *tlv_data, int tlv_data_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +010082{
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -070083 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +010084 int new_tlv_space = TLV_SPACE(tlv_data_size);
85
86 if (skb_tailroom(buf) < new_tlv_space) {
Per Liden4323add2006-01-18 00:38:21 +010087 dbg("tipc_cfg_append_tlv unable to append TLV\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +010088 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
Per Liden4323add2006-01-18 00:38:21 +010098struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
Per Lidenb97bf3f2006-01-02 19:04:38 +010099{
100 struct sk_buff *buf;
Al Viro3e6c8cd2006-11-08 00:19:09 -0800101 __be32 value_net;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100102
Per Liden4323add2006-01-18 00:38:21 +0100103 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100104 if (buf) {
105 value_net = htonl(value);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900106 tipc_cfg_append_tlv(buf, tlv_type, &value_net,
Per Liden4323add2006-01-18 00:38:21 +0100107 sizeof(value_net));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108 }
109 return buf;
110}
111
Per Liden4323add2006-01-18 00:38:21 +0100112struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100113{
114 struct sk_buff *buf;
115 int string_len = strlen(string) + 1;
116
Per Liden4323add2006-01-18 00:38:21 +0100117 buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100118 if (buf)
Per Liden4323add2006-01-18 00:38:21 +0100119 tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100120 return buf;
121}
122
123
Per Lidenb97bf3f2006-01-02 19:04:38 +0100124#if 0
125
126/* Now obsolete code for handling commands not yet implemented the new way */
127
Allan Stephens289464e2010-05-11 14:30:05 +0000128/*
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
Per Lidenb97bf3f2006-01-02 19:04:38 +0100142int 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,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900188 u32 sz,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100189 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
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900198 cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100199 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;
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800214 sub = kmalloc(sizeof(*sub),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100215 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 }
249 exit:
250 rmsg.result_len = htonl(msg_sect[1].iov_len);
251 rmsg.retval = htonl(rv);
Per Liden4323add2006-01-18 00:38:21 +0100252 tipc_cfg_respond(msg_sect, 2u, orig);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100253}
254#endif
255
256static struct sk_buff *cfg_enable_bearer(void)
257{
258 struct tipc_bearer_config *args;
259
260 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +0100261 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100262
263 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
264 if (tipc_enable_bearer(args->name,
265 ntohl(args->detect_scope),
266 ntohl(args->priority)))
Per Liden4323add2006-01-18 00:38:21 +0100267 return tipc_cfg_reply_error_string("unable to enable bearer");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100268
Per Liden4323add2006-01-18 00:38:21 +0100269 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100270}
271
272static struct sk_buff *cfg_disable_bearer(void)
273{
274 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
Per Liden4323add2006-01-18 00:38:21 +0100275 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100276
277 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
Per Liden4323add2006-01-18 00:38:21 +0100278 return tipc_cfg_reply_error_string("unable to disable bearer");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100279
Per Liden4323add2006-01-18 00:38:21 +0100280 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100281}
282
283static struct sk_buff *cfg_set_own_addr(void)
284{
285 u32 addr;
286
287 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100288 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100289
Al Viro3e6c8cd2006-11-08 00:19:09 -0800290 addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100291 if (addr == tipc_own_addr)
Per Liden4323add2006-01-18 00:38:21 +0100292 return tipc_cfg_reply_none();
293 if (!tipc_addr_node_valid(addr))
294 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
295 " (node address)");
Allan Stephense100ae92006-06-25 23:51:08 -0700296 if (tipc_mode == TIPC_NET_MODE)
Per Liden4323add2006-01-18 00:38:21 +0100297 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
298 " (cannot change node address once assigned)");
Allan Stephense100ae92006-06-25 23:51:08 -0700299
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900300 /*
Allan Stephense100ae92006-06-25 23:51:08 -0700301 * Must release all spinlocks before calling start_net() because
302 * Linux version of TIPC calls eth_media_start() which calls
303 * register_netdevice_notifier() which may block!
304 *
305 * Temporarily releasing the lock should be harmless for non-Linux TIPC,
306 * but Linux version of eth_media_start() should really be reworked
307 * so that it can be called with spinlocks held.
308 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100309
310 spin_unlock_bh(&config_lock);
Allan Stephens03194372008-05-21 14:55:04 -0700311 tipc_core_start_net(addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100312 spin_lock_bh(&config_lock);
Per Liden4323add2006-01-18 00:38:21 +0100313 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100314}
315
316static struct sk_buff *cfg_set_remote_mng(void)
317{
318 u32 value;
319
320 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100321 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100322
Al Viro3e6c8cd2006-11-08 00:19:09 -0800323 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100324 tipc_remote_management = (value != 0);
Per Liden4323add2006-01-18 00:38:21 +0100325 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100326}
327
328static struct sk_buff *cfg_set_max_publications(void)
329{
330 u32 value;
331
332 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100333 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100334
Al Viro3e6c8cd2006-11-08 00:19:09 -0800335 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100336 if (value != delimit(value, 1, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100337 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
338 " (max publications must be 1-65535)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100339 tipc_max_publications = value;
Per Liden4323add2006-01-18 00:38:21 +0100340 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100341}
342
343static struct sk_buff *cfg_set_max_subscriptions(void)
344{
345 u32 value;
346
347 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100348 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100349
Al Viro3e6c8cd2006-11-08 00:19:09 -0800350 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100351 if (value != delimit(value, 1, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100352 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
353 " (max subscriptions must be 1-65535");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100354 tipc_max_subscriptions = value;
Per Liden4323add2006-01-18 00:38:21 +0100355 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100356}
357
358static struct sk_buff *cfg_set_max_ports(void)
359{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100360 u32 value;
361
362 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100363 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800364 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700365 if (value == tipc_max_ports)
366 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100367 if (value != delimit(value, 127, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100368 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
369 " (max ports must be 127-65535)");
Allan Stephense100ae92006-06-25 23:51:08 -0700370 if (tipc_mode != TIPC_NOT_RUNNING)
Per Liden4323add2006-01-18 00:38:21 +0100371 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Allan Stephense100ae92006-06-25 23:51:08 -0700372 " (cannot change max ports while TIPC is active)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100373 tipc_max_ports = value;
Per Liden4323add2006-01-18 00:38:21 +0100374 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100375}
376
377static struct sk_buff *cfg_set_max_zones(void)
378{
379 u32 value;
380
381 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100382 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800383 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700384 if (value == tipc_max_zones)
385 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100386 if (value != delimit(value, 1, 255))
Per Liden4323add2006-01-18 00:38:21 +0100387 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
388 " (max zones must be 1-255)");
Allan Stephense100ae92006-06-25 23:51:08 -0700389 if (tipc_mode == TIPC_NET_MODE)
390 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
391 " (cannot change max zones once TIPC has joined a network)");
392 tipc_max_zones = value;
393 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100394}
395
396static struct sk_buff *cfg_set_max_clusters(void)
397{
398 u32 value;
399
400 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100401 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800402 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700403 if (value != delimit(value, 1, 1))
404 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
Per Liden4323add2006-01-18 00:38:21 +0100405 " (max clusters fixed at 1)");
406 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100407}
408
409static struct sk_buff *cfg_set_max_nodes(void)
410{
411 u32 value;
412
413 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100414 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800415 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700416 if (value == tipc_max_nodes)
417 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100418 if (value != delimit(value, 8, 2047))
Per Liden4323add2006-01-18 00:38:21 +0100419 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
420 " (max nodes must be 8-2047)");
Allan Stephense100ae92006-06-25 23:51:08 -0700421 if (tipc_mode == TIPC_NET_MODE)
422 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
423 " (cannot change max nodes once TIPC has joined a network)");
424 tipc_max_nodes = value;
425 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100426}
427
428static struct sk_buff *cfg_set_max_slaves(void)
429{
430 u32 value;
431
432 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100433 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800434 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100435 if (value != 0)
Per Liden4323add2006-01-18 00:38:21 +0100436 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
437 " (max secondary nodes fixed at 0)");
438 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100439}
440
441static struct sk_buff *cfg_set_netid(void)
442{
443 u32 value;
444
445 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100446 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800447 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700448 if (value == tipc_net_id)
449 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100450 if (value != delimit(value, 1, 9999))
Per Liden4323add2006-01-18 00:38:21 +0100451 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
452 " (network id must be 1-9999)");
Allan Stephense100ae92006-06-25 23:51:08 -0700453 if (tipc_mode == TIPC_NET_MODE)
Per Liden4323add2006-01-18 00:38:21 +0100454 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Allan Stephense100ae92006-06-25 23:51:08 -0700455 " (cannot change network id once TIPC has joined a network)");
456 tipc_net_id = value;
457 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100458}
459
Per Liden4323add2006-01-18 00:38:21 +0100460struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
461 int request_space, int reply_headroom)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100462{
463 struct sk_buff *rep_tlv_buf;
464
465 spin_lock_bh(&config_lock);
466
467 /* Save request and reply details in a well-known location */
468
469 req_tlv_area = request_area;
470 req_tlv_space = request_space;
471 rep_headroom = reply_headroom;
472
473 /* Check command authorization */
474
475 if (likely(orig_node == tipc_own_addr)) {
476 /* command is permitted */
477 } else if (cmd >= 0x8000) {
Per Liden4323add2006-01-18 00:38:21 +0100478 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
479 " (cannot be done remotely)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100480 goto exit;
481 } else if (!tipc_remote_management) {
Per Liden4323add2006-01-18 00:38:21 +0100482 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100483 goto exit;
484 }
485 else if (cmd >= 0x4000) {
486 u32 domain = 0;
487
Per Liden4323add2006-01-18 00:38:21 +0100488 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100489 (domain != orig_node)) {
Per Liden4323add2006-01-18 00:38:21 +0100490 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100491 goto exit;
492 }
493 }
494
495 /* Call appropriate processing routine */
496
497 switch (cmd) {
498 case TIPC_CMD_NOOP:
Per Liden4323add2006-01-18 00:38:21 +0100499 rep_tlv_buf = tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100500 break;
501 case TIPC_CMD_GET_NODES:
Per Liden4323add2006-01-18 00:38:21 +0100502 rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100503 break;
504 case TIPC_CMD_GET_LINKS:
Per Liden4323add2006-01-18 00:38:21 +0100505 rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100506 break;
507 case TIPC_CMD_SHOW_LINK_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100508 rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100509 break;
510 case TIPC_CMD_RESET_LINK_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100511 rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100512 break;
513 case TIPC_CMD_SHOW_NAME_TABLE:
Per Liden4323add2006-01-18 00:38:21 +0100514 rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100515 break;
516 case TIPC_CMD_GET_BEARER_NAMES:
Per Liden4323add2006-01-18 00:38:21 +0100517 rep_tlv_buf = tipc_bearer_get_names();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100518 break;
519 case TIPC_CMD_GET_MEDIA_NAMES:
Per Liden4323add2006-01-18 00:38:21 +0100520 rep_tlv_buf = tipc_media_get_names();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100521 break;
522 case TIPC_CMD_SHOW_PORTS:
Per Liden4323add2006-01-18 00:38:21 +0100523 rep_tlv_buf = tipc_port_get_ports();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100524 break;
525#if 0
526 case TIPC_CMD_SHOW_PORT_STATS:
527 rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
528 break;
529 case TIPC_CMD_RESET_PORT_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100530 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100531 break;
532#endif
533 case TIPC_CMD_SET_LOG_SIZE:
Allan Stephens025adbe2008-05-05 01:20:04 -0700534 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100535 break;
536 case TIPC_CMD_DUMP_LOG:
Per Liden4323add2006-01-18 00:38:21 +0100537 rep_tlv_buf = tipc_log_dump();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100538 break;
539 case TIPC_CMD_SET_LINK_TOL:
540 case TIPC_CMD_SET_LINK_PRI:
541 case TIPC_CMD_SET_LINK_WINDOW:
Per Liden4323add2006-01-18 00:38:21 +0100542 rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100543 break;
544 case TIPC_CMD_ENABLE_BEARER:
545 rep_tlv_buf = cfg_enable_bearer();
546 break;
547 case TIPC_CMD_DISABLE_BEARER:
548 rep_tlv_buf = cfg_disable_bearer();
549 break;
550 case TIPC_CMD_SET_NODE_ADDR:
551 rep_tlv_buf = cfg_set_own_addr();
552 break;
553 case TIPC_CMD_SET_REMOTE_MNG:
554 rep_tlv_buf = cfg_set_remote_mng();
555 break;
556 case TIPC_CMD_SET_MAX_PORTS:
557 rep_tlv_buf = cfg_set_max_ports();
558 break;
559 case TIPC_CMD_SET_MAX_PUBL:
560 rep_tlv_buf = cfg_set_max_publications();
561 break;
562 case TIPC_CMD_SET_MAX_SUBSCR:
563 rep_tlv_buf = cfg_set_max_subscriptions();
564 break;
565 case TIPC_CMD_SET_MAX_ZONES:
566 rep_tlv_buf = cfg_set_max_zones();
567 break;
568 case TIPC_CMD_SET_MAX_CLUSTERS:
569 rep_tlv_buf = cfg_set_max_clusters();
570 break;
571 case TIPC_CMD_SET_MAX_NODES:
572 rep_tlv_buf = cfg_set_max_nodes();
573 break;
574 case TIPC_CMD_SET_MAX_SLAVES:
575 rep_tlv_buf = cfg_set_max_slaves();
576 break;
577 case TIPC_CMD_SET_NETID:
578 rep_tlv_buf = cfg_set_netid();
579 break;
580 case TIPC_CMD_GET_REMOTE_MNG:
Per Liden4323add2006-01-18 00:38:21 +0100581 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100582 break;
583 case TIPC_CMD_GET_MAX_PORTS:
Per Liden4323add2006-01-18 00:38:21 +0100584 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100585 break;
586 case TIPC_CMD_GET_MAX_PUBL:
Per Liden4323add2006-01-18 00:38:21 +0100587 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100588 break;
589 case TIPC_CMD_GET_MAX_SUBSCR:
Per Liden4323add2006-01-18 00:38:21 +0100590 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100591 break;
592 case TIPC_CMD_GET_MAX_ZONES:
Per Liden4323add2006-01-18 00:38:21 +0100593 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100594 break;
595 case TIPC_CMD_GET_MAX_CLUSTERS:
Per Liden4323add2006-01-18 00:38:21 +0100596 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100597 break;
598 case TIPC_CMD_GET_MAX_NODES:
Per Liden4323add2006-01-18 00:38:21 +0100599 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100600 break;
601 case TIPC_CMD_GET_MAX_SLAVES:
Per Liden4323add2006-01-18 00:38:21 +0100602 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100603 break;
604 case TIPC_CMD_GET_NETID:
Per Liden4323add2006-01-18 00:38:21 +0100605 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100606 break;
Allan Stephens59f0c452008-05-21 14:52:30 -0700607 case TIPC_CMD_NOT_NET_ADMIN:
608 rep_tlv_buf =
609 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
610 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100611 default:
Allan Stephens53cfd1e2006-10-16 22:00:56 -0700612 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
613 " (unknown command)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100614 break;
615 }
616
617 /* Return reply buffer */
618exit:
619 spin_unlock_bh(&config_lock);
620 return rep_tlv_buf;
621}
622
623static void cfg_named_msg_event(void *userdata,
624 u32 port_ref,
625 struct sk_buff **buf,
626 const unchar *msg,
627 u32 size,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900628 u32 importance,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100629 struct tipc_portid const *orig,
630 struct tipc_name_seq const *dest)
631{
632 struct tipc_cfg_msg_hdr *req_hdr;
633 struct tipc_cfg_msg_hdr *rep_hdr;
634 struct sk_buff *rep_buf;
635
636 /* Validate configuration message header (ignore invalid message) */
637
638 req_hdr = (struct tipc_cfg_msg_hdr *)msg;
639 if ((size < sizeof(*req_hdr)) ||
640 (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
641 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700642 warn("Invalid configuration message discarded\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100643 return;
644 }
645
646 /* Generate reply for request (if can't, return request) */
647
Per Liden4323add2006-01-18 00:38:21 +0100648 rep_buf = tipc_cfg_do_cmd(orig->node,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900649 ntohs(req_hdr->tcm_type),
Per Liden4323add2006-01-18 00:38:21 +0100650 msg + sizeof(*req_hdr),
651 size - sizeof(*req_hdr),
652 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100653 if (rep_buf) {
654 skb_push(rep_buf, sizeof(*rep_hdr));
655 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
656 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
657 rep_hdr->tcm_len = htonl(rep_buf->len);
658 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
659 } else {
660 rep_buf = *buf;
661 *buf = NULL;
662 }
663
664 /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
665 tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
666}
667
Per Liden4323add2006-01-18 00:38:21 +0100668int tipc_cfg_init(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100669{
670 struct tipc_name_seq seq;
671 int res;
672
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800673 res = tipc_attach(&mng.user_ref, NULL, NULL);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100674 if (res)
675 goto failed;
676
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800677 res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100678 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;
Per Liden4323add2006-01-18 00:38:21 +0100686 res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100687 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
Per Liden4323add2006-01-18 00:38:21 +0100699void tipc_cfg_stop(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100700{
701 if (mng.user_ref) {
702 tipc_detach(mng.user_ref);
703 mng.user_ref = 0;
704 }
705}