config.c 19 KB

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