config.c 19 KB

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