config.c 19.0 KB
Newer Older
P
Per Liden 已提交
1 2 3
/*
 * net/tipc/config.c: TIPC configuration management code
 * 
P
Per Liden 已提交
4
 * Copyright (c) 2002-2006, Ericsson AB
P
Per Liden 已提交
5 6 7
 * Copyright (c) 2004-2005, Wind River Systems
 * All rights reserved.
 *
P
Per Liden 已提交
8
 * Redistribution and use in source and binary forms, with or without
P
Per Liden 已提交
9 10
 * modification, are permitted provided that the following conditions are met:
 *
P
Per Liden 已提交
11 12 13 14 15 16 17 18
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the names of the copyright holders nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
P
Per Liden 已提交
19
 *
P
Per Liden 已提交
20 21 22 23 24 25 26 27 28 29 30 31 32 33
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
P
Per Liden 已提交
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include "core.h"
#include "dbg.h"
#include "bearer.h"
#include "port.h"
#include "link.h"
#include "zone.h"
#include "addr.h"
#include "name_table.h"
#include "node.h"
#include "config.h"
#include "discover.h"

struct subscr_data {
	char usr_handle[8];
	u32 domain;
	u32 port_ref;
	struct list_head subd_list;
};

struct manager {
	u32 user_ref;
	u32 port_ref;
	u32 subscr_ref;
	u32 link_subscriptions;
	struct list_head link_subscribers;
};

static struct manager mng = { 0};

static spinlock_t config_lock = SPIN_LOCK_UNLOCKED;

static const void *req_tlv_area;	/* request message TLV area */
static int req_tlv_space;		/* request message TLV area size */
static int rep_headroom;		/* reply message headroom to use */


73
void tipc_cfg_link_event(u32 addr, char *name, int up)
P
Per Liden 已提交
74 75 76 77 78
{
	/* TIPC DOESN'T HANDLE LINK EVENT SUBSCRIPTIONS AT THE MOMENT */
}


79
struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
P
Per Liden 已提交
80 81 82 83 84 85 86 87 88
{
	struct sk_buff *buf;

	buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
	if (buf)
		skb_reserve(buf, rep_headroom);
	return buf;
}

89 90
int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type, 
			void *tlv_data, int tlv_data_size)
P
Per Liden 已提交
91 92 93 94 95
{
	struct tlv_desc *tlv = (struct tlv_desc *)buf->tail;
	int new_tlv_space = TLV_SPACE(tlv_data_size);

	if (skb_tailroom(buf) < new_tlv_space) {
96
		dbg("tipc_cfg_append_tlv unable to append TLV\n");
P
Per Liden 已提交
97 98 99 100 101 102 103 104 105 106
		return 0;
	}
	skb_put(buf, new_tlv_space);
	tlv->tlv_type = htons(tlv_type);
	tlv->tlv_len  = htons(TLV_LENGTH(tlv_data_size));
	if (tlv_data_size && tlv_data)
		memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
	return 1;
}

107
struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
P
Per Liden 已提交
108 109 110 111
{
	struct sk_buff *buf;
	u32 value_net;

112
	buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
P
Per Liden 已提交
113 114
	if (buf) {
		value_net = htonl(value);
115 116
		tipc_cfg_append_tlv(buf, tlv_type, &value_net, 
				    sizeof(value_net));
P
Per Liden 已提交
117 118 119 120
	}
	return buf;
}

121
struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
P
Per Liden 已提交
122 123 124 125
{
	struct sk_buff *buf;
	int string_len = strlen(string) + 1;

126
	buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
P
Per Liden 已提交
127
	if (buf)
128
		tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
P
Per Liden 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
	return buf;
}




#if 0

/* Now obsolete code for handling commands not yet implemented the new way */

int tipc_cfg_cmd(const struct tipc_cmd_msg * msg,
		 char *data,
		 u32 sz,
		 u32 *ret_size,
		 struct tipc_portid *orig)
{
	int rv = -EINVAL;
	u32 cmd = msg->cmd;

