| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* | 
 | 2 |  * net/tipc/config.c: TIPC configuration management code | 
| YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 |  * | 
| Per Liden | 593a5f2 | 2006-01-11 19:14:19 +0100 | [diff] [blame] | 4 |  * Copyright (c) 2002-2006, Ericsson AB | 
| Allan Stephens | 59f0c45 | 2008-05-21 14:52:30 -0700 | [diff] [blame] | 5 |  * Copyright (c) 2004-2007, Wind River Systems | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 |  * All rights reserved. | 
 | 7 |  * | 
| Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 |  * Redistribution and use in source and binary forms, with or without | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 |  * modification, are permitted provided that the following conditions are met: | 
 | 10 |  * | 
| Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 |  * | 
| Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 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. | 
 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 34 |  * 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 |  | 
 | 49 | struct subscr_data { | 
 | 50 | 	char usr_handle[8]; | 
 | 51 | 	u32 domain; | 
 | 52 | 	u32 port_ref; | 
 | 53 | 	struct list_head subd_list; | 
 | 54 | }; | 
 | 55 |  | 
 | 56 | struct manager { | 
 | 57 | 	u32 user_ref; | 
 | 58 | 	u32 port_ref; | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 59 | }; | 
 | 60 |  | 
 | 61 | static struct manager mng = { 0}; | 
 | 62 |  | 
| Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 63 | static DEFINE_SPINLOCK(config_lock); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 64 |  | 
 | 65 | static const void *req_tlv_area;	/* request message TLV area */ | 
 | 66 | static int req_tlv_space;		/* request message TLV area size */ | 
 | 67 | static int rep_headroom;		/* reply message headroom to use */ | 
 | 68 |  | 
 | 69 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 70 | struct sk_buff *tipc_cfg_reply_alloc(int payload_size) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 71 | { | 
 | 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 Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 80 | int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type, | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 81 | 			void *tlv_data, int tlv_data_size) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 82 | { | 
| Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 83 | 	struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 84 | 	int new_tlv_space = TLV_SPACE(tlv_data_size); | 
 | 85 |  | 
 | 86 | 	if (skb_tailroom(buf) < new_tlv_space) { | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 87 | 		dbg("tipc_cfg_append_tlv unable to append TLV\n"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 88 | 		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 |  | 
| stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 98 | static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 99 | { | 
 | 100 | 	struct sk_buff *buf; | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 101 | 	__be32 value_net; | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 102 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 103 | 	buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value))); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 104 | 	if (buf) { | 
 | 105 | 		value_net = htonl(value); | 
| YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 106 | 		tipc_cfg_append_tlv(buf, tlv_type, &value_net, | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 107 | 				    sizeof(value_net)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 108 | 	} | 
 | 109 | 	return buf; | 
 | 110 | } | 
 | 111 |  | 
| stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 112 | static struct sk_buff *tipc_cfg_reply_unsigned(u32 value) | 
 | 113 | { | 
 | 114 | 	return tipc_cfg_reply_unsigned_type(TIPC_TLV_UNSIGNED, value); | 
 | 115 | } | 
 | 116 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 117 | struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 118 | { | 
 | 119 | 	struct sk_buff *buf; | 
 | 120 | 	int string_len = strlen(string) + 1; | 
 | 121 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 122 | 	buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 123 | 	if (buf) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 124 | 		tipc_cfg_append_tlv(buf, tlv_type, string, string_len); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 125 | 	return buf; | 
 | 126 | } | 
 | 127 |  | 
| Allan Stephens | 107e7be | 2010-05-11 14:30:08 +0000 | [diff] [blame] | 128 | #define MAX_STATS_INFO 2000 | 
 | 129 |  | 
 | 130 | static struct sk_buff *tipc_show_stats(void) | 
 | 131 | { | 
 | 132 | 	struct sk_buff *buf; | 
 | 133 | 	struct tlv_desc *rep_tlv; | 
 | 134 | 	struct print_buf pb; | 
 | 135 | 	int str_len; | 
 | 136 | 	u32 value; | 
 | 137 |  | 
 | 138 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
 | 139 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
 | 140 |  | 
 | 141 | 	value = ntohl(*(u32 *)TLV_DATA(req_tlv_area)); | 
 | 142 | 	if (value != 0) | 
 | 143 | 		return tipc_cfg_reply_error_string("unsupported argument"); | 
 | 144 |  | 
 | 145 | 	buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_STATS_INFO)); | 
 | 146 | 	if (buf == NULL) | 
 | 147 | 		return NULL; | 
 | 148 |  | 
 | 149 | 	rep_tlv = (struct tlv_desc *)buf->data; | 
 | 150 | 	tipc_printbuf_init(&pb, (char *)TLV_DATA(rep_tlv), MAX_STATS_INFO); | 
 | 151 |  | 
 | 152 | 	tipc_printf(&pb, "TIPC version " TIPC_MOD_VER "\n"); | 
 | 153 |  | 
 | 154 | 	/* Use additional tipc_printf()'s to return more info ... */ | 
 | 155 |  | 
 | 156 | 	str_len = tipc_printbuf_validate(&pb); | 
 | 157 | 	skb_put(buf, TLV_SPACE(str_len)); | 
 | 158 | 	TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); | 
 | 159 |  | 
 | 160 | 	return buf; | 
 | 161 | } | 
 | 162 |  | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 163 | static struct sk_buff *cfg_enable_bearer(void) | 
 | 164 | { | 
 | 165 | 	struct tipc_bearer_config *args; | 
 | 166 |  | 
 | 167 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 168 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 169 |  | 
 | 170 | 	args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area); | 
 | 171 | 	if (tipc_enable_bearer(args->name, | 
 | 172 | 			       ntohl(args->detect_scope), | 
 | 173 | 			       ntohl(args->priority))) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 174 | 		return tipc_cfg_reply_error_string("unable to enable bearer"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 175 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 176 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 177 | } | 
 | 178 |  | 
 | 179 | static struct sk_buff *cfg_disable_bearer(void) | 
 | 180 | { | 
 | 181 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 182 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 183 |  | 
 | 184 | 	if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area))) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 185 | 		return tipc_cfg_reply_error_string("unable to disable bearer"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 186 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 187 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 188 | } | 
 | 189 |  | 
 | 190 | static struct sk_buff *cfg_set_own_addr(void) | 
 | 191 | { | 
 | 192 | 	u32 addr; | 
 | 193 |  | 
 | 194 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 195 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 196 |  | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 197 | 	addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 198 | 	if (addr == tipc_own_addr) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 199 | 		return tipc_cfg_reply_none(); | 
 | 200 | 	if (!tipc_addr_node_valid(addr)) | 
 | 201 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 202 | 						   " (node address)"); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 203 | 	if (tipc_mode == TIPC_NET_MODE) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 204 | 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
 | 205 | 						   " (cannot change node address once assigned)"); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 206 |  | 
| YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 207 | 	/* | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 208 | 	 * Must release all spinlocks before calling start_net() because | 
 | 209 | 	 * Linux version of TIPC calls eth_media_start() which calls | 
 | 210 | 	 * register_netdevice_notifier() which may block! | 
 | 211 | 	 * | 
 | 212 | 	 * Temporarily releasing the lock should be harmless for non-Linux TIPC, | 
 | 213 | 	 * but Linux version of eth_media_start() should really be reworked | 
 | 214 | 	 * so that it can be called with spinlocks held. | 
 | 215 | 	 */ | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 216 |  | 
 | 217 | 	spin_unlock_bh(&config_lock); | 
| Allan Stephens | 0319437 | 2008-05-21 14:55:04 -0700 | [diff] [blame] | 218 | 	tipc_core_start_net(addr); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 219 | 	spin_lock_bh(&config_lock); | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 220 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 221 | } | 
 | 222 |  | 
 | 223 | static struct sk_buff *cfg_set_remote_mng(void) | 
 | 224 | { | 
 | 225 | 	u32 value; | 
 | 226 |  | 
 | 227 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 228 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 229 |  | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 230 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 231 | 	tipc_remote_management = (value != 0); | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 232 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 233 | } | 
 | 234 |  | 
 | 235 | static struct sk_buff *cfg_set_max_publications(void) | 
 | 236 | { | 
 | 237 | 	u32 value; | 
 | 238 |  | 
 | 239 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 240 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 241 |  | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 242 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 243 | 	if (value != delimit(value, 1, 65535)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 244 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 245 | 						   " (max publications must be 1-65535)"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 246 | 	tipc_max_publications = value; | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 247 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 248 | } | 
 | 249 |  | 
 | 250 | static struct sk_buff *cfg_set_max_subscriptions(void) | 
 | 251 | { | 
 | 252 | 	u32 value; | 
 | 253 |  | 
 | 254 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 255 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 256 |  | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 257 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 258 | 	if (value != delimit(value, 1, 65535)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 259 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 260 | 						   " (max subscriptions must be 1-65535"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 261 | 	tipc_max_subscriptions = value; | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 262 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 263 | } | 
 | 264 |  | 
 | 265 | static struct sk_buff *cfg_set_max_ports(void) | 
 | 266 | { | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 267 | 	u32 value; | 
 | 268 |  | 
 | 269 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 270 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 271 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 272 | 	if (value == tipc_max_ports) | 
 | 273 | 		return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 274 | 	if (value != delimit(value, 127, 65535)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 275 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 276 | 						   " (max ports must be 127-65535)"); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 277 | 	if (tipc_mode != TIPC_NOT_RUNNING) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 278 | 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 279 | 			" (cannot change max ports while TIPC is active)"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 280 | 	tipc_max_ports = value; | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 281 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 282 | } | 
 | 283 |  | 
 | 284 | static struct sk_buff *cfg_set_max_zones(void) | 
 | 285 | { | 
 | 286 | 	u32 value; | 
 | 287 |  | 
 | 288 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 289 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 290 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 291 | 	if (value == tipc_max_zones) | 
 | 292 | 		return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 293 | 	if (value != delimit(value, 1, 255)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 294 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 295 | 						   " (max zones must be 1-255)"); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 296 | 	if (tipc_mode == TIPC_NET_MODE) | 
 | 297 | 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
 | 298 | 			" (cannot change max zones once TIPC has joined a network)"); | 
 | 299 | 	tipc_max_zones = value; | 
 | 300 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 301 | } | 
 | 302 |  | 
 | 303 | static struct sk_buff *cfg_set_max_clusters(void) | 
 | 304 | { | 
 | 305 | 	u32 value; | 
 | 306 |  | 
 | 307 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 308 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 309 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 310 | 	if (value != delimit(value, 1, 1)) | 
 | 311 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 312 | 						   " (max clusters fixed at 1)"); | 
 | 313 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 314 | } | 
 | 315 |  | 
 | 316 | static struct sk_buff *cfg_set_max_nodes(void) | 
 | 317 | { | 
 | 318 | 	u32 value; | 
 | 319 |  | 
 | 320 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 321 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 322 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 323 | 	if (value == tipc_max_nodes) | 
 | 324 | 		return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 325 | 	if (value != delimit(value, 8, 2047)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 326 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 327 | 						   " (max nodes must be 8-2047)"); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 328 | 	if (tipc_mode == TIPC_NET_MODE) | 
 | 329 | 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
 | 330 | 			" (cannot change max nodes once TIPC has joined a network)"); | 
 | 331 | 	tipc_max_nodes = value; | 
 | 332 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 333 | } | 
 | 334 |  | 
 | 335 | static struct sk_buff *cfg_set_max_slaves(void) | 
 | 336 | { | 
 | 337 | 	u32 value; | 
 | 338 |  | 
 | 339 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 340 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 341 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 342 | 	if (value != 0) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 343 | 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
 | 344 | 						   " (max secondary nodes fixed at 0)"); | 
 | 345 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | } | 
 | 347 |  | 
 | 348 | static struct sk_buff *cfg_set_netid(void) | 
 | 349 | { | 
 | 350 | 	u32 value; | 
 | 351 |  | 
 | 352 | 	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 353 | 		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); | 
| Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 354 | 	value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 355 | 	if (value == tipc_net_id) | 
 | 356 | 		return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 357 | 	if (value != delimit(value, 1, 9999)) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 358 | 		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | 
 | 359 | 						   " (network id must be 1-9999)"); | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 360 | 	if (tipc_mode == TIPC_NET_MODE) | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 361 | 		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
| Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 362 | 			" (cannot change network id once TIPC has joined a network)"); | 
 | 363 | 	tipc_net_id = value; | 
 | 364 | 	return tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 365 | } | 
 | 366 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 367 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area, | 
 | 368 | 				int request_space, int reply_headroom) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 369 | { | 
 | 370 | 	struct sk_buff *rep_tlv_buf; | 
 | 371 |  | 
 | 372 | 	spin_lock_bh(&config_lock); | 
 | 373 |  | 
 | 374 | 	/* Save request and reply details in a well-known location */ | 
 | 375 |  | 
 | 376 | 	req_tlv_area = request_area; | 
 | 377 | 	req_tlv_space = request_space; | 
 | 378 | 	rep_headroom = reply_headroom; | 
 | 379 |  | 
 | 380 | 	/* Check command authorization */ | 
 | 381 |  | 
 | 382 | 	if (likely(orig_node == tipc_own_addr)) { | 
 | 383 | 		/* command is permitted */ | 
 | 384 | 	} else if (cmd >= 0x8000) { | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 385 | 		rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
 | 386 | 							  " (cannot be done remotely)"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 387 | 		goto exit; | 
 | 388 | 	} else if (!tipc_remote_management) { | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 389 | 		rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 390 | 		goto exit; | 
 | 391 | 	} | 
 | 392 | 	else if (cmd >= 0x4000) { | 
 | 393 | 		u32 domain = 0; | 
 | 394 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 395 | 		if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) || | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 396 | 		    (domain != orig_node)) { | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 397 | 			rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 398 | 			goto exit; | 
 | 399 | 		} | 
 | 400 | 	} | 
 | 401 |  | 
 | 402 | 	/* Call appropriate processing routine */ | 
 | 403 |  | 
 | 404 | 	switch (cmd) { | 
 | 405 | 	case TIPC_CMD_NOOP: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 406 | 		rep_tlv_buf = tipc_cfg_reply_none(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 407 | 		break; | 
 | 408 | 	case TIPC_CMD_GET_NODES: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 409 | 		rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 410 | 		break; | 
 | 411 | 	case TIPC_CMD_GET_LINKS: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 412 | 		rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 413 | 		break; | 
 | 414 | 	case TIPC_CMD_SHOW_LINK_STATS: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 415 | 		rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 416 | 		break; | 
 | 417 | 	case TIPC_CMD_RESET_LINK_STATS: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 418 | 		rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 419 | 		break; | 
 | 420 | 	case TIPC_CMD_SHOW_NAME_TABLE: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 421 | 		rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 422 | 		break; | 
 | 423 | 	case TIPC_CMD_GET_BEARER_NAMES: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 424 | 		rep_tlv_buf = tipc_bearer_get_names(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 425 | 		break; | 
 | 426 | 	case TIPC_CMD_GET_MEDIA_NAMES: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 427 | 		rep_tlv_buf = tipc_media_get_names(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 428 | 		break; | 
 | 429 | 	case TIPC_CMD_SHOW_PORTS: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 430 | 		rep_tlv_buf = tipc_port_get_ports(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 431 | 		break; | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 432 | 	case TIPC_CMD_SET_LOG_SIZE: | 
| Allan Stephens | 025adbe | 2008-05-05 01:20:04 -0700 | [diff] [blame] | 433 | 		rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 434 | 		break; | 
 | 435 | 	case TIPC_CMD_DUMP_LOG: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 436 | 		rep_tlv_buf = tipc_log_dump(); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 437 | 		break; | 
| Allan Stephens | 107e7be | 2010-05-11 14:30:08 +0000 | [diff] [blame] | 438 | 	case TIPC_CMD_SHOW_STATS: | 
 | 439 | 		rep_tlv_buf = tipc_show_stats(); | 
 | 440 | 		break; | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 441 | 	case TIPC_CMD_SET_LINK_TOL: | 
 | 442 | 	case TIPC_CMD_SET_LINK_PRI: | 
 | 443 | 	case TIPC_CMD_SET_LINK_WINDOW: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 444 | 		rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 445 | 		break; | 
 | 446 | 	case TIPC_CMD_ENABLE_BEARER: | 
 | 447 | 		rep_tlv_buf = cfg_enable_bearer(); | 
 | 448 | 		break; | 
 | 449 | 	case TIPC_CMD_DISABLE_BEARER: | 
 | 450 | 		rep_tlv_buf = cfg_disable_bearer(); | 
 | 451 | 		break; | 
 | 452 | 	case TIPC_CMD_SET_NODE_ADDR: | 
 | 453 | 		rep_tlv_buf = cfg_set_own_addr(); | 
 | 454 | 		break; | 
 | 455 | 	case TIPC_CMD_SET_REMOTE_MNG: | 
 | 456 | 		rep_tlv_buf = cfg_set_remote_mng(); | 
 | 457 | 		break; | 
 | 458 | 	case TIPC_CMD_SET_MAX_PORTS: | 
 | 459 | 		rep_tlv_buf = cfg_set_max_ports(); | 
 | 460 | 		break; | 
 | 461 | 	case TIPC_CMD_SET_MAX_PUBL: | 
 | 462 | 		rep_tlv_buf = cfg_set_max_publications(); | 
 | 463 | 		break; | 
 | 464 | 	case TIPC_CMD_SET_MAX_SUBSCR: | 
 | 465 | 		rep_tlv_buf = cfg_set_max_subscriptions(); | 
 | 466 | 		break; | 
 | 467 | 	case TIPC_CMD_SET_MAX_ZONES: | 
 | 468 | 		rep_tlv_buf = cfg_set_max_zones(); | 
 | 469 | 		break; | 
 | 470 | 	case TIPC_CMD_SET_MAX_CLUSTERS: | 
 | 471 | 		rep_tlv_buf = cfg_set_max_clusters(); | 
 | 472 | 		break; | 
 | 473 | 	case TIPC_CMD_SET_MAX_NODES: | 
 | 474 | 		rep_tlv_buf = cfg_set_max_nodes(); | 
 | 475 | 		break; | 
 | 476 | 	case TIPC_CMD_SET_MAX_SLAVES: | 
 | 477 | 		rep_tlv_buf = cfg_set_max_slaves(); | 
 | 478 | 		break; | 
 | 479 | 	case TIPC_CMD_SET_NETID: | 
 | 480 | 		rep_tlv_buf = cfg_set_netid(); | 
 | 481 | 		break; | 
 | 482 | 	case TIPC_CMD_GET_REMOTE_MNG: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 483 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 484 | 		break; | 
 | 485 | 	case TIPC_CMD_GET_MAX_PORTS: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 486 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 487 | 		break; | 
 | 488 | 	case TIPC_CMD_GET_MAX_PUBL: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 489 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 490 | 		break; | 
 | 491 | 	case TIPC_CMD_GET_MAX_SUBSCR: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 492 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 493 | 		break; | 
 | 494 | 	case TIPC_CMD_GET_MAX_ZONES: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 495 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 496 | 		break; | 
 | 497 | 	case TIPC_CMD_GET_MAX_CLUSTERS: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 498 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 499 | 		break; | 
 | 500 | 	case TIPC_CMD_GET_MAX_NODES: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 501 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 502 | 		break; | 
 | 503 | 	case TIPC_CMD_GET_MAX_SLAVES: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 504 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 505 | 		break; | 
 | 506 | 	case TIPC_CMD_GET_NETID: | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 507 | 		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 508 | 		break; | 
| Allan Stephens | 59f0c45 | 2008-05-21 14:52:30 -0700 | [diff] [blame] | 509 | 	case TIPC_CMD_NOT_NET_ADMIN: | 
 | 510 | 		rep_tlv_buf = | 
 | 511 | 			tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN); | 
 | 512 | 		break; | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 513 | 	default: | 
| Allan Stephens | 53cfd1e | 2006-10-16 22:00:56 -0700 | [diff] [blame] | 514 | 		rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED | 
 | 515 | 							  " (unknown command)"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 516 | 		break; | 
 | 517 | 	} | 
 | 518 |  | 
 | 519 | 	/* Return reply buffer */ | 
 | 520 | exit: | 
 | 521 | 	spin_unlock_bh(&config_lock); | 
 | 522 | 	return rep_tlv_buf; | 
 | 523 | } | 
 | 524 |  | 
 | 525 | static void cfg_named_msg_event(void *userdata, | 
 | 526 | 				u32 port_ref, | 
 | 527 | 				struct sk_buff **buf, | 
 | 528 | 				const unchar *msg, | 
 | 529 | 				u32 size, | 
| YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 530 | 				u32 importance, | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 531 | 				struct tipc_portid const *orig, | 
 | 532 | 				struct tipc_name_seq const *dest) | 
 | 533 | { | 
 | 534 | 	struct tipc_cfg_msg_hdr *req_hdr; | 
 | 535 | 	struct tipc_cfg_msg_hdr *rep_hdr; | 
 | 536 | 	struct sk_buff *rep_buf; | 
 | 537 |  | 
 | 538 | 	/* Validate configuration message header (ignore invalid message) */ | 
 | 539 |  | 
 | 540 | 	req_hdr = (struct tipc_cfg_msg_hdr *)msg; | 
 | 541 | 	if ((size < sizeof(*req_hdr)) || | 
 | 542 | 	    (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) || | 
 | 543 | 	    (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) { | 
| Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 544 | 		warn("Invalid configuration message discarded\n"); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 545 | 		return; | 
 | 546 | 	} | 
 | 547 |  | 
 | 548 | 	/* Generate reply for request (if can't, return request) */ | 
 | 549 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 550 | 	rep_buf = tipc_cfg_do_cmd(orig->node, | 
| YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 551 | 				  ntohs(req_hdr->tcm_type), | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 552 | 				  msg + sizeof(*req_hdr), | 
 | 553 | 				  size - sizeof(*req_hdr), | 
 | 554 | 				  BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr)); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 555 | 	if (rep_buf) { | 
 | 556 | 		skb_push(rep_buf, sizeof(*rep_hdr)); | 
 | 557 | 		rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data; | 
 | 558 | 		memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); | 
 | 559 | 		rep_hdr->tcm_len = htonl(rep_buf->len); | 
 | 560 | 		rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); | 
 | 561 | 	} else { | 
 | 562 | 		rep_buf = *buf; | 
 | 563 | 		*buf = NULL; | 
 | 564 | 	} | 
 | 565 |  | 
 | 566 | 	/* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */ | 
 | 567 | 	tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len); | 
 | 568 | } | 
 | 569 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 570 | int tipc_cfg_init(void) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 571 | { | 
 | 572 | 	struct tipc_name_seq seq; | 
 | 573 | 	int res; | 
 | 574 |  | 
| Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 575 | 	res = tipc_attach(&mng.user_ref, NULL, NULL); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 576 | 	if (res) | 
 | 577 | 		goto failed; | 
 | 578 |  | 
| Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 579 | 	res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE, | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 580 | 			      NULL, NULL, NULL, | 
 | 581 | 			      NULL, cfg_named_msg_event, NULL, | 
 | 582 | 			      NULL, &mng.port_ref); | 
 | 583 | 	if (res) | 
 | 584 | 		goto failed; | 
 | 585 |  | 
 | 586 | 	seq.type = TIPC_CFG_SRV; | 
 | 587 | 	seq.lower = seq.upper = tipc_own_addr; | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 588 | 	res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq); | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 589 | 	if (res) | 
 | 590 | 		goto failed; | 
 | 591 |  | 
 | 592 | 	return 0; | 
 | 593 |  | 
 | 594 | failed: | 
 | 595 | 	err("Unable to create configuration service\n"); | 
 | 596 | 	tipc_detach(mng.user_ref); | 
 | 597 | 	mng.user_ref = 0; | 
 | 598 | 	return res; | 
 | 599 | } | 
 | 600 |  | 
| Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 601 | void tipc_cfg_stop(void) | 
| Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 602 | { | 
 | 603 | 	if (mng.user_ref) { | 
 | 604 | 		tipc_detach(mng.user_ref); | 
 | 605 | 		mng.user_ref = 0; | 
 | 606 | 	} | 
 | 607 | } |