]>
Commit | Line | Data |
---|---|---|
b97bf3fd PL |
1 | /* |
2 | * net/tipc/node.c: TIPC node management routines | |
c4307285 | 3 | * |
593a5f22 | 4 | * Copyright (c) 2000-2006, Ericsson AB |
ea13847b | 5 | * Copyright (c) 2005-2006, Wind River Systems |
b97bf3fd PL |
6 | * All rights reserved. |
7 | * | |
9ea1fd3c | 8 | * Redistribution and use in source and binary forms, with or without |
b97bf3fd PL |
9 | * modification, are permitted provided that the following conditions are met: |
10 | * | |
9ea1fd3c PL |
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. | |
b97bf3fd | 19 | * |
9ea1fd3c PL |
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 | |
b97bf3fd PL |
34 | * POSSIBILITY OF SUCH DAMAGE. |
35 | */ | |
36 | ||
37 | #include "core.h" | |
38 | #include "config.h" | |
39 | #include "node.h" | |
b97bf3fd | 40 | #include "port.h" |
b97bf3fd | 41 | #include "name_distr.h" |
b97bf3fd | 42 | |
6c00055a DM |
43 | static void node_lost_contact(struct tipc_node *n_ptr); |
44 | static void node_established_contact(struct tipc_node *n_ptr); | |
b97bf3fd | 45 | |
31e3c3f6 | 46 | /* sorted list of nodes within cluster */ |
47 | static struct tipc_node *tipc_nodes = NULL; | |
b97bf3fd | 48 | |
2ecb0924 AS |
49 | static DEFINE_SPINLOCK(node_create_lock); |
50 | ||
b97bf3fd PL |
51 | u32 tipc_own_tag = 0; |
52 | ||
2ecb0924 AS |
53 | /** |
54 | * tipc_node_create - create neighboring node | |
55 | * | |
56 | * Currently, this routine is called by neighbor discovery code, which holds | |
57 | * net_lock for reading only. We must take node_create_lock to ensure a node | |
58 | * isn't created twice if two different bearers discover the node at the same | |
59 | * time. (It would be preferable to switch to holding net_lock in write mode, | |
60 | * but this is a non-trivial change.) | |
61 | */ | |
62 | ||
6c00055a | 63 | struct tipc_node *tipc_node_create(u32 addr) |
b97bf3fd | 64 | { |
6c00055a DM |
65 | struct tipc_node *n_ptr; |
66 | struct tipc_node **curr_node; | |
8f92df6a | 67 | u32 n_num; |
b97bf3fd | 68 | |
2ecb0924 AS |
69 | spin_lock_bh(&node_create_lock); |
70 | ||
71 | for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) { | |
72 | if (addr < n_ptr->addr) | |
73 | break; | |
74 | if (addr == n_ptr->addr) { | |
75 | spin_unlock_bh(&node_create_lock); | |
76 | return n_ptr; | |
77 | } | |
78 | } | |
79 | ||
2710b57f | 80 | n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC); |
a10bd924 | 81 | if (!n_ptr) { |
2ecb0924 | 82 | spin_unlock_bh(&node_create_lock); |
a10bd924 AS |
83 | warn("Node creation failed, no memory\n"); |
84 | return NULL; | |
85 | } | |
86 | ||
a10bd924 | 87 | n_ptr->addr = addr; |
51a8e4de | 88 | spin_lock_init(&n_ptr->lock); |
a10bd924 | 89 | INIT_LIST_HEAD(&n_ptr->nsub); |
8f92df6a AS |
90 | |
91 | n_num = tipc_node(addr); | |
92 | tipc_net.nodes[n_num] = n_ptr; | |
93 | if (n_num > tipc_net.highest_node) | |
94 | tipc_net.highest_node = n_num; | |
a10bd924 AS |
95 | |
96 | /* Insert node into ordered list */ | |
c4307285 | 97 | for (curr_node = &tipc_nodes; *curr_node; |
a10bd924 AS |
98 | curr_node = &(*curr_node)->next) { |
99 | if (addr < (*curr_node)->addr) { | |
100 | n_ptr->next = *curr_node; | |
101 | break; | |
102 | } | |
103 | } | |
104 | (*curr_node) = n_ptr; | |
2ecb0924 | 105 | spin_unlock_bh(&node_create_lock); |
b97bf3fd PL |
106 | return n_ptr; |
107 | } | |
108 | ||
6c00055a | 109 | void tipc_node_delete(struct tipc_node *n_ptr) |
b97bf3fd | 110 | { |
8f92df6a AS |
111 | u32 n_num; |
112 | ||
b97bf3fd PL |
113 | if (!n_ptr) |
114 | return; | |
115 | ||
b97bf3fd | 116 | dbg("node %x deleted\n", n_ptr->addr); |
8f92df6a AS |
117 | n_num = tipc_node(n_ptr->addr); |
118 | tipc_net.nodes[n_num] = NULL; | |
b97bf3fd | 119 | kfree(n_ptr); |
8f92df6a AS |
120 | |
121 | while (!tipc_net.nodes[tipc_net.highest_node]) | |
122 | if (--tipc_net.highest_node == 0) | |
123 | break; | |
b97bf3fd PL |
124 | } |
125 | ||
126 | ||
127 | /** | |
4323add6 | 128 | * tipc_node_link_up - handle addition of link |
c4307285 | 129 | * |
b97bf3fd PL |
130 | * Link becomes active (alone or shared) or standby, depending on its priority. |
131 | */ | |
132 | ||
6c00055a | 133 | void tipc_node_link_up(struct tipc_node *n_ptr, struct link *l_ptr) |
b97bf3fd PL |
134 | { |
135 | struct link **active = &n_ptr->active_links[0]; | |
136 | ||
5392d646 AS |
137 | n_ptr->working_links++; |
138 | ||
b97bf3fd PL |
139 | info("Established link <%s> on network plane %c\n", |
140 | l_ptr->name, l_ptr->b_ptr->net_plane); | |
c4307285 | 141 | |
b97bf3fd PL |
142 | if (!active[0]) { |
143 | dbg(" link %x into %x/%x\n", l_ptr, &active[0], &active[1]); | |
144 | active[0] = active[1] = l_ptr; | |
145 | node_established_contact(n_ptr); | |
146 | return; | |
147 | } | |
c4307285 | 148 | if (l_ptr->priority < active[0]->priority) { |
a10bd924 | 149 | info("New link <%s> becomes standby\n", l_ptr->name); |
b97bf3fd PL |
150 | return; |
151 | } | |
4323add6 | 152 | tipc_link_send_duplicate(active[0], l_ptr); |
c4307285 | 153 | if (l_ptr->priority == active[0]->priority) { |
b97bf3fd PL |
154 | active[0] = l_ptr; |
155 | return; | |
156 | } | |
a10bd924 AS |
157 | info("Old link <%s> becomes standby\n", active[0]->name); |
158 | if (active[1] != active[0]) | |
159 | info("Old link <%s> becomes standby\n", active[1]->name); | |
b97bf3fd PL |
160 | active[0] = active[1] = l_ptr; |
161 | } | |
162 | ||
163 | /** | |
164 | * node_select_active_links - select active link | |
165 | */ | |
166 | ||
6c00055a | 167 | static void node_select_active_links(struct tipc_node *n_ptr) |
b97bf3fd PL |
168 | { |
169 | struct link **active = &n_ptr->active_links[0]; | |
170 | u32 i; | |
171 | u32 highest_prio = 0; | |
172 | ||
c4307285 | 173 | active[0] = active[1] = NULL; |
b97bf3fd PL |
174 | |
175 | for (i = 0; i < MAX_BEARERS; i++) { | |
c4307285 | 176 | struct link *l_ptr = n_ptr->links[i]; |
b97bf3fd | 177 | |
4323add6 | 178 | if (!l_ptr || !tipc_link_is_up(l_ptr) || |
b97bf3fd PL |
179 | (l_ptr->priority < highest_prio)) |
180 | continue; | |
181 | ||
182 | if (l_ptr->priority > highest_prio) { | |
c4307285 | 183 | highest_prio = l_ptr->priority; |
b97bf3fd PL |
184 | active[0] = active[1] = l_ptr; |
185 | } else { | |
186 | active[1] = l_ptr; | |
187 | } | |
188 | } | |
189 | } | |
190 | ||
191 | /** | |
4323add6 | 192 | * tipc_node_link_down - handle loss of link |
b97bf3fd PL |
193 | */ |
194 | ||
6c00055a | 195 | void tipc_node_link_down(struct tipc_node *n_ptr, struct link *l_ptr) |
b97bf3fd PL |
196 | { |
197 | struct link **active; | |
198 | ||
5392d646 AS |
199 | n_ptr->working_links--; |
200 | ||
4323add6 | 201 | if (!tipc_link_is_active(l_ptr)) { |
b97bf3fd PL |
202 | info("Lost standby link <%s> on network plane %c\n", |
203 | l_ptr->name, l_ptr->b_ptr->net_plane); | |
204 | return; | |
205 | } | |
206 | info("Lost link <%s> on network plane %c\n", | |
207 | l_ptr->name, l_ptr->b_ptr->net_plane); | |
208 | ||
209 | active = &n_ptr->active_links[0]; | |
210 | if (active[0] == l_ptr) | |
211 | active[0] = active[1]; | |
212 | if (active[1] == l_ptr) | |
213 | active[1] = active[0]; | |
214 | if (active[0] == l_ptr) | |
215 | node_select_active_links(n_ptr); | |
c4307285 | 216 | if (tipc_node_is_up(n_ptr)) |
4323add6 | 217 | tipc_link_changeover(l_ptr); |
c4307285 | 218 | else |
b97bf3fd PL |
219 | node_lost_contact(n_ptr); |
220 | } | |
221 | ||
6c00055a | 222 | int tipc_node_has_active_links(struct tipc_node *n_ptr) |
b97bf3fd | 223 | { |
76ae0d71 | 224 | return n_ptr->active_links[0] != NULL; |
b97bf3fd PL |
225 | } |
226 | ||
6c00055a | 227 | int tipc_node_has_redundant_links(struct tipc_node *n_ptr) |
b97bf3fd | 228 | { |
a02cec21 | 229 | return n_ptr->working_links > 1; |
b97bf3fd PL |
230 | } |
231 | ||
6c00055a | 232 | int tipc_node_is_up(struct tipc_node *n_ptr) |
b97bf3fd | 233 | { |
51a8e4de | 234 | return tipc_node_has_active_links(n_ptr); |
b97bf3fd PL |
235 | } |
236 | ||
6c00055a | 237 | struct tipc_node *tipc_node_attach_link(struct link *l_ptr) |
b97bf3fd | 238 | { |
6c00055a | 239 | struct tipc_node *n_ptr = tipc_node_find(l_ptr->addr); |
b97bf3fd PL |
240 | |
241 | if (!n_ptr) | |
4323add6 | 242 | n_ptr = tipc_node_create(l_ptr->addr); |
c4307285 | 243 | if (n_ptr) { |
b97bf3fd PL |
244 | u32 bearer_id = l_ptr->b_ptr->identity; |
245 | char addr_string[16]; | |
246 | ||
c4307285 | 247 | if (n_ptr->link_cnt >= 2) { |
c4307285 | 248 | err("Attempt to create third link to %s\n", |
c68ca7b7 | 249 | tipc_addr_string_fill(addr_string, n_ptr->addr)); |
c4307285 YH |
250 | return NULL; |
251 | } | |
252 | ||
253 | if (!n_ptr->links[bearer_id]) { | |
254 | n_ptr->links[bearer_id] = l_ptr; | |
51f98a8d | 255 | tipc_net.links++; |
c4307285 YH |
256 | n_ptr->link_cnt++; |
257 | return n_ptr; | |
258 | } | |
a570f095 | 259 | err("Attempt to establish second link on <%s> to %s\n", |
c4307285 | 260 | l_ptr->b_ptr->publ.name, |
c68ca7b7 | 261 | tipc_addr_string_fill(addr_string, l_ptr->addr)); |
c4307285 | 262 | } |
1fc54d8f | 263 | return NULL; |
b97bf3fd PL |
264 | } |
265 | ||
6c00055a | 266 | void tipc_node_detach_link(struct tipc_node *n_ptr, struct link *l_ptr) |
b97bf3fd | 267 | { |
1fc54d8f | 268 | n_ptr->links[l_ptr->b_ptr->identity] = NULL; |
51f98a8d | 269 | tipc_net.links--; |
b97bf3fd PL |
270 | n_ptr->link_cnt--; |
271 | } | |
272 | ||
273 | /* | |
274 | * Routing table management - five cases to handle: | |
275 | * | |
276 | * 1: A link towards a zone/cluster external node comes up. | |
c4307285 YH |
277 | * => Send a multicast message updating routing tables of all |
278 | * system nodes within own cluster that the new destination | |
279 | * can be reached via this node. | |
b97bf3fd PL |
280 | * (node.establishedContact()=>cluster.multicastNewRoute()) |
281 | * | |
282 | * 2: A link towards a slave node comes up. | |
c4307285 YH |
283 | * => Send a multicast message updating routing tables of all |
284 | * system nodes within own cluster that the new destination | |
285 | * can be reached via this node. | |
b97bf3fd | 286 | * (node.establishedContact()=>cluster.multicastNewRoute()) |
c4307285 | 287 | * => Send a message to the slave node about existence |
b97bf3fd PL |
288 | * of all system nodes within cluster: |
289 | * (node.establishedContact()=>cluster.sendLocalRoutes()) | |
290 | * | |
291 | * 3: A new cluster local system node becomes available. | |
292 | * => Send message(s) to this particular node containing | |
293 | * information about all cluster external and slave | |
294 | * nodes which can be reached via this node. | |
295 | * (node.establishedContact()==>network.sendExternalRoutes()) | |
296 | * (node.establishedContact()==>network.sendSlaveRoutes()) | |
c4307285 | 297 | * => Send messages to all directly connected slave nodes |
b97bf3fd PL |
298 | * containing information about the existence of the new node |
299 | * (node.establishedContact()=>cluster.multicastNewRoute()) | |
c4307285 | 300 | * |
b97bf3fd PL |
301 | * 4: The link towards a zone/cluster external node or slave |
302 | * node goes down. | |
c4307285 | 303 | * => Send a multcast message updating routing tables of all |
b97bf3fd PL |
304 | * nodes within cluster that the new destination can not any |
305 | * longer be reached via this node. | |
306 | * (node.lostAllLinks()=>cluster.bcastLostRoute()) | |
307 | * | |
308 | * 5: A cluster local system node becomes unavailable. | |
309 | * => Remove all references to this node from the local | |
310 | * routing tables. Note: This is a completely node | |
311 | * local operation. | |
312 | * (node.lostAllLinks()=>network.removeAsRouter()) | |
c4307285 | 313 | * => Send messages to all directly connected slave nodes |
b97bf3fd PL |
314 | * containing information about loss of the node |
315 | * (node.establishedContact()=>cluster.multicastLostRoute()) | |
316 | * | |
317 | */ | |
318 | ||
6c00055a | 319 | static void node_established_contact(struct tipc_node *n_ptr) |
b97bf3fd | 320 | { |
b97bf3fd | 321 | dbg("node_established_contact:-> %x\n", n_ptr->addr); |
51a8e4de | 322 | tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr); |
b97bf3fd | 323 | |
c4307285 YH |
324 | /* Syncronize broadcast acks */ |
325 | n_ptr->bclink.acked = tipc_bclink_get_last_sent(); | |
b97bf3fd | 326 | |
b97bf3fd | 327 | if (n_ptr->bclink.supported) { |
8f92df6a | 328 | tipc_nmap_add(&tipc_bcast_nmap, n_ptr->addr); |
b97bf3fd PL |
329 | if (n_ptr->addr < tipc_own_addr) |
330 | tipc_own_tag++; | |
331 | } | |
b97bf3fd PL |
332 | } |
333 | ||
5a68d5ee AS |
334 | static void node_cleanup_finished(unsigned long node_addr) |
335 | { | |
336 | struct tipc_node *n_ptr; | |
337 | ||
338 | read_lock_bh(&tipc_net_lock); | |
339 | n_ptr = tipc_node_find(node_addr); | |
340 | if (n_ptr) { | |
341 | tipc_node_lock(n_ptr); | |
342 | n_ptr->cleanup_required = 0; | |
343 | tipc_node_unlock(n_ptr); | |
344 | } | |
345 | read_unlock_bh(&tipc_net_lock); | |
346 | } | |
347 | ||
6c00055a | 348 | static void node_lost_contact(struct tipc_node *n_ptr) |
b97bf3fd | 349 | { |
6c00055a | 350 | struct tipc_node_subscr *ns, *tns; |
b97bf3fd PL |
351 | char addr_string[16]; |
352 | u32 i; | |
353 | ||
c4307285 YH |
354 | /* Clean up broadcast reception remains */ |
355 | n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0; | |
356 | while (n_ptr->bclink.deferred_head) { | |
357 | struct sk_buff* buf = n_ptr->bclink.deferred_head; | |
358 | 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 | } | |
c4307285 | 365 | |
51a8e4de | 366 | if (n_ptr->bclink.supported) { |
8f92df6a AS |
367 | tipc_bclink_acknowledge(n_ptr, |
368 | mod(n_ptr->bclink.acked + 10000)); | |
369 | tipc_nmap_remove(&tipc_bcast_nmap, n_ptr->addr); | |
51a8e4de AS |
370 | if (n_ptr->addr < tipc_own_addr) |
371 | tipc_own_tag--; | |
b97bf3fd | 372 | } |
b97bf3fd | 373 | |
c4307285 | 374 | info("Lost contact with %s\n", |
c68ca7b7 | 375 | tipc_addr_string_fill(addr_string, n_ptr->addr)); |
b97bf3fd PL |
376 | |
377 | /* Abort link changeover */ | |
378 | for (i = 0; i < MAX_BEARERS; i++) { | |
379 | struct link *l_ptr = n_ptr->links[i]; | |
c4307285 | 380 | if (!l_ptr) |
b97bf3fd PL |
381 | continue; |
382 | l_ptr->reset_checkpoint = l_ptr->next_in_no; | |
383 | l_ptr->exp_msg_count = 0; | |
4323add6 | 384 | tipc_link_reset_fragments(l_ptr); |
b97bf3fd PL |
385 | } |
386 | ||
387 | /* Notify subscribers */ | |
388 | list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) { | |
c4307285 | 389 | ns->node = NULL; |
b97bf3fd | 390 | list_del_init(&ns->nodesub_list); |
4323add6 PL |
391 | tipc_k_signal((Handler)ns->handle_node_down, |
392 | (unsigned long)ns->usr_handle); | |
b97bf3fd | 393 | } |
5a68d5ee AS |
394 | |
395 | /* Prevent re-contact with node until all cleanup is done */ | |
396 | ||
397 | n_ptr->cleanup_required = 1; | |
398 | tipc_k_signal((Handler)node_cleanup_finished, n_ptr->addr); | |
b97bf3fd PL |
399 | } |
400 | ||
4323add6 | 401 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space) |
b97bf3fd PL |
402 | { |
403 | u32 domain; | |
404 | struct sk_buff *buf; | |
6c00055a | 405 | struct tipc_node *n_ptr; |
c4307285 | 406 | struct tipc_node_info node_info; |
ea13847b | 407 | u32 payload_size; |
b97bf3fd PL |
408 | |
409 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | |
4323add6 | 410 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd | 411 | |
3e6c8cd5 | 412 | domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
4323add6 PL |
413 | if (!tipc_addr_domain_valid(domain)) |
414 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | |
415 | " (network address)"); | |
b97bf3fd | 416 | |
1aad72d6 AS |
417 | read_lock_bh(&tipc_net_lock); |
418 | if (!tipc_nodes) { | |
419 | read_unlock_bh(&tipc_net_lock); | |
c4307285 | 420 | return tipc_cfg_reply_none(); |
1aad72d6 | 421 | } |
b97bf3fd | 422 | |
08c80e9a | 423 | /* For now, get space for all other nodes */ |
b97bf3fd | 424 | |
ea13847b | 425 | payload_size = TLV_SPACE(sizeof(node_info)) * (tipc_max_nodes - 1); |
1aad72d6 AS |
426 | if (payload_size > 32768u) { |
427 | read_unlock_bh(&tipc_net_lock); | |
ea13847b AS |
428 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
429 | " (too many nodes)"); | |
1aad72d6 | 430 | } |
ea13847b | 431 | buf = tipc_cfg_reply_alloc(payload_size); |
1aad72d6 AS |
432 | if (!buf) { |
433 | read_unlock_bh(&tipc_net_lock); | |
b97bf3fd | 434 | return NULL; |
1aad72d6 | 435 | } |
b97bf3fd PL |
436 | |
437 | /* Add TLVs for all nodes in scope */ | |
438 | ||
4323add6 | 439 | for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) { |
c68ca7b7 | 440 | if (!tipc_in_scope(domain, n_ptr->addr)) |
b97bf3fd | 441 | continue; |
c4307285 YH |
442 | node_info.addr = htonl(n_ptr->addr); |
443 | node_info.up = htonl(tipc_node_is_up(n_ptr)); | |
444 | tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO, | |
4323add6 | 445 | &node_info, sizeof(node_info)); |
b97bf3fd PL |
446 | } |
447 | ||
1aad72d6 | 448 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
449 | return buf; |
450 | } | |
451 | ||
4323add6 | 452 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) |
b97bf3fd PL |
453 | { |
454 | u32 domain; | |
455 | struct sk_buff *buf; | |
6c00055a | 456 | struct tipc_node *n_ptr; |
c4307285 | 457 | struct tipc_link_info link_info; |
ea13847b | 458 | u32 payload_size; |
b97bf3fd PL |
459 | |
460 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR)) | |
4323add6 | 461 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
b97bf3fd | 462 | |
3e6c8cd5 | 463 | domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area)); |
4323add6 PL |
464 | if (!tipc_addr_domain_valid(domain)) |
465 | return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE | |
466 | " (network address)"); | |
b97bf3fd | 467 | |
c4307285 YH |
468 | if (tipc_mode != TIPC_NET_MODE) |
469 | return tipc_cfg_reply_none(); | |
470 | ||
1aad72d6 AS |
471 | read_lock_bh(&tipc_net_lock); |
472 | ||
ea13847b AS |
473 | /* Get space for all unicast links + multicast link */ |
474 | ||
51f98a8d | 475 | payload_size = TLV_SPACE(sizeof(link_info)) * (tipc_net.links + 1); |
1aad72d6 AS |
476 | if (payload_size > 32768u) { |
477 | read_unlock_bh(&tipc_net_lock); | |
ea13847b AS |
478 | return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED |
479 | " (too many links)"); | |
1aad72d6 | 480 | } |
ea13847b | 481 | buf = tipc_cfg_reply_alloc(payload_size); |
1aad72d6 AS |
482 | if (!buf) { |
483 | read_unlock_bh(&tipc_net_lock); | |
b97bf3fd | 484 | return NULL; |
1aad72d6 | 485 | } |
b97bf3fd PL |
486 | |
487 | /* Add TLV for broadcast link */ | |
488 | ||
c4307285 YH |
489 | link_info.dest = htonl(tipc_own_addr & 0xfffff00); |
490 | link_info.up = htonl(1); | |
4b704d59 | 491 | strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME); |
4323add6 | 492 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info)); |
b97bf3fd PL |
493 | |
494 | /* Add TLVs for any other links in scope */ | |
495 | ||
4323add6 | 496 | for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) { |
c4307285 | 497 | u32 i; |
b97bf3fd | 498 | |
c68ca7b7 | 499 | if (!tipc_in_scope(domain, n_ptr->addr)) |
b97bf3fd | 500 | continue; |
1aad72d6 | 501 | tipc_node_lock(n_ptr); |
c4307285 YH |
502 | for (i = 0; i < MAX_BEARERS; i++) { |
503 | if (!n_ptr->links[i]) | |
504 | continue; | |
505 | link_info.dest = htonl(n_ptr->addr); | |
506 | link_info.up = htonl(tipc_link_is_up(n_ptr->links[i])); | |
507 | strcpy(link_info.str, n_ptr->links[i]->name); | |
508 | tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, | |
4323add6 | 509 | &link_info, sizeof(link_info)); |
c4307285 | 510 | } |
1aad72d6 | 511 | tipc_node_unlock(n_ptr); |
b97bf3fd PL |
512 | } |
513 | ||
1aad72d6 | 514 | read_unlock_bh(&tipc_net_lock); |
b97bf3fd PL |
515 | return buf; |
516 | } |