blob: 31dcca98201ab9a2a2d0e5ebbe3718f757a25455 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/node.c: TIPC node management routines
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Per Liden593a5f22006-01-11 19:14:19 +01004 * Copyright (c) 2000-2006, Ericsson AB
Allan Stephensea138472006-06-29 12:33:20 -07005 * Copyright (c) 2005-2006, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01006 * All rights reserved.
7 *
Per Liden9ea1fd32006-01-11 13:30:43 +01008 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +01009 * modification, are permitted provided that the following conditions are met:
10 *
Per Liden9ea1fd32006-01-11 13:30:43 +010011 * 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.
Per Lidenb97bf3f2006-01-02 19:04:38 +010019 *
Per Liden9ea1fd32006-01-11 13:30:43 +010020 * 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
Per Lidenb97bf3f2006-01-02 19:04:38 +010034 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "config.h"
39#include "node.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040#include "port.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010041#include "name_distr.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010042
David S. Miller6c000552008-09-02 23:38:32 -070043static void node_lost_contact(struct tipc_node *n_ptr);
44static void node_established_contact(struct tipc_node *n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +010045
Allan Stephens2ecb0922008-05-21 14:53:00 -070046static DEFINE_SPINLOCK(node_create_lock);
47
Per Lidenb97bf3f2006-01-02 19:04:38 +010048u32 tipc_own_tag = 0;
49
Allan Stephens2ecb0922008-05-21 14:53:00 -070050/**
51 * tipc_node_create - create neighboring node
52 *
53 * Currently, this routine is called by neighbor discovery code, which holds
54 * net_lock for reading only. We must take node_create_lock to ensure a node
55 * isn't created twice if two different bearers discover the node at the same
56 * time. (It would be preferable to switch to holding net_lock in write mode,
57 * but this is a non-trivial change.)
58 */
59
David S. Miller6c000552008-09-02 23:38:32 -070060struct tipc_node *tipc_node_create(u32 addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010061{
David S. Miller6c000552008-09-02 23:38:32 -070062 struct tipc_node *n_ptr;
Allan Stephens8f92df62010-12-31 18:59:19 +000063 u32 n_num;
Per Lidenb97bf3f2006-01-02 19:04:38 +010064
Allan Stephens2ecb0922008-05-21 14:53:00 -070065 spin_lock_bh(&node_create_lock);
66
Allan Stephens5af54792010-12-31 18:59:23 +000067 n_ptr = tipc_node_find(addr);
68 if (n_ptr) {
69 spin_unlock_bh(&node_create_lock);
70 return n_ptr;
Allan Stephens2ecb0922008-05-21 14:53:00 -070071 }
72
Allan Stephens5af54792010-12-31 18:59:23 +000073 n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -070074 if (!n_ptr) {
Allan Stephens2ecb0922008-05-21 14:53:00 -070075 spin_unlock_bh(&node_create_lock);
Allan Stephensa10bd922006-06-25 23:52:17 -070076 warn("Node creation failed, no memory\n");
77 return NULL;
78 }
Per Lidenb97bf3f2006-01-02 19:04:38 +010079
Allan Stephensa10bd922006-06-25 23:52:17 -070080 n_ptr->addr = addr;
Allan Stephens51a8e4d2010-12-31 18:59:18 +000081 spin_lock_init(&n_ptr->lock);
Allan Stephensa10bd922006-06-25 23:52:17 -070082 INIT_LIST_HEAD(&n_ptr->nsub);
Allan Stephens8f92df62010-12-31 18:59:19 +000083
84 n_num = tipc_node(addr);
85 tipc_net.nodes[n_num] = n_ptr;
86 if (n_num > tipc_net.highest_node)
87 tipc_net.highest_node = n_num;
Allan Stephensa10bd922006-06-25 23:52:17 -070088
Allan Stephens2ecb0922008-05-21 14:53:00 -070089 spin_unlock_bh(&node_create_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +010090 return n_ptr;
91}
92
David S. Miller6c000552008-09-02 23:38:32 -070093void tipc_node_delete(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010094{
Allan Stephens8f92df62010-12-31 18:59:19 +000095 u32 n_num;
96
Per Lidenb97bf3f2006-01-02 19:04:38 +010097 if (!n_ptr)
98 return;
99
Per Lidenb97bf3f2006-01-02 19:04:38 +0100100 dbg("node %x deleted\n", n_ptr->addr);
Allan Stephens8f92df62010-12-31 18:59:19 +0000101 n_num = tipc_node(n_ptr->addr);
102 tipc_net.nodes[n_num] = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100103 kfree(n_ptr);
Allan Stephens8f92df62010-12-31 18:59:19 +0000104
105 while (!tipc_net.nodes[tipc_net.highest_node])
106 if (--tipc_net.highest_node == 0)
107 break;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108}
109
110
111/**
Per Liden4323add2006-01-18 00:38:21 +0100112 * tipc_node_link_up - handle addition of link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900113 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100114 * Link becomes active (alone or shared) or standby, depending on its priority.
115 */
116
David S. Miller6c000552008-09-02 23:38:32 -0700117void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100118{
119 struct link **active = &n_ptr->active_links[0];
120
Allan Stephens5392d642006-06-25 23:52:50 -0700121 n_ptr->working_links++;
122
Per Lidenb97bf3f2006-01-02 19:04:38 +0100123 info("Established link <%s> on network plane %c\n",
124 l_ptr->name, l_ptr->b_ptr->net_plane);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900125
Per Lidenb97bf3f2006-01-02 19:04:38 +0100126 if (!active[0]) {
127 dbg(" link %x into %x/%x\n", l_ptr, &active[0], &active[1]);
128 active[0] = active[1] = l_ptr;
129 node_established_contact(n_ptr);
130 return;
131 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900132 if (l_ptr->priority < active[0]->priority) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700133 info("New link <%s> becomes standby\n", l_ptr->name);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100134 return;
135 }
Per Liden4323add2006-01-18 00:38:21 +0100136 tipc_link_send_duplicate(active[0], l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900137 if (l_ptr->priority == active[0]->priority) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100138 active[0] = l_ptr;
139 return;
140 }
Allan Stephensa10bd922006-06-25 23:52:17 -0700141 info("Old link <%s> becomes standby\n", active[0]->name);
142 if (active[1] != active[0])
143 info("Old link <%s> becomes standby\n", active[1]->name);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100144 active[0] = active[1] = l_ptr;
145}
146
147/**
148 * node_select_active_links - select active link
149 */
150
David S. Miller6c000552008-09-02 23:38:32 -0700151static void node_select_active_links(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100152{
153 struct link **active = &n_ptr->active_links[0];
154 u32 i;
155 u32 highest_prio = 0;
156
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900157 active[0] = active[1] = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100158
159 for (i = 0; i < MAX_BEARERS; i++) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900160 struct link *l_ptr = n_ptr->links[i];
Per Lidenb97bf3f2006-01-02 19:04:38 +0100161
Per Liden4323add2006-01-18 00:38:21 +0100162 if (!l_ptr || !tipc_link_is_up(l_ptr) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100163 (l_ptr->priority < highest_prio))
164 continue;
165
166 if (l_ptr->priority > highest_prio) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900167 highest_prio = l_ptr->priority;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100168 active[0] = active[1] = l_ptr;
169 } else {
170 active[1] = l_ptr;
171 }
172 }
173}
174
175/**
Per Liden4323add2006-01-18 00:38:21 +0100176 * tipc_node_link_down - handle loss of link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100177 */
178
David S. Miller6c000552008-09-02 23:38:32 -0700179void tipc_node_link_down(struct tipc_node *n_ptr, struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100180{
181 struct link **active;
182
Allan Stephens5392d642006-06-25 23:52:50 -0700183 n_ptr->working_links--;
184
Per Liden4323add2006-01-18 00:38:21 +0100185 if (!tipc_link_is_active(l_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100186 info("Lost standby link <%s> on network plane %c\n",
187 l_ptr->name, l_ptr->b_ptr->net_plane);
188 return;
189 }
190 info("Lost link <%s> on network plane %c\n",
191 l_ptr->name, l_ptr->b_ptr->net_plane);
192
193 active = &n_ptr->active_links[0];
194 if (active[0] == l_ptr)
195 active[0] = active[1];
196 if (active[1] == l_ptr)
197 active[1] = active[0];
198 if (active[0] == l_ptr)
199 node_select_active_links(n_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900200 if (tipc_node_is_up(n_ptr))
Per Liden4323add2006-01-18 00:38:21 +0100201 tipc_link_changeover(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900202 else
Per Lidenb97bf3f2006-01-02 19:04:38 +0100203 node_lost_contact(n_ptr);
204}
205
David S. Miller6c000552008-09-02 23:38:32 -0700206int tipc_node_has_active_links(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100207{
Allan Stephens76ae0d72010-08-17 11:00:12 +0000208 return n_ptr->active_links[0] != NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100209}
210
David S. Miller6c000552008-09-02 23:38:32 -0700211int tipc_node_has_redundant_links(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100212{
Eric Dumazeta02cec22010-09-22 20:43:57 +0000213 return n_ptr->working_links > 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100214}
215
David S. Miller6c000552008-09-02 23:38:32 -0700216int tipc_node_is_up(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100217{
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000218 return tipc_node_has_active_links(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100219}
220
David S. Miller6c000552008-09-02 23:38:32 -0700221struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100222{
David S. Miller6c000552008-09-02 23:38:32 -0700223 struct tipc_node *n_ptr = tipc_node_find(l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100224
225 if (!n_ptr)
Per Liden4323add2006-01-18 00:38:21 +0100226 n_ptr = tipc_node_create(l_ptr->addr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900227 if (n_ptr) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100228 u32 bearer_id = l_ptr->b_ptr->identity;
229 char addr_string[16];
230
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900231 if (n_ptr->link_cnt >= 2) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900232 err("Attempt to create third link to %s\n",
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000233 tipc_addr_string_fill(addr_string, n_ptr->addr));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900234 return NULL;
235 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100236
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900237 if (!n_ptr->links[bearer_id]) {
238 n_ptr->links[bearer_id] = l_ptr;
Allan Stephens51f98a82010-12-31 18:59:16 +0000239 tipc_net.links++;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900240 n_ptr->link_cnt++;
241 return n_ptr;
242 }
Frans Popa570f092010-03-24 07:57:29 +0000243 err("Attempt to establish second link on <%s> to %s\n",
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900244 l_ptr->b_ptr->publ.name,
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000245 tipc_addr_string_fill(addr_string, l_ptr->addr));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900246 }
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800247 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100248}
249
David S. Miller6c000552008-09-02 23:38:32 -0700250void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100251{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800252 n_ptr->links[l_ptr->b_ptr->identity] = NULL;
Allan Stephens51f98a82010-12-31 18:59:16 +0000253 tipc_net.links--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100254 n_ptr->link_cnt--;
255}
256
257/*
258 * Routing table management - five cases to handle:
259 *
260 * 1: A link towards a zone/cluster external node comes up.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900261 * => Send a multicast message updating routing tables of all
262 * system nodes within own cluster that the new destination
263 * can be reached via this node.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100264 * (node.establishedContact()=>cluster.multicastNewRoute())
265 *
266 * 2: A link towards a slave node comes up.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900267 * => Send a multicast message updating routing tables of all
268 * system nodes within own cluster that the new destination
269 * can be reached via this node.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100270 * (node.establishedContact()=>cluster.multicastNewRoute())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900271 * => Send a message to the slave node about existence
Per Lidenb97bf3f2006-01-02 19:04:38 +0100272 * of all system nodes within cluster:
273 * (node.establishedContact()=>cluster.sendLocalRoutes())
274 *
275 * 3: A new cluster local system node becomes available.
276 * => Send message(s) to this particular node containing
277 * information about all cluster external and slave
278 * nodes which can be reached via this node.
279 * (node.establishedContact()==>network.sendExternalRoutes())
280 * (node.establishedContact()==>network.sendSlaveRoutes())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900281 * => Send messages to all directly connected slave nodes
Per Lidenb97bf3f2006-01-02 19:04:38 +0100282 * containing information about the existence of the new node
283 * (node.establishedContact()=>cluster.multicastNewRoute())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900284 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100285 * 4: The link towards a zone/cluster external node or slave
286 * node goes down.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900287 * => Send a multcast message updating routing tables of all
Per Lidenb97bf3f2006-01-02 19:04:38 +0100288 * nodes within cluster that the new destination can not any
289 * longer be reached via this node.
290 * (node.lostAllLinks()=>cluster.bcastLostRoute())
291 *
292 * 5: A cluster local system node becomes unavailable.
293 * => Remove all references to this node from the local
294 * routing tables. Note: This is a completely node
295 * local operation.
296 * (node.lostAllLinks()=>network.removeAsRouter())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900297 * => Send messages to all directly connected slave nodes
Per Lidenb97bf3f2006-01-02 19:04:38 +0100298 * containing information about loss of the node
299 * (node.establishedContact()=>cluster.multicastLostRoute())
300 *
301 */
302
David S. Miller6c000552008-09-02 23:38:32 -0700303static void node_established_contact(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100304{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100305 dbg("node_established_contact:-> %x\n", n_ptr->addr);
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000306 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100307
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900308 /* Syncronize broadcast acks */
309 n_ptr->bclink.acked = tipc_bclink_get_last_sent();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100310
Per Lidenb97bf3f2006-01-02 19:04:38 +0100311 if (n_ptr->bclink.supported) {
Allan Stephens8f92df62010-12-31 18:59:19 +0000312 tipc_nmap_add(&tipc_bcast_nmap, n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100313 if (n_ptr->addr < tipc_own_addr)
314 tipc_own_tag++;
315 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100316}
317
Allan Stephens5a68d5e2010-08-17 11:00:16 +0000318static void node_cleanup_finished(unsigned long node_addr)
319{
320 struct tipc_node *n_ptr;
321
322 read_lock_bh(&tipc_net_lock);
323 n_ptr = tipc_node_find(node_addr);
324 if (n_ptr) {
325 tipc_node_lock(n_ptr);
326 n_ptr->cleanup_required = 0;
327 tipc_node_unlock(n_ptr);
328 }
329 read_unlock_bh(&tipc_net_lock);
330}
331
David S. Miller6c000552008-09-02 23:38:32 -0700332static void node_lost_contact(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100333{
David S. Miller6c000552008-09-02 23:38:32 -0700334 struct tipc_node_subscr *ns, *tns;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100335 char addr_string[16];
336 u32 i;
337
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900338 /* 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 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100349
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000350 if (n_ptr->bclink.supported) {
Allan Stephens8f92df62010-12-31 18:59:19 +0000351 tipc_bclink_acknowledge(n_ptr,
352 mod(n_ptr->bclink.acked + 10000));
353 tipc_nmap_remove(&tipc_bcast_nmap, n_ptr->addr);
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000354 if (n_ptr->addr < tipc_own_addr)
355 tipc_own_tag--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100356 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100357
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900358 info("Lost contact with %s\n",
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000359 tipc_addr_string_fill(addr_string, n_ptr->addr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100360
361 /* Abort link changeover */
362 for (i = 0; i < MAX_BEARERS; i++) {
363 struct link *l_ptr = n_ptr->links[i];
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900364 if (!l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100365 continue;
366 l_ptr->reset_checkpoint = l_ptr->next_in_no;
367 l_ptr->exp_msg_count = 0;
Per Liden4323add2006-01-18 00:38:21 +0100368 tipc_link_reset_fragments(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100369 }
370
371 /* Notify subscribers */
372 list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900373 ns->node = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100374 list_del_init(&ns->nodesub_list);
Per Liden4323add2006-01-18 00:38:21 +0100375 tipc_k_signal((Handler)ns->handle_node_down,
376 (unsigned long)ns->usr_handle);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100377 }
Allan Stephens5a68d5e2010-08-17 11:00:16 +0000378
379 /* Prevent re-contact with node until all cleanup is done */
380
381 n_ptr->cleanup_required = 1;
382 tipc_k_signal((Handler)node_cleanup_finished, n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100383}
384
Per Liden4323add2006-01-18 00:38:21 +0100385struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100386{
387 u32 domain;
388 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -0700389 struct tipc_node *n_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900390 struct tipc_node_info node_info;
Allan Stephensea138472006-06-29 12:33:20 -0700391 u32 payload_size;
Allan Stephens5af54792010-12-31 18:59:23 +0000392 u32 n_num;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100393
394 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100395 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100396
Al Viro3e6c8cd2006-11-08 00:19:09 -0800397 domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Liden4323add2006-01-18 00:38:21 +0100398 if (!tipc_addr_domain_valid(domain))
399 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
400 " (network address)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100401
Allan Stephens1aad72d2008-07-14 22:44:58 -0700402 read_lock_bh(&tipc_net_lock);
Allan Stephens5af54792010-12-31 18:59:23 +0000403 if (!tipc_net.nodes) {
Allan Stephens1aad72d2008-07-14 22:44:58 -0700404 read_unlock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900405 return tipc_cfg_reply_none();
Allan Stephens1aad72d2008-07-14 22:44:58 -0700406 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100407
Allan Stephens08c80e92010-12-31 18:59:17 +0000408 /* For now, get space for all other nodes */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100409
Allan Stephens5af54792010-12-31 18:59:23 +0000410 payload_size = TLV_SPACE(sizeof(node_info)) *
411 (tipc_net.highest_node - 1);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700412 if (payload_size > 32768u) {
413 read_unlock_bh(&tipc_net_lock);
Allan Stephensea138472006-06-29 12:33:20 -0700414 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
415 " (too many nodes)");
Allan Stephens1aad72d2008-07-14 22:44:58 -0700416 }
Allan Stephensea138472006-06-29 12:33:20 -0700417 buf = tipc_cfg_reply_alloc(payload_size);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700418 if (!buf) {
419 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100420 return NULL;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700421 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100422
423 /* Add TLVs for all nodes in scope */
424
Allan Stephens5af54792010-12-31 18:59:23 +0000425 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++) {
426 n_ptr = tipc_net.nodes[n_num];
427 if (!n_ptr || !tipc_in_scope(domain, n_ptr->addr))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100428 continue;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900429 node_info.addr = htonl(n_ptr->addr);
430 node_info.up = htonl(tipc_node_is_up(n_ptr));
431 tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
Per Liden4323add2006-01-18 00:38:21 +0100432 &node_info, sizeof(node_info));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100433 }
434
Allan Stephens1aad72d2008-07-14 22:44:58 -0700435 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100436 return buf;
437}
438
Per Liden4323add2006-01-18 00:38:21 +0100439struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100440{
441 u32 domain;
442 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -0700443 struct tipc_node *n_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900444 struct tipc_link_info link_info;
Allan Stephensea138472006-06-29 12:33:20 -0700445 u32 payload_size;
Allan Stephens5af54792010-12-31 18:59:23 +0000446 u32 n_num;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100447
448 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100449 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100450
Al Viro3e6c8cd2006-11-08 00:19:09 -0800451 domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Liden4323add2006-01-18 00:38:21 +0100452 if (!tipc_addr_domain_valid(domain))
453 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
454 " (network address)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100455
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900456 if (tipc_mode != TIPC_NET_MODE)
457 return tipc_cfg_reply_none();
458
Allan Stephens1aad72d2008-07-14 22:44:58 -0700459 read_lock_bh(&tipc_net_lock);
460
Allan Stephensea138472006-06-29 12:33:20 -0700461 /* Get space for all unicast links + multicast link */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100462
Allan Stephens51f98a82010-12-31 18:59:16 +0000463 payload_size = TLV_SPACE(sizeof(link_info)) * (tipc_net.links + 1);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700464 if (payload_size > 32768u) {
465 read_unlock_bh(&tipc_net_lock);
Allan Stephensea138472006-06-29 12:33:20 -0700466 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
467 " (too many links)");
Allan Stephens1aad72d2008-07-14 22:44:58 -0700468 }
Allan Stephensea138472006-06-29 12:33:20 -0700469 buf = tipc_cfg_reply_alloc(payload_size);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700470 if (!buf) {
471 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100472 return NULL;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700473 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100474
475 /* Add TLV for broadcast link */
476
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900477 link_info.dest = htonl(tipc_own_addr & 0xfffff00);
478 link_info.up = htonl(1);
Stephen Hemminger4b704d52009-03-18 19:11:29 -0700479 strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME);
Per Liden4323add2006-01-18 00:38:21 +0100480 tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100481
482 /* Add TLVs for any other links in scope */
483
Allan Stephens5af54792010-12-31 18:59:23 +0000484 for (n_num = 1; n_num <= tipc_net.highest_node; n_num++) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900485 u32 i;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100486
Allan Stephens5af54792010-12-31 18:59:23 +0000487 n_ptr = tipc_net.nodes[n_num];
488 if (!n_ptr || !tipc_in_scope(domain, n_ptr->addr))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100489 continue;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700490 tipc_node_lock(n_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900491 for (i = 0; i < MAX_BEARERS; i++) {
492 if (!n_ptr->links[i])
493 continue;
494 link_info.dest = htonl(n_ptr->addr);
495 link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
496 strcpy(link_info.str, n_ptr->links[i]->name);
497 tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
Per Liden4323add2006-01-18 00:38:21 +0100498 &link_info, sizeof(link_info));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900499 }
Allan Stephens1aad72d2008-07-14 22:44:58 -0700500 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100501 }
502
Allan Stephens1aad72d2008-07-14 22:44:58 -0700503 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100504 return buf;
505}