[TIPC]: Disallow config operations that aren't supported in certain modes.
[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
237 assert(bearer_id < MAX_BEARERS);
238 if (n_ptr->link_cnt >= 2) {
239 char addr_string[16];
240
241 err("Attempt to create third link to %s\n",
242 addr_string_fill(addr_string, n_ptr->addr));
1fc54d8f 243 return NULL;
b97bf3fd
PL
244 }
245
246 if (!n_ptr->links[bearer_id]) {
247 n_ptr->links[bearer_id] = l_ptr;
4323add6 248 tipc_net.zones[tipc_zone(l_ptr->addr)]->links++;
b97bf3fd
PL
249 n_ptr->link_cnt++;
250 return n_ptr;
251 }
252 err("Attempt to establish second link on <%s> to <%s> \n",
253 l_ptr->b_ptr->publ.name,
254 addr_string_fill(addr_string, l_ptr->addr));
255 }
1fc54d8f 256 return NULL;
b97bf3fd
PL
257}
258
4323add6 259void tipc_node_detach_link(struct node *n_ptr, struct link *l_ptr)
b97bf3fd 260{
1fc54d8f 261 n_ptr->links[l_ptr->b_ptr->identity] = NULL;
4323add6 262 tipc_net.zones[tipc_zone(l_ptr->addr)]->links--;
b97bf3fd
PL
263 n_ptr->link_cnt--;
264}
265
266/*
267 * Routing table management - five cases to handle:
268 *
269 * 1: A link towards a zone/cluster external node comes up.
270 * => Send a multicast message updating routing tables of all
271 * system nodes within own cluster that the new destination
272 * can be reached via this node.
273 * (node.establishedContact()=>cluster.multicastNewRoute())
274 *
275 * 2: A link towards a slave node comes up.
276 * => Send a multicast message updating routing tables of all
277 * system nodes within own cluster that the new destination
278 * can be reached via this node.
279 * (node.establishedContact()=>cluster.multicastNewRoute())
280 * => Send a message to the slave node about existence
281 * of all system nodes within cluster:
282 * (node.establishedContact()=>cluster.sendLocalRoutes())
283 *
284 * 3: A new cluster local system node becomes available.
285 * => Send message(s) to this particular node containing
286 * information about all cluster external and slave
287 * nodes which can be reached via this node.
288 * (node.establishedContact()==>network.sendExternalRoutes())
289 * (node.establishedContact()==>network.sendSlaveRoutes())
290 * => Send messages to all directly connected slave nodes
291 * containing information about the existence of the new node
292 * (node.establishedContact()=>cluster.multicastNewRoute())
293 *
294 * 4: The link towards a zone/cluster external node or slave
295 * node goes down.
296 * => Send a multcast message updating routing tables of all
297 * nodes within cluster that the new destination can not any
298 * longer be reached via this node.
299 * (node.lostAllLinks()=>cluster.bcastLostRoute())
300 *
301 * 5: A cluster local system node becomes unavailable.
302 * => Remove all references to this node from the local
303 * routing tables. Note: This is a completely node
304 * local operation.
305 * (node.lostAllLinks()=>network.removeAsRouter())
306 * => Send messages to all directly connected slave nodes
307 * containing information about loss of the node
308 * (node.establishedContact()=>cluster.multicastLostRoute())
309 *
310 */
311
312static void node_established_contact(struct node *n_ptr)
313{
314 struct cluster *c_ptr;
315
316 dbg("node_established_contact:-> %x\n", n_ptr->addr);
4323add6
PL
317 if (!tipc_node_has_active_routes(n_ptr)) {
318 tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);
b97bf3fd
PL
319 }
320
321 /* Syncronize broadcast acks */
4323add6 322 n_ptr->bclink.acked = tipc_bclink_get_last_sent();
b97bf3fd
PL
323
324 if (is_slave(tipc_own_addr))
325 return;
326 if (!in_own_cluster(n_ptr->addr)) {
327 /* Usage case 1 (see above) */
4323add6 328 c_ptr = tipc_cltr_find(tipc_own_addr);
b97bf3fd 329 if (!c_ptr)
4323add6 330 c_ptr = tipc_cltr_create(tipc_own_addr);
b97bf3fd 331 if (c_ptr)
4323add6
PL
332 tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1,
333 tipc_max_nodes);
b97bf3fd
PL
334 return;
335 }
336
337 c_ptr = n_ptr->owner;
338 if (is_slave(n_ptr->addr)) {
339 /* Usage case 2 (see above) */
4323add6
PL
340 tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1, tipc_max_nodes);
341 tipc_cltr_send_local_routes(c_ptr, n_ptr->addr);
b97bf3fd
PL
342 return;
343 }
344
345 if (n_ptr->bclink.supported) {
4323add6 346 tipc_nmap_add(&tipc_cltr_bcast_nodes, n_ptr->addr);
b97bf3fd
PL
347 if (n_ptr->addr < tipc_own_addr)
348 tipc_own_tag++;
349 }
350
351 /* Case 3 (see above) */
4323add6
PL
352 tipc_net_send_external_routes(n_ptr->addr);
353 tipc_cltr_send_slave_routes(c_ptr, n_ptr->addr);
354 tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, LOWEST_SLAVE,
355 tipc_highest_allowed_slave);
b97bf3fd
PL
356}
357
358static void node_lost_contact(struct node *n_ptr)
359{
360 struct cluster *c_ptr;
361 struct node_subscr *ns, *tns;
362 char addr_string[16];
363 u32 i;
364
365 /* Clean up broadcast reception remains */
366 n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0;
367 while (n_ptr->bclink.deferred_head) {
368 struct sk_buff* buf = n_ptr->bclink.deferred_head;
369 n_ptr->bclink.deferred_head = buf->next;
370 buf_discard(buf);
371 }
372 if (n_ptr->bclink.defragm) {
373 buf_discard(n_ptr->bclink.defragm);
374 n_ptr->bclink.defragm = NULL;
375 }
376 if (in_own_cluster(n_ptr->addr) && n_ptr->bclink.supported) {
4323add6 377 tipc_bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));
b97bf3fd
PL
378 }
379
380 /* Update routing tables */
381 if (is_slave(tipc_own_addr)) {
4323add6 382 tipc_net_remove_as_router(n_ptr->addr);
b97bf3fd
PL
383 } else {
384 if (!in_own_cluster(n_ptr->addr)) {
385 /* Case 4 (see above) */
4323add6
PL
386 c_ptr = tipc_cltr_find(tipc_own_addr);
387 tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
388 tipc_max_nodes);
b97bf3fd
PL
389 } else {
390 /* Case 5 (see above) */
4323add6 391 c_ptr = tipc_cltr_find(n_ptr->addr);
b97bf3fd 392 if (is_slave(n_ptr->addr)) {
4323add6
PL
393 tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,
394 tipc_max_nodes);
b97bf3fd
PL
395 } else {
396 if (n_ptr->bclink.supported) {
4323add6
PL
397 tipc_nmap_remove(&tipc_cltr_bcast_nodes,
398 n_ptr->addr);
b97bf3fd
PL
399 if (n_ptr->addr < tipc_own_addr)
400 tipc_own_tag--;
401 }
4323add6
PL
402 tipc_net_remove_as_router(n_ptr->addr);
403 tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr,
404 LOWEST_SLAVE,
405 tipc_highest_allowed_slave);
b97bf3fd
PL
406 }
407 }
408 }
4323add6 409 if (tipc_node_has_active_routes(n_ptr))
b97bf3fd
PL
410 return;
411
412 info("Lost contact with %s\n",
413 addr_string_fill(addr_string, n_ptr->addr));
414
415 /* Abort link changeover */
416 for (i = 0; i < MAX_BEARERS; i++) {
417 struct link *l_ptr = n_ptr->links[i];
418 if (!l_ptr)
419 continue;
420 l_ptr->reset_checkpoint = l_ptr->next_in_no;
421 l_ptr->exp_msg_count = 0;
4323add6 422 tipc_link_reset_fragments(l_ptr);
b97bf3fd
PL
423 }
424
425 /* Notify subscribers */
426 list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) {
1fc54d8f 427 ns->node = NULL;
b97bf3fd 428 list_del_init(&ns->nodesub_list);
4323add6
PL
429 tipc_k_signal((Handler)ns->handle_node_down,
430 (unsigned long)ns->usr_handle);
b97bf3fd
PL
431 }
432}
433
434/**
4323add6 435 * tipc_node_select_next_hop - find the next-hop node for a message
b97bf3fd
PL
436 *
437 * Called by when cluster local lookup has failed.
438 */
439
4323add6 440struct node *tipc_node_select_next_hop(u32 addr, u32 selector)
b97bf3fd
PL
441{
442 struct node *n_ptr;
443 u32 router_addr;
444
4323add6 445 if (!tipc_addr_domain_valid(addr))
1fc54d8f 446 return NULL;
b97bf3fd
PL
447
448 /* Look for direct link to destination processsor */
4323add6
PL
449 n_ptr = tipc_node_find(addr);
450 if (n_ptr && tipc_node_has_active_links(n_ptr))
b97bf3fd
PL
451 return n_ptr;
452
453 /* Cluster local system nodes *must* have direct links */
454 if (!is_slave(addr) && in_own_cluster(addr))
1fc54d8f 455 return NULL;
b97bf3fd
PL
456
457 /* Look for cluster local router with direct link to node */
4323add6 458 router_addr = tipc_node_select_router(n_ptr, selector);
b97bf3fd 459 if (router_addr)
4323add6 460 return tipc_node_select(router_addr, selector);
b97bf3fd
PL
461
462 /* Slave nodes can only be accessed within own cluster via a
463 known router with direct link -- if no router was found,give up */
464 if (is_slave(addr))
1fc54d8f 465 return NULL;
b97bf3fd
PL
466
467 /* Inter zone/cluster -- find any direct link to remote cluster */
468 addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);
4323add6
PL
469 n_ptr = tipc_net_select_remote_node(addr, selector);
470 if (n_ptr && tipc_node_has_active_links(n_ptr))
b97bf3fd
PL
471 return n_ptr;
472
473 /* Last resort -- look for any router to anywhere in remote zone */
4323add6 474 router_addr = tipc_net_select_router(addr, selector);
b97bf3fd 475 if (router_addr)
4323add6 476 return tipc_node_select(router_addr, selector);
b97bf3fd 477
1fc54d8f 478 return NULL;
b97bf3fd
PL
479}
480
481/**
4323add6 482 * tipc_node_select_router - select router to reach specified node
b97bf3fd
PL
483 *
484 * Uses a deterministic and fair algorithm for selecting router node.
485 */
486
4323add6 487u32 tipc_node_select_router(struct node *n_ptr, u32 ref)
b97bf3fd
PL
488{
489 u32 ulim;
490 u32 mask;
491 u32 start;
492 u32 r;
493
494 if (!n_ptr)
495 return 0;
496
497 if (n_ptr->last_router < 0)
498 return 0;
499 ulim = ((n_ptr->last_router + 1) * 32) - 1;
500
501 /* Start entry must be random */
502 mask = tipc_max_nodes;
503 while (mask > ulim)
504 mask >>= 1;
505 start = ref & mask;
506 r = start;
507
508 /* Lookup upwards with wrap-around */
509 do {
510 if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
511 break;
512 } while (++r <= ulim);
513 if (r > ulim) {
514 r = 1;
515 do {
516 if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)
517 break;
518 } while (++r < start);
519 assert(r != start);
520 }
521 assert(r && (r <= ulim));
522 return tipc_addr(own_zone(), own_cluster(), r);
523}
524
4323add6 525void tipc_node_add_router(struct node *n_ptr, u32 router)
b97bf3fd
PL
526{
527 u32 r_num = tipc_node(router);
528
529 n_ptr->routers[r_num / 32] =
530 ((1 << (r_num % 32)) | n_ptr->routers[r_num / 32]);
531 n_ptr->last_router = tipc_max_nodes / 32;
532 while ((--n_ptr->last_router >= 0) &&
533 !n_ptr->routers[n_ptr->last_router]);
534}
535
4323add6 536void tipc_node_remove_router(struct node *n_ptr, u32 router)
b97bf3fd
PL
537{
538 u32 r_num = tipc_node(router);
539
540 if (n_ptr->last_router < 0)
541 return; /* No routes */
542
543 n_ptr->routers[r_num / 32] =
544 ((~(1 << (r_num % 32))) & (n_ptr->routers[r_num / 32]));
545 n_ptr->last_router = tipc_max_nodes / 32;
546 while ((--n_ptr->last_router >= 0) &&
547 !n_ptr->routers[n_ptr->last_router]);
548
4323add6 549 if (!tipc_node_is_up(n_ptr))
b97bf3fd
PL
550 node_lost_contact(n_ptr);
551}
552
553#if 0
554void node_print(struct print_buf *buf, struct node *n_ptr, char *str)
555{
556 u32 i;
557
558 tipc_printf(buf, "\n\n%s", str);
559 for (i = 0; i < MAX_BEARERS; i++) {
560 if (!n_ptr->links[i])
561 continue;
562 tipc_printf(buf, "Links[%u]: %x, ", i, n_ptr->links[i]);
563 }
564 tipc_printf(buf, "Active links: [%x,%x]\n",
565 n_ptr->active_links[0], n_ptr->active_links[1]);
566}
567#endif
568
569u32 tipc_available_nodes(const u32 domain)
570{
571 struct node *n_ptr;
572 u32 cnt = 0;
573
4323add6 574 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
b97bf3fd
PL
575 if (!in_scope(domain, n_ptr->addr))
576 continue;
4323add6 577 if (tipc_node_is_up(n_ptr))
b97bf3fd
PL
578 cnt++;
579 }
580 return cnt;
581}
582
4323add6 583struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space)
b97bf3fd
PL
584{
585 u32 domain;
586 struct sk_buff *buf;
587 struct node *n_ptr;
588 struct tipc_node_info node_info;
589
590 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
4323add6 591 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd
PL
592
593 domain = *(u32 *)TLV_DATA(req_tlv_area);
594 domain = ntohl(domain);
4323add6
PL
595 if (!tipc_addr_domain_valid(domain))
596 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
597 " (network address)");
b97bf3fd 598
4323add6
PL
599 if (!tipc_nodes)
600 return tipc_cfg_reply_none();
b97bf3fd
PL
601
602 /* For now, get space for all other nodes
603 (will need to modify this when slave nodes are supported */
604
4323add6
PL
605 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(node_info)) *
606 (tipc_max_nodes - 1));
b97bf3fd
PL
607 if (!buf)
608 return NULL;
609
610 /* Add TLVs for all nodes in scope */
611
4323add6 612 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
b97bf3fd
PL
613 if (!in_scope(domain, n_ptr->addr))
614 continue;
615 node_info.addr = htonl(n_ptr->addr);
4323add6
PL
616 node_info.up = htonl(tipc_node_is_up(n_ptr));
617 tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
618 &node_info, sizeof(node_info));
b97bf3fd
PL
619 }
620
621 return buf;
622}
623
4323add6 624struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space)
b97bf3fd
PL
625{
626 u32 domain;
627 struct sk_buff *buf;
628 struct node *n_ptr;
629 struct tipc_link_info link_info;
630
631 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
4323add6 632 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
b97bf3fd
PL
633
634 domain = *(u32 *)TLV_DATA(req_tlv_area);
635 domain = ntohl(domain);
4323add6
PL
636 if (!tipc_addr_domain_valid(domain))
637 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
638 " (network address)");
b97bf3fd 639
4323add6
PL
640 if (!tipc_nodes)
641 return tipc_cfg_reply_none();
b97bf3fd
PL
642
643 /* For now, get space for 2 links to all other nodes + bcast link
644 (will need to modify this when slave nodes are supported */
645
4323add6
PL
646 buf = tipc_cfg_reply_alloc(TLV_SPACE(sizeof(link_info)) *
647 (2 * (tipc_max_nodes - 1) + 1));
b97bf3fd
PL
648 if (!buf)
649 return NULL;
650
651 /* Add TLV for broadcast link */
652
653 link_info.dest = tipc_own_addr & 0xfffff00;
654 link_info.dest = htonl(link_info.dest);
655 link_info.up = htonl(1);
4323add6
PL
656 sprintf(link_info.str, tipc_bclink_name);
657 tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
b97bf3fd
PL
658
659 /* Add TLVs for any other links in scope */
660
4323add6 661 for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {
b97bf3fd
PL
662 u32 i;
663
664 if (!in_scope(domain, n_ptr->addr))
665 continue;
666 for (i = 0; i < MAX_BEARERS; i++) {
667 if (!n_ptr->links[i])
668 continue;
669 link_info.dest = htonl(n_ptr->addr);
4323add6 670 link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
b97bf3fd 671 strcpy(link_info.str, n_ptr->links[i]->name);
4323add6
PL
672 tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
673 &link_info, sizeof(link_info));
b97bf3fd
PL
674 }
675 }
676
677 return buf;
678}
This page took 0.118489 seconds and 5 git commands to generate.