config.c 19 KB

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