config.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * net/tipc/config.c: TIPC configuration management code
  3. *
  4. * Copyright (c) 2002-2006, Ericsson AB
  5. * Copyright (c) 2004-2007, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "core.h"
  37. #include "dbg.h"
  38. #include "bearer.h"
  39. #include "port.h"
  40. #include "link.h"
  41. #include "zone.h"
  42. #include "addr.h"
  43. #include "name_table.h"
  44. #include "node.h"
  45. #include "config.h"
  46. #include "discover.h"
  47. struct subscr_data {
  48. char usr_handle[8];
  49. u32 domain;
  50. u32 port_ref;
  51. struct list_head subd_list;
  52. };
  53. struct manager {
  54. u32 user_ref;
  55. u32 port_ref;
  56. };
  57. static struct manager mng = { 0};
  58. static DEFINE_SPINLOCK(config_lock);
  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. struct sk_buff *tipc_cfg_reply_alloc(int payload_size)
  63. {
  64. struct sk_buff *buf;
  65. buf = alloc_skb(rep_headroom + payload_size, GFP_ATOMIC);
  66. if (buf)
  67. skb_reserve(buf, rep_headroom);
  68. return buf;
  69. }
  70. int tipc_cfg_append_tlv(struct sk_buff *buf, int tlv_type,
  71. void *tlv_data, int tlv_data_size)
  72. {
  73. struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(buf);
  74. int new_tlv_space = TLV_SPACE(tlv_data_size);
  75. if (skb_tailroom(buf) < new_tlv_space) {
  76. dbg("tipc_cfg_append_tlv unable to append TLV\n");
  77. return 0;
  78. }
  79. skb_put(buf, new_tlv_space);
  80. tlv->tlv_type = htons(tlv_type);
  81. tlv->tlv_len = htons(TLV_LENGTH(tlv_data_size));
  82. if (tlv_data_size && tlv_data)
  83. memcpy(TLV_DATA(tlv), tlv_data, tlv_data_size);
  84. return 1;
  85. }
  86. static struct sk_buff *tipc_cfg_reply_unsigned_type(u16 tlv_type, u32 value)
  87. {
  88. struct sk_buff *buf;
  89. __be32 value_net;
  90. buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(value)));
  91. if (buf) {
  92. value_net = htonl(value);
  93. tipc_cfg_append_tlv(buf, tlv_type, &value_net,
  94. sizeof(value_net));
  95. }
  96. return buf;
  97. }
  98. static struct sk_buff *tipc_cfg_reply_unsigned(u32 value)
  99. {
  100. return tipc_cfg_reply_unsigned_type(TIPC_TLV_UNSIGNED, value);
  101. }
  102. struct sk_buff *tipc_cfg_reply_string_type(u16 tlv_type, char *string)
  103. {
  104. struct sk_buff *buf;
  105. int string_len = strlen(string) + 1;
  106. buf = tipc_cfg_reply_alloc(TLV_SPACE(string_len));
  107. if (buf)
  108. tipc_cfg_append_tlv(buf, tlv_type, string, string_len);
  109. return buf;
  110. }
  111. #define MAX_STATS_INFO 2000
  112. static struct sk_buff *tipc_show_stats(void)
  113. {
  114. struct sk_buff *buf;
  115. struct tlv_desc *rep_tlv;
  116. struct print_buf pb;
  117. int str_len;
  118. u32 value;
  119. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  120. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  121. value = ntohl(*(u32 *)TLV_DATA(req_tlv_area));
  122. if (value != 0)
  123. return tipc_cfg_reply_error_string("unsupported argument");
  124. buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_STATS_INFO));
  125. if (buf == NULL)
  126. return NULL;
  127. rep_tlv = (struct tlv_desc *)buf->data;
  128. tipc_printbuf_init(&pb, (char *)TLV_DATA(rep_tlv), MAX_STATS_INFO);
  129. tipc_printf(&pb, "TIPC version " TIPC_MOD_VER "\n");
  130. /* Use additional tipc_printf()'s to return more info ... */
  131. str_len = tipc_printbuf_validate(&pb);
  132. skb_put(buf, TLV_SPACE(str_len));
  133. TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
  134. return buf;
  135. }
  136. static struct sk_buff *cfg_enable_bearer(void)
  137. {
  138. struct tipc_bearer_config *args;
  139. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG))
  140. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  141. args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area);
  142. if (tipc_enable_bearer(args->name,
  143. ntohl(args->detect_scope),
  144. ntohl(args->priority)))
  145. return tipc_cfg_reply_error_string("unable to enable bearer");
  146. return tipc_cfg_reply_none();
  147. }
  148. static struct sk_buff *cfg_disable_bearer(void)
  149. {
  150. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME))
  151. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  152. if (tipc_disable_bearer((char *)TLV_DATA(req_tlv_area)))
  153. return tipc_cfg_reply_error_string("unable to disable bearer");
  154. return tipc_cfg_reply_none();
  155. }
  156. static struct sk_buff *cfg_set_own_addr(void)
  157. {
  158. u32 addr;
  159. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  160. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  161. addr = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  162. if (addr == tipc_own_addr)
  163. return tipc_cfg_reply_none();
  164. if (!tipc_addr_node_valid(addr))
  165. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  166. " (node address)");
  167. if (tipc_mode == TIPC_NET_MODE)
  168. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  169. " (cannot change node address once assigned)");
  170. /*
  171. * Must release all spinlocks before calling start_net() because
  172. * Linux version of TIPC calls eth_media_start() which calls
  173. * register_netdevice_notifier() which may block!
  174. *
  175. * Temporarily releasing the lock should be harmless for non-Linux TIPC,
  176. * but Linux version of eth_media_start() should really be reworked
  177. * so that it can be called with spinlocks held.
  178. */
  179. spin_unlock_bh(&config_lock);
  180. tipc_core_start_net(addr);
  181. spin_lock_bh(&config_lock);
  182. return tipc_cfg_reply_none();
  183. }
  184. static struct sk_buff *cfg_set_remote_mng(void)
  185. {
  186. u32 value;
  187. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  188. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  189. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  190. tipc_remote_management = (value != 0);
  191. return tipc_cfg_reply_none();
  192. }
  193. static struct sk_buff *cfg_set_max_publications(void)
  194. {
  195. u32 value;
  196. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  197. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  198. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  199. if (value != delimit(value, 1, 65535))
  200. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  201. " (max publications must be 1-65535)");
  202. tipc_max_publications = value;
  203. return tipc_cfg_reply_none();
  204. }
  205. static struct sk_buff *cfg_set_max_subscriptions(void)
  206. {
  207. u32 value;
  208. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  209. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  210. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  211. if (value != delimit(value, 1, 65535))
  212. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  213. " (max subscriptions must be 1-65535");
  214. tipc_max_subscriptions = value;
  215. return tipc_cfg_reply_none();
  216. }
  217. static struct sk_buff *cfg_set_max_ports(void)
  218. {
  219. u32 value;
  220. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  221. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  222. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  223. if (value == tipc_max_ports)
  224. return tipc_cfg_reply_none();
  225. if (value != delimit(value, 127, 65535))
  226. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  227. " (max ports must be 127-65535)");
  228. if (tipc_mode != TIPC_NOT_RUNNING)
  229. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  230. " (cannot change max ports while TIPC is active)");
  231. tipc_max_ports = value;
  232. return tipc_cfg_reply_none();
  233. }
  234. static struct sk_buff *cfg_set_max_zones(void)
  235. {
  236. u32 value;
  237. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  238. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  239. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  240. if (value == tipc_max_zones)
  241. return tipc_cfg_reply_none();
  242. if (value != delimit(value, 1, 255))
  243. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  244. " (max zones must be 1-255)");
  245. if (tipc_mode == TIPC_NET_MODE)
  246. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  247. " (cannot change max zones once TIPC has joined a network)");
  248. tipc_max_zones = value;
  249. return tipc_cfg_reply_none();
  250. }
  251. static struct sk_buff *cfg_set_max_clusters(void)
  252. {
  253. u32 value;
  254. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  255. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  256. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  257. if (value != delimit(value, 1, 1))
  258. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  259. " (max clusters fixed at 1)");
  260. return tipc_cfg_reply_none();
  261. }
  262. static struct sk_buff *cfg_set_max_nodes(void)
  263. {
  264. u32 value;
  265. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  266. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  267. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  268. if (value == tipc_max_nodes)
  269. return tipc_cfg_reply_none();
  270. if (value != delimit(value, 8, 2047))
  271. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  272. " (max nodes must be 8-2047)");
  273. if (tipc_mode == TIPC_NET_MODE)
  274. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  275. " (cannot change max nodes once TIPC has joined a network)");
  276. tipc_max_nodes = value;
  277. return tipc_cfg_reply_none();
  278. }
  279. static struct sk_buff *cfg_set_max_slaves(void)
  280. {
  281. u32 value;
  282. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  283. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  284. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  285. if (value != 0)
  286. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  287. " (max secondary nodes fixed at 0)");
  288. return tipc_cfg_reply_none();
  289. }
  290. static struct sk_buff *cfg_set_netid(void)
  291. {
  292. u32 value;
  293. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_UNSIGNED))
  294. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  295. value = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  296. if (value == tipc_net_id)
  297. return tipc_cfg_reply_none();
  298. if (value != delimit(value, 1, 9999))
  299. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  300. " (network id must be 1-9999)");
  301. if (tipc_mode == TIPC_NET_MODE)
  302. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  303. " (cannot change network id once TIPC has joined a network)");
  304. tipc_net_id = value;
  305. return tipc_cfg_reply_none();
  306. }
  307. struct sk_buff *tipc_cfg_do_cmd(u32 orig_node, u16 cmd, const void *request_area,
  308. int request_space, int reply_headroom)
  309. {
  310. struct sk_buff *rep_tlv_buf;
  311. spin_lock_bh(&config_lock);
  312. /* Save request and reply details in a well-known location */
  313. req_tlv_area = request_area;
  314. req_tlv_space = request_space;
  315. rep_headroom = reply_headroom;
  316. /* Check command authorization */
  317. if (likely(orig_node == tipc_own_addr)) {
  318. /* command is permitted */
  319. } else if (cmd >= 0x8000) {
  320. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  321. " (cannot be done remotely)");
  322. goto exit;
  323. } else if (!tipc_remote_management) {
  324. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NO_REMOTE);
  325. goto exit;
  326. }
  327. else if (cmd >= 0x4000) {
  328. u32 domain = 0;
  329. if ((tipc_nametbl_translate(TIPC_ZM_SRV, 0, &domain) == 0) ||
  330. (domain != orig_node)) {
  331. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_ZONE_MSTR);
  332. goto exit;
  333. }
  334. }
  335. /* Call appropriate processing routine */
  336. switch (cmd) {
  337. case TIPC_CMD_NOOP:
  338. rep_tlv_buf = tipc_cfg_reply_none();
  339. break;
  340. case TIPC_CMD_GET_NODES:
  341. rep_tlv_buf = tipc_node_get_nodes(req_tlv_area, req_tlv_space);
  342. break;
  343. case TIPC_CMD_GET_LINKS:
  344. rep_tlv_buf = tipc_node_get_links(req_tlv_area, req_tlv_space);
  345. break;
  346. case TIPC_CMD_SHOW_LINK_STATS:
  347. rep_tlv_buf = tipc_link_cmd_show_stats(req_tlv_area, req_tlv_space);
  348. break;
  349. case TIPC_CMD_RESET_LINK_STATS:
  350. rep_tlv_buf = tipc_link_cmd_reset_stats(req_tlv_area, req_tlv_space);
  351. break;
  352. case TIPC_CMD_SHOW_NAME_TABLE:
  353. rep_tlv_buf = tipc_nametbl_get(req_tlv_area, req_tlv_space);
  354. break;
  355. case TIPC_CMD_GET_BEARER_NAMES:
  356. rep_tlv_buf = tipc_bearer_get_names();
  357. break;
  358. case TIPC_CMD_GET_MEDIA_NAMES:
  359. rep_tlv_buf = tipc_media_get_names();
  360. break;
  361. case TIPC_CMD_SHOW_PORTS:
  362. rep_tlv_buf = tipc_port_get_ports();
  363. break;
  364. case TIPC_CMD_SET_LOG_SIZE:
  365. rep_tlv_buf = tipc_log_resize_cmd(req_tlv_area, req_tlv_space);
  366. break;
  367. case TIPC_CMD_DUMP_LOG:
  368. rep_tlv_buf = tipc_log_dump();
  369. break;
  370. case TIPC_CMD_SHOW_STATS:
  371. rep_tlv_buf = tipc_show_stats();
  372. break;
  373. case TIPC_CMD_SET_LINK_TOL:
  374. case TIPC_CMD_SET_LINK_PRI:
  375. case TIPC_CMD_SET_LINK_WINDOW:
  376. rep_tlv_buf = tipc_link_cmd_config(req_tlv_area, req_tlv_space, cmd);
  377. break;
  378. case TIPC_CMD_ENABLE_BEARER:
  379. rep_tlv_buf = cfg_enable_bearer();
  380. break;
  381. case TIPC_CMD_DISABLE_BEARER:
  382. rep_tlv_buf = cfg_disable_bearer();
  383. break;
  384. case TIPC_CMD_SET_NODE_ADDR:
  385. rep_tlv_buf = cfg_set_own_addr();
  386. break;
  387. case TIPC_CMD_SET_REMOTE_MNG:
  388. rep_tlv_buf = cfg_set_remote_mng();
  389. break;
  390. case TIPC_CMD_SET_MAX_PORTS:
  391. rep_tlv_buf = cfg_set_max_ports();
  392. break;
  393. case TIPC_CMD_SET_MAX_PUBL:
  394. rep_tlv_buf = cfg_set_max_publications();
  395. break;
  396. case TIPC_CMD_SET_MAX_SUBSCR:
  397. rep_tlv_buf = cfg_set_max_subscriptions();
  398. break;
  399. case TIPC_CMD_SET_MAX_ZONES:
  400. rep_tlv_buf = cfg_set_max_zones();
  401. break;
  402. case TIPC_CMD_SET_MAX_CLUSTERS:
  403. rep_tlv_buf = cfg_set_max_clusters();
  404. break;
  405. case TIPC_CMD_SET_MAX_NODES:
  406. rep_tlv_buf = cfg_set_max_nodes();
  407. break;
  408. case TIPC_CMD_SET_MAX_SLAVES:
  409. rep_tlv_buf = cfg_set_max_slaves();
  410. break;
  411. case TIPC_CMD_SET_NETID:
  412. rep_tlv_buf = cfg_set_netid();
  413. break;
  414. case TIPC_CMD_GET_REMOTE_MNG:
  415. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_remote_management);
  416. break;
  417. case TIPC_CMD_GET_MAX_PORTS:
  418. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_ports);
  419. break;
  420. case TIPC_CMD_GET_MAX_PUBL:
  421. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_publications);
  422. break;
  423. case TIPC_CMD_GET_MAX_SUBSCR:
  424. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_subscriptions);
  425. break;
  426. case TIPC_CMD_GET_MAX_ZONES:
  427. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_zones);
  428. break;
  429. case TIPC_CMD_GET_MAX_CLUSTERS:
  430. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_clusters);
  431. break;
  432. case TIPC_CMD_GET_MAX_NODES:
  433. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_nodes);
  434. break;
  435. case TIPC_CMD_GET_MAX_SLAVES:
  436. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_max_slaves);
  437. break;
  438. case TIPC_CMD_GET_NETID:
  439. rep_tlv_buf = tipc_cfg_reply_unsigned(tipc_net_id);
  440. break;
  441. case TIPC_CMD_NOT_NET_ADMIN:
  442. rep_tlv_buf =
  443. tipc_cfg_reply_error_string(TIPC_CFG_NOT_NET_ADMIN);
  444. break;
  445. default:
  446. rep_tlv_buf = tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  447. " (unknown command)");
  448. break;
  449. }
  450. /* Return reply buffer */
  451. exit:
  452. spin_unlock_bh(&config_lock);
  453. return rep_tlv_buf;
  454. }
  455. static void cfg_named_msg_event(void *userdata,
  456. u32 port_ref,
  457. struct sk_buff **buf,
  458. const unchar *msg,
  459. u32 size,
  460. u32 importance,
  461. struct tipc_portid const *orig,
  462. struct tipc_name_seq const *dest)
  463. {
  464. struct tipc_cfg_msg_hdr *req_hdr;
  465. struct tipc_cfg_msg_hdr *rep_hdr;
  466. struct sk_buff *rep_buf;
  467. /* Validate configuration message header (ignore invalid message) */
  468. req_hdr = (struct tipc_cfg_msg_hdr *)msg;
  469. if ((size < sizeof(*req_hdr)) ||
  470. (size != TCM_ALIGN(ntohl(req_hdr->tcm_len))) ||
  471. (ntohs(req_hdr->tcm_flags) != TCM_F_REQUEST)) {
  472. warn("Invalid configuration message discarded\n");
  473. return;
  474. }
  475. /* Generate reply for request (if can't, return request) */
  476. rep_buf = tipc_cfg_do_cmd(orig->node,
  477. ntohs(req_hdr->tcm_type),
  478. msg + sizeof(*req_hdr),
  479. size - sizeof(*req_hdr),
  480. BUF_HEADROOM + MAX_H_SIZE + sizeof(*rep_hdr));
  481. if (rep_buf) {
  482. skb_push(rep_buf, sizeof(*rep_hdr));
  483. rep_hdr = (struct tipc_cfg_msg_hdr *)rep_buf->data;
  484. memcpy(rep_hdr, req_hdr, sizeof(*rep_hdr));
  485. rep_hdr->tcm_len = htonl(rep_buf->len);
  486. rep_hdr->tcm_flags &= htons(~TCM_F_REQUEST);
  487. } else {
  488. rep_buf = *buf;
  489. *buf = NULL;
  490. }
  491. /* NEED TO ADD CODE TO HANDLE FAILED SEND (SUCH AS CONGESTION) */
  492. tipc_send_buf2port(port_ref, orig, rep_buf, rep_buf->len);
  493. }
  494. int tipc_cfg_init(void)
  495. {
  496. struct tipc_name_seq seq;
  497. int res;
  498. res = tipc_attach(&mng.user_ref, NULL, NULL);
  499. if (res)
  500. goto failed;
  501. res = tipc_createport(mng.user_ref, NULL, TIPC_CRITICAL_IMPORTANCE,
  502. NULL, NULL, NULL,
  503. NULL, cfg_named_msg_event, NULL,
  504. NULL, &mng.port_ref);
  505. if (res)
  506. goto failed;
  507. seq.type = TIPC_CFG_SRV;
  508. seq.lower = seq.upper = tipc_own_addr;
  509. res = tipc_nametbl_publish_rsv(mng.port_ref, TIPC_ZONE_SCOPE, &seq);
  510. if (res)
  511. goto failed;
  512. return 0;
  513. failed:
  514. err("Unable to create configuration service\n");
  515. tipc_detach(mng.user_ref);
  516. mng.user_ref = 0;
  517. return res;
  518. }
  519. void tipc_cfg_stop(void)
  520. {
  521. if (mng.user_ref) {
  522. tipc_detach(mng.user_ref);
  523. mng.user_ref = 0;
  524. }
  525. }