	*ret_size = 0;
	switch (cmd) {
	case TIPC_REMOVE_LINK:
	case TIPC_CMD_BLOCK_LINK:
	case TIPC_CMD_UNBLOCK_LINK:
		if (!cfg_check_connection(orig))
			rv = link_control(msg->argv.link_name, msg->cmd, 0);
		break;
	case TIPC_ESTABLISH:
		{
			int connected;

			tipc_isconnected(mng.conn_port_ref, &connected);
			if (connected || !orig) {
				rv = TIPC_FAILURE;
				break;
			}
			rv = tipc_connect2port(mng.conn_port_ref, orig);
			if (rv == TIPC_OK)
				orig = 0;
			break;
		}
	case TIPC_GET_PEER_ADDRESS:
		*ret_size = link_peer_addr(msg->argv.link_name, data, sz);
		break;
	case TIPC_GET_ROUTES:
		rv = TIPC_OK;
		break;
	default: {}
	}
	if (*ret_size)
		rv = TIPC_OK;
	return rv;
}

static void cfg_cmd_event(struct tipc_cmd_msg *msg,
			  char *data,
			  u32 sz,        
			  struct tipc_portid const *orig)
{
	int rv = -EINVAL;
	struct tipc_cmd_result_msg rmsg;
	struct iovec msg_sect[2];
	int *arg;

	msg->cmd = ntohl(msg->cmd);

	cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect, 
			    data, 0);
	if (ntohl(msg->magic) != TIPC_MAGIC)
		goto exit;

	switch (msg->cmd) {
	case TIPC_CREATE_LINK:
		if (!cfg_check_connection(orig))
			rv = disc_create_link(&msg->argv.create_link);
		break;
	case TIPC_LINK_SUBSCRIBE:
		{
			struct subscr_data *sub;

			if (mng.link_subscriptions > 64)
				break;
			sub = (struct subscr_data *)kmalloc(sizeof(*sub),
							    GFP_ATOMIC);
			if (sub == NULL) {
				warn("Memory squeeze; dropped remote link subscription\n");
				break;
			}
			INIT_LIST_HEAD(&sub->subd_list);
			tipc_createport(mng.user_ref,
					(void *)sub,
					TIPC_HIGH_IMPORTANCE,
					0,
					0,
					(tipc_conn_shutdown_event)cfg_linksubscr_cancel,
					0,
					0,
					(tipc_conn_msg_event)cfg_linksubscr_cancel,
					0,
					&sub->port_ref);
			if (!sub->port_ref) {
				kfree(sub);
				break;
			}
			memcpy(sub->usr_handle,msg->usr_handle,
			       sizeof(sub->usr_handle));
			sub->domain = msg->argv.domain;
			list_add_tail(&sub->subd_list, &mng.link_subscribers);
			tipc_connect2port(sub->port_ref, orig);
			rmsg.retval = TIPC_OK;
			tipc_send(sub->port_ref, 2u, msg_sect);
			mng.link_subscriptions++;
			return;
		}
	default:
		rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig);
	}
	exit:
	rmsg.result_len = htonl(msg_sect[1].iov_len);
	rmsg.retval = htonl(rv);
249
	tipc_cfg_respond(msg_sect, 2u, orig);
P
Per Liden 已提交
250 251 252 253 254 255 256 257
}
#endif

static struct sk_buff *cfg_enable_bearer(void)
{
	struct tipc_bearer_config *args;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
258
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
259 260 261 262 263

	args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
	if (tipc_enable_bearer(args->name,
			       ntohl(args->detect_scope),
			       ntohl(args->priority)))
264
		return tipc_cfg_reply_error_string("unable to enable bearer");
P
Per Liden 已提交
265

266
	return tipc_cfg_reply_none();
P
Per Liden 已提交
267 268 269 270 271
}

static struct sk_buff *cfg_disable_bearer(void)
{
	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
272
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
273 274

	if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
275
		return tipc_cfg_reply_error_string("unable to disable bearer");
P
Per Liden 已提交
276

277
	return tipc_cfg_reply_none();
P
Per Liden 已提交
278 279 280 281 282 283 284
}

static struct sk_buff *cfg_set_own_addr(void)
{
	u32 addr;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
285
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
286 287 288 289

	addr = *(u32 *)TLV_DATA(req_tlv_area);
	addr = ntohl(addr);
	if (addr == tipc_own_addr)
290 291 292 293
		return tipc_cfg_reply_none();
	if (!tipc_addr_node_valid(addr))
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (node address)");
P
Per Liden 已提交
294
	if (tipc_own_addr)
295 296
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
						   " (cannot change node address once assigned)");
P
Per Liden 已提交
297 298

	spin_unlock_bh(&config_lock);
299
	tipc_core_stop_net();
P
Per Liden 已提交
300
	tipc_own_addr = addr;
301
	tipc_core_start_net();
