config.c 20 KB

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