node.c 19 KB

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