node.c 20 KB

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