P
Per Liden 已提交
302
	spin_lock_bh(&config_lock);
303
	return tipc_cfg_reply_none();
P
Per Liden 已提交
304 305 306 307 308 309 310
}

static struct sk_buff *cfg_set_remote_mng(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
311
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
312 313 314 315

	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	tipc_remote_management = (value != 0);
316
	return tipc_cfg_reply_none();
P
Per Liden 已提交
317 318 319 320 321 322 323
}

static struct sk_buff *cfg_set_max_publications(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
324
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
325 326 327 328

	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != delimit(value, 1, 65535))
329 330
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (max publications must be 1-65535)");
P
Per Liden 已提交
331
	tipc_max_publications = value;
332
	return tipc_cfg_reply_none();
P
Per Liden 已提交
333 334 335 336 337 338 339
}

static struct sk_buff *cfg_set_max_subscriptions(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
340
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
341 342 343 344

	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != delimit(value, 1, 65535))
345 346
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (max subscriptions must be 1-65535");
P
Per Liden 已提交
347
	tipc_max_subscriptions = value;
348
	return tipc_cfg_reply_none();
P
Per Liden 已提交
349 350 351 352 353 354 355 356
}

static struct sk_buff *cfg_set_max_ports(void)
{
	int orig_mode;
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
357
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
358 359 360
	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != delimit(value, 127, 65535))
361 362
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (max ports must be 127-65535)");
P
Per Liden 已提交
363 364

	if (value == tipc_max_ports)
365
		return tipc_cfg_reply_none();
P
Per Liden 已提交
366 367

	if (atomic_read(&tipc_user_count) > 2)
368 369
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
						   " (cannot change max ports while TIPC users exist)");
P
Per Liden 已提交
370 371 372 373

	spin_unlock_bh(&config_lock);
	orig_mode = tipc_get_mode();
	if (orig_mode == TIPC_NET_MODE)
374 375
		tipc_core_stop_net();
	tipc_core_stop();
P
Per Liden 已提交
376
	tipc_max_ports = value;
377
	tipc_core_start();
P
Per Liden 已提交
378
	if (orig_mode == TIPC_NET_MODE)
379
		tipc_core_start_net();
P
Per Liden 已提交
380
	spin_lock_bh(&config_lock);
381
	return tipc_cfg_reply_none();
P
Per Liden 已提交
382 383 384 385 386 387 388 389 390
}

static struct sk_buff *set_net_max(int value, int *parameter)
{
	int orig_mode;

	if (value != *parameter) {
		orig_mode = tipc_get_mode();
		if (orig_mode == TIPC_NET_MODE)
391
			tipc_core_stop_net();
P
Per Liden 已提交
392 393
		*parameter = value;
		if (orig_mode == TIPC_NET_MODE)
394
			tipc_core_start_net();
P
Per Liden 已提交
395 396
	}

397
	return tipc_cfg_reply_none();
P
Per Liden 已提交
398 399 400 401 402 403 404
}

static struct sk_buff *cfg_set_max_zones(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
405
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
406 407 408
	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != delimit(value, 1, 255))
409 410
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (max zones must be 1-255)");
P
Per Liden 已提交
411 412 413 414 415 416 417 418
	return set_net_max(value, &tipc_max_zones);
}

static struct sk_buff *cfg_set_max_clusters(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
419
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
420 421 422
	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != 1)
423 424 425
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
						   " (max clusters fixed at 1)");
	return tipc_cfg_reply_none();
P
Per Liden 已提交
426 427 428 429 430 431 432
}

static struct sk_buff *cfg_set_max_nodes(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
433
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
434 435 436
	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != delimit(value, 8, 2047))
437 438
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (max nodes must be 8-2047)");
P
Per Liden 已提交
439 440 441 442 443 444 445 446
	return set_net_max(value, &tipc_max_nodes);
}

static struct sk_buff *cfg_set_max_slaves(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
447
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
448 449 450
	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != 0)
451 452 453
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
						   " (max secondary nodes fixed at 0)");
	return tipc_cfg_reply_none();
P
Per Liden 已提交
454 455 456 457 458 459 460
}

static struct sk_buff *cfg_set_netid(void)
{
	u32 value;

	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
461
		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
P
Per Liden 已提交
462 463 464
	value = *(u32 *)TLV_DATA(req_tlv_area);
	value = ntohl(value);
	if (value != delimit(value, 1, 9999))
465 466
		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
						   " (network id must be 1-9999)");
