config.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * net/tipc/config.c: TIPC configuration management code
  3. *
  4. * Copyright (c) 2002-2006, Ericsson AB
  5. * Copyright (c) 2004-2006, 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 *)buf->tail;
  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. tipc_own_addr = addr;
  257. /*
  258. * Must release all spinlocks before calling start_net() because
  259. * Linux version of TIPC calls eth_media_start() which calls
  260. * register_netdevice_notifier() which may block!
  261. *
  262. * Temporarily releasing the lock should be harmless for non-Linux TIPC,
  263. * but Linux version of eth_media_start() should really be reworked
  264. * so that it can be called with spinlocks held.
  265. */
  266. spin_unlock_bh(&config_lock);
  267. tipc_core_start_net();
  268. spin_lock_bh(&config_lock);
  269. return tipc_cfg_reply_none();
  270. }
  271. static struct sk_buff *cfg_set_remote_mng(void)
  272. {
  273. u32 value;
  274. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  275. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  276. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  277. tipc_remote_management = (value != 0);
  278. return tipc_cfg_reply_none();
  279. }
  280. static struct sk_buff *cfg_set_max_publications(void)
  281. {
  282. u32 value;
  283. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  284. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  285. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  286. if (value != delimit(value, 1, 65535))
  287. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  288. " (max publications must be 1-65535)");
  289. tipc_max_publications = value;
  290. return tipc_cfg_reply_none();
  291. }
  292. static struct sk_buff *cfg_set_max_subscriptions(void)
  293. {
  294. u32 value;
  295. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  296. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  297. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  298. if (value != delimit(value, 1, 65535))
  299. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  300. " (max subscriptions must be 1-65535");
  301. tipc_max_subscriptions = value;
  302. return tipc_cfg_reply_none();
  303. }
  304. static struct sk_buff *cfg_set_max_ports(void)
  305. {
  306. u32 value;
  307. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  308. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  309. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  310. if (value == tipc_max_ports)
  311. return tipc_cfg_reply_none();
  312. if (value != delimit(value, 127, 65535))
  313. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  314. " (max ports must be 127-65535)");
  315. if (tipc_mode != TIPC_NOT_RUNNING)
  316. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  317. " (cannot change max ports while TIPC is active)");
  318. tipc_max_ports = value;
  319. return tipc_cfg_reply_none();
  320. }
  321. static struct sk_buff *cfg_set_max_zones(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 == tipc_max_zones)
  328. return tipc_cfg_reply_none();
  329. if (value != delimit(value, 1, 255))
  330. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  331. " (max zones must be 1-255)");
  332. if (tipc_mode == TIPC_NET_MODE)
  333. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  334. " (cannot change max zones once TIPC has joined a network)");
  335. tipc_max_zones = value;
  336. return tipc_cfg_reply_none();
  337. }
  338. static struct sk_buff *cfg_set_max_clusters(void)
  339. {
  340. u32 value;
  341. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  342. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  343. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  344. if (value != delimit(value, 1, 1))
  345. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  346. " (max clusters fixed at 1)");
  347. return tipc_cfg_reply_none();
  348. }
  349. static struct sk_buff *cfg_set_max_nodes(void)
  350. {
  351. u32 value;
  352. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  353. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  354. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  355. if (value == tipc_max_nodes)
  356. return tipc_cfg_reply_none();
  357. if (value != delimit(value, 8, 2047))
  358. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  359. " (max nodes must be 8-2047)");
  360. if (tipc_mode == TIPC_NET_MODE)
  361. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  362. " (cannot change max nodes once TIPC has joined a network)");
  363. tipc_max_nodes = value;
  364. return tipc_cfg_reply_none();
  365. }
  366. static struct sk_buff *cfg_set_max_slaves(void)
  367. {
  368. u32 value;
  369. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  370. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  371. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  372. if (value != 0)
  373. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  374. " (max secondary nodes fixed at 0)");
  375. return tipc_cfg_reply_none();
  376. }
  377. static struct sk_buff *cfg_set_netid(void)
  378. {
  379. u32 value;
  380. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  381. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  382. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  383. if (value == tipc_net_id)
  384. return tipc_cfg_reply_none();
  385. if (value != delimit(value, 1, 9999))
  386. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  387. " (network id must be 1-9999)");
  388. if (tipc_mode == TIPC_NET_MODE)
  389. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  390. " (cannot change network id once TIPC has joined a network)");
  391. tipc_net_id = value;
  392. return tipc_cfg_reply_none();
  393. }
  394. struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
  395. int request_space, int reply_headroom)
  396. {
  397. struct sk_buff *rep_tlv_buf;
  398. spin_lock_bh(&config_lock);
  399. /* Save request and reply details in a well-known location */
  400. req_tlv_area = request_area;
  401. req_tlv_space = request_space;
  402. rep_headroom = reply_headroom;
  403. /* Check command authorization */
  404. if (likely(orig_node == tipc_own_addr)) {
  405. /* command is permitted */
  406. } else if (cmd >= 0x8000) {
  407. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  408. " (cannot be done remotely)");
  409. goto exit;
  410. } else if (!tipc_remote_management) {
  411. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
  412. goto exit;
  413. }
  414. else if (cmd >= 0x4000) {
  415. u32 domain = 0;
  416. if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
  417. (domain != orig_node)) {
  418. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
  419. goto exit;
  420. }
  421. }
  422. /* Call appropriate processing routine */
  423. switch (cmd) {
  424. case TIPC_CMD_NOOP:
  425. rep_tlv_buf = tipc_cfg_reply_none();
  426. break;
  427. case TIPC_CMD_GET_NODES:
  428. rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
  429. break;
  430. case TIPC_CMD_GET_LINKS:
  431. rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
  432. break;
  433. case TIPC_CMD_SHOW_LINK_STATS:
  434. rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
  435. break;
  436. case TIPC_CMD_RESET_LINK_STATS:
  437. rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
  438. break;
  439. case TIPC_CMD_SHOW_NAME_TABLE:
  440. rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
  441. break;
  442. case TIPC_CMD_GET_BEARER_NAMES:
  443. rep_tlv_buf = tipc_bearer_get_names();
  444. break;
  445. case TIPC_CMD_GET_MEDIA_NAMES:
  446. rep_tlv_buf = tipc_media_get_names();
  447. break;
  448. case TIPC_CMD_SHOW_PORTS:
  449. rep_tlv_buf = tipc_port_get_ports();
  450. break;
  451. #if 0
  452. case TIPC_CMD_SHOW_PORT_STATS:
  453. rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
  454. break;
  455. case TIPC_CMD_RESET_PORT_STATS:
  456. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
  457. break;
  458. #endif
  459. case TIPC_CMD_SET_LOG_SIZE:
  460. rep_tlv_buf = tipc_log_resize(req_tlv_area, req_tlv_space);
  461. break;
  462. case TIPC_CMD_DUMP_LOG:
  463. rep_tlv_buf = tipc_log_dump();
  464. break;
  465. case TIPC_CMD_SET_LINK_TOL:
  466. case TIPC_CMD_SET_LINK_PRI:
  467. case TIPC_CMD_SET_LINK_WINDOW:
  468. rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
  469. break;
  470. case TIPC_CMD_ENABLE_BEARER:
  471. rep_tlv_buf = cfg_enable_bearer();
  472. break;
  473. case TIPC_CMD_DISABLE_BEARER:
  474. rep_tlv_buf = cfg_disable_bearer();
  475. break;
  476. case TIPC_CMD_SET_NODE_ADDR:
  477. rep_tlv_buf = cfg_set_own_addr();
  478. break;
  479. case TIPC_CMD_SET_REMOTE_MNG:
  480. rep_tlv_buf = cfg_set_remote_mng();
  481. break;
  482. case TIPC_CMD_SET_MAX_PORTS:
  483. rep_tlv_buf = cfg_set_max_ports();
  484. break;
  485. case TIPC_CMD_SET_MAX_PUBL:
  486. rep_tlv_buf = cfg_set_max_publications();
  487. break;
  488. case TIPC_CMD_SET_MAX_SUBSCR:
  489. rep_tlv_buf = cfg_set_max_subscriptions();
  490. break;
  491. case TIPC_CMD_SET_MAX_ZONES:
  492. rep_tlv_buf = cfg_set_max_zones();
  493. break;
  494. case TIPC_CMD_SET_MAX_CLUSTERS:
  495. rep_tlv_buf = cfg_set_max_clusters();
  496. break;
  497. case TIPC_CMD_SET_MAX_NODES:
  498. rep_tlv_buf = cfg_set_max_nodes();
  499. break;
  500. case TIPC_CMD_SET_MAX_SLAVES:
  501. rep_tlv_buf = cfg_set_max_slaves();
  502. break;
  503. case TIPC_CMD_SET_NETID:
  504. rep_tlv_buf = cfg_set_netid();
  505. break;
  506. case TIPC_CMD_GET_REMOTE_MNG:
  507. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
  508. break;
  509. case TIPC_CMD_GET_MAX_PORTS:
  510. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
  511. break;
  512. case TIPC_CMD_GET_MAX_PUBL:
  513. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
  514. break;
  515. case TIPC_CMD_GET_MAX_SUBSCR:
  516. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
  517. break;
  518. case TIPC_CMD_GET_MAX_ZONES:
  519. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
  520. break;
  521. case TIPC_CMD_GET_MAX_CLUSTERS:
  522. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
  523. break;
  524. case TIPC_CMD_GET_MAX_NODES:
  525. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
  526. break;
  527. case TIPC_CMD_GET_MAX_SLAVES:
  528. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
  529. break;
  530. case TIPC_CMD_GET_NETID:
  531. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
  532. break;
  533. default:
  534. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  535. " (unknown command)");
  536. break;
  537. }
  538. /* Return reply buffer */
  539. exit:
  540. spin_unlock_bh(&config_lock);
  541. return rep_tlv_buf;
  542. }
  543. static void cfg_named_msg_event(void *userdata,
  544. u32 port_ref,
  545. struct sk_buff **buf,
  546. const unchar *msg,
  547. u32 size,
  548. u32 importance,
  549. struct tipc_portid const *orig,
  550. struct tipc_name_seq const *dest)
  551. {
  552. struct tipc_cfg_msg_hdr *req_hdr;
  553. struct tipc_cfg_msg_hdr *rep_hdr;
  554. struct sk_buff *rep_buf;
  555. /* Validate configuration message header (ignore invalid message) */
  556. req_hdr = (struct tipc_cfg_msg_hdr *)msg;
  557. if ((size < sizeof(*req_hdr)) ||
  558. (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
  559. (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
  560. warn("Invalid configuration message discarded\n");
  561. return;
  562. }
  563. /* Generate reply for request (if can't, return request) */
  564. rep_buf = tipc_cfg_do_cmd(orig->node,
  565. ntohs(req_hdr->tcm_type),
  566. msg + sizeof(*req_hdr),
  567. size - sizeof(*req_hdr),
  568. BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
  569. if (rep_buf) {
  570. skb_push(rep_buf, sizeof(*rep_hdr));
  571. rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
  572. memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
  573. rep_hdr->tcm_len = htonl(rep_buf->len);
  574. rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
  575. } else {
  576. rep_buf = *buf;
  577. *buf = NULL;
  578. }
  579. /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
  580. tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
  581. }
  582. int tipc_cfg_init(void)
  583. {
  584. struct tipc_name_seq seq;
  585. int res;
  586. memset(&mng, 0, sizeof(mng));
  587. INIT_LIST_HEAD(&mng.link_subscribers);
  588. res = tipc_attach(&mng.user_ref, NULL, NULL);
  589. if (res)
  590. goto failed;
  591. res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
  592. NULL, NULL, NULL,
  593. NULL, cfg_named_msg_event, NULL,
  594. NULL, &mng.port_ref);
  595. if (res)
  596. goto failed;
  597. seq.type = TIPC_CFG_SRV;
  598. seq.lower = seq.upper = tipc_own_addr;
  599. res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
  600. if (res)
  601. goto failed;
  602. return 0;
  603. failed:
  604. err("Unable to create configuration service\n");
  605. tipc_detach(mng.user_ref);
  606. mng.user_ref = 0;
  607. return res;
  608. }
  609. void tipc_cfg_stop(void)
  610. {
  611. if (mng.user_ref) {
  612. tipc_detach(mng.user_ref);
  613. mng.user_ref = 0;
  614. }
  615. }