node.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * net/tipc/node.c: TIPC node management routines
  3. *
  4. * Copyright (c) 2000-2006, Ericsson AB
  5. * Copyright (c) 2005-2006, Wind River Systems
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include "core.h"
  37. #include "config.h"
  38. #include "node.h"
  39. #include "cluster.h"
  40. #include "net.h"
  41. #include "addr.h"
  42. #include "node_subscr.h"
  43. #include "link.h"
  44. #include "port.h"
  45. #include "bearer.h"
  46. #include "name_distr.h"
  47. void node_print(struct print_buf *buf, struct node *n_ptr, char *str);
  48. static void node_lost_contact(struct node *n_ptr);
  49. static void node_established_contact(struct node *n_ptr);
  50. struct node *tipc_nodes = NULL; /* sorted list of nodes within cluster */
  51. u32 tipc_own_tag = 0;
  52. struct node *tipc_node_create(u32 addr)
  53. {
  54. struct cluster *c_ptr;
  55. struct node *n_ptr;
  56. struct node **curr_node;
  57. n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC);
  58. if (!n_ptr) {
  59. warn("Node creation failed, no memory\n");
  60. return NULL;
  61. }
  62. c_ptr = tipc_cltr_find(addr);
  63. if (!c_ptr) {
  64. c_ptr = tipc_cltr_create(addr);
  65. }
  66. if (!c_ptr) {
  67. kfree(n_ptr);
  68. return NULL;
  69. }
  70. n_ptr->addr = addr;
  71. spin_lock_init(&n_ptr->lock);
  72. INIT_LIST_HEAD(&n_ptr->nsub);
  73. n_ptr->owner = c_ptr;
  74. tipc_cltr_attach_node(c_ptr, n_ptr);
  75. n_ptr->last_router = -1;
  76. /* Insert node into ordered list */
  77. for (curr_node = &tipc_nodes; *curr_node;
  78. curr_node = &(*curr_node)->next) {
  79. if (addr < (*curr_node)->addr) {
  80. n_ptr->next = *curr_node;
  81. break;
  82. }
  83. }
  84. (*curr_node) = n_ptr;
  85. return n_ptr;
  86. }
  87. void tipc_node_delete(struct node *n_ptr)
  88. {
  89. if (!n_ptr)
  90. return;
  91. #if 0
  92. /* Not needed because links are already deleted via tipc_bearer_stop() */
  93. u32 l_num;
  94. for (l_num = 0; l_num < MAX_BEARERS; l_num++) {
  95. link_delete(n_ptr->links[l_num]);
  96. }
  97. #endif
  98. dbg("node %x deleted\n", n_ptr->addr);
  99. kfree(n_ptr);
  100. }
  101. /**
  102. * tipc_node_link_up - handle addition of link
  103. *
  104. * Link becomes active (alone or shared) or standby, depending on its priority.
  105. */
  106. void tipc_node_link_up(struct node *n_ptr, struct link *l_ptr)
  107. {
  108. struct link **active = &n_ptr->active_links[0];
  109. n_ptr->working_links++;
  110. info("Established link <%s> on network plane %c\n",
  111. l_ptr->name, l_ptr->b_ptr->net_plane);
  112. if (!active[0]) {
  113. dbg(" link %x into %x/%x\n", l_ptr, &active[0], &active[1]);
  114. active[0] = active[1] = l_ptr;
  115. node_established_contact(n_ptr);
  116. return;
  117. }
  118. if (l_ptr->priority < active[0]->priority) {
  119. info("New link <%s> becomes standby\n", l_ptr->name);
  120. return;
  121. }
  122. tipc_link_send_duplicate(active[0], l_ptr);
  123. if (l_ptr->priority == active[0]->priority) {
  124. active[0] = l_ptr;
  125. return;
  126. }
  127. info("Old link <%s> becomes standby\n", active[0]->name);
  128. if (active[1] != active[0])
  129. info("Old link <%s> becomes standby\n", active[1]->name);
  130. active[0] = active[1] = l_ptr;
  131. }
  132. /**
  133. * node_select_active_links - select active link
  134. */
  135. static void node_select_active_links(struct node *n_ptr)
  136. {
  137. struct link **active = &n_ptr->active_links[0];
  138. u32 i;
  139. u32 highest_prio = 0;
  140. active[0] = active[1] = NULL;
  141. for (i = 0; i < MAX_BEARERS; i++) {
  142. struct link *l_ptr = n_ptr->links[i];
  143. if (!l_ptr || !tipc_link_is_up(l_ptr) ||
  144. (l_ptr->priority < highest_prio))
  145. continue;
  146. if (l_ptr->priority > highest_prio) {
  147. highest_prio = l_ptr->priority;
  148. active[0] = active[1] = l_ptr;
  149. } else {
  150. active[1] = l_ptr;
  151. }
  152. }
  153. }
  154. /**
  155. * tipc_node_link_down - handle loss of link
  156. */
  157. void tipc_node_link_down(struct node *n_ptr, struct link *l_ptr)
  158. {
  159. struct link **active;
  160. n_ptr->working_links--;
  161. if (!tipc_link_is_active(l_ptr)) {
  162. info("Lost standby link <%s> on network plane %c\n",
  163. l_ptr->name, l_ptr->b_ptr->net_plane);
  164. return;
  165. }
  166. info("Lost link <%s> on network plane %c\n",
  167. l_ptr->name, l_ptr->b_ptr->net_plane);
  168. active = &n_ptr->active_links[0];
  169. if (active[0] == l_ptr)
  170. active[0] = active[1];
  171. if (active[1] == l_ptr)
  172. active[1] = active[0];
  173. if (active[0] == l_ptr)
  174. node_select_active_links(n_ptr);
  175. if (tipc_node_is_up(n_ptr))
  176. tipc_link_changeover(l_ptr);
  177. else
  178. node_lost_contact(n_ptr);
  179. }
  180. int tipc_node_has_active_links(struct node *n_ptr)
  181. {
  182. return (n_ptr &&
  183. ((n_ptr->active_links[0]) || (n_ptr->active_links[1])));
  184. }
  185. int tipc_node_has_redundant_links(struct node *n_ptr)
  186. {
  187. return (n_ptr->working_links > 1);
  188. }
  189. static int tipc_node_has_active_routes(struct node *n_ptr)
  190. {
  191. return (n_ptr && (n_ptr->last_router >= 0));
  192. }
  193. int tipc_node_is_up(struct node *n_ptr)
  194. {
  195. return (tipc_node_has_active_links(n_ptr) || tipc_node_has_active_routes(n_ptr));
  196. }
  197. struct node *tipc_node_attach_link(struct link *l_ptr)
  198. {
  199. struct node *n_ptr = tipc_node_find(l_ptr->addr);
  200. if (!n_ptr)
  201. n_ptr = tipc_node_create(l_ptr->addr);
  202. if (n_ptr) {
  203. u32 bearer_id = l_ptr->b_ptr->identity;
  204. char addr_string[16];
  205. if (n_ptr->link_cnt >= 2) {
  206. char addr_string[16];
  207. err("Attempt to create third link to %s\n",
  208. addr_string_fill(addr_string, n_ptr->addr));
  209. return NULL;
  210. }
  211. if (!n_ptr->links[bearer_id]) {
  212. n_ptr->links[bearer_id] = l_ptr;
  213. tipc_net.zones[tipc_zone(l_ptr->addr)]->links++;
  214. n_ptr->link_cnt++;
  215. return n_ptr;
  216. }
  217. err("Attempt to establish second link on <%s> to %s \n",
  218. l_ptr->b_ptr->publ.name,
  219. addr_string_fill(addr_string, l_ptr->addr));
  220. }
  221. return NULL;
  222. }
  223. void tipc_node_detach_link(struct node *n_ptr, struct link *l_ptr)
  224. {
  225. n_ptr->links[l_ptr->b_ptr->identity] = NULL;
  226. tipc_net.zones[tipc_zone(l_ptr->addr)]->links--;
  227. n_ptr->link_cnt--;
  228. }
  229. /*
  230. * Routing table management - five cases to handle:
  231. *
  232. * 1: A link towards a zone/cluster external node comes up.
  233. * => Send a multicast message updating routing tables of all
  234. * system nodes within own cluster that the new destination
  235. * can be reached via this node.
  236. * (node.establishedContact()=>cluster.multicastNewRoute())
  237. *
  238. * 2: A link towards a slave node comes up.
  239. * => Send a multicast message updating routing tables of all
  240. * system nodes within own cluster that the new destination
  241. * can be reached via this node.
  242. * (node.establishedContact()=>cluster.multicastNewRoute())
  243. * => Send a message to the slave node about existence
  244. * of all system nodes within cluster:
  245. * (node.establishedContact()=>cluster.sendLocalRoutes())
  246. *
  247. * 3: A new cluster local system node becomes available.
  248. * => Send message(s) to this particular node containing
  249. * information about all cluster external and slave
  250. * nodes which can be reached via this node.
  251. * (node.establishedContact()==>network.sendExternalRoutes())
  252. * (node.establishedContact()==>network.sendSlaveRoutes())
  253. * => Send messages to all directly connected slave nodes
  254. * containing information about the existence of the new node
  255. * (node.establishedContact()=>cluster.multicastNewRoute())
  256. *
  257. * 4: The link towards a zone/cluster external node or slave
  258. * node goes down.
  259. * => Send a multcast message updating routing tables of all
  260. * nodes within cluster that the new destination can not any
  261. * longer be reached via this node.
  262. * (node.lostAllLinks()=>cluster.bcastLostRoute())
  263. *
  264. * 5: A cluster local system node becomes unavailable.
  265. * => Remove all references to this node from the local
  266. * routing tables. Note: This is a completely node
  267. * local operation.
  268. * (node.lostAllLinks()=>network.removeAsRouter())
  269. * => Send messages to all directly connected slave nodes
  270. * containing information about loss of the node
  271. * (node.establishedContact()=>cluster.multicastLostRoute())
  272. *
  273. */
  274. static void node_established_contact(struct node *n_ptr)
  275. {
  276. struct cluster *c_ptr;
  277. dbg("node_established_contact:-> %x\n", n_ptr->addr);
  278. if (!tipc_node_has_active_routes(n_ptr) && in_own_cluster(n_ptr->addr)) {
  279. tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
  280. }
  281. /* Syncronize broadcast acks */
  282. n_ptr->bclink.acked = tipc_bclink_get_last_sent();
  283. if (is_slave(tipc_own_addr))
  284. return;
  285. if (!in_own_cluster(n_ptr->addr)) {
  286. /* Usage case 1 (see above) */
  287. c_ptr = tipc_cltr_find(tipc_own_addr);
  288. if (!c_ptr)
  289. c_ptr = tipc_cltr_create(tipc_own_addr);
  290. if (c_ptr)
  291. tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1,
  292. tipc_max_nodes);
  293. return;
  294. }
  295. c_ptr = n_ptr->owner;
  296. if (is_slave(n_ptr->addr)) {
  297. /* Usage case 2 (see above) */
  298. tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1, tipc_max_nodes);
  299. tipc_cltr_send_local_routes(c_ptr, n_ptr->addr);
  300. return;
  301. }
  302. if (n_ptr->bclink.supported) {
  303. tipc_nmap_add(&tipc_cltr_bcast_nodes, n_ptr->addr);
  304. if (n_ptr->addr < tipc_own_addr)
  305. tipc_own_tag++;
  306. }
  307. /* Case 3 (see above) */
  308. tipc_net_send_external_routes(n_ptr->addr);
  309. tipc_cltr_send_slave_routes(c_ptr, n_ptr->addr);
  310. tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, LOWEST_SLAVE,
  311. tipc_highest_allowed_slave);
  312. }
  313. static void node_lost_contact(struct node *n_ptr)
  314. {
  315. struct cluster *c_ptr;
  316. struct node_subscr *ns, *tns;
  317. char addr_string[16];
  318. u32 i;
  319. /* Clean up broadcast reception remains */
  320. n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0;
  321. while (n_ptr->bclink.deferred_head) {
  322. struct sk_buff* buf = n_ptr->bclink.deferred_head;
  323. n_ptr->bclink.deferred_head = buf->next;
  324. buf_discard(buf);
  325. }
  326. if (n_ptr->bclink.defragm) {
  327. buf_discard(n_ptr->bclink.defragm);
  328. n_ptr->bclink.defragm = NULL;
  329. }
  330. if (in_own_cluster(n_ptr->addr) && n_ptr->bclink.supported) {
  331. tipc_bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));
  332. }
  333. /* Update routing tables */
  334. if (is_slave(tipc_own_addr)) {
  335. tipc_net_remove_as_router(n_ptr->addr);
  336. } else {
  337. if (!in_own_cluster(n_ptr->addr)) {
  338. /* Case 4 (see above) */
  339. c_ptr = tipc_cltr_find(tipc_own_addr);
  340. tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
  341. tipc_max_nodes);
  342. } else {
  343. /* Case 5 (see above) */
  344. c_ptr = tipc_cltr_find(n_ptr->addr);
  345. if (is_slave(n_ptr->addr)) {
  346. tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
  347. tipc_max_nodes);
  348. } else {
  349. if (n_ptr->bclink.supported) {
  350. tipc_nmap_remove(&tipc_cltr_bcast_nodes,
  351. n_ptr->addr);
  352. if (n_ptr->addr < tipc_own_addr)
  353. tipc_own_tag--;
  354. }
  355. tipc_net_remove_as_router(n_ptr->addr);
  356. tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr,
  357. LOWEST_SLAVE,
  358. tipc_highest_allowed_slave);
  359. }
  360. }
  361. }
  362. if (tipc_node_has_active_routes(n_ptr))
  363. return;
  364. info("Lost contact with %s\n",
  365. addr_string_fill(addr_string, n_ptr->addr));
  366. /* Abort link changeover */
  367. for (i = 0; i < MAX_BEARERS; i++) {
  368. struct link *l_ptr = n_ptr->links[i];
  369. if (!l_ptr)
  370. continue;
  371. l_ptr->reset_checkpoint = l_ptr->next_in_no;
  372. l_ptr->exp_msg_count = 0;
  373. tipc_link_reset_fragments(l_ptr);
  374. }
  375. /* Notify subscribers */
  376. list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) {
  377. ns->node = NULL;
  378. list_del_init(&ns->nodesub_list);
  379. tipc_k_signal((Handler)ns->handle_node_down,
  380. (unsigned long)ns->usr_handle);
  381. }
  382. }
  383. /**
  384. * tipc_node_select_next_hop - find the next-hop node for a message
  385. *
  386. * Called by when cluster local lookup has failed.
  387. */
  388. struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
  389. {
  390. struct node *n_ptr;
  391. u32 router_addr;
  392. if (!tipc_addr_domain_valid(addr))
  393. return NULL;
  394. /* Look for direct link to destination processsor */
  395. n_ptr = tipc_node_find(addr);
  396. if (n_ptr && tipc_node_has_active_links(n_ptr))
  397. return n_ptr;
  398. /* Cluster local system nodes *must* have direct links */
  399. if (!is_slave(addr) && in_own_cluster(addr))
  400. return NULL;
  401. /* Look for cluster local router with direct link to node */
  402. router_addr = tipc_node_select_router(n_ptr, selector);
  403. if (router_addr)
  404. return tipc_node_select(router_addr, selector);
  405. /* Slave nodes can only be accessed within own cluster via a
  406. known router with direct link -- if no router was found,give up */
  407. if (is_slave(addr))
  408. return NULL;
  409. /* Inter zone/cluster -- find any direct link to remote cluster */
  410. addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
  411. n_ptr = tipc_net_select_remote_node(addr, selector);
  412. if (n_ptr && tipc_node_has_active_links(n_ptr))
  413. return n_ptr;
  414. /* Last resort -- look for any router to anywhere in remote zone */
  415. router_addr = tipc_net_select_router(addr, selector);
  416. if (router_addr)
  417. return tipc_node_select(router_addr, selector);
  418. return NULL;
  419. }
  420. /**
  421. * tipc_node_select_router - select router to reach specified node
  422. *
  423. * Uses a deterministic and fair algorithm for selecting router node.
  424. */
  425. u32 tipc_node_select_router(struct node *n_ptr, u32 ref)
  426. {
  427. u32 ulim;
  428. u32 mask;
  429. u32 start;
  430. u32 r;
  431. if (!n_ptr)
  432. return 0;
  433. if (n_ptr->last_router < 0)
  434. return 0;
  435. ulim = ((n_ptr->last_router + 1) * 32) - 1;
  436. /* Start entry must be random */
  437. mask = tipc_max_nodes;
  438. while (mask > ulim)
  439. mask >>= 1;
  440. start = ref & mask;
  441. r = start;
  442. /* Lookup upwards with wrap-around */
  443. do {
  444. if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
  445. break;
  446. } while (++r <= ulim);
  447. if (r > ulim) {
  448. r = 1;
  449. do {
  450. if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
  451. break;
  452. } while (++r < start);
  453. assert(r != start);
  454. }
  455. assert(r && (r <= ulim));
  456. return tipc_addr(own_zone(), own_cluster(), r);
  457. }
  458. void tipc_node_add_router(struct node *n_ptr, u32 router)
  459. {
  460. u32 r_num = tipc_node(router);
  461. n_ptr->routers[r_num / 32] =
  462. ((1 << (r_num % 32)) | n_ptr->routers[r_num / 32]);
  463. n_ptr->last_router = tipc_max_nodes / 32;
  464. while ((--n_ptr->last_router >= 0) &&
  465. !n_ptr->routers[n_ptr->last_router]);
  466. }
  467. void tipc_node_remove_router(struct node *n_ptr, u32 router)
  468. {
  469. u32 r_num = tipc_node(router);
  470. if (n_ptr->last_router < 0)
  471. return; /* No routes */
  472. n_ptr->routers[r_num / 32] =
  473. ((~(1 << (r_num % 32))) & (n_ptr->routers[r_num / 32]));
  474. n_ptr->last_router = tipc_max_nodes / 32;
  475. while ((--n_ptr->last_router >= 0) &&
  476. !n_ptr->routers[n_ptr->last_router]);
  477. if (!tipc_node_is_up(n_ptr))
  478. node_lost_contact(n_ptr);
  479. }
  480. #if 0
  481. void node_print(struct print_buf *buf, struct node *n_ptr, char *str)
  482. {
  483. u32 i;
  484. tipc_printf(buf, "\n\n%s", str);
  485. for (i = 0; i < MAX_BEARERS; i++) {
  486. if (!n_ptr->links[i])
  487. continue;
  488. tipc_printf(buf, "Links[%u]: %x, ", i, n_ptr->links[i]);
  489. }
  490. tipc_printf(buf, "Active links: [%x,%x]\n",
  491. n_ptr->active_links[0], n_ptr->active_links[1]);
  492. }
  493. #endif
  494. u32 tipc_available_nodes(const u32 domain)
  495. {
  496. struct node *n_ptr;
  497. u32 cnt = 0;
  498. for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
  499. if (!in_scope(domain, n_ptr->addr))
  500. continue;
  501. if (tipc_node_is_up(n_ptr))
  502. cnt++;
  503. }
  504. return cnt;
  505. }
  506. struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
  507. {
  508. u32 domain;
  509. struct sk_buff *buf;
  510. struct node *n_ptr;
  511. struct tipc_node_info node_info;
  512. u32 payload_size;
  513. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  514. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  515. domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  516. if (!tipc_addr_domain_valid(domain))
  517. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  518. " (network address)");
  519. if (!tipc_nodes)
  520. return tipc_cfg_reply_none();
  521. /* For now, get space for all other nodes
  522. (will need to modify this when slave nodes are supported */
  523. payload_size = TLV_SPACE(sizeof(node_info)) * (tipc_max_nodes - 1);
  524. if (payload_size > 32768u)
  525. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  526. " (too many nodes)");
  527. buf = tipc_cfg_reply_alloc(payload_size);
  528. if (!buf)
  529. return NULL;
  530. /* Add TLVs for all nodes in scope */
  531. for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
  532. if (!in_scope(domain, n_ptr->addr))
  533. continue;
  534. node_info.addr = htonl(n_ptr->addr);
  535. node_info.up = htonl(tipc_node_is_up(n_ptr));
  536. tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
  537. &node_info, sizeof(node_info));
  538. }
  539. return buf;
  540. }
  541. struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
  542. {
  543. u32 domain;
  544. struct sk_buff *buf;
  545. struct node *n_ptr;
  546. struct tipc_link_info link_info;
  547. u32 payload_size;
  548. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  549. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  550. domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
  551. if (!tipc_addr_domain_valid(domain))
  552. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  553. " (network address)");
  554. if (tipc_mode != TIPC_NET_MODE)
  555. return tipc_cfg_reply_none();
  556. /* Get space for all unicast links + multicast link */
  557. payload_size = TLV_SPACE(sizeof(link_info)) *
  558. (tipc_net.zones[tipc_zone(tipc_own_addr)]->links + 1);
  559. if (payload_size > 32768u)
  560. return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
  561. " (too many links)");
  562. buf = tipc_cfg_reply_alloc(payload_size);
  563. if (!buf)
  564. return NULL;
  565. /* Add TLV for broadcast link */
  566. link_info.dest = htonl(tipc_own_addr & 0xfffff00);
  567. link_info.up = htonl(1);
  568. sprintf(link_info.str, tipc_bclink_name);
  569. tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
  570. /* Add TLVs for any other links in scope */
  571. for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
  572. u32 i;
  573. if (!in_scope(domain, n_ptr->addr))
  574. continue;
  575. for (i = 0; i < MAX_BEARERS; i++) {
  576. if (!n_ptr->links[i])
  577. continue;
  578. link_info.dest = htonl(n_ptr->addr);
  579. link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
  580. strcpy(link_info.str, n_ptr->links[i]->name);
  581. tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
  582. &link_info, sizeof(link_info));
  583. }
  584. }
  585. return buf;
  586. }