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