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; |
| 59 | u32 subscr_ref; |
| 60 | u32 link_subscriptions; |
| 61 | struct list_head link_subscribers; |
| 62 | }; |
| 63 | |
| 64 | static struct manager mng = { 0}; |
| 65 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 66 | static DEFINE_SPINLOCK(config_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 67 | |
| 68 | static const void *req_tlv_area; /* request message TLV area */ |
| 69 | static int req_tlv_space; /* request message TLV area size */ |
| 70 | static int rep_headroom; /* reply message headroom to use */ |
| 71 | |
| 72 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 73 | void tipc_cfg_link_event(u32 addr, char *name, int up) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 74 | { |
| 75 | /* TIPC DOESN'T HANDLE LINK EVENT SUBSCRIPTIONS AT THE MOMENT */ |
| 76 | } |
| 77 | |
| 78 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 79 | struct sk_buff *tipc_cfg_reply_alloc(int payload_size) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 80 | { |
| 81 | struct sk_buff *buf; |
| 82 | |
| 83 | buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC); |
| 84 | if (buf) |
| 85 | skb_reserve(buf, rep_headroom); |
| 86 | return buf; |
| 87 | } |
| 88 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 89 | int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 90 | void *tlv_data, int tlv_data_size) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 91 | { |
Arnaldo Carvalho de Melo | 27a884d | 2007-04-19 20:29:13 -0700 | [diff] [blame] | 92 | struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 93 | int new_tlv_space = TLV_SPACE(tlv_data_size); |
| 94 | |
| 95 | if (skb_tailroom(buf) < new_tlv_space) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 96 | dbg("tipc_cfg_append_tlv unable to append TLV\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 97 | return 0; |
| 98 | } |
| 99 | skb_put(buf, new_tlv_space); |
| 100 | tlv->tlv_type = htons(tlv_type); |
| 101 | tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size)); |
| 102 | if (tlv_data_size && tlv_data) |
| 103 | memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size); |
| 104 | return 1; |
| 105 | } |
| 106 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 107 | 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] | 108 | { |
| 109 | struct sk_buff *buf; |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 110 | __be32 value_net; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 111 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 112 | buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value))); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 113 | if (buf) { |
| 114 | value_net = htonl(value); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 115 | tipc_cfg_append_tlv(buf, tlv_type, &value_net, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 116 | sizeof(value_net)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 117 | } |
| 118 | return buf; |
| 119 | } |
| 120 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 121 | 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] | 122 | { |
| 123 | struct sk_buff *buf; |
| 124 | int string_len = strlen(string) + 1; |
| 125 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 126 | buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 127 | if (buf) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 128 | tipc_cfg_append_tlv(buf, tlv_type, string, string_len); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 129 | return buf; |
| 130 | } |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | #if 0 |
| 136 | |
| 137 | /* Now obsolete code for handling commands not yet implemented the new way */ |
| 138 | |
| 139 | int tipc_cfg_cmd(const struct tipc_cmd_msg * msg, |
| 140 | char *data, |
| 141 | u32 sz, |
| 142 | u32 *ret_size, |
| 143 | struct tipc_portid *orig) |
| 144 | { |
| 145 | int rv = -EINVAL; |
| 146 | u32 cmd = msg->cmd; |
| 147 | |
| 148 | *ret_size = 0; |
| 149 | switch (cmd) { |
| 150 | case TIPC_REMOVE_LINK: |
| 151 | case TIPC_CMD_BLOCK_LINK: |
| 152 | case TIPC_CMD_UNBLOCK_LINK: |
| 153 | if (!cfg_check_connection(orig)) |
| 154 | rv = link_control(msg->argv.link_name, msg->cmd, 0); |
| 155 | break; |
| 156 | case TIPC_ESTABLISH: |
| 157 | { |
| 158 | int connected; |
| 159 | |
| 160 | tipc_isconnected(mng.conn_port_ref, &connected); |
| 161 | if (connected || !orig) { |
| 162 | rv = TIPC_FAILURE; |
| 163 | break; |
| 164 | } |
| 165 | rv = tipc_connect2port(mng.conn_port_ref, orig); |
| 166 | if (rv == TIPC_OK) |
| 167 | orig = 0; |
| 168 | break; |
| 169 | } |
| 170 | case TIPC_GET_PEER_ADDRESS: |
| 171 | *ret_size = link_peer_addr(msg->argv.link_name, data, sz); |
| 172 | break; |
| 173 | case TIPC_GET_ROUTES: |
| 174 | rv = TIPC_OK; |
| 175 | break; |
| 176 | default: {} |
| 177 | } |
| 178 | if (*ret_size) |
| 179 | rv = TIPC_OK; |
| 180 | return rv; |
| 181 | } |
| 182 | |
| 183 | static void cfg_cmd_event(struct tipc_cmd_msg *msg, |
| 184 | char *data, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 185 | u32 sz, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 186 | struct tipc_portid const *orig) |
| 187 | { |
| 188 | int rv = -EINVAL; |
| 189 | struct tipc_cmd_result_msg rmsg; |
| 190 | struct iovec msg_sect[2]; |
| 191 | int *arg; |
| 192 | |
| 193 | msg->cmd = ntohl(msg->cmd); |
| 194 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 195 | cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 196 | data, 0); |
| 197 | if (ntohl(msg->magic) != TIPC_MAGIC) |
| 198 | goto exit; |
| 199 | |
| 200 | switch (msg->cmd) { |
| 201 | case TIPC_CREATE_LINK: |
| 202 | if (!cfg_check_connection(orig)) |
| 203 | rv = disc_create_link(&msg->argv.create_link); |
| 204 | break; |
| 205 | case TIPC_LINK_SUBSCRIBE: |
| 206 | { |
| 207 | struct subscr_data *sub; |
| 208 | |
| 209 | if (mng.link_subscriptions > 64) |
| 210 | break; |
Robert P. J. Day | 5cbded5 | 2006-12-13 00:35:56 -0800 | [diff] [blame] | 211 | sub = kmalloc(sizeof(*sub), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 212 | GFP_ATOMIC); |
| 213 | if (sub == NULL) { |
| 214 | warn("Memory squeeze; dropped remote link subscription\n"); |
| 215 | break; |
| 216 | } |
| 217 | INIT_LIST_HEAD(&sub->subd_list); |
| 218 | tipc_createport(mng.user_ref, |
| 219 | (void *)sub, |
| 220 | TIPC_HIGH_IMPORTANCE, |
| 221 | 0, |
| 222 | 0, |
| 223 | (tipc_conn_shutdown_event)cfg_linksubscr_cancel, |
| 224 | 0, |
| 225 | 0, |
| 226 | (tipc_conn_msg_event)cfg_linksubscr_cancel, |
| 227 | 0, |
| 228 | &sub->port_ref); |
| 229 | if (!sub->port_ref) { |
| 230 | kfree(sub); |
| 231 | break; |
| 232 | } |
| 233 | memcpy(sub->usr_handle,msg->usr_handle, |
| 234 | sizeof(sub->usr_handle)); |
| 235 | sub->domain = msg->argv.domain; |
| 236 | list_add_tail(&sub->subd_list, &mng.link_subscribers); |
| 237 | tipc_connect2port(sub->port_ref, orig); |
| 238 | rmsg.retval = TIPC_OK; |
| 239 | tipc_send(sub->port_ref, 2u, msg_sect); |
| 240 | mng.link_subscriptions++; |
| 241 | return; |
| 242 | } |
| 243 | default: |
| 244 | rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig); |
| 245 | } |
| 246 | exit: |
| 247 | rmsg.result_len = htonl(msg_sect[1].iov_len); |
| 248 | rmsg.retval = htonl(rv); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 249 | tipc_cfg_respond(msg_sect, 2u, orig); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 250 | } |
| 251 | #endif |
| 252 | |
| 253 | static struct sk_buff *cfg_enable_bearer(void) |
| 254 | { |
| 255 | struct tipc_bearer_config *args; |
| 256 | |
| 257 | 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] | 258 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 259 | |
| 260 | args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area); |
| 261 | if (tipc_enable_bearer(args->name, |
| 262 | ntohl(args->detect_scope), |
| 263 | ntohl(args->priority))) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 264 | return tipc_cfg_reply_error_string("unable to enable bearer"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 265 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 266 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | static struct sk_buff *cfg_disable_bearer(void) |
| 270 | { |
| 271 | 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] | 272 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 273 | |
| 274 | if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area))) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 275 | return tipc_cfg_reply_error_string("unable to disable bearer"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 276 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 277 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | static struct sk_buff *cfg_set_own_addr(void) |
| 281 | { |
| 282 | u32 addr; |
| 283 | |
| 284 | 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] | 285 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 286 | |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 287 | addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 288 | if (addr == tipc_own_addr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 289 | return tipc_cfg_reply_none(); |
| 290 | if (!tipc_addr_node_valid(addr)) |
| 291 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 292 | " (node address)"); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 293 | if (tipc_mode == TIPC_NET_MODE) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 294 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 295 | " (cannot change node address once assigned)"); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 296 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 297 | /* |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 298 | * Must release all spinlocks before calling start_net() because |
| 299 | * Linux version of TIPC calls eth_media_start() which calls |
| 300 | * register_netdevice_notifier() which may block! |
| 301 | * |
| 302 | * Temporarily releasing the lock should be harmless for non-Linux TIPC, |
| 303 | * but Linux version of eth_media_start() should really be reworked |
| 304 | * so that it can be called with spinlocks held. |
| 305 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 306 | |
| 307 | spin_unlock_bh(&config_lock); |
Allan Stephens | 0319437 | 2008-05-21 14:55:04 -0700 | [diff] [blame] | 308 | tipc_core_start_net(addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 309 | spin_lock_bh(&config_lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 310 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static struct sk_buff *cfg_set_remote_mng(void) |
| 314 | { |
| 315 | u32 value; |
| 316 | |
| 317 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 318 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 319 | |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 320 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 321 | tipc_remote_management = (value != 0); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 322 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static struct sk_buff *cfg_set_max_publications(void) |
| 326 | { |
| 327 | u32 value; |
| 328 | |
| 329 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 330 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 331 | |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 332 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 333 | if (value != delimit(value, 1, 65535)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 334 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 335 | " (max publications must be 1-65535)"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 336 | tipc_max_publications = value; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 337 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static struct sk_buff *cfg_set_max_subscriptions(void) |
| 341 | { |
| 342 | u32 value; |
| 343 | |
| 344 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 345 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 347 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 348 | if (value != delimit(value, 1, 65535)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 349 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 350 | " (max subscriptions must be 1-65535"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | tipc_max_subscriptions = value; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 352 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | static struct sk_buff *cfg_set_max_ports(void) |
| 356 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 357 | u32 value; |
| 358 | |
| 359 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 360 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 361 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 362 | if (value == tipc_max_ports) |
| 363 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 364 | if (value != delimit(value, 127, 65535)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 365 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 366 | " (max ports must be 127-65535)"); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 367 | if (tipc_mode != TIPC_NOT_RUNNING) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 368 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 369 | " (cannot change max ports while TIPC is active)"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 370 | tipc_max_ports = value; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 371 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | static struct sk_buff *cfg_set_max_zones(void) |
| 375 | { |
| 376 | u32 value; |
| 377 | |
| 378 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 379 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 380 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 381 | if (value == tipc_max_zones) |
| 382 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 383 | if (value != delimit(value, 1, 255)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 384 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 385 | " (max zones must be 1-255)"); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 386 | if (tipc_mode == TIPC_NET_MODE) |
| 387 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 388 | " (cannot change max zones once TIPC has joined a network)"); |
| 389 | tipc_max_zones = value; |
| 390 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | static struct sk_buff *cfg_set_max_clusters(void) |
| 394 | { |
| 395 | u32 value; |
| 396 | |
| 397 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 398 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 399 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 400 | if (value != delimit(value, 1, 1)) |
| 401 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 402 | " (max clusters fixed at 1)"); |
| 403 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | static struct sk_buff *cfg_set_max_nodes(void) |
| 407 | { |
| 408 | u32 value; |
| 409 | |
| 410 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 411 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 412 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 413 | if (value == tipc_max_nodes) |
| 414 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 415 | if (value != delimit(value, 8, 2047)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 416 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 417 | " (max nodes must be 8-2047)"); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 418 | if (tipc_mode == TIPC_NET_MODE) |
| 419 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 420 | " (cannot change max nodes once TIPC has joined a network)"); |
| 421 | tipc_max_nodes = value; |
| 422 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | static struct sk_buff *cfg_set_max_slaves(void) |
| 426 | { |
| 427 | u32 value; |
| 428 | |
| 429 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 430 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 431 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 432 | if (value != 0) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 433 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 434 | " (max secondary nodes fixed at 0)"); |
| 435 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | static struct sk_buff *cfg_set_netid(void) |
| 439 | { |
| 440 | u32 value; |
| 441 | |
| 442 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 443 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Al Viro | 3e6c8cd | 2006-11-08 00:19:09 -0800 | [diff] [blame] | 444 | value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 445 | if (value == tipc_net_id) |
| 446 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 447 | if (value != delimit(value, 1, 9999)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 448 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE |
| 449 | " (network id must be 1-9999)"); |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 450 | if (tipc_mode == TIPC_NET_MODE) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 451 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
Allan Stephens | e100ae9 | 2006-06-25 23:51:08 -0700 | [diff] [blame] | 452 | " (cannot change network id once TIPC has joined a network)"); |
| 453 | tipc_net_id = value; |
| 454 | return tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 457 | struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area, |
| 458 | int request_space, int reply_headroom) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 459 | { |
| 460 | struct sk_buff *rep_tlv_buf; |
| 461 | |
| 462 | spin_lock_bh(&config_lock); |
| 463 | |
| 464 | /* Save request and reply details in a well-known location */ |
| 465 | |
| 466 | req_tlv_area = request_area; |
| 467 | req_tlv_space = request_space; |
| 468 | rep_headroom = reply_headroom; |
| 469 | |
| 470 | /* Check command authorization */ |
| 471 | |
| 472 | if (likely(orig_node == tipc_own_addr)) { |
| 473 | /* command is permitted */ |
| 474 | } else if (cmd >= 0x8000) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 475 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 476 | " (cannot be done remotely)"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 477 | goto exit; |
| 478 | } else if (!tipc_remote_management) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 479 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 480 | goto exit; |
| 481 | } |
| 482 | else if (cmd >= 0x4000) { |
| 483 | u32 domain = 0; |
| 484 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 485 | if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) || |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 486 | (domain != orig_node)) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 487 | 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] | 488 | goto exit; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | /* Call appropriate processing routine */ |
| 493 | |
| 494 | switch (cmd) { |
| 495 | case TIPC_CMD_NOOP: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 496 | rep_tlv_buf = tipc_cfg_reply_none(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 497 | break; |
| 498 | case TIPC_CMD_GET_NODES: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 499 | 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] | 500 | break; |
| 501 | case TIPC_CMD_GET_LINKS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 502 | 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] | 503 | break; |
| 504 | case TIPC_CMD_SHOW_LINK_STATS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 505 | 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] | 506 | break; |
| 507 | case TIPC_CMD_RESET_LINK_STATS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 508 | 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] | 509 | break; |
| 510 | case TIPC_CMD_SHOW_NAME_TABLE: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 511 | rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 512 | break; |
| 513 | case TIPC_CMD_GET_BEARER_NAMES: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 514 | rep_tlv_buf = tipc_bearer_get_names(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 515 | break; |
| 516 | case TIPC_CMD_GET_MEDIA_NAMES: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 517 | rep_tlv_buf = tipc_media_get_names(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 518 | break; |
| 519 | case TIPC_CMD_SHOW_PORTS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 520 | rep_tlv_buf = tipc_port_get_ports(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 521 | break; |
| 522 | #if 0 |
| 523 | case TIPC_CMD_SHOW_PORT_STATS: |
| 524 | rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space); |
| 525 | break; |
| 526 | case TIPC_CMD_RESET_PORT_STATS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 527 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 528 | break; |
| 529 | #endif |
| 530 | case TIPC_CMD_SET_LOG_SIZE: |
Allan Stephens | 025adbe | 2008-05-05 01:20:04 -0700 | [diff] [blame] | 531 | 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] | 532 | break; |
| 533 | case TIPC_CMD_DUMP_LOG: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 534 | rep_tlv_buf = tipc_log_dump(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 535 | break; |
| 536 | case TIPC_CMD_SET_LINK_TOL: |
| 537 | case TIPC_CMD_SET_LINK_PRI: |
| 538 | case TIPC_CMD_SET_LINK_WINDOW: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 539 | 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] | 540 | break; |
| 541 | case TIPC_CMD_ENABLE_BEARER: |
| 542 | rep_tlv_buf = cfg_enable_bearer(); |
| 543 | break; |
| 544 | case TIPC_CMD_DISABLE_BEARER: |
| 545 | rep_tlv_buf = cfg_disable_bearer(); |
| 546 | break; |
| 547 | case TIPC_CMD_SET_NODE_ADDR: |
| 548 | rep_tlv_buf = cfg_set_own_addr(); |
| 549 | break; |
| 550 | case TIPC_CMD_SET_REMOTE_MNG: |
| 551 | rep_tlv_buf = cfg_set_remote_mng(); |
| 552 | break; |
| 553 | case TIPC_CMD_SET_MAX_PORTS: |
| 554 | rep_tlv_buf = cfg_set_max_ports(); |
| 555 | break; |
| 556 | case TIPC_CMD_SET_MAX_PUBL: |
| 557 | rep_tlv_buf = cfg_set_max_publications(); |
| 558 | break; |
| 559 | case TIPC_CMD_SET_MAX_SUBSCR: |
| 560 | rep_tlv_buf = cfg_set_max_subscriptions(); |
| 561 | break; |
| 562 | case TIPC_CMD_SET_MAX_ZONES: |
| 563 | rep_tlv_buf = cfg_set_max_zones(); |
| 564 | break; |
| 565 | case TIPC_CMD_SET_MAX_CLUSTERS: |
| 566 | rep_tlv_buf = cfg_set_max_clusters(); |
| 567 | break; |
| 568 | case TIPC_CMD_SET_MAX_NODES: |
| 569 | rep_tlv_buf = cfg_set_max_nodes(); |
| 570 | break; |
| 571 | case TIPC_CMD_SET_MAX_SLAVES: |
| 572 | rep_tlv_buf = cfg_set_max_slaves(); |
| 573 | break; |
| 574 | case TIPC_CMD_SET_NETID: |
| 575 | rep_tlv_buf = cfg_set_netid(); |
| 576 | break; |
| 577 | case TIPC_CMD_GET_REMOTE_MNG: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 578 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 579 | break; |
| 580 | case TIPC_CMD_GET_MAX_PORTS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 581 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 582 | break; |
| 583 | case TIPC_CMD_GET_MAX_PUBL: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 584 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 585 | break; |
| 586 | case TIPC_CMD_GET_MAX_SUBSCR: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 587 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 588 | break; |
| 589 | case TIPC_CMD_GET_MAX_ZONES: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 590 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 591 | break; |
| 592 | case TIPC_CMD_GET_MAX_CLUSTERS: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 593 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 594 | break; |
| 595 | case TIPC_CMD_GET_MAX_NODES: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 596 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 597 | break; |
| 598 | case TIPC_CMD_GET_MAX_SLAVES: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 599 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 600 | break; |
| 601 | case TIPC_CMD_GET_NETID: |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 602 | rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 603 | break; |
Allan Stephens | 59f0c45 | 2008-05-21 14:52:30 -0700 | [diff] [blame] | 604 | case TIPC_CMD_NOT_NET_ADMIN: |
| 605 | rep_tlv_buf = |
| 606 | tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN); |
| 607 | break; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 608 | default: |
Allan Stephens | 53cfd1e | 2006-10-16 22:00:56 -0700 | [diff] [blame] | 609 | rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
| 610 | " (unknown command)"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 611 | break; |
| 612 | } |
| 613 | |
| 614 | /* Return reply buffer */ |
| 615 | exit: |
| 616 | spin_unlock_bh(&config_lock); |
| 617 | return rep_tlv_buf; |
| 618 | } |
| 619 | |
| 620 | static void cfg_named_msg_event(void *userdata, |
| 621 | u32 port_ref, |
| 622 | struct sk_buff **buf, |
| 623 | const unchar *msg, |
| 624 | u32 size, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 625 | u32 importance, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 626 | struct tipc_portid const *orig, |
| 627 | struct tipc_name_seq const *dest) |
| 628 | { |
| 629 | struct tipc_cfg_msg_hdr *req_hdr; |
| 630 | struct tipc_cfg_msg_hdr *rep_hdr; |
| 631 | struct sk_buff *rep_buf; |
| 632 | |
| 633 | /* Validate configuration message header (ignore invalid message) */ |
| 634 | |
| 635 | req_hdr = (struct tipc_cfg_msg_hdr *)msg; |
| 636 | if ((size < sizeof(*req_hdr)) || |
| 637 | (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) || |
| 638 | (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 639 | warn("Invalid configuration message discarded\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 640 | return; |
| 641 | } |
| 642 | |
| 643 | /* Generate reply for request (if can't, return request) */ |
| 644 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 645 | rep_buf = tipc_cfg_do_cmd(orig->node, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 646 | ntohs(req_hdr->tcm_type), |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 647 | msg + sizeof(*req_hdr), |
| 648 | size - sizeof(*req_hdr), |
| 649 | BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 650 | if (rep_buf) { |
| 651 | skb_push(rep_buf, sizeof(*rep_hdr)); |
| 652 | rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data; |
| 653 | memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr)); |
| 654 | rep_hdr->tcm_len = htonl(rep_buf->len); |
| 655 | rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST); |
| 656 | } else { |
| 657 | rep_buf = *buf; |
| 658 | *buf = NULL; |
| 659 | } |
| 660 | |
| 661 | /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */ |
| 662 | tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len); |
| 663 | } |
| 664 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 665 | int tipc_cfg_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 666 | { |
| 667 | struct tipc_name_seq seq; |
| 668 | int res; |
| 669 | |
| 670 | memset(&mng, 0, sizeof(mng)); |
| 671 | INIT_LIST_HEAD(&mng.link_subscribers); |
| 672 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 673 | res = tipc_attach(&mng.user_ref, NULL, NULL); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 674 | if (res) |
| 675 | goto failed; |
| 676 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 677 | res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 678 | 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 Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 686 | res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 687 | if (res) |
| 688 | goto failed; |
| 689 | |
| 690 | return 0; |
| 691 | |
| 692 | failed: |
| 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 Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 699 | void tipc_cfg_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 700 | { |
| 701 | if (mng.user_ref) { |
| 702 | tipc_detach(mng.user_ref); |
| 703 | mng.user_ref = 0; |
| 704 | } |
| 705 | } |