node.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * net/tipc/node.c: TIPC node management routines
  3. *
  4. * Copyright (c) 2000-2006, 2012-2014, Ericsson AB
  5. * Copyright (c) 2005-2006, 2010-2014, 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 "link.h"
  38. #include "node.h"
  39. #include "name_distr.h"
  40. #include "socket.h"
  41. static void node_lost_contact(struct tipc_node *n_ptr);
  42. static void node_established_contact(struct tipc_node *n_ptr);
  43. static void tipc_node_delete(struct tipc_node *node);
  44. struct tipc_sock_conn {
  45. u32 port;
  46. u32 peer_port;
  47. u32 peer_node;
  48. struct list_head list;
  49. };
  50. static const struct nla_policy tipc_nl_node_policy[TIPC_NLA_NODE_MAX + 1] = {
  51. [TIPC_NLA_NODE_UNSPEC] = { .type = NLA_UNSPEC },
  52. [TIPC_NLA_NODE_ADDR] = { .type = NLA_U32 },
  53. [TIPC_NLA_NODE_UP] = { .type = NLA_FLAG }
  54. };
  55. /*
  56. * A trivial power-of-two bitmask technique is used for speed, since this
  57. * operation is done for every incoming TIPC packet. The number of hash table
  58. * entries has been chosen so that no hash chain exceeds 8 nodes and will
  59. * usually be much smaller (typically only a single node).
  60. */
  61. static unsigned int tipc_hashfn(u32 addr)
  62. {
  63. return addr & (NODE_HTABLE_SIZE - 1);
  64. }
  65. static void tipc_node_kref_release(struct kref *kref)
  66. {
  67. struct tipc_node *node = container_of(kref, struct tipc_node, kref);
  68. tipc_node_delete(node);
  69. }
  70. void tipc_node_put(struct tipc_node *node)
  71. {
  72. kref_put(&node->kref, tipc_node_kref_release);
  73. }
  74. static void tipc_node_get(struct tipc_node *node)
  75. {
  76. kref_get(&node->kref);
  77. }
  78. /*
  79. * tipc_node_find - locate specified node object, if it exists
  80. */
  81. struct tipc_node *tipc_node_find(struct net *net, u32 addr)
  82. {
  83. struct tipc_net *tn = net_generic(net, tipc_net_id);
  84. struct tipc_node *node;
  85. if (unlikely(!in_own_cluster_exact(net, addr)))
  86. return NULL;
  87. rcu_read_lock();
  88. hlist_for_each_entry_rcu(node, &tn->node_htable[tipc_hashfn(addr)],
  89. hash) {
  90. if (node->addr == addr) {
  91. tipc_node_get(node);
  92. rcu_read_unlock();
  93. return node;
  94. }
  95. }
  96. rcu_read_unlock();
  97. return NULL;
  98. }
  99. struct tipc_node *tipc_node_create(struct net *net, u32 addr)
  100. {
  101. struct tipc_net *tn = net_generic(net, tipc_net_id);
  102. struct tipc_node *n_ptr, *temp_node;
  103. spin_lock_bh(&tn->node_list_lock);
  104. n_ptr = tipc_node_find(net, addr);
  105. if (n_ptr)
  106. goto exit;
  107. n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC);
  108. if (!n_ptr) {
  109. pr_warn("Node creation failed, no memory\n");
  110. goto exit;
  111. }
  112. n_ptr->addr = addr;
  113. n_ptr->net = net;
  114. kref_init(&n_ptr->kref);
  115. spin_lock_init(&n_ptr->lock);
  116. INIT_HLIST_NODE(&n_ptr->hash);
  117. INIT_LIST_HEAD(&n_ptr->list);
  118. INIT_LIST_HEAD(&n_ptr->publ_list);
  119. INIT_LIST_HEAD(&n_ptr->conn_sks);
  120. __skb_queue_head_init(&n_ptr->bclink.deferdq);
  121. hlist_add_head_rcu(&n_ptr->hash, &tn->node_htable[tipc_hashfn(addr)]);
  122. list_for_each_entry_rcu(temp_node, &tn->node_list, list) {
  123. if (n_ptr->addr < temp_node->addr)
  124. break;
  125. }
  126. list_add_tail_rcu(&n_ptr->list, &temp_node->list);
  127. n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN;
  128. n_ptr->signature = INVALID_NODE_SIG;
  129. tipc_node_get(n_ptr);
  130. exit:
  131. spin_unlock_bh(&tn->node_list_lock);
  132. return n_ptr;
  133. }
  134. static void tipc_node_delete(struct tipc_node *node)
  135. {
  136. list_del_rcu(&node->list);
  137. hlist_del_rcu(&node->hash);
  138. kfree_rcu(node, rcu);
  139. }
  140. void tipc_node_stop(struct net *net)
  141. {
  142. struct tipc_net *tn = net_generic(net, tipc_net_id);
  143. struct tipc_node *node, *t_node;
  144. spin_lock_bh(&tn->node_list_lock);
  145. list_for_each_entry_safe(node, t_node, &tn->node_list, list)
  146. tipc_node_put(node);
  147. spin_unlock_bh(&tn->node_list_lock);
  148. }
  149. int tipc_node_add_conn(struct net *net, u32 dnode, u32 port, u32 peer_port)
  150. {
  151. struct tipc_node *node;
  152. struct tipc_sock_conn *conn;
  153. int err = 0;
  154. if (in_own_node(net, dnode))
  155. return 0;
  156. node = tipc_node_find(net, dnode);
  157. if (!node) {
  158. pr_warn("Connecting sock to node 0x%x failed\n", dnode);
  159. return -EHOSTUNREACH;
  160. }
  161. conn = kmalloc(sizeof(*conn), GFP_ATOMIC);
  162. if (!conn) {
  163. err = -EHOSTUNREACH;
  164. goto exit;
  165. }
  166. conn->peer_node = dnode;
  167. conn->port = port;
  168. conn->peer_port = peer_port;
  169. tipc_node_lock(node);
  170. list_add_tail(&conn->list, &node->conn_sks);
  171. tipc_node_unlock(node);
  172. exit:
  173. tipc_node_put(node);
  174. return err;
  175. }
  176. void tipc_node_remove_conn(struct net *net, u32 dnode, u32 port)
  177. {
  178. struct tipc_node *node;
  179. struct tipc_sock_conn *conn, *safe;
  180. if (in_own_node(net, dnode))
  181. return;
  182. node = tipc_node_find(net, dnode);
  183. if (!node)
  184. return;
  185. tipc_node_lock(node);
  186. list_for_each_entry_safe(conn, safe, &node->conn_sks, list) {
  187. if (port != conn->port)
  188. continue;
  189. list_del(&conn->list);
  190. kfree(conn);
  191. }
  192. tipc_node_unlock(node);
  193. tipc_node_put(node);
  194. }
  195. /**
  196. * tipc_node_link_up - handle addition of link
  197. *
  198. * Link becomes active (alone or shared) or standby, depending on its priority.
  199. */
  200. void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
  201. {
  202. struct tipc_link **active = &n_ptr->active_links[0];
  203. n_ptr->working_links++;
  204. n_ptr->action_flags |= TIPC_NOTIFY_LINK_UP;
  205. n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id;
  206. pr_debug("Established link <%s> on network plane %c\n",
  207. l_ptr->name, l_ptr->net_plane);
  208. if (!active[0]) {
  209. active[0] = active[1] = l_ptr;
  210. node_established_contact(n_ptr);
  211. goto exit;
  212. }
  213. if (l_ptr->priority < active[0]->priority) {
  214. pr_debug("New link <%s> becomes standby\n", l_ptr->name);
  215. goto exit;
  216. }
  217. tipc_link_dup_queue_xmit(active[0], l_ptr);
  218. if (l_ptr->priority == active[0]->priority) {
  219. active[0] = l_ptr;
  220. goto exit;
  221. }
  222. pr_debug("Old link <%s> becomes standby\n", active[0]->name);
  223. if (active[1] != active[0])
  224. pr_debug("Old link <%s> becomes standby\n", active[1]->name);
  225. active[0] = active[1] = l_ptr;
  226. exit:
  227. /* Leave room for changeover header when returning 'mtu' to users: */
  228. n_ptr->act_mtus[0] = active[0]->mtu - INT_H_SIZE;
  229. n_ptr->act_mtus[1] = active[1]->mtu - INT_H_SIZE;
  230. }
  231. /**
  232. * node_select_active_links - select active link
  233. */
  234. static void node_select_active_links(struct tipc_node *n_ptr)
  235. {
  236. struct tipc_link **active = &n_ptr->active_links[0];
  237. u32 i;
  238. u32 highest_prio = 0;
  239. active[0] = active[1] = NULL;
  240. for (i = 0; i < MAX_BEARERS; i++) {
  241. struct tipc_link *l_ptr = n_ptr->links[i];
  242. if (!l_ptr || !tipc_link_is_up(l_ptr) ||
  243. (l_ptr->priority < highest_prio))
  244. continue;
  245. if (l_ptr->priority > highest_prio) {
  246. highest_prio = l_ptr->priority;
  247. active[0] = active[1] = l_ptr;
  248. } else {
  249. active[1] = l_ptr;
  250. }
  251. }
  252. }
  253. /**
  254. * tipc_node_link_down - handle loss of link
  255. */
  256. void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
  257. {
  258. struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
  259. struct tipc_link **active;
  260. n_ptr->working_links--;
  261. n_ptr->action_flags |= TIPC_NOTIFY_LINK_DOWN;
  262. n_ptr->link_id = l_ptr->peer_bearer_id << 16 | l_ptr->bearer_id;
  263. if (!tipc_link_is_active(l_ptr)) {
  264. pr_debug("Lost standby link <%s> on network plane %c\n",
  265. l_ptr->name, l_ptr->net_plane);
  266. return;
  267. }
  268. pr_debug("Lost link <%s> on network plane %c\n",
  269. l_ptr->name, l_ptr->net_plane);
  270. active = &n_ptr->active_links[0];
  271. if (active[0] == l_ptr)
  272. active[0] = active[1];
  273. if (active[1] == l_ptr)
  274. active[1] = active[0];
  275. if (active[0] == l_ptr)
  276. node_select_active_links(n_ptr);
  277. if (tipc_node_is_up(n_ptr))
  278. tipc_link_failover_send_queue(l_ptr);
  279. else
  280. node_lost_contact(n_ptr);
  281. /* Leave room for changeover header when returning 'mtu' to users: */
  282. if (active[0]) {
  283. n_ptr->act_mtus[0] = active[0]->mtu - INT_H_SIZE;
  284. n_ptr->act_mtus[1] = active[1]->mtu - INT_H_SIZE;
  285. return;
  286. }
  287. /* Loopback link went down? No fragmentation needed from now on. */
  288. if (n_ptr->addr == tn->own_addr) {
  289. n_ptr->act_mtus[0] = MAX_MSG_SIZE;
  290. n_ptr->act_mtus[1] = MAX_MSG_SIZE;
  291. }
  292. }
  293. int tipc_node_active_links(struct tipc_node *n_ptr)
  294. {
  295. return n_ptr->active_links[0] != NULL;
  296. }
  297. int tipc_node_is_up(struct tipc_node *n_ptr)
  298. {
  299. return tipc_node_active_links(n_ptr);
  300. }
  301. void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
  302. {
  303. n_ptr->links[l_ptr->bearer_id] = l_ptr;
  304. n_ptr->link_cnt++;
  305. }
  306. void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
  307. {
  308. int i;
  309. for (i = 0; i < MAX_BEARERS; i++) {
  310. if (l_ptr != n_ptr->links[i])
  311. continue;
  312. n_ptr->links[i] = NULL;
  313. n_ptr->link_cnt--;
  314. }
  315. }
  316. static void node_established_contact(struct tipc_node *n_ptr)
  317. {
  318. n_ptr->action_flags |= TIPC_NOTIFY_NODE_UP;
  319. n_ptr->bclink.oos_state = 0;
  320. n_ptr->bclink.acked = tipc_bclink_get_last_sent(n_ptr->net);
  321. tipc_bclink_add_node(n_ptr->net, n_ptr->addr);
  322. }
  323. static void node_lost_contact(struct tipc_node *n_ptr)
  324. {
  325. char addr_string[16];
  326. struct tipc_sock_conn *conn, *safe;
  327. struct list_head *conns = &n_ptr->conn_sks;
  328. struct sk_buff *skb;
  329. struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
  330. uint i;
  331. pr_debug("Lost contact with %s\n",
  332. tipc_addr_string_fill(addr_string, n_ptr->addr));
  333. /* Flush broadcast link info associated with lost node */
  334. if (n_ptr->bclink.recv_permitted) {
  335. __skb_queue_purge(&n_ptr->bclink.deferdq);
  336. if (n_ptr->bclink.reasm_buf) {
  337. kfree_skb(n_ptr->bclink.reasm_buf);
  338. n_ptr->bclink.reasm_buf = NULL;
  339. }
  340. tipc_bclink_remove_node(n_ptr->net, n_ptr->addr);
  341. tipc_bclink_acknowledge(n_ptr, INVALID_LINK_SEQ);
  342. n_ptr->bclink.recv_permitted = false;
  343. }
  344. /* Abort any ongoing link failover */
  345. for (i = 0; i < MAX_BEARERS; i++) {
  346. struct tipc_link *l_ptr = n_ptr->links[i];
  347. if (!l_ptr)
  348. continue;
  349. l_ptr->flags &= ~LINK_FAILINGOVER;
  350. l_ptr->failover_checkpt = 0;
  351. l_ptr->failover_pkts = 0;
  352. kfree_skb(l_ptr->failover_skb);
  353. l_ptr->failover_skb = NULL;
  354. tipc_link_reset_fragments(l_ptr);
  355. }
  356. n_ptr->action_flags &= ~TIPC_WAIT_OWN_LINKS_DOWN;
  357. /* Prevent re-contact with node until cleanup is done */
  358. n_ptr->action_flags |= TIPC_WAIT_PEER_LINKS_DOWN;
  359. /* Notify publications from this node */
  360. n_ptr->action_flags |= TIPC_NOTIFY_NODE_DOWN;
  361. /* Notify sockets connected to node */
  362. list_for_each_entry_safe(conn, safe, conns, list) {
  363. skb = tipc_msg_create(TIPC_CRITICAL_IMPORTANCE, TIPC_CONN_MSG,
  364. SHORT_H_SIZE, 0, tn->own_addr,
  365. conn->peer_node, conn->port,
  366. conn->peer_port, TIPC_ERR_NO_NODE);
  367. if (likely(skb)) {
  368. skb_queue_tail(n_ptr->inputq, skb);
  369. n_ptr->action_flags |= TIPC_MSG_EVT;
  370. }
  371. list_del(&conn->list);
  372. kfree(conn);
  373. }
  374. }
  375. /**
  376. * tipc_node_get_linkname - get the name of a link
  377. *
  378. * @bearer_id: id of the bearer
  379. * @node: peer node address
  380. * @linkname: link name output buffer
  381. *
  382. * Returns 0 on success
  383. */
  384. int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 addr,
  385. char *linkname, size_t len)
  386. {
  387. struct tipc_link *link;
  388. int err = -EINVAL;
  389. struct tipc_node *node = tipc_node_find(net, addr);
  390. if (!node)
  391. return err;
  392. if (bearer_id >= MAX_BEARERS)
  393. goto exit;
  394. tipc_node_lock(node);
  395. link = node->links[bearer_id];
  396. if (link) {
  397. strncpy(linkname, link->name, len);
  398. err = 0;
  399. }
  400. exit:
  401. tipc_node_unlock(node);
  402. tipc_node_put(node);
  403. return err;
  404. }
  405. void tipc_node_unlock(struct tipc_node *node)
  406. {
  407. struct net *net = node->net;
  408. u32 addr = 0;
  409. u32 flags = node->action_flags;
  410. u32 link_id = 0;
  411. struct list_head *publ_list;
  412. struct sk_buff_head *inputq = node->inputq;
  413. struct sk_buff_head *namedq;
  414. if (likely(!flags || (flags == TIPC_MSG_EVT))) {
  415. node->action_flags = 0;
  416. spin_unlock_bh(&node->lock);
  417. if (flags == TIPC_MSG_EVT)
  418. tipc_sk_rcv(net, inputq);
  419. return;
  420. }
  421. addr = node->addr;
  422. link_id = node->link_id;
  423. namedq = node->namedq;
  424. publ_list = &node->publ_list;
  425. node->action_flags &= ~(TIPC_MSG_EVT |
  426. TIPC_NOTIFY_NODE_DOWN | TIPC_NOTIFY_NODE_UP |
  427. TIPC_NOTIFY_LINK_DOWN | TIPC_NOTIFY_LINK_UP |
  428. TIPC_WAKEUP_BCAST_USERS | TIPC_BCAST_MSG_EVT |
  429. TIPC_NAMED_MSG_EVT | TIPC_BCAST_RESET);
  430. spin_unlock_bh(&node->lock);
  431. if (flags & TIPC_NOTIFY_NODE_DOWN)
  432. tipc_publ_notify(net, publ_list, addr);
  433. if (flags & TIPC_WAKEUP_BCAST_USERS)
  434. tipc_bclink_wakeup_users(net);
  435. if (flags & TIPC_NOTIFY_NODE_UP)
  436. tipc_named_node_up(net, addr);
  437. if (flags & TIPC_NOTIFY_LINK_UP)
  438. tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr,
  439. TIPC_NODE_SCOPE, link_id, addr);
  440. if (flags & TIPC_NOTIFY_LINK_DOWN)
  441. tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr,
  442. link_id, addr);
  443. if (flags & TIPC_MSG_EVT)
  444. tipc_sk_rcv(net, inputq);
  445. if (flags & TIPC_NAMED_MSG_EVT)
  446. tipc_named_rcv(net, namedq);
  447. if (flags & TIPC_BCAST_MSG_EVT)
  448. tipc_bclink_input(net);
  449. if (flags & TIPC_BCAST_RESET)
  450. tipc_link_reset_all(node);
  451. }
  452. /* Caller should hold node lock for the passed node */
  453. static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
  454. {
  455. void *hdr;
  456. struct nlattr *attrs;
  457. hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
  458. NLM_F_MULTI, TIPC_NL_NODE_GET);
  459. if (!hdr)
  460. return -EMSGSIZE;
  461. attrs = nla_nest_start(msg->skb, TIPC_NLA_NODE);
  462. if (!attrs)
  463. goto msg_full;
  464. if (nla_put_u32(msg->skb, TIPC_NLA_NODE_ADDR, node->addr))
  465. goto attr_msg_full;
  466. if (tipc_node_is_up(node))
  467. if (nla_put_flag(msg->skb, TIPC_NLA_NODE_UP))
  468. goto attr_msg_full;
  469. nla_nest_end(msg->skb, attrs);
  470. genlmsg_end(msg->skb, hdr);
  471. return 0;
  472. attr_msg_full:
  473. nla_nest_cancel(msg->skb, attrs);
  474. msg_full:
  475. genlmsg_cancel(msg->skb, hdr);
  476. return -EMSGSIZE;
  477. }
  478. int tipc_nl_node_dump(struct sk_buff *skb, struct netlink_callback *cb)
  479. {
  480. int err;
  481. struct net *net = sock_net(skb->sk);
  482. struct tipc_net *tn = net_generic(net, tipc_net_id);
  483. int done = cb->args[0];
  484. int last_addr = cb->args[1];
  485. struct tipc_node *node;
  486. struct tipc_nl_msg msg;
  487. if (done)
  488. return 0;
  489. msg.skb = skb;
  490. msg.portid = NETLINK_CB(cb->skb).portid;
  491. msg.seq = cb->nlh->nlmsg_seq;
  492. rcu_read_lock();
  493. if (last_addr) {
  494. node = tipc_node_find(net, last_addr);
  495. if (!node) {
  496. rcu_read_unlock();
  497. /* We never set seq or call nl_dump_check_consistent()
  498. * this means that setting prev_seq here will cause the
  499. * consistence check to fail in the netlink callback
  500. * handler. Resulting in the NLMSG_DONE message having
  501. * the NLM_F_DUMP_INTR flag set if the node state
  502. * changed while we released the lock.
  503. */
  504. cb->prev_seq = 1;
  505. return -EPIPE;
  506. }
  507. tipc_node_put(node);
  508. }
  509. list_for_each_entry_rcu(node, &tn->node_list, list) {
  510. if (last_addr) {
  511. if (node->addr == last_addr)
  512. last_addr = 0;
  513. else
  514. continue;
  515. }
  516. tipc_node_lock(node);
  517. err = __tipc_nl_add_node(&msg, node);
  518. if (err) {
  519. last_addr = node->addr;
  520. tipc_node_unlock(node);
  521. goto out;
  522. }
  523. tipc_node_unlock(node);
  524. }
  525. done = 1;
  526. out:
  527. cb->args[0] = done;
  528. cb->args[1] = last_addr;
  529. rcu_read_unlock();
  530. return skb->len;
  531. }