P
Per Liden 已提交
467 468

	if (tipc_own_addr)
469 470
		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
						   " (cannot change network id once part of network)");
P
Per Liden 已提交
471 472 473 474
	
	return set_net_max(value, &tipc_net_id);
}

475 476
struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
				int request_space, int reply_headroom)
P
Per Liden 已提交
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492
{
	struct sk_buff *rep_tlv_buf;

	spin_lock_bh(&config_lock);

	/* Save request and reply details in a well-known location */

	req_tlv_area = request_area;
	req_tlv_space = request_space;
	rep_headroom = reply_headroom;

	/* Check command authorization */

	if (likely(orig_node == tipc_own_addr)) {
		/* command is permitted */
	} else if (cmd >= 0x8000) {
493 494
		rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
							  " (cannot be done remotely)");
P
Per Liden 已提交
495 496
		goto exit;
	} else if (!tipc_remote_management) {
497
		rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
P
Per Liden 已提交
498 499 500 501 502
		goto exit;
	}
	else if (cmd >= 0x4000) {
		u32 domain = 0;

503
		if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
P
Per Liden 已提交
504
		    (domain != orig_node)) {
505
			rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
P
Per Liden 已提交
506 507 508 509 510 511 512 513
			goto exit;
		}
	}

	/* Call appropriate processing routine */

	switch (cmd) {
	case TIPC_CMD_NOOP:
514
		rep_tlv_buf = tipc_cfg_reply_none();
P
Per Liden 已提交
515 516
		break;
	case TIPC_CMD_GET_NODES:
517
		rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
P
Per Liden 已提交
518 519
		break;
	case TIPC_CMD_GET_LINKS:
520
		rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
P
Per Liden 已提交
521 522
		break;
	case TIPC_CMD_SHOW_LINK_STATS:
523
		rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
P
Per Liden 已提交
524 525
		break;
	case TIPC_CMD_RESET_LINK_STATS:
526
		rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
P
Per Liden 已提交
527 528
		break;
	case TIPC_CMD_SHOW_NAME_TABLE:
529
		rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
P
Per Liden 已提交
530 531
		break;
	case TIPC_CMD_GET_BEARER_NAMES:
532
		rep_tlv_buf = tipc_bearer_get_names();
P
Per Liden 已提交
533 534
		break;
	case TIPC_CMD_GET_MEDIA_NAMES:
535
		rep_tlv_buf = tipc_media_get_names();
P
Per Liden 已提交
536 537
		break;
	case TIPC_CMD_SHOW_PORTS:
538
		rep_tlv_buf = tipc_port_get_ports();
P
Per Liden 已提交
539 540 541 542 543 544
		break;
#if 0
	case TIPC_CMD_SHOW_PORT_STATS:
		rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
		break;
	case TIPC_CMD_RESET_PORT_STATS:
545
		rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
P
Per Liden 已提交
546 547 548
		break;
#endif
	case TIPC_CMD_SET_LOG_SIZE:
549
		rep_tlv_buf = tipc_log_resize(req_tlv_area, req_tlv_space);
P
Per Liden 已提交
550 551
		break;
	case TIPC_CMD_DUMP_LOG:
552
		rep_tlv_buf = tipc_log_dump();
P
Per Liden 已提交
553 554 555 556
		break;
	case TIPC_CMD_SET_LINK_TOL:
	case TIPC_CMD_SET_LINK_PRI:
	case TIPC_CMD_SET_LINK_WINDOW:
557
		rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
P
Per Liden 已提交
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
		break;
	case TIPC_CMD_ENABLE_BEARER:
		rep_tlv_buf = cfg_enable_bearer();
		break;
	case TIPC_CMD_DISABLE_BEARER:
		rep_tlv_buf = cfg_disable_bearer();
		break;
	case TIPC_CMD_SET_NODE_ADDR:
		rep_tlv_buf = cfg_set_own_addr();
		break;
	case TIPC_CMD_SET_REMOTE_MNG:
		rep_tlv_buf = cfg_set_remote_mng();
		break;
	case TIPC_CMD_SET_MAX_PORTS:
		rep_tlv_buf = cfg_set_max_ports();
		break;
	case TIPC_CMD_SET_MAX_PUBL:
		rep_tlv_buf = cfg_set_max_publications();
		break;
	case TIPC_CMD_SET_MAX_SUBSCR:
		rep_tlv_buf = cfg_set_max_subscriptions();
		break;
	case TIPC_CMD_SET_MAX_ZONES:
		rep_tlv_buf = cfg_set_max_zones();
		break;
	case TIPC_CMD_SET_MAX_CLUSTERS:
		rep_tlv_buf = cfg_set_max_clusters();
		break;
	case TIPC_CMD_SET_MAX_NODES:
		rep_tlv_buf = cfg_set_max_nodes();
		break;
	case TIPC_CMD_SET_MAX_SLAVES:
		rep_tlv_buf = cfg_set_max_slaves();
		break;
	case TIPC_CMD_SET_NETID:
		rep_tlv_buf = cfg_set_netid();
		break;
	case TIPC_CMD_GET_REMOTE_MNG:
596
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
P
Per Liden 已提交
597 598
		break;
	case TIPC_CMD_GET_MAX_PORTS:
599
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
P
Per Liden 已提交
600 601
		break;
	case TIPC_CMD_GET_MAX_PUBL:
602
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
P
Per Liden 已提交
603 604
		break;
	case TIPC_CMD_GET_MAX_SUBSCR:
605
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
P
Per Liden 已提交
606 607
		break;
	case TIPC_CMD_GET_MAX_ZONES:
608
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
P
Per Liden 已提交
609 610
		break;
	case TIPC_CMD_GET_MAX_CLUSTERS:
611
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
P
Per Liden 已提交
612 613
		break;
	case TIPC_CMD_GET_MAX_NODES:
614
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
P
Per Liden 已提交
615 616
		break;
	case TIPC_CMD_GET_MAX_SLAVES:
617
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
P
Per Liden 已提交
618 619
		break;
	case TIPC_CMD_GET_NETID:
620
		rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
P
Per Liden 已提交
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657
		break;
	default:
		rep_tlv_buf = NULL;
		break;
	}

	/* Return reply buffer */
