node.c 19 KB

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