2 * net/tipc/config.c: TIPC configuration management code
4 * Copyright (c) 2002-2006, Ericsson AB
5 * Copyright (c) 2004-2007, 2010-2013, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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
34 * POSSIBILITY OF SUCH DAMAGE.
39 #include "name_table.h"
43 #define REPLY_TRUNCATED "<truncated>\n"
45 static const void *req_tlv_area; /* request message TLV area */
46 static int req_tlv_space; /* request message TLV area size */
47 static int rep_headroom; /* reply message headroom to use */
49 struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
53 buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
55 skb_reserve(buf, rep_headroom);
59 int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
60 void *tlv_data, int tlv_data_size)
62 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
63 int new_tlv_space = TLV_SPACE(tlv_data_size);
65 if (skb_tailroom(buf) < new_tlv_space)
67 skb_put(buf, new_tlv_space);
68 tlv->tlv_type = htons(tlv_type);
69 tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
70 if (tlv_data_size && tlv_data)
71 memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
75 struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
78 int string_len = strlen(string) + 1;
80 buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
82 tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
86 struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
87 const void *request_area, int request_space,
90 struct sk_buff *rep_tlv_buf;
94 /* Save request and reply details in a well-known location */
95 req_tlv_area = request_area;
96 req_tlv_space = request_space;
97 rep_headroom = reply_headroom;
99 /* Check command authorization */
100 if (likely(in_own_node(net, orig_node))) {
101 /* command is permitted */
103 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
104 " (cannot be done remotely)");
108 /* Call appropriate processing routine */
111 rep_tlv_buf = tipc_cfg_reply_none();
113 case TIPC_CMD_NOT_NET_ADMIN:
115 tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
117 case TIPC_CMD_SET_MAX_ZONES:
118 case TIPC_CMD_GET_MAX_ZONES:
119 case TIPC_CMD_SET_MAX_SLAVES:
120 case TIPC_CMD_GET_MAX_SLAVES:
121 case TIPC_CMD_SET_MAX_CLUSTERS:
122 case TIPC_CMD_GET_MAX_CLUSTERS:
123 case TIPC_CMD_SET_MAX_NODES:
124 case TIPC_CMD_GET_MAX_NODES:
125 case TIPC_CMD_SET_MAX_SUBSCR:
126 case TIPC_CMD_GET_MAX_SUBSCR:
127 case TIPC_CMD_SET_MAX_PUBL:
128 case TIPC_CMD_GET_MAX_PUBL:
129 case TIPC_CMD_SET_LOG_SIZE:
130 case TIPC_CMD_SET_REMOTE_MNG:
131 case TIPC_CMD_GET_REMOTE_MNG:
132 case TIPC_CMD_DUMP_LOG:
133 case TIPC_CMD_SET_MAX_PORTS:
134 case TIPC_CMD_GET_MAX_PORTS:
135 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
136 " (obsolete command)");
139 rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
140 " (unknown command)");
144 WARN_ON(rep_tlv_buf->len > TLV_SPACE(ULTRA_STRING_MAX_LEN));
146 /* Append an error message if we cannot return all requested data */
147 if (rep_tlv_buf->len == TLV_SPACE(ULTRA_STRING_MAX_LEN)) {
148 if (*(rep_tlv_buf->data + ULTRA_STRING_MAX_LEN) != '\0')
149 sprintf(rep_tlv_buf->data + rep_tlv_buf->len -
150 sizeof(REPLY_TRUNCATED) - 1, REPLY_TRUNCATED);
153 /* Return reply buffer */