node.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the names of the copyright holders nor the names of its
  18. * contributors may be used to endorse or promote products derived from
  19. * this software without specific prior written permission.
  20. *
  21. * Alternatively, this software may be distributed under the terms of the
  22. * GNU General Public License ("GPL") version 2 as published by the Free
  23. * Software Foundation.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  29. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  30. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  31. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  32. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  33. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. */
  37. #include "core.h"
  38. #include "config.h"
  39. #include "node.h"
  40. #include "cluster.h"
  41. #include "net.h"
  42. #include "addr.h"
  43. #include "node_subscr.h"
  44. #include "link.h"
  45. #include "port.h"
  46. #include "bearer.h"
  47. #include "name_distr.h"
  48. #include "net.h"
  49. void node_print(struct print_buf *buf, struct node *n_ptr, char *str);
  50. static void node_lost_contact(struct node *n_ptr);
  51. static void node_established_contact(struct node *n_ptr);
  52. struct node *nodes = NULL; /* sorted list of nodes within cluster */
  53. u32 tipc_own_tag = 0;
  54. struct node *node_create(u32 addr)
  55. {
  56. struct cluster *c_ptr;
  57. struct node *n_ptr;
  58. struct node **curr_node;
  59. n_ptr = kmalloc(sizeof(*n_ptr),GFP_ATOMIC);
  60. if (n_ptr != NULL) {
  61. memset(n_ptr, 0, sizeof(*n_ptr));
  62. n_ptr->addr = addr;
  63. n_ptr->lock = SPIN_LOCK_UNLOCKED;
  64. INIT_LIST_HEAD(&n_ptr->nsub);
  65. c_ptr = cluster_find(addr);
  66. if (c_ptr == NULL)
  67. c_ptr = cluster_create(addr);
  68. if (c_ptr != NULL) {
  69. n_ptr->owner = c_ptr;
  70. cluster_attach_node(c_ptr, n_ptr);
  71. n_ptr->last_router = -1;
  72. /* Insert node into ordered list */
  73. for (curr_node = &nodes; *curr_node;
  74. curr_node = &(*curr_node)->next) {
  75. if (addr < (*curr_node)->addr) {
  76. n_ptr->next = *curr_node;
  77. break;
  78. }
  79. }
  80. (*curr_node) = n_ptr;
  81. } else {
  82. kfree(n_ptr);
  83. n_ptr = NULL;
  84. }
  85. }
  86. return n_ptr;
  87. }
  88. void 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 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. * node_link_up - handle addition of link
  104. *
  105. * Link becomes active (alone or shared) or standby, depending on its priority.
  106. */
  107. void node_link_up(struct node *n_ptr, struct link *l_ptr)
  108. {
  109. struct link **active = &n_ptr->active_links[0];
  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("Link is standby\n");
  120. return;
  121. }
  122. 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("Link <%s> on network plane %c becomes standby\n",
  128. active[0]->name, active[0]->b_ptr->net_plane);
  129. active[0] = active[1] = l_ptr;
  130. }
  131. /**
  132. * node_select_active_links - select active link
  133. */
  134. static void node_select_active_links(struct node *n_ptr)
  135. {
  136. struct link **active = &n_ptr->active_links[0];
  137. u32 i;
  138. u32 highest_prio = 0;
  139. active[0] = active[1] = 0;
  140. for (i = 0; i < MAX_BEARERS; i++) {
  141. struct link *l_ptr = n_ptr->links[i];
  142. if (!l_ptr || !link_is_up(l_ptr) ||
  143. (l_ptr->priority < highest_prio))
  144. continue;
  145. if (l_ptr->priority > highest_prio) {
  146. highest_prio = l_ptr->priority;
  147. active[0] = active[1] = l_ptr;
  148. } else {
  149. active[1] = l_ptr;
  150. }
  151. }
  152. }
  153. /**
  154. * node_link_down - handle loss of link
  155. */
  156. void node_link_down(struct node *n_ptr, struct link *l_ptr)
  157. {
  158. struct link **active;
  159. if (!link_is_active(l_ptr)) {
  160. info("Lost standby link <%s> on network plane %c\n",
  161. l_ptr->name, l_ptr->b_ptr->net_plane);
  162. return;
  163. }
  164. info("Lost link <%s> on network plane %c\n",
  165. l_ptr->name, l_ptr->b_ptr->net_plane);
  166. active = &n_ptr->active_links[0];
  167. if (active[0] == l_ptr)
  168. active[0] = active[1];
  169. if (active[1] == l_ptr)
  170. active[1] = active[0];
  171. if (active[0] == l_ptr)
  172. node_select_active_links(n_ptr);
  173. if (node_is_up(n_ptr))
  174. link_changeover(l_ptr);
  175. else
  176. node_lost_contact(n_ptr);
  177. }
  178. int node_has_active_links(struct node *n_ptr)
  179. {
  180. return (n_ptr &&
  181. ((n_ptr->active_links[0]) || (n_ptr->active_links[1])));
  182. }
  183. int node_has_redundant_links(struct node *n_ptr)
  184. {
  185. return (node_has_active_links(n_ptr) &&
  186. (n_ptr->active_links[0] != n_ptr->active_links[1]));
  187. }
  188. int node_has_active_routes(struct node *n_ptr)
  189. {
  190. return (n_ptr && (n_ptr->last_router >= 0));
  191. }
  192. int node_is_up(struct node *n_ptr)
  193. {
  194. return (node_has_active_links(n_ptr) || node_has_active_routes(n_ptr));
  195. }
  196. struct node *node_attach_link(struct link *l_ptr)
  197. {
  198. struct node *n_ptr = node_find(l_ptr->addr);
  199. if (!n_ptr)
  200. n_ptr = node_create(l_ptr->addr);
  201. if (n_ptr) {
  202. u32 bearer_id = l_ptr->b_ptr->identity;
  203. char addr_string[16];
  204. assert(bearer_id < MAX_BEARERS);
  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 0;
  210. }
  211. if (!n_ptr->links[bearer_id]) {
  212. n_ptr->links[bearer_id] = l_ptr;
  213. 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 0;
  222. }
  223. void node_detach_link(struct node *n_ptr, struct link *l_ptr)
  224. {
  225. n_ptr->links[l_ptr->b_ptr->identity] = 0;
  226. 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 (!node_has_active_routes(n_ptr)) {
  279. k_signal((Handler)named_node_up, n_ptr->addr);
  280. }
  281. /* Syncronize broadcast acks */
  282. n_ptr->bclink.acked = 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 = cluster_find(tipc_own_addr);
  288. if (!c_ptr)
  289. c_ptr = cluster_create(tipc_own_addr);
  290. if (c_ptr)
  291. cluster_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. cluster_bcast_new_route(c_ptr, n_ptr->addr, 1, tipc_max_nodes);
  299. cluster_send_local_routes(c_ptr, n_ptr->addr);
  300. return;
  301. }
  302. if (n_ptr->bclink.supported) {
  303. nmap_add(&cluster_bcast_nodes, n_ptr->addr);
  304. if (n_ptr->addr < tipc_own_addr)
  305. tipc_own_tag++;
  306. }
  307. /* Case 3 (see above) */
  308. net_send_external_routes(n_ptr->addr);
  309. cluster_send_slave_routes(c_ptr, n_ptr->addr);
  310. cluster_bcast_new_route(c_ptr, n_ptr->addr, LOWEST_SLAVE,
  311. 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. bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));
  332. }
  333. /* Update routing tables */
  334. if (is_slave(tipc_own_addr)) {
  335. 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 = cluster_find(tipc_own_addr);
  340. cluster_bcast_lost_route(c_ptr, n_ptr->addr, 1,
  341. tipc_max_nodes);
  342. } else {
  343. /* Case 5 (see above) */
  344. c_ptr = cluster_find(n_ptr->addr);
  345. if (is_slave(n_ptr->addr)) {
  346. cluster_bcast_lost_route(c_ptr, n_ptr->addr, 1,
  347. tipc_max_nodes);
  348. } else {
  349. if (n_ptr->bclink.supported) {
  350. nmap_remove(&cluster_bcast_nodes,
  351. n_ptr->addr);
  352. if (n_ptr->addr < tipc_own_addr)
  353. tipc_own_tag--;
  354. }
  355. net_remove_as_router(n_ptr->addr);
  356. cluster_bcast_lost_route(c_ptr, n_ptr->addr,
  357. LOWEST_SLAVE,
  358. highest_allowed_slave);
  359. }
  360. }
  361. }
  362. if (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. 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 = 0;
  378. list_del_init(&ns->nodesub_list);
  379. k_signal((Handler)ns->handle_node_down,
  380. (unsigned long)ns->usr_handle);
  381. }
  382. }
  383. /**
  384. * 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 *node_select_next_hop(u32 addr, u32 selector)
  389. {
  390. struct node *n_ptr;
  391. u32 router_addr;
  392. if (!addr_domain_valid(addr))
  393. return 0;
  394. /* Look for direct link to destination processsor */
  395. n_ptr = node_find(addr);
  396. if (n_ptr && 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 0;
  401. /* Look for cluster local router with direct link to node */
  402. router_addr = node_select_router(n_ptr, selector);
  403. if (router_addr)
  404. return 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 0;
  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 = net_select_remote_node(addr, selector);
  412. if (n_ptr && 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 = net_select_router(addr, selector);
  416. if (router_addr)
  417. return node_select(router_addr, selector);
  418. return 0;
  419. }
  420. /**
  421. * node_select_router - select router to reach specified node
  422. *
  423. * Uses a deterministic and fair algorithm for selecting router node.
  424. */
  425. u32 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 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 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 (!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 = nodes; n_ptr; n_ptr = n_ptr->next) {
  499. if (!in_scope(domain, n_ptr->addr))
  500. continue;
  501. if (node_is_up(n_ptr))
  502. cnt++;
  503. }
  504. return cnt;
  505. }
  506. struct sk_buff *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. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  513. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  514. domain = *(u32 *)TLV_DATA(req_tlv_area);
  515. domain = ntohl(domain);
  516. if (!addr_domain_valid(domain))
  517. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  518. " (network address)");
  519. if (!nodes)
  520. return cfg_reply_none();
  521. /* For now, get space for all other nodes
  522. (will need to modify this when slave nodes are supported */
  523. buf = cfg_reply_alloc(TLV_SPACE(sizeof(node_info)) *
  524. (tipc_max_nodes - 1));
  525. if (!buf)
  526. return NULL;
  527. /* Add TLVs for all nodes in scope */
  528. for (n_ptr = nodes; n_ptr; n_ptr = n_ptr->next) {
  529. if (!in_scope(domain, n_ptr->addr))
  530. continue;
  531. node_info.addr = htonl(n_ptr->addr);
  532. node_info.up = htonl(node_is_up(n_ptr));
  533. cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
  534. &node_info, sizeof(node_info));
  535. }
  536. return buf;
  537. }
  538. struct sk_buff *node_get_links(const void *req_tlv_area, int req_tlv_space)
  539. {
  540. u32 domain;
  541. struct sk_buff *buf;
  542. struct node *n_ptr;
  543. struct tipc_link_info link_info;
  544. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  545. return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  546. domain = *(u32 *)TLV_DATA(req_tlv_area);
  547. domain = ntohl(domain);
  548. if (!addr_domain_valid(domain))
  549. return cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  550. " (network address)");
  551. if (!nodes)
  552. return cfg_reply_none();
  553. /* For now, get space for 2 links to all other nodes + bcast link
  554. (will need to modify this when slave nodes are supported */
  555. buf = cfg_reply_alloc(TLV_SPACE(sizeof(link_info)) *
  556. (2 * (tipc_max_nodes - 1) + 1));
  557. if (!buf)
  558. return NULL;
  559. /* Add TLV for broadcast link */
  560. link_info.dest = tipc_own_addr & 0xfffff00;
  561. link_info.dest = htonl(link_info.dest);
  562. link_info.up = htonl(1);
  563. sprintf(link_info.str, bc_link_name);
  564. cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
  565. /* Add TLVs for any other links in scope */
  566. for (n_ptr = nodes; n_ptr; n_ptr = n_ptr->next) {
  567. u32 i;
  568. if (!in_scope(domain, n_ptr->addr))
  569. continue;
  570. for (i = 0; i < MAX_BEARERS; i++) {
  571. if (!n_ptr->links[i])
  572. continue;
  573. link_info.dest = htonl(n_ptr->addr);
  574. link_info.up = htonl(link_is_up(n_ptr->links[i]));
  575. strcpy(link_info.str, n_ptr->links[i]->name);
  576. cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
  577. &link_info, sizeof(link_info));
  578. }
  579. }
  580. return buf;
  581. }