node.c 19 KB

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