exit:
	spin_unlock_bh(&config_lock);
	return rep_tlv_buf;
}

static void cfg_named_msg_event(void *userdata,
				u32 port_ref,
				struct sk_buff **buf,
				const unchar *msg,
				u32 size,
				u32 importance, 
				struct tipc_portid const *orig,
				struct tipc_name_seq const *dest)
{
	struct tipc_cfg_msg_hdr *req_hdr;
	struct tipc_cfg_msg_hdr *rep_hdr;
	struct sk_buff *rep_buf;

	/* Validate configuration message header (ignore invalid message) */

	req_hdr = (struct tipc_cfg_msg_hdr *)msg;
	if ((size < sizeof(*req_hdr)) ||
	    (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
	    (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
		warn("discarded invalid configuration message\n");
		return;
	}

	/* Generate reply for request (if can't, return request) */

658 659 660 661 662
	rep_buf = tipc_cfg_do_cmd(orig->node,
				  ntohs(req_hdr->tcm_type), 
				  msg + sizeof(*req_hdr),
				  size - sizeof(*req_hdr),
				  BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
P
Per Liden 已提交
663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
	if (rep_buf) {
		skb_push(rep_buf, sizeof(*rep_hdr));
		rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
		memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
		rep_hdr->tcm_len = htonl(rep_buf->len);
		rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
	} else {
		rep_buf = *buf;
		*buf = NULL;
	}

	/* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
	tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
}

678
int tipc_cfg_init(void)
P
Per Liden 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
{
	struct tipc_name_seq seq;
	int res;

	memset(&mng, 0, sizeof(mng));
	INIT_LIST_HEAD(&mng.link_subscribers);

	res = tipc_attach(&mng.user_ref, 0, 0);
	if (res)
		goto failed;

	res = tipc_createport(mng.user_ref, 0, TIPC_CRITICAL_IMPORTANCE,
			      NULL, NULL, NULL,
			      NULL, cfg_named_msg_event, NULL,
			      NULL, &mng.port_ref);
	if (res)
		goto failed;

	seq.type = TIPC_CFG_SRV;
	seq.lower = seq.upper = tipc_own_addr;
699
	res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
P
Per Liden 已提交
700 701 702 703 704 705 706 707 708 709 710 711
	if (res)
		goto failed;

	return 0;

failed:
	err("Unable to create configuration service\n");
	tipc_detach(mng.user_ref);
	mng.user_ref = 0;
	return res;
}

712
void tipc_cfg_stop(void)
P
Per Liden 已提交
713 714 715 716 717 718
{
	if (mng.user_ref) {
		tipc_detach(mng.user_ref);
		mng.user_ref = 0;
	}
}