node.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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. assert(bearer_id < MAX_BEARERS);
  203. if (n_ptr->link_cnt >= 2) {
  204. char addr_string[16];
  205. err("Attempt to create third link to %s\n",
  206. addr_string_fill(addr_string, n_ptr->addr));
  207. return NULL;
  208. }
  209. if (!n_ptr->links[bearer_id]) {
  210. n_ptr->links[bearer_id] = l_ptr;
  211. tipc_net.zones[tipc_zone(l_ptr->addr)]->links++;
  212. n_ptr->link_cnt++;
  213. return n_ptr;
  214. }
  215. err("Attempt to establish second link on <%s> to <%s> \n",
  216. l_ptr->b_ptr->publ.name,
  217. addr_string_fill(addr_string, l_ptr->addr));
  218. }
  219. return NULL;
  220. }
  221. void tipc_node_detach_link(struct node *n_ptr, struct link *l_ptr)
  222. {
  223. n_ptr->links[l_ptr->b_ptr->identity] = NULL;
  224. tipc_net.zones[tipc_zone(l_ptr->addr)]->links--;
  225. n_ptr->link_cnt--;
  226. }
  227. /*
  228. * Routing table management - five cases to handle:
  229. *
  230. * 1: A link towards a zone/cluster external node comes up.
  231. * => Send a multicast message updating routing tables of all
  232. * system nodes within own cluster that the new destination
  233. * can be reached via this node.
  234. * (node.establishedContact()=>cluster.multicastNewRoute())
  235. *
  236. * 2: A link towards a slave node comes up.
  237. * => Send a multicast message updating routing tables of all
  238. * system nodes within own cluster that the new destination
  239. * can be reached via this node.
  240. * (node.establishedContact()=>cluster.multicastNewRoute())
  241. * => Send a message to the slave node about existence
  242. * of all system nodes within cluster:
  243. * (node.establishedContact()=>cluster.sendLocalRoutes())
  244. *
  245. * 3: A new cluster local system node becomes available.
  246. * => Send message(s) to this particular node containing
  247. * information about all cluster external and slave
  248. * nodes which can be reached via this node.
  249. * (node.establishedContact()==>network.sendExternalRoutes())
  250. * (node.establishedContact()==>network.sendSlaveRoutes())
  251. * => Send messages to all directly connected slave nodes
  252. * containing information about the existence of the new node
  253. * (node.establishedContact()=>cluster.multicastNewRoute())
  254. *
  255. * 4: The link towards a zone/cluster external node or slave
  256. * node goes down.
  257. * => Send a multcast message updating routing tables of all
  258. * nodes within cluster that the new destination can not any
  259. * longer be reached via this node.
  260. * (node.lostAllLinks()=>cluster.bcastLostRoute())
  261. *
  262. * 5: A cluster local system node becomes unavailable.
  263. * => Remove all references to this node from the local
  264. * routing tables. Note: This is a completely node
  265. * local operation.
  266. * (node.lostAllLinks()=>network.removeAsRouter())
  267. * => Send messages to all directly connected slave nodes
  268. * containing information about loss of the node
  269. * (node.establishedContact()=>cluster.multicastLostRoute())
  270. *
  271. */
  272. static void node_established_contact(struct node *n_ptr)
  273. {
  274. struct cluster *c_ptr;
  275. dbg("node_established_contact:-> %x\n", n_ptr->addr);
  276. if (!tipc_node_has_active_routes(n_ptr)) {
  277. tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
  278. }
  279. /* Syncronize broadcast acks */
  280. n_ptr->bclink.acked = tipc_bclink_get_last_sent();
  281. if (is_slave(tipc_own_addr))
  282. return;
  283. if (!in_own_cluster(n_ptr->addr)) {
  284. /* Usage case 1 (see above) */
  285. c_ptr = tipc_cltr_find(tipc_own_addr);
  286. if (!c_ptr)
  287. c_ptr = tipc_cltr_create(tipc_own_addr);
  288. if (c_ptr)
  289. tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1,
  290. tipc_max_nodes);
  291. return;
  292. }
  293. c_ptr = n_ptr->owner;
  294. if (is_slave(n_ptr->addr)) {
  295. /* Usage case 2 (see above) */
  296. tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1, tipc_max_nodes);
  297. tipc_cltr_send_local_routes(c_ptr, n_ptr->addr);
  298. return;
  299. }
  300. if (n_ptr->bclink.supported) {
  301. tipc_nmap_add(&tipc_cltr_bcast_nodes, n_ptr->addr);
  302. if (n_ptr->addr < tipc_own_addr)
  303. tipc_own_tag++;
  304. }
  305. /* Case 3 (see above) */
  306. tipc_net_send_external_routes(n_ptr->addr);
  307. tipc_cltr_send_slave_routes(c_ptr, n_ptr->addr);
  308. tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, LOWEST_SLAVE,
  309. tipc_highest_allowed_slave);
  310. }
  311. static void node_lost_contact(struct node *n_ptr)
  312. {
  313. struct cluster *c_ptr;
  314. struct node_subscr *ns, *tns;
  315. char addr_string[16];
  316. u32 i;
  317. /* Clean up broadcast reception remains */
  318. n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0;
  319. while (n_ptr->bclink.deferred_head) {
  320. struct sk_buff* buf = n_ptr->bclink.deferred_head;
  321. n_ptr->bclink.deferred_head = buf->next;
  322. buf_discard(buf);
  323. }
  324. if (n_ptr->bclink.defragm) {
  325. buf_discard(n_ptr->bclink.defragm);
  326. n_ptr->bclink.defragm = NULL;
  327. }
  328. if (in_own_cluster(n_ptr->addr) && n_ptr->bclink.supported) {
  329. tipc_bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));
  330. }
  331. /* Update routing tables */
  332. if (is_slave(tipc_own_addr)) {
  333. tipc_net_remove_as_router(n_ptr->addr);
  334. } else {
  335. if (!in_own_cluster(n_ptr->addr)) {
  336. /* Case 4 (see above) */
  337. c_ptr = tipc_cltr_find(tipc_own_addr);
  338. tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
  339. tipc_max_nodes);
  340. } else {
  341. /* Case 5 (see above) */
  342. c_ptr = tipc_cltr_find(n_ptr->addr);
  343. if (is_slave(n_ptr->addr)) {
  344. tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
  345. tipc_max_nodes);
  346. } else {
  347. if (n_ptr->bclink.supported) {
  348. tipc_nmap_remove(&tipc_cltr_bcast_nodes,
  349. n_ptr->addr);
  350. if (n_ptr->addr < tipc_own_addr)
  351. tipc_own_tag--;
  352. }
  353. tipc_net_remove_as_router(n_ptr->addr);
  354. tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr,
  355. LOWEST_SLAVE,
  356. tipc_highest_allowed_slave);
  357. }
  358. }
  359. }
  360. if (tipc_node_has_active_routes(n_ptr))
  361. return;
  362. info("Lost contact with %s\n",
  363. addr_string_fill(addr_string, n_ptr->addr));
  364. /* Abort link changeover */
  365. for (i = 0; i < MAX_BEARERS; i++) {
  366. struct link *l_ptr = n_ptr->links[i];
  367. if (!l_ptr)
  368. continue;
  369. l_ptr->reset_checkpoint = l_ptr->next_in_no;
  370. l_ptr->exp_msg_count = 0;
  371. tipc_link_reset_fragments(l_ptr);
  372. }
  373. /* Notify subscribers */
  374. list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) {
  375. ns->node = NULL;
  376. list_del_init(&ns->nodesub_list);
  377. tipc_k_signal((Handler)ns->handle_node_down,
  378. (unsigned long)ns->usr_handle);
  379. }
  380. }
  381. /**
  382. * tipc_node_select_next_hop - find the next-hop node for a message
  383. *
  384. * Called by when cluster local lookup has failed.
  385. */
  386. struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
  387. {
  388. struct node *n_ptr;
  389. u32 router_addr;
  390. if (!tipc_addr_domain_valid(addr))
  391. return NULL;
  392. /* Look for direct link to destination processsor */
  393. n_ptr = tipc_node_find(addr);
  394. if (n_ptr && tipc_node_has_active_links(n_ptr))
  395. return n_ptr;
  396. /* Cluster local system nodes *must* have direct links */
  397. if (!is_slave(addr) && in_own_cluster(addr))
  398. return NULL;
  399. /* Look for cluster local router with direct link to node */
  400. router_addr = tipc_node_select_router(n_ptr, selector);
  401. if (router_addr)
  402. return tipc_node_select(router_addr, selector);
  403. /* Slave nodes can only be accessed within own cluster via a
  404. known router with direct link -- if no router was found,give up */
  405. if (is_slave(addr))
  406. return NULL;
  407. /* Inter zone/cluster -- find any direct link to remote cluster */
  408. addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
  409. n_ptr = tipc_net_select_remote_node(addr, selector);
  410. if (n_ptr && tipc_node_has_active_links(n_ptr))
  411. return n_ptr;
  412. /* Last resort -- look for any router to anywhere in remote zone */
  413. router_addr = tipc_net_select_router(addr, selector);
  414. if (router_addr)
  415. return tipc_node_select(router_addr, selector);
  416. return NULL;
  417. }
  418. /**
  419. * tipc_node_select_router - select router to reach specified node
  420. *
  421. * Uses a deterministic and fair algorithm for selecting router node.
  422. */
  423. u32 tipc_node_select_router(struct node *n_ptr, u32 ref)
  424. {
  425. u32 ulim;
  426. u32 mask;
  427. u32 start;
  428. u32 r;
  429. if (!n_ptr)
  430. return 0;
  431. if (n_ptr->last_router < 0)
  432. return 0;
  433. ulim = ((n_ptr->last_router + 1) * 32) - 1;
  434. /* Start entry must be random */
  435. mask = tipc_max_nodes;
  436. while (mask > ulim)
  437. mask >>= 1;
  438. start = ref & mask;
  439. r = start;
  440. /* Lookup upwards with wrap-around */
  441. do {
  442. if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
  443. break;
  444. } while (++r <= ulim);
  445. if (r > ulim) {
  446. r = 1;
  447. do {
  448. if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
  449. break;
  450. } while (++r < start);
  451. assert(r != start);
  452. }
  453. assert(r && (r <= ulim));
  454. return tipc_addr(own_zone(), own_cluster(), r);
  455. }
  456. void tipc_node_add_router(struct node *n_ptr, u32 router)
  457. {
  458. u32 r_num = tipc_node(router);
  459. n_ptr->routers[r_num / 32] =
  460. ((1 << (r_num % 32)) | n_ptr->routers[r_num / 32]);
  461. n_ptr->last_router = tipc_max_nodes / 32;
  462. while ((--n_ptr->last_router >= 0) &&
  463. !n_ptr->routers[n_ptr->last_router]);
  464. }
  465. void tipc_node_remove_router(struct node *n_ptr, u32 router)
  466. {
  467. u32 r_num = tipc_node(router);
  468. if (n_ptr->last_router < 0)
  469. return; /* No routes */
  470. n_ptr->routers[r_num / 32] =
  471. ((~(1 << (r_num % 32))) & (n_ptr->routers[r_num / 32]));
  472. n_ptr->last_router = tipc_max_nodes / 32;
  473. while ((--n_ptr->last_router >= 0) &&
  474. !n_ptr->routers[n_ptr->last_router]);
  475. if (!tipc_node_is_up(n_ptr))
  476. node_lost_contact(n_ptr);
  477. }
  478. #if 0
  479. void node_print(struct print_buf *buf, struct node *n_ptr, char *str)
  480. {
  481. u32 i;
  482. tipc_printf(buf, "\n\n%s", str);
  483. for (i = 0; i < MAX_BEARERS; i++) {
  484. if (!n_ptr->links[i])
  485. continue;
  486. tipc_printf(buf, "Links[%u]: %x, ", i, n_ptr->links[i]);
  487. }
  488. tipc_printf(buf, "Active links: [%x,%x]\n",
  489. n_ptr->active_links[0], n_ptr->active_links[1]);
  490. }
  491. #endif
  492. u32 tipc_available_nodes(const u32 domain)
  493. {
  494. struct node *n_ptr;
  495. u32 cnt = 0;
  496. for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
  497. if (!in_scope(domain, n_ptr->addr))
  498. continue;
  499. if (tipc_node_is_up(n_ptr))
  500. cnt++;
  501. }
  502. return cnt;
  503. }
  504. struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
  505. {
  506. u32 domain;
  507. struct sk_buff *buf;
  508. struct node *n_ptr;
  509. struct tipc_node_info node_info;
  510. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  511. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  512. domain = *(u32 *)TLV_DATA(req_tlv_area);
  513. domain = ntohl(domain);
  514. if (!tipc_addr_domain_valid(domain))
  515. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  516. " (network address)");
  517. if (!tipc_nodes)
  518. return tipc_cfg_reply_none();
  519. /* For now, get space for all other nodes
  520. (will need to modify this when slave nodes are supported */
  521. buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(node_info)) *
  522. (tipc_max_nodes - 1));
  523. if (!buf)
  524. return NULL;
  525. /* Add TLVs for all nodes in scope */
  526. for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
  527. if (!in_scope(domain, n_ptr->addr))
  528. continue;
  529. node_info.addr = htonl(n_ptr->addr);
  530. node_info.up = htonl(tipc_node_is_up(n_ptr));
  531. tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
  532. &node_info, sizeof(node_info));
  533. }
  534. return buf;
  535. }
  536. struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
  537. {
  538. u32 domain;
  539. struct sk_buff *buf;
  540. struct node *n_ptr;
  541. struct tipc_link_info link_info;
  542. if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
  543. return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
  544. domain = *(u32 *)TLV_DATA(req_tlv_area);
  545. domain = ntohl(domain);
  546. if (!tipc_addr_domain_valid(domain))
  547. return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
  548. " (network address)");
  549. if (!tipc_nodes)
  550. return tipc_cfg_reply_none();
  551. /* For now, get space for 2 links to all other nodes + bcast link
  552. (will need to modify this when slave nodes are supported */
  553. buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(link_info)) *
  554. (2 * (tipc_max_nodes - 1) + 1));
  555. if (!buf)
  556. return NULL;
  557. /* Add TLV for broadcast link */
  558. link_info.dest = tipc_own_addr & 0xfffff00;
  559. link_info.dest = htonl(link_info.dest);
  560. link_info.up = htonl(1);
  561. sprintf(link_info.str, tipc_bclink_name);
  562. tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
  563. /* Add TLVs for any other links in scope */
  564. for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
  565. u32 i;
  566. if (!in_scope(domain, n_ptr->addr))
  567. continue;
  568. for (i = 0; i < MAX_BEARERS; i++) {
  569. if (!n_ptr->links[i])
  570. continue;
  571. link_info.dest = htonl(n_ptr->addr);
  572. link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
  573. strcpy(link_info.str, n_ptr->links[i]->name);
  574. tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
  575. &link_info, sizeof(link_info));
  576. }
  577. }
  578. return buf;
  579. }