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