blob: 22aeb2b7ad00b96db6e5a3594161c2dd70c2f771 [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 Stephens2d627b92011-01-07 13:00:11 -05005 * Copyright (c) 2005-2006, 2010-2011, 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 "name_distr.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010041
David S. Miller6c000552008-09-02 23:38:32 -070042static void node_lost_contact(struct tipc_node *n_ptr);
43static void node_established_contact(struct tipc_node *n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +010044
Allan Stephens2ecb0922008-05-21 14:53:00 -070045static DEFINE_SPINLOCK(node_create_lock);
46
Allan Stephens672d99e2011-02-25 18:42:52 -050047static struct hlist_head node_htable[NODE_HTABLE_SIZE];
48LIST_HEAD(tipc_node_list);
49static u32 tipc_num_nodes;
Allan Stephense3ec9c72010-12-31 18:59:34 +000050u32 tipc_own_tag;
Per Lidenb97bf3f2006-01-02 19:04:38 +010051
Allan Stephens2ecb0922008-05-21 14:53:00 -070052/**
Allan Stephens672d99e2011-02-25 18:42:52 -050053 * tipc_node_find - locate specified node object, if it exists
54 */
55
56struct tipc_node *tipc_node_find(u32 addr)
57{
58 struct tipc_node *node;
59 struct hlist_node *pos;
60
61 if (unlikely(!in_own_cluster(addr)))
62 return NULL;
63
64 hlist_for_each_entry(node, pos, &node_htable[tipc_hashfn(addr)], hash) {
65 if (node->addr == addr)
66 return node;
67 }
68 return NULL;
69}
70
71/**
Allan Stephens2ecb0922008-05-21 14:53:00 -070072 * tipc_node_create - create neighboring node
73 *
74 * Currently, this routine is called by neighbor discovery code, which holds
75 * net_lock for reading only. We must take node_create_lock to ensure a node
76 * isn't created twice if two different bearers discover the node at the same
77 * time. (It would be preferable to switch to holding net_lock in write mode,
78 * but this is a non-trivial change.)
79 */
80
David S. Miller6c000552008-09-02 23:38:32 -070081struct tipc_node *tipc_node_create(u32 addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +010082{
Allan Stephens672d99e2011-02-25 18:42:52 -050083 struct tipc_node *n_ptr, *temp_node;
Per Lidenb97bf3f2006-01-02 19:04:38 +010084
Allan Stephens2ecb0922008-05-21 14:53:00 -070085 spin_lock_bh(&node_create_lock);
86
Allan Stephens5af54792010-12-31 18:59:23 +000087 n_ptr = tipc_node_find(addr);
88 if (n_ptr) {
89 spin_unlock_bh(&node_create_lock);
90 return n_ptr;
Allan Stephens2ecb0922008-05-21 14:53:00 -070091 }
92
Allan Stephens5af54792010-12-31 18:59:23 +000093 n_ptr = kzalloc(sizeof(*n_ptr), GFP_ATOMIC);
Allan Stephensa10bd922006-06-25 23:52:17 -070094 if (!n_ptr) {
Allan Stephens2ecb0922008-05-21 14:53:00 -070095 spin_unlock_bh(&node_create_lock);
Allan Stephensa10bd922006-06-25 23:52:17 -070096 warn("Node creation failed, no memory\n");
97 return NULL;
98 }
Per Lidenb97bf3f2006-01-02 19:04:38 +010099
Allan Stephensa10bd922006-06-25 23:52:17 -0700100 n_ptr->addr = addr;
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000101 spin_lock_init(&n_ptr->lock);
Allan Stephens672d99e2011-02-25 18:42:52 -0500102 INIT_HLIST_NODE(&n_ptr->hash);
103 INIT_LIST_HEAD(&n_ptr->list);
Allan Stephensa10bd922006-06-25 23:52:17 -0700104 INIT_LIST_HEAD(&n_ptr->nsub);
Allan Stephens8f92df62010-12-31 18:59:19 +0000105
Allan Stephens672d99e2011-02-25 18:42:52 -0500106 hlist_add_head(&n_ptr->hash, &node_htable[tipc_hashfn(addr)]);
107
108 list_for_each_entry(temp_node, &tipc_node_list, list) {
109 if (n_ptr->addr < temp_node->addr)
110 break;
111 }
112 list_add_tail(&n_ptr->list, &temp_node->list);
113
114 tipc_num_nodes++;
Allan Stephensa10bd922006-06-25 23:52:17 -0700115
Allan Stephens2ecb0922008-05-21 14:53:00 -0700116 spin_unlock_bh(&node_create_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100117 return n_ptr;
118}
119
David S. Miller6c000552008-09-02 23:38:32 -0700120void tipc_node_delete(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100121{
Allan Stephens672d99e2011-02-25 18:42:52 -0500122 list_del(&n_ptr->list);
123 hlist_del(&n_ptr->hash);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100124 kfree(n_ptr);
Allan Stephens8f92df62010-12-31 18:59:19 +0000125
Allan Stephens672d99e2011-02-25 18:42:52 -0500126 tipc_num_nodes--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100127}
128
129
130/**
Per Liden4323add2006-01-18 00:38:21 +0100131 * tipc_node_link_up - handle addition of link
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900132 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100133 * Link becomes active (alone or shared) or standby, depending on its priority.
134 */
135
David S. Miller6c000552008-09-02 23:38:32 -0700136void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100137{
138 struct link **active = &n_ptr->active_links[0];
139
Allan Stephens5392d642006-06-25 23:52:50 -0700140 n_ptr->working_links++;
141
Per Lidenb97bf3f2006-01-02 19:04:38 +0100142 info("Established link <%s> on network plane %c\n",
143 l_ptr->name, l_ptr->b_ptr->net_plane);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900144
Per Lidenb97bf3f2006-01-02 19:04:38 +0100145 if (!active[0]) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146 active[0] = active[1] = l_ptr;
147 node_established_contact(n_ptr);
148 return;
149 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900150 if (l_ptr->priority < active[0]->priority) {
Allan Stephensa10bd922006-06-25 23:52:17 -0700151 info("New link <%s> becomes standby\n", l_ptr->name);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100152 return;
153 }
Per Liden4323add2006-01-18 00:38:21 +0100154 tipc_link_send_duplicate(active[0], l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900155 if (l_ptr->priority == active[0]->priority) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100156 active[0] = l_ptr;
157 return;
158 }
Allan Stephensa10bd922006-06-25 23:52:17 -0700159 info("Old link <%s> becomes standby\n", active[0]->name);
160 if (active[1] != active[0])
161 info("Old link <%s> becomes standby\n", active[1]->name);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100162 active[0] = active[1] = l_ptr;
163}
164
165/**
166 * node_select_active_links - select active link
167 */
168
David S. Miller6c000552008-09-02 23:38:32 -0700169static void node_select_active_links(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100170{
171 struct link **active = &n_ptr->active_links[0];
172 u32 i;
173 u32 highest_prio = 0;
174
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900175 active[0] = active[1] = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100176
177 for (i = 0; i < MAX_BEARERS; i++) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900178 struct link *l_ptr = n_ptr->links[i];
Per Lidenb97bf3f2006-01-02 19:04:38 +0100179
Per Liden4323add2006-01-18 00:38:21 +0100180 if (!l_ptr || !tipc_link_is_up(l_ptr) ||
Per Lidenb97bf3f2006-01-02 19:04:38 +0100181 (l_ptr->priority < highest_prio))
182 continue;
183
184 if (l_ptr->priority > highest_prio) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900185 highest_prio = l_ptr->priority;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100186 active[0] = active[1] = l_ptr;
187 } else {
188 active[1] = l_ptr;
189 }
190 }
191}
192
193/**
Per Liden4323add2006-01-18 00:38:21 +0100194 * tipc_node_link_down - handle loss of link
Per Lidenb97bf3f2006-01-02 19:04:38 +0100195 */
196
David S. Miller6c000552008-09-02 23:38:32 -0700197void tipc_node_link_down(struct tipc_node *n_ptr, struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100198{
199 struct link **active;
200
Allan Stephens5392d642006-06-25 23:52:50 -0700201 n_ptr->working_links--;
202
Per Liden4323add2006-01-18 00:38:21 +0100203 if (!tipc_link_is_active(l_ptr)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100204 info("Lost standby link <%s> on network plane %c\n",
205 l_ptr->name, l_ptr->b_ptr->net_plane);
206 return;
207 }
208 info("Lost link <%s> on network plane %c\n",
209 l_ptr->name, l_ptr->b_ptr->net_plane);
210
211 active = &n_ptr->active_links[0];
212 if (active[0] == l_ptr)
213 active[0] = active[1];
214 if (active[1] == l_ptr)
215 active[1] = active[0];
216 if (active[0] == l_ptr)
217 node_select_active_links(n_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900218 if (tipc_node_is_up(n_ptr))
Per Liden4323add2006-01-18 00:38:21 +0100219 tipc_link_changeover(l_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900220 else
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221 node_lost_contact(n_ptr);
222}
223
David S. Miller6c000552008-09-02 23:38:32 -0700224int tipc_node_has_active_links(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100225{
Allan Stephens76ae0d72010-08-17 11:00:12 +0000226 return n_ptr->active_links[0] != NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100227}
228
David S. Miller6c000552008-09-02 23:38:32 -0700229int tipc_node_has_redundant_links(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100230{
Eric Dumazeta02cec22010-09-22 20:43:57 +0000231 return n_ptr->working_links > 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100232}
233
David S. Miller6c000552008-09-02 23:38:32 -0700234int tipc_node_is_up(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100235{
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000236 return tipc_node_has_active_links(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100237}
238
David S. Miller6c000552008-09-02 23:38:32 -0700239struct tipc_node *tipc_node_attach_link(struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100240{
David S. Miller6c000552008-09-02 23:38:32 -0700241 struct tipc_node *n_ptr = tipc_node_find(l_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100242
243 if (!n_ptr)
Per Liden4323add2006-01-18 00:38:21 +0100244 n_ptr = tipc_node_create(l_ptr->addr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900245 if (n_ptr) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100246 u32 bearer_id = l_ptr->b_ptr->identity;
247 char addr_string[16];
248
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900249 if (n_ptr->link_cnt >= 2) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900250 err("Attempt to create third link to %s\n",
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000251 tipc_addr_string_fill(addr_string, n_ptr->addr));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900252 return NULL;
253 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100254
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900255 if (!n_ptr->links[bearer_id]) {
256 n_ptr->links[bearer_id] = l_ptr;
Allan Stephensd1bcb112011-02-25 10:01:58 -0500257 atomic_inc(&tipc_num_links);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900258 n_ptr->link_cnt++;
259 return n_ptr;
260 }
Frans Popa570f092010-03-24 07:57:29 +0000261 err("Attempt to establish second link on <%s> to %s\n",
Allan Stephens2d627b92011-01-07 13:00:11 -0500262 l_ptr->b_ptr->name,
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000263 tipc_addr_string_fill(addr_string, l_ptr->addr));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900264 }
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800265 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100266}
267
David S. Miller6c000552008-09-02 23:38:32 -0700268void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100269{
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800270 n_ptr->links[l_ptr->b_ptr->identity] = NULL;
Allan Stephensd1bcb112011-02-25 10:01:58 -0500271 atomic_dec(&tipc_num_links);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100272 n_ptr->link_cnt--;
273}
274
275/*
276 * Routing table management - five cases to handle:
277 *
278 * 1: A link towards a zone/cluster external node comes up.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900279 * => Send a multicast message updating routing tables of all
280 * system nodes within own cluster that the new destination
281 * can be reached via this node.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100282 * (node.establishedContact()=>cluster.multicastNewRoute())
283 *
284 * 2: A link towards a slave node comes up.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900285 * => Send a multicast message updating routing tables of all
286 * system nodes within own cluster that the new destination
287 * can be reached via this node.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100288 * (node.establishedContact()=>cluster.multicastNewRoute())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900289 * => Send a message to the slave node about existence
Per Lidenb97bf3f2006-01-02 19:04:38 +0100290 * of all system nodes within cluster:
291 * (node.establishedContact()=>cluster.sendLocalRoutes())
292 *
293 * 3: A new cluster local system node becomes available.
294 * => Send message(s) to this particular node containing
295 * information about all cluster external and slave
296 * nodes which can be reached via this node.
297 * (node.establishedContact()==>network.sendExternalRoutes())
298 * (node.establishedContact()==>network.sendSlaveRoutes())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900299 * => Send messages to all directly connected slave nodes
Per Lidenb97bf3f2006-01-02 19:04:38 +0100300 * containing information about the existence of the new node
301 * (node.establishedContact()=>cluster.multicastNewRoute())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900302 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100303 * 4: The link towards a zone/cluster external node or slave
304 * node goes down.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900305 * => Send a multcast message updating routing tables of all
Per Lidenb97bf3f2006-01-02 19:04:38 +0100306 * nodes within cluster that the new destination can not any
307 * longer be reached via this node.
308 * (node.lostAllLinks()=>cluster.bcastLostRoute())
309 *
310 * 5: A cluster local system node becomes unavailable.
311 * => Remove all references to this node from the local
312 * routing tables. Note: This is a completely node
313 * local operation.
314 * (node.lostAllLinks()=>network.removeAsRouter())
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900315 * => Send messages to all directly connected slave nodes
Per Lidenb97bf3f2006-01-02 19:04:38 +0100316 * containing information about loss of the node
317 * (node.establishedContact()=>cluster.multicastLostRoute())
318 *
319 */
320
David S. Miller6c000552008-09-02 23:38:32 -0700321static void node_established_contact(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100322{
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000323 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100324
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900325 /* Syncronize broadcast acks */
326 n_ptr->bclink.acked = tipc_bclink_get_last_sent();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100327
Per Lidenb97bf3f2006-01-02 19:04:38 +0100328 if (n_ptr->bclink.supported) {
Allan Stephens8f92df62010-12-31 18:59:19 +0000329 tipc_nmap_add(&tipc_bcast_nmap, n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100330 if (n_ptr->addr < tipc_own_addr)
331 tipc_own_tag++;
332 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100333}
334
Allan Stephens5a68d5e2010-08-17 11:00:16 +0000335static void node_cleanup_finished(unsigned long node_addr)
336{
337 struct tipc_node *n_ptr;
338
339 read_lock_bh(&tipc_net_lock);
340 n_ptr = tipc_node_find(node_addr);
341 if (n_ptr) {
342 tipc_node_lock(n_ptr);
343 n_ptr->cleanup_required = 0;
344 tipc_node_unlock(n_ptr);
345 }
346 read_unlock_bh(&tipc_net_lock);
347}
348
David S. Miller6c000552008-09-02 23:38:32 -0700349static void node_lost_contact(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100350{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100351 char addr_string[16];
352 u32 i;
353
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900354 /* Clean up broadcast reception remains */
355 n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0;
356 while (n_ptr->bclink.deferred_head) {
Allan Stephens0e659672010-12-31 18:59:32 +0000357 struct sk_buff *buf = n_ptr->bclink.deferred_head;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900358 n_ptr->bclink.deferred_head = buf->next;
359 buf_discard(buf);
360 }
361 if (n_ptr->bclink.defragm) {
362 buf_discard(n_ptr->bclink.defragm);
363 n_ptr->bclink.defragm = NULL;
364 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100365
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000366 if (n_ptr->bclink.supported) {
Allan Stephens8f92df62010-12-31 18:59:19 +0000367 tipc_bclink_acknowledge(n_ptr,
368 mod(n_ptr->bclink.acked + 10000));
369 tipc_nmap_remove(&tipc_bcast_nmap, n_ptr->addr);
Allan Stephens51a8e4d2010-12-31 18:59:18 +0000370 if (n_ptr->addr < tipc_own_addr)
371 tipc_own_tag--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100372 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100373
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900374 info("Lost contact with %s\n",
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000375 tipc_addr_string_fill(addr_string, n_ptr->addr));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100376
377 /* Abort link changeover */
378 for (i = 0; i < MAX_BEARERS; i++) {
379 struct link *l_ptr = n_ptr->links[i];
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900380 if (!l_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100381 continue;
382 l_ptr->reset_checkpoint = l_ptr->next_in_no;
383 l_ptr->exp_msg_count = 0;
Per Liden4323add2006-01-18 00:38:21 +0100384 tipc_link_reset_fragments(l_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100385 }
386
387 /* Notify subscribers */
Allan Stephensf1379172011-02-23 14:13:41 -0500388 tipc_nodesub_notify(n_ptr);
Allan Stephens5a68d5e2010-08-17 11:00:16 +0000389
390 /* Prevent re-contact with node until all cleanup is done */
391
392 n_ptr->cleanup_required = 1;
393 tipc_k_signal((Handler)node_cleanup_finished, n_ptr->addr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100394}
395
Per Liden4323add2006-01-18 00:38:21 +0100396struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100397{
398 u32 domain;
399 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -0700400 struct tipc_node *n_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900401 struct tipc_node_info node_info;
Allan Stephensea138472006-06-29 12:33:20 -0700402 u32 payload_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100403
404 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100405 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100406
Al Viro3e6c8cd2006-11-08 00:19:09 -0800407 domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Liden4323add2006-01-18 00:38:21 +0100408 if (!tipc_addr_domain_valid(domain))
409 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
410 " (network address)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100411
Allan Stephens1aad72d2008-07-14 22:44:58 -0700412 read_lock_bh(&tipc_net_lock);
Allan Stephens672d99e2011-02-25 18:42:52 -0500413 if (!tipc_num_nodes) {
Allan Stephens1aad72d2008-07-14 22:44:58 -0700414 read_unlock_bh(&tipc_net_lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900415 return tipc_cfg_reply_none();
Allan Stephens1aad72d2008-07-14 22:44:58 -0700416 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100417
Allan Stephens08c80e92010-12-31 18:59:17 +0000418 /* For now, get space for all other nodes */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100419
Allan Stephens672d99e2011-02-25 18:42:52 -0500420 payload_size = TLV_SPACE(sizeof(node_info)) * tipc_num_nodes;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700421 if (payload_size > 32768u) {
422 read_unlock_bh(&tipc_net_lock);
Allan Stephensea138472006-06-29 12:33:20 -0700423 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
424 " (too many nodes)");
Allan Stephens1aad72d2008-07-14 22:44:58 -0700425 }
Allan Stephensea138472006-06-29 12:33:20 -0700426 buf = tipc_cfg_reply_alloc(payload_size);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700427 if (!buf) {
428 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100429 return NULL;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700430 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100431
432 /* Add TLVs for all nodes in scope */
433
Allan Stephens672d99e2011-02-25 18:42:52 -0500434 list_for_each_entry(n_ptr, &tipc_node_list, list) {
435 if (!tipc_in_scope(domain, n_ptr->addr))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100436 continue;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900437 node_info.addr = htonl(n_ptr->addr);
438 node_info.up = htonl(tipc_node_is_up(n_ptr));
439 tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
Per Liden4323add2006-01-18 00:38:21 +0100440 &node_info, sizeof(node_info));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100441 }
442
Allan Stephens1aad72d2008-07-14 22:44:58 -0700443 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100444 return buf;
445}
446
Per Liden4323add2006-01-18 00:38:21 +0100447struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100448{
449 u32 domain;
450 struct sk_buff *buf;
David S. Miller6c000552008-09-02 23:38:32 -0700451 struct tipc_node *n_ptr;
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900452 struct tipc_link_info link_info;
Allan Stephensea138472006-06-29 12:33:20 -0700453 u32 payload_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100454
455 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
Per Liden4323add2006-01-18 00:38:21 +0100456 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100457
Al Viro3e6c8cd2006-11-08 00:19:09 -0800458 domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
Per Liden4323add2006-01-18 00:38:21 +0100459 if (!tipc_addr_domain_valid(domain))
460 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
461 " (network address)");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100462
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900463 if (tipc_mode != TIPC_NET_MODE)
464 return tipc_cfg_reply_none();
465
Allan Stephens1aad72d2008-07-14 22:44:58 -0700466 read_lock_bh(&tipc_net_lock);
467
Allan Stephensea138472006-06-29 12:33:20 -0700468 /* Get space for all unicast links + multicast link */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100469
Allan Stephens9df3b7e2011-02-24 13:20:20 -0500470 payload_size = TLV_SPACE(sizeof(link_info)) *
Allan Stephensd1bcb112011-02-25 10:01:58 -0500471 (atomic_read(&tipc_num_links) + 1);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700472 if (payload_size > 32768u) {
473 read_unlock_bh(&tipc_net_lock);
Allan Stephensea138472006-06-29 12:33:20 -0700474 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
475 " (too many links)");
Allan Stephens1aad72d2008-07-14 22:44:58 -0700476 }
Allan Stephensea138472006-06-29 12:33:20 -0700477 buf = tipc_cfg_reply_alloc(payload_size);
Allan Stephens1aad72d2008-07-14 22:44:58 -0700478 if (!buf) {
479 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100480 return NULL;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700481 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100482
483 /* Add TLV for broadcast link */
484
Allan Stephensa3796f82011-02-23 11:44:49 -0500485 link_info.dest = htonl(tipc_cluster_mask(tipc_own_addr));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900486 link_info.up = htonl(1);
Stephen Hemminger4b704d52009-03-18 19:11:29 -0700487 strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME);
Per Liden4323add2006-01-18 00:38:21 +0100488 tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100489
490 /* Add TLVs for any other links in scope */
491
Allan Stephens672d99e2011-02-25 18:42:52 -0500492 list_for_each_entry(n_ptr, &tipc_node_list, list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900493 u32 i;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100494
Allan Stephens672d99e2011-02-25 18:42:52 -0500495 if (!tipc_in_scope(domain, n_ptr->addr))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100496 continue;
Allan Stephens1aad72d2008-07-14 22:44:58 -0700497 tipc_node_lock(n_ptr);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900498 for (i = 0; i < MAX_BEARERS; i++) {
499 if (!n_ptr->links[i])
500 continue;
501 link_info.dest = htonl(n_ptr->addr);
502 link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
503 strcpy(link_info.str, n_ptr->links[i]->name);
504 tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
Per Liden4323add2006-01-18 00:38:21 +0100505 &link_info, sizeof(link_info));
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900506 }
Allan Stephens1aad72d2008-07-14 22:44:58 -0700507 tipc_node_unlock(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100508 }
509
Allan Stephens1aad72d2008-07-14 22:44:58 -0700510 read_unlock_bh(&tipc_net_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100511 return buf;
512}