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