config.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * net/tipc/config.c: TIPC configuration management code
  3. *
  4. * Copyright (c) 2003-2005, Ericsson Research Canada
  5. * Copyright (c) 2004-2005, Wind River Systems
  6. * Copyright (c) 2005-2006, Ericsson AB
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions are met:
  11. *
  12. * Redistributions of source code must retain the above copyright notice, this
  13. * list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from this
  19. * software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  25. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  26. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  27. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  28. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  29. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  30. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  31. * POSSIBILITY OF SUCH DAMAGE.
  32. */
  33. #include "core.h"
  34. #include "dbg.h"
  35. #include "bearer.h"
  36. #include "port.h"
  37. #include "link.h"
  38. #include "zone.h"
  39. #include "addr.h"
  40. #include "name_table.h"
  41. #include "node.h"
  42. #include "config.h"
  43. #include "discover.h"
  44. struct subscr_data {
  45. char usr_handle[8];
  46. u32 domain;
  47. u32 port_ref;
  48. struct list_head subd_list;
  49. };
  50. struct manager {
  51. u32 user_ref;
  52. u32 port_ref;
  53. u32 subscr_ref;
  54. u32 link_subscriptions;
  55. struct list_head link_subscribers;
  56. };
  57. static struct manager mng = { 0};
  58. static spinlock_t config_lock = SPIN_LOCK_UNLOCKED;
  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. void cfg_link_event(u32 addr, char *name, int up)
  63. {
  64. /* TIPC DOESN'T HANDLE LINK EVENT SUBSCRIPTIONS AT THE MOMENT */
  65. }
  66. struct sk_buff *cfg_reply_alloc(int payload_size)
  67. {
  68. struct sk_buff *buf;
  69. buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
  70. if (buf)
  71. skb_reserve(buf, rep_headroom);
  72. return buf;
  73. }
  74. int cfg_append_tlv(struct sk_buff *buf, int tlv_type,
  75. void *tlv_data, int tlv_data_size)
  76. {
  77. struct tlv_desc *tlv = (struct tlv_desc *)buf->tail;
  78. int new_tlv_space = TLV_SPACE(tlv_data_size);
  79. if (skb_tailroom(buf) < new_tlv_space) {
  80. dbg("cfg_append_tlv unable to append TLV\n");
  81. return 0;
  82. }
  83. skb_put(buf, new_tlv_space);
  84. tlv->tlv_type = htons(tlv_type);
  85. tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
  86. if (tlv_data_size && tlv_data)
  87. memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
  88. return 1;
  89. }
  90. struct sk_buff *cfg_reply_unsigned_type(u16 tlv_type, u32 value)
  91. {
  92. struct sk_buff *buf;
  93. u32 value_net;
  94. buf = cfg_reply_alloc(TLV_SPACE(sizeof(value)));
  95. if (buf) {
  96. value_net = htonl(value);
  97. cfg_append_tlv(buf, tlv_type, &value_net,
  98. sizeof(value_net));
  99. }
  100. return buf;
  101. }
  102. struct sk_buff *cfg_reply_string_type(u16 tlv_type, char *string)
  103. {
  104. struct sk_buff *buf;
  105. int string_len = strlen(string) + 1;
  106. buf = cfg_reply_alloc(TLV_SPACE(string_len));
  107. if (buf)
  108. cfg_append_tlv(buf, tlv_type, string, string_len);
  109. return buf;
  110. }
  111. #if 0
  112. /* Now obsolete code for handling commands not yet implemented the new way */
  113. int tipc_cfg_cmd(const struct tipc_cmd_msg * msg,
  114. char *data,
  115. u32 sz,
  116. u32 *ret_size,
  117. struct tipc_portid *orig)
  118. {
  119. int rv = -EINVAL;
  120. u32 cmd = msg->cmd;
  121. *ret_size = 0;
  122. switch (cmd) {
  123. case TIPC_REMOVE_LINK:
  124. case TIPC_CMD_BLOCK_LINK:
  125. case TIPC_CMD_UNBLOCK_LINK:
  126. if (!cfg_check_connection(orig))
  127. rv = link_control(msg->argv.link_name, msg->cmd, 0);
  128. break;
  129. case TIPC_ESTABLISH:
  130. {
  131. int connected;
  132. tipc_isconnected(mng.conn_port_ref, &connected);
  133. if (connected || !orig) {
  134. rv = TIPC_FAILURE;
  135. break;
  136. }
  137. rv = tipc_connect2port(mng.conn_port_ref, orig);
  138. if (rv == TIPC_OK)
  139. orig = 0;
  140. break;
  141. }
  142. case TIPC_GET_PEER_ADDRESS:
  143. *ret_size = link_peer_addr(msg->argv.link_name, data, sz);
  144. break;
  145. case TIPC_GET_ROUTES:
  146. rv = TIPC_OK;
  147. break;
  148. default: {}
  149. }
  150. if (*ret_size)
  151. rv = TIPC_OK;
  152. return rv;
  153. }
  154. static void cfg_cmd_event(struct tipc_cmd_msg *msg,
  155. char *data,
  156. u32 sz,
  157. struct tipc_portid const *orig)
  158. {
  159. int rv = -EINVAL;
  160. struct tipc_cmd_result_msg rmsg;
  161. struct iovec msg_sect[2];
  162. int *arg;
  163. msg->cmd = ntohl(msg->cmd);
  164. cfg_prepare_res_msg(msg->cmd, msg->usr_handle, rv, &rmsg, msg_sect,
  165. data, 0);
  166. if (ntohl(msg->magic) != TIPC_MAGIC)
  167. goto exit;
  168. switch (msg->cmd) {
  169. case TIPC_CREATE_LINK:
  170. if (!cfg_check_connection(orig))
  171. rv = disc_create_link(&msg->argv.create_link);
  172. break;
  173. case TIPC_LINK_SUBSCRIBE:
  174. {
  175. struct subscr_data *sub;
  176. if (mng.link_subscriptions > 64)
  177. break;
  178. sub = (struct subscr_data *)kmalloc(sizeof(*sub),
  179. GFP_ATOMIC);
  180. if (sub == NULL) {
  181. warn("Memory squeeze; dropped remote link subscription\n");
  182. break;
  183. }
  184. INIT_LIST_HEAD(&sub->subd_list);
  185. tipc_createport(mng.user_ref,
  186. (void *)sub,
  187. TIPC_HIGH_IMPORTANCE,
  188. 0,
  189. 0,
  190. (tipc_conn_shutdown_event)cfg_linksubscr_cancel,
  191. 0,
  192. 0,
  193. (tipc_conn_msg_event)cfg_linksubscr_cancel,
  194. 0,
  195. &sub->port_ref);
  196. if (!sub->port_ref) {
  197. kfree(sub);
  198. break;
  199. }
  200. memcpy(sub->usr_handle,msg->usr_handle,
  201. sizeof(sub->usr_handle));
  202. sub->domain = msg->argv.domain;
  203. list_add_tail(&sub->subd_list, &mng.link_subscribers);
  204. tipc_connect2port(sub->port_ref, orig);
  205. rmsg.retval = TIPC_OK;
  206. tipc_send(sub->port_ref, 2u, msg_sect);
  207. mng.link_subscriptions++;
  208. return;
  209. }
  210. default:
  211. rv = tipc_cfg_cmd(msg, data, sz, (u32 *)&msg_sect[1].iov_len, orig);
  212. }
  213. exit:
  214. rmsg.result_len = htonl(msg_sect[1].iov_len);
  215. rmsg.retval = htonl(rv);
  216. cfg_respond(msg_sect, 2u, orig);
  217. }
  218. #endif
  219. static struct sk_buff *cfg_enable_bearer(void)
  220. {
  221. struct tipc_bearer_config *args;
  222. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
  223. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  224. args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
  225. if (tipc_enable_bearer(args->name,
  226. ntohl(args->detect_scope),
  227. ntohl(args->priority)))
  228. return cfg_reply_error_string("unable to enable bearer");
  229. return cfg_reply_none();
  230. }
  231. static struct sk_buff *cfg_disable_bearer(void)
  232. {
  233. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
  234. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  235. if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
  236. return cfg_reply_error_string("unable to disable bearer");
  237. return cfg_reply_none();
  238. }
  239. static struct sk_buff *cfg_set_own_addr(void)
  240. {
  241. u32 addr;
  242. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  243. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  244. addr = *(u32 *)TLV_DATA(req_tlv_area);
  245. addr = ntohl(addr);
  246. if (addr == tipc_own_addr)
  247. return cfg_reply_none();
  248. if (!addr_node_valid(addr))
  249. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  250. " (node address)");
  251. if (tipc_own_addr)
  252. return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  253. " (cannot change node address once assigned)");
  254. spin_unlock_bh(&config_lock);
  255. stop_net();
  256. tipc_own_addr = addr;
  257. start_net();
  258. spin_lock_bh(&config_lock);
  259. return cfg_reply_none();
  260. }
  261. static struct sk_buff *cfg_set_remote_mng(void)
  262. {
  263. u32 value;
  264. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  265. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  266. value = *(u32 *)TLV_DATA(req_tlv_area);
  267. value = ntohl(value);
  268. tipc_remote_management = (value != 0);
  269. return cfg_reply_none();
  270. }
  271. static struct sk_buff *cfg_set_max_publications(void)
  272. {
  273. u32 value;
  274. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  275. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  276. value = *(u32 *)TLV_DATA(req_tlv_area);
  277. value = ntohl(value);
  278. if (value != delimit(value, 1, 65535))
  279. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  280. " (max publications must be 1-65535)");
  281. tipc_max_publications = value;
  282. return cfg_reply_none();
  283. }
  284. static struct sk_buff *cfg_set_max_subscriptions(void)
  285. {
  286. u32 value;
  287. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  288. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  289. value = *(u32 *)TLV_DATA(req_tlv_area);
  290. value = ntohl(value);
  291. if (value != delimit(value, 1, 65535))
  292. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  293. " (max subscriptions must be 1-65535");
  294. tipc_max_subscriptions = value;
  295. return cfg_reply_none();
  296. }
  297. static struct sk_buff *cfg_set_max_ports(void)
  298. {
  299. int orig_mode;
  300. u32 value;
  301. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  302. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  303. value = *(u32 *)TLV_DATA(req_tlv_area);
  304. value = ntohl(value);
  305. if (value != delimit(value, 127, 65535))
  306. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  307. " (max ports must be 127-65535)");
  308. if (value == tipc_max_ports)
  309. return cfg_reply_none();
  310. if (atomic_read(&tipc_user_count) > 2)
  311. return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  312. " (cannot change max ports while TIPC users exist)");
  313. spin_unlock_bh(&config_lock);
  314. orig_mode = tipc_get_mode();
  315. if (orig_mode == TIPC_NET_MODE)
  316. stop_net();
  317. stop_core();
  318. tipc_max_ports = value;
  319. start_core();
  320. if (orig_mode == TIPC_NET_MODE)
  321. start_net();
  322. spin_lock_bh(&config_lock);
  323. return cfg_reply_none();
  324. }
  325. static struct sk_buff *set_net_max(int value, int *parameter)
  326. {
  327. int orig_mode;
  328. if (value != *parameter) {
  329. orig_mode = tipc_get_mode();
  330. if (orig_mode == TIPC_NET_MODE)
  331. stop_net();
  332. *parameter = value;
  333. if (orig_mode == TIPC_NET_MODE)
  334. start_net();
  335. }
  336. return cfg_reply_none();
  337. }
  338. static struct sk_buff *cfg_set_max_zones(void)
  339. {
  340. u32 value;
  341. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  342. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  343. value = *(u32 *)TLV_DATA(req_tlv_area);
  344. value = ntohl(value);
  345. if (value != delimit(value, 1, 255))
  346. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  347. " (max zones must be 1-255)");
  348. return set_net_max(value, &tipc_max_zones);
  349. }
  350. static struct sk_buff *cfg_set_max_clusters(void)
  351. {
  352. u32 value;
  353. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  354. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  355. value = *(u32 *)TLV_DATA(req_tlv_area);
  356. value = ntohl(value);
  357. if (value != 1)
  358. return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  359. " (max clusters fixed at 1)");
  360. return cfg_reply_none();
  361. }
  362. static struct sk_buff *cfg_set_max_nodes(void)
  363. {
  364. u32 value;
  365. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  366. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  367. value = *(u32 *)TLV_DATA(req_tlv_area);
  368. value = ntohl(value);
  369. if (value != delimit(value, 8, 2047))
  370. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  371. " (max nodes must be 8-2047)");
  372. return set_net_max(value, &tipc_max_nodes);
  373. }
  374. static struct sk_buff *cfg_set_max_slaves(void)
  375. {
  376. u32 value;
  377. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  378. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  379. value = *(u32 *)TLV_DATA(req_tlv_area);
  380. value = ntohl(value);
  381. if (value != 0)
  382. return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  383. " (max secondary nodes fixed at 0)");
  384. return cfg_reply_none();
  385. }
  386. static struct sk_buff *cfg_set_netid(void)
  387. {
  388. u32 value;
  389. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  390. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  391. value = *(u32 *)TLV_DATA(req_tlv_area);
  392. value = ntohl(value);
  393. if (value != delimit(value, 1, 9999))
  394. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  395. " (network id must be 1-9999)");
  396. if (tipc_own_addr)
  397. return cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  398. " (cannot change network id once part of network)");
  399. return set_net_max(value, &tipc_net_id);
  400. }
  401. struct sk_buff *cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
  402. int request_space, int reply_headroom)
  403. {
  404. struct sk_buff *rep_tlv_buf;
  405. spin_lock_bh(&config_lock);
  406. /* Save request and reply details in a well-known location */
  407. req_tlv_area = request_area;
  408. req_tlv_space = request_space;
  409. rep_headroom = reply_headroom;
  410. /* Check command authorization */
  411. if (likely(orig_node == tipc_own_addr)) {
  412. /* command is permitted */
  413. } else if (cmd >= 0x8000) {
  414. rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  415. " (cannot be done remotely)");
  416. goto exit;
  417. } else if (!tipc_remote_management) {
  418. rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
  419. goto exit;
  420. }
  421. else if (cmd >= 0x4000) {
  422. u32 domain = 0;
  423. if ((nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
  424. (domain != orig_node)) {
  425. rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
  426. goto exit;
  427. }
  428. }
  429. /* Call appropriate processing routine */
  430. switch (cmd) {
  431. case TIPC_CMD_NOOP:
  432. rep_tlv_buf = cfg_reply_none();
  433. break;
  434. case TIPC_CMD_GET_NODES:
  435. rep_tlv_buf = node_get_nodes(req_tlv_area, req_tlv_space);
  436. break;
  437. case TIPC_CMD_GET_LINKS:
  438. rep_tlv_buf = node_get_links(req_tlv_area, req_tlv_space);
  439. break;
  440. case TIPC_CMD_SHOW_LINK_STATS:
  441. rep_tlv_buf = link_cmd_show_stats(req_tlv_area, req_tlv_space);
  442. break;
  443. case TIPC_CMD_RESET_LINK_STATS:
  444. rep_tlv_buf = link_cmd_reset_stats(req_tlv_area, req_tlv_space);
  445. break;
  446. case TIPC_CMD_SHOW_NAME_TABLE:
  447. rep_tlv_buf = nametbl_get(req_tlv_area, req_tlv_space);
  448. break;
  449. case TIPC_CMD_GET_BEARER_NAMES:
  450. rep_tlv_buf = bearer_get_names();
  451. break;
  452. case TIPC_CMD_GET_MEDIA_NAMES:
  453. rep_tlv_buf = media_get_names();
  454. break;
  455. case TIPC_CMD_SHOW_PORTS:
  456. rep_tlv_buf = port_get_ports();
  457. break;
  458. #if 0
  459. case TIPC_CMD_SHOW_PORT_STATS:
  460. rep_tlv_buf = port_show_stats(req_tlv_area, req_tlv_space);
  461. break;
  462. case TIPC_CMD_RESET_PORT_STATS:
  463. rep_tlv_buf = cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED);
  464. break;
  465. #endif
  466. case TIPC_CMD_SET_LOG_SIZE:
  467. rep_tlv_buf = log_resize(req_tlv_area, req_tlv_space);
  468. break;
  469. case TIPC_CMD_DUMP_LOG:
  470. rep_tlv_buf = log_dump();
  471. break;
  472. case TIPC_CMD_SET_LINK_TOL:
  473. case TIPC_CMD_SET_LINK_PRI:
  474. case TIPC_CMD_SET_LINK_WINDOW:
  475. rep_tlv_buf = link_cmd_config(req_tlv_area, req_tlv_space, cmd);
  476. break;
  477. case TIPC_CMD_ENABLE_BEARER:
  478. rep_tlv_buf = cfg_enable_bearer();
  479. break;
  480. case TIPC_CMD_DISABLE_BEARER:
  481. rep_tlv_buf = cfg_disable_bearer();
  482. break;
  483. case TIPC_CMD_SET_NODE_ADDR:
  484. rep_tlv_buf = cfg_set_own_addr();
  485. break;
  486. case TIPC_CMD_SET_REMOTE_MNG:
  487. rep_tlv_buf = cfg_set_remote_mng();
  488. break;
  489. case TIPC_CMD_SET_MAX_PORTS:
  490. rep_tlv_buf = cfg_set_max_ports();
  491. break;
  492. case TIPC_CMD_SET_MAX_PUBL:
  493. rep_tlv_buf = cfg_set_max_publications();
  494. break;
  495. case TIPC_CMD_SET_MAX_SUBSCR:
  496. rep_tlv_buf = cfg_set_max_subscriptions();
  497. break;
  498. case TIPC_CMD_SET_MAX_ZONES:
  499. rep_tlv_buf = cfg_set_max_zones();
  500. break;
  501. case TIPC_CMD_SET_MAX_CLUSTERS:
  502. rep_tlv_buf = cfg_set_max_clusters();
  503. break;
  504. case TIPC_CMD_SET_MAX_NODES:
  505. rep_tlv_buf = cfg_set_max_nodes();
  506. break;
  507. case TIPC_CMD_SET_MAX_SLAVES:
  508. rep_tlv_buf = cfg_set_max_slaves();
  509. break;
  510. case TIPC_CMD_SET_NETID:
  511. rep_tlv_buf = cfg_set_netid();
  512. break;
  513. case TIPC_CMD_GET_REMOTE_MNG:
  514. rep_tlv_buf = cfg_reply_unsigned(tipc_remote_management);
  515. break;
  516. case TIPC_CMD_GET_MAX_PORTS:
  517. rep_tlv_buf = cfg_reply_unsigned(tipc_max_ports);
  518. break;
  519. case TIPC_CMD_GET_MAX_PUBL:
  520. rep_tlv_buf = cfg_reply_unsigned(tipc_max_publications);
  521. break;
  522. case TIPC_CMD_GET_MAX_SUBSCR:
  523. rep_tlv_buf = cfg_reply_unsigned(tipc_max_subscriptions);
  524. break;
  525. case TIPC_CMD_GET_MAX_ZONES:
  526. rep_tlv_buf = cfg_reply_unsigned(tipc_max_zones);
  527. break;
  528. case TIPC_CMD_GET_MAX_CLUSTERS:
  529. rep_tlv_buf = cfg_reply_unsigned(tipc_max_clusters);
  530. break;
  531. case TIPC_CMD_GET_MAX_NODES:
  532. rep_tlv_buf = cfg_reply_unsigned(tipc_max_nodes);
  533. break;
  534. case TIPC_CMD_GET_MAX_SLAVES:
  535. rep_tlv_buf = cfg_reply_unsigned(tipc_max_slaves);
  536. break;
  537. case TIPC_CMD_GET_NETID:
  538. rep_tlv_buf = cfg_reply_unsigned(tipc_net_id);
  539. break;
  540. default:
  541. rep_tlv_buf = NULL;
  542. break;
  543. }
  544. /* Return reply buffer */
  545. exit:
  546. spin_unlock_bh(&config_lock);
  547. return rep_tlv_buf;
  548. }
  549. static void cfg_named_msg_event(void *userdata,
  550. u32 port_ref,
  551. struct sk_buff **buf,
  552. const unchar *msg,
  553. u32 size,
  554. u32 importance,
  555. struct tipc_portid const *orig,
  556. struct tipc_name_seq const *dest)
  557. {
  558. struct tipc_cfg_msg_hdr *req_hdr;
  559. struct tipc_cfg_msg_hdr *rep_hdr;
  560. struct sk_buff *rep_buf;
  561. /* Validate configuration message header (ignore invalid message) */
  562. req_hdr = (struct tipc_cfg_msg_hdr *)msg;
  563. if ((size < sizeof(*req_hdr)) ||
  564. (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
  565. (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
  566. warn("discarded invalid configuration message\n");
  567. return;
  568. }
  569. /* Generate reply for request (if can't, return request) */
  570. rep_buf = cfg_do_cmd(orig->node,
  571. ntohs(req_hdr->tcm_type),
  572. msg + sizeof(*req_hdr),
  573. size - sizeof(*req_hdr),
  574. BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
  575. if (rep_buf) {
  576. skb_push(rep_buf, sizeof(*rep_hdr));
  577. rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
  578. memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
  579. rep_hdr->tcm_len = htonl(rep_buf->len);
  580. rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
  581. } else {
  582. rep_buf = *buf;
  583. *buf = NULL;
  584. }
  585. /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
  586. tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
  587. }
  588. int cfg_init(void)
  589. {
  590. struct tipc_name_seq seq;
  591. int res;
  592. memset(&mng, 0, sizeof(mng));
  593. INIT_LIST_HEAD(&mng.link_subscribers);
  594. res = tipc_attach(&mng.user_ref, 0, 0);
  595. if (res)
  596. goto failed;
  597. res = tipc_createport(mng.user_ref, 0, TIPC_CRITICAL_IMPORTANCE,
  598. NULL, NULL, NULL,
  599. NULL, cfg_named_msg_event, NULL,
  600. NULL, &mng.port_ref);
  601. if (res)
  602. goto failed;
  603. seq.type = TIPC_CFG_SRV;
  604. seq.lower = seq.upper = tipc_own_addr;
  605. res = nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
  606. if (res)
  607. goto failed;
  608. return 0;
  609. failed:
  610. err("Unable to create configuration service\n");
  611. tipc_detach(mng.user_ref);
  612. mng.user_ref = 0;
  613. return res;
  614. }
  615. void cfg_stop(void)
  616. {
  617. if (mng.user_ref) {
  618. tipc_detach(mng.user_ref);
  619. mng.user_ref = 0;
  620. }
  621. }