node.c 20 KB

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