blob: a7894ff77ae99051bb3bbc99dddf7065c7bf0072 [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"
Per Lidenb97bf3f2006-01-02 19:04:38 +010038#include "port.h"
39#include "link.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040#include "name_table.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010041#include "config.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010042
Allan Stephens7a488fd32010-12-31 18:59:20 +000043static u32 config_port_ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +010044
Ingo Molnar34af9462006-06-27 02:53:55 -070045static DEFINE_SPINLOCK(config_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +010046
47static const void *req_tlv_area; /* request message TLV area */
48static int req_tlv_space; /* request message TLV area size */
49static int rep_headroom; /* reply message headroom to use */
50
51
Per Liden4323add2006-01-18 00:38:21 +010052struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +010053{
54 struct sk_buff *buf;
55
56 buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
57 if (buf)
58 skb_reserve(buf, rep_headroom);
59 return buf;
60}
61
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090062int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
Per Liden4323add2006-01-18 00:38:21 +010063 void *tlv_data, int tlv_data_size)
Per Lidenb97bf3f2006-01-02 19:04:38 +010064{
Arnaldo Carvalho de Melo27a884d2007-04-19 20:29:13 -070065 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +010066 int new_tlv_space = TLV_SPACE(tlv_data_size);
67
Allan Stephensb29f1422010-12-31 18:59:25 +000068 if (skb_tailroom(buf) < new_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +010069 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +010070 skb_put(buf, new_tlv_space);
71 tlv->tlv_type = htons(tlv_type);
72 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
73 if (tlv_data_size && tlv_data)
74 memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
75 return 1;
76}
77
stephen hemminger31e3c3f2010-10-13 13:20:35 +000078static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
Per Lidenb97bf3f2006-01-02 19:04:38 +010079{
80 struct sk_buff *buf;
Al Viro3e6c8cd2006-11-08 00:19:09 -080081 __be32 value_net;
Per Lidenb97bf3f2006-01-02 19:04:38 +010082
Per Liden4323add2006-01-18 00:38:21 +010083 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
Per Lidenb97bf3f2006-01-02 19:04:38 +010084 if (buf) {
85 value_net = htonl(value);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090086 tipc_cfg_append_tlv(buf, tlv_type, &value_net,
Per Liden4323add2006-01-18 00:38:21 +010087 sizeof(value_net));
Per Lidenb97bf3f2006-01-02 19:04:38 +010088 }
89 return buf;
90}
91
stephen hemminger31e3c3f2010-10-13 13:20:35 +000092static struct sk_buff *tipc_cfg_reply_unsigned(u32 value)
93{
94 return tipc_cfg_reply_unsigned_type(TIPC_TLV_UNSIGNED, value);
95}
96
Per Liden4323add2006-01-18 00:38:21 +010097struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
Per Lidenb97bf3f2006-01-02 19:04:38 +010098{
99 struct sk_buff *buf;
100 int string_len = strlen(string) + 1;
101
Per Liden4323add2006-01-18 00:38:21 +0100102 buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100103 if (buf)
Per Liden4323add2006-01-18 00:38:21 +0100104 tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100105 return buf;
106}
107
Allan Stephens107e7be2010-05-11 14:30:08 +0000108#define MAX_STATS_INFO 2000
109
110static struct sk_buff *tipc_show_stats(void)
111{
112 struct sk_buff *buf;
113 struct tlv_desc *rep_tlv;
114 struct print_buf pb;
115 int str_len;
116 u32 value;
117
118 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
119 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
120
121 value = ntohl(*(u32 *)TLV_DATA(req_tlv_area));
122 if (value != 0)
123 return tipc_cfg_reply_error_string("unsupported argument");
124
125 buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_STATS_INFO));
126 if (buf == NULL)
127 return NULL;
128
129 rep_tlv = (struct tlv_desc *)buf->data;
130 tipc_printbuf_init(&pb, (char *)TLV_DATA(rep_tlv), MAX_STATS_INFO);
131
132 tipc_printf(&pb, "TIPC version " TIPC_MOD_VER "\n");
133
134 /* Use additional tipc_printf()'s to return more info ... */
135
136 str_len = tipc_printbuf_validate(&pb);
137 skb_put(buf, TLV_SPACE(str_len));
138 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
139
140 return buf;
141}
142
Per Lidenb97bf3f2006-01-02 19:04:38 +0100143static struct sk_buff *cfg_enable_bearer(void)
144{
145 struct tipc_bearer_config *args;
146
147 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
Per Liden4323add2006-01-18 00:38:21 +0100148 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100149
150 args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
151 if (tipc_enable_bearer(args->name,
152 ntohl(args->detect_scope),
153 ntohl(args->priority)))
Per Liden4323add2006-01-18 00:38:21 +0100154 return tipc_cfg_reply_error_string("unable to enable bearer");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100155
Per Liden4323add2006-01-18 00:38:21 +0100156 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100157}
158
159static struct sk_buff *cfg_disable_bearer(void)
160{
161 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
Per Liden4323add2006-01-18 00:38:21 +0100162 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100163
164 if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
Per Liden4323add2006-01-18 00:38:21 +0100165 return tipc_cfg_reply_error_string("unable to disable bearer");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100166
Per Liden4323add2006-01-18 00:38:21 +0100167 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100168}
169
170static struct sk_buff *cfg_set_own_addr(void)
171{
172 u32 addr;
173
174 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100175 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100176
Al Viro3e6c8cd2006-11-08 00:19:09 -0800177 addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100178 if (addr == tipc_own_addr)
Per Liden4323add2006-01-18 00:38:21 +0100179 return tipc_cfg_reply_none();
180 if (!tipc_addr_node_valid(addr))
181 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
182 " (node address)");
Allan Stephense100ae92006-06-25 23:51:08 -0700183 if (tipc_mode == TIPC_NET_MODE)
Per Liden4323add2006-01-18 00:38:21 +0100184 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
185 " (cannot change node address once assigned)");
Allan Stephense100ae92006-06-25 23:51:08 -0700186
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900187 /*
Allan Stephense100ae92006-06-25 23:51:08 -0700188 * Must release all spinlocks before calling start_net() because
189 * Linux version of TIPC calls eth_media_start() which calls
190 * register_netdevice_notifier() which may block!
191 *
192 * Temporarily releasing the lock should be harmless for non-Linux TIPC,
193 * but Linux version of eth_media_start() should really be reworked
194 * so that it can be called with spinlocks held.
195 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100196
197 spin_unlock_bh(&config_lock);
Allan Stephens03194372008-05-21 14:55:04 -0700198 tipc_core_start_net(addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100199 spin_lock_bh(&config_lock);
Per Liden4323add2006-01-18 00:38:21 +0100200 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100201}
202
203static struct sk_buff *cfg_set_remote_mng(void)
204{
205 u32 value;
206
207 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100208 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100209
Al Viro3e6c8cd2006-11-08 00:19:09 -0800210 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100211 tipc_remote_management = (value != 0);
Per Liden4323add2006-01-18 00:38:21 +0100212 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100213}
214
215static struct sk_buff *cfg_set_max_publications(void)
216{
217 u32 value;
218
219 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100220 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221
Al Viro3e6c8cd2006-11-08 00:19:09 -0800222 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100223 if (value != delimit(value, 1, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100224 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
225 " (max publications must be 1-65535)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100226 tipc_max_publications = value;
Per Liden4323add2006-01-18 00:38:21 +0100227 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100228}
229
230static struct sk_buff *cfg_set_max_subscriptions(void)
231{
232 u32 value;
233
234 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100235 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100236
Al Viro3e6c8cd2006-11-08 00:19:09 -0800237 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100238 if (value != delimit(value, 1, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100239 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
240 " (max subscriptions must be 1-65535");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100241 tipc_max_subscriptions = value;
Per Liden4323add2006-01-18 00:38:21 +0100242 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100243}
244
245static struct sk_buff *cfg_set_max_ports(void)
246{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100247 u32 value;
248
249 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100250 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800251 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700252 if (value == tipc_max_ports)
253 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100254 if (value != delimit(value, 127, 65535))
Per Liden4323add2006-01-18 00:38:21 +0100255 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
256 " (max ports must be 127-65535)");
Allan Stephense100ae92006-06-25 23:51:08 -0700257 if (tipc_mode != TIPC_NOT_RUNNING)
Per Liden4323add2006-01-18 00:38:21 +0100258 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Allan Stephense100ae92006-06-25 23:51:08 -0700259 " (cannot change max ports while TIPC is active)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100260 tipc_max_ports = value;
Per Liden4323add2006-01-18 00:38:21 +0100261 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100262}
263
Per Lidenb97bf3f2006-01-02 19:04:38 +0100264static struct sk_buff *cfg_set_max_nodes(void)
265{
266 u32 value;
267
268 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100269 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800270 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700271 if (value == tipc_max_nodes)
272 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100273 if (value != delimit(value, 8, 2047))
Per Liden4323add2006-01-18 00:38:21 +0100274 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
275 " (max nodes must be 8-2047)");
Allan Stephense100ae92006-06-25 23:51:08 -0700276 if (tipc_mode == TIPC_NET_MODE)
277 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
278 " (cannot change max nodes once TIPC has joined a network)");
279 tipc_max_nodes = value;
280 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100281}
282
Per Lidenb97bf3f2006-01-02 19:04:38 +0100283static struct sk_buff *cfg_set_netid(void)
284{
285 u32 value;
286
287 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
Per Liden4323add2006-01-18 00:38:21 +0100288 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Al Viro3e6c8cd2006-11-08 00:19:09 -0800289 value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Allan Stephense100ae92006-06-25 23:51:08 -0700290 if (value == tipc_net_id)
291 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100292 if (value != delimit(value, 1, 9999))
Per Liden4323add2006-01-18 00:38:21 +0100293 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
294 " (network id must be 1-9999)");
Allan Stephense100ae92006-06-25 23:51:08 -0700295 if (tipc_mode == TIPC_NET_MODE)
Per Liden4323add2006-01-18 00:38:21 +0100296 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
Allan Stephense100ae92006-06-25 23:51:08 -0700297 " (cannot change network id once TIPC has joined a network)");
298 tipc_net_id = value;
299 return tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100300}
301
Per Liden4323add2006-01-18 00:38:21 +0100302struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
303 int request_space, int reply_headroom)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100304{
305 struct sk_buff *rep_tlv_buf;
306
307 spin_lock_bh(&config_lock);
308
309 /* Save request and reply details in a well-known location */
310
311 req_tlv_area = request_area;
312 req_tlv_space = request_space;
313 rep_headroom = reply_headroom;
314
315 /* Check command authorization */
316
317 if (likely(orig_node == tipc_own_addr)) {
318 /* command is permitted */
319 } else if (cmd >= 0x8000) {
Per Liden4323add2006-01-18 00:38:21 +0100320 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
321 " (cannot be done remotely)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100322 goto exit;
323 } else if (!tipc_remote_management) {
Per Liden4323add2006-01-18 00:38:21 +0100324 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100325 goto exit;
326 }
327 else if (cmd >= 0x4000) {
328 u32 domain = 0;
329
Per Liden4323add2006-01-18 00:38:21 +0100330 if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100331 (domain != orig_node)) {
Per Liden4323add2006-01-18 00:38:21 +0100332 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100333 goto exit;
334 }
335 }
336
337 /* Call appropriate processing routine */
338
339 switch (cmd) {
340 case TIPC_CMD_NOOP:
Per Liden4323add2006-01-18 00:38:21 +0100341 rep_tlv_buf = tipc_cfg_reply_none();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100342 break;
343 case TIPC_CMD_GET_NODES:
Per Liden4323add2006-01-18 00:38:21 +0100344 rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100345 break;
346 case TIPC_CMD_GET_LINKS:
Per Liden4323add2006-01-18 00:38:21 +0100347 rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100348 break;
349 case TIPC_CMD_SHOW_LINK_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100350 rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100351 break;
352 case TIPC_CMD_RESET_LINK_STATS:
Per Liden4323add2006-01-18 00:38:21 +0100353 rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100354 break;
355 case TIPC_CMD_SHOW_NAME_TABLE:
Per Liden4323add2006-01-18 00:38:21 +0100356 rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100357 break;
358 case TIPC_CMD_GET_BEARER_NAMES:
Per Liden4323add2006-01-18 00:38:21 +0100359 rep_tlv_buf = tipc_bearer_get_names();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100360 break;
361 case TIPC_CMD_GET_MEDIA_NAMES:
Per Liden4323add2006-01-18 00:38:21 +0100362 rep_tlv_buf = tipc_media_get_names();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100363 break;
364 case TIPC_CMD_SHOW_PORTS:
Per Liden4323add2006-01-18 00:38:21 +0100365 rep_tlv_buf = tipc_port_get_ports();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100366 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100367 case TIPC_CMD_SET_LOG_SIZE:
Allan Stephens025adbe2008-05-05 01:20:04 -0700368 rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100369 break;
370 case TIPC_CMD_DUMP_LOG:
Per Liden4323add2006-01-18 00:38:21 +0100371 rep_tlv_buf = tipc_log_dump();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100372 break;
Allan Stephens107e7be2010-05-11 14:30:08 +0000373 case TIPC_CMD_SHOW_STATS:
374 rep_tlv_buf = tipc_show_stats();
375 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100376 case TIPC_CMD_SET_LINK_TOL:
377 case TIPC_CMD_SET_LINK_PRI:
378 case TIPC_CMD_SET_LINK_WINDOW:
Per Liden4323add2006-01-18 00:38:21 +0100379 rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100380 break;
381 case TIPC_CMD_ENABLE_BEARER:
382 rep_tlv_buf = cfg_enable_bearer();
383 break;
384 case TIPC_CMD_DISABLE_BEARER:
385 rep_tlv_buf = cfg_disable_bearer();
386 break;
387 case TIPC_CMD_SET_NODE_ADDR:
388 rep_tlv_buf = cfg_set_own_addr();
389 break;
390 case TIPC_CMD_SET_REMOTE_MNG:
391 rep_tlv_buf = cfg_set_remote_mng();
392 break;
393 case TIPC_CMD_SET_MAX_PORTS:
394 rep_tlv_buf = cfg_set_max_ports();
395 break;
396 case TIPC_CMD_SET_MAX_PUBL:
397 rep_tlv_buf = cfg_set_max_publications();
398 break;
399 case TIPC_CMD_SET_MAX_SUBSCR:
400 rep_tlv_buf = cfg_set_max_subscriptions();
401 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100402 case TIPC_CMD_SET_MAX_NODES:
403 rep_tlv_buf = cfg_set_max_nodes();
404 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100405 case TIPC_CMD_SET_NETID:
406 rep_tlv_buf = cfg_set_netid();
407 break;
408 case TIPC_CMD_GET_REMOTE_MNG:
Per Liden4323add2006-01-18 00:38:21 +0100409 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100410 break;
411 case TIPC_CMD_GET_MAX_PORTS:
Per Liden4323add2006-01-18 00:38:21 +0100412 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100413 break;
414 case TIPC_CMD_GET_MAX_PUBL:
Per Liden4323add2006-01-18 00:38:21 +0100415 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100416 break;
417 case TIPC_CMD_GET_MAX_SUBSCR:
Per Liden4323add2006-01-18 00:38:21 +0100418 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100419 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100420 case TIPC_CMD_GET_MAX_NODES:
Per Liden4323add2006-01-18 00:38:21 +0100421 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100422 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100423 case TIPC_CMD_GET_NETID:
Per Liden4323add2006-01-18 00:38:21 +0100424 rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100425 break;
Allan Stephens59f0c452008-05-21 14:52:30 -0700426 case TIPC_CMD_NOT_NET_ADMIN:
427 rep_tlv_buf =
428 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
429 break;
Allan Stephens51f98a82010-12-31 18:59:16 +0000430 case TIPC_CMD_SET_MAX_ZONES:
431 case TIPC_CMD_GET_MAX_ZONES:
Allan Stephens08c80e92010-12-31 18:59:17 +0000432 case TIPC_CMD_SET_MAX_SLAVES:
433 case TIPC_CMD_GET_MAX_SLAVES:
Allan Stephens8f92df62010-12-31 18:59:19 +0000434 case TIPC_CMD_SET_MAX_CLUSTERS:
435 case TIPC_CMD_GET_MAX_CLUSTERS:
Allan Stephens51f98a82010-12-31 18:59:16 +0000436 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
437 " (obsolete command)");
438 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100439 default:
Allan Stephens53cfd1e2006-10-16 22:00:56 -0700440 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
441 " (unknown command)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100442 break;
443 }
444
445 /* Return reply buffer */
446exit:
447 spin_unlock_bh(&config_lock);
448 return rep_tlv_buf;
449}
450
451static void cfg_named_msg_event(void *userdata,
452 u32 port_ref,
453 struct sk_buff **buf,
454 const unchar *msg,
455 u32 size,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900456 u32 importance,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100457 struct tipc_portid const *orig,
458 struct tipc_name_seq const *dest)
459{
460 struct tipc_cfg_msg_hdr *req_hdr;
461 struct tipc_cfg_msg_hdr *rep_hdr;
462 struct sk_buff *rep_buf;
463
464 /* Validate configuration message header (ignore invalid message) */
465
466 req_hdr = (struct tipc_cfg_msg_hdr *)msg;
467 if ((size < sizeof(*req_hdr)) ||
468 (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
469 (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700470 warn("Invalid configuration message discarded\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100471 return;
472 }
473
474 /* Generate reply for request (if can't, return request) */
475
Per Liden4323add2006-01-18 00:38:21 +0100476 rep_buf = tipc_cfg_do_cmd(orig->node,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900477 ntohs(req_hdr->tcm_type),
Per Liden4323add2006-01-18 00:38:21 +0100478 msg + sizeof(*req_hdr),
479 size - sizeof(*req_hdr),
480 BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100481 if (rep_buf) {
482 skb_push(rep_buf, sizeof(*rep_hdr));
483 rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
484 memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
485 rep_hdr->tcm_len = htonl(rep_buf->len);
486 rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
487 } else {
488 rep_buf = *buf;
489 *buf = NULL;
490 }
491
492 /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
493 tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
494}
495
Per Liden4323add2006-01-18 00:38:21 +0100496int tipc_cfg_init(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100497{
498 struct tipc_name_seq seq;
499 int res;
500
Allan Stephensb0c1e922010-12-31 18:59:22 +0000501 res = tipc_createport(NULL, TIPC_CRITICAL_IMPORTANCE,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100502 NULL, NULL, NULL,
503 NULL, cfg_named_msg_event, NULL,
Allan Stephens7a488fd32010-12-31 18:59:20 +0000504 NULL, &config_port_ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100505 if (res)
506 goto failed;
507
508 seq.type = TIPC_CFG_SRV;
509 seq.lower = seq.upper = tipc_own_addr;
Allan Stephens7a488fd32010-12-31 18:59:20 +0000510 res = tipc_nametbl_publish_rsv(config_port_ref, TIPC_ZONE_SCOPE, &seq);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100511 if (res)
512 goto failed;
513
514 return 0;
515
516failed:
517 err("Unable to create configuration service\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100518 return res;
519}
520
Per Liden4323add2006-01-18 00:38:21 +0100521void tipc_cfg_stop(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100522{
Allan Stephens7a488fd32010-12-31 18:59:20 +0000523 if (config_port_ref) {
524 tipc_deleteport(config_port_ref);
525 config_port_ref = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100526 }
527}