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