Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/cluster.c: TIPC cluster management routines |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Per Liden | 593a5f2 | 2006-01-11 19:14:19 +0100 | [diff] [blame] | 4 | * Copyright (c) 2000-2006, Ericsson AB |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 5 | * Copyright (c) 2005, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 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. |
| 19 | * |
| 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. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 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 |
| 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
| 37 | #include "core.h" |
| 38 | #include "cluster.h" |
| 39 | #include "addr.h" |
| 40 | #include "node_subscr.h" |
| 41 | #include "link.h" |
| 42 | #include "node.h" |
| 43 | #include "net.h" |
| 44 | #include "msg.h" |
| 45 | #include "bearer.h" |
| 46 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 47 | static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf, |
| 48 | u32 lower, u32 upper); |
Per Liden | 87546b1 | 2006-03-20 22:38:33 -0800 | [diff] [blame] | 49 | static struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 50 | |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 51 | struct tipc_node **tipc_local_nodes = NULL; |
| 52 | struct tipc_node_map tipc_cltr_bcast_nodes = {0,{0,}}; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 53 | u32 tipc_highest_allowed_slave = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 54 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 55 | struct cluster *tipc_cltr_create(u32 addr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 56 | { |
| 57 | struct _zone *z_ptr; |
| 58 | struct cluster *c_ptr; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 59 | int max_nodes; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 60 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 61 | c_ptr = kzalloc(sizeof(*c_ptr), GFP_ATOMIC); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 62 | if (c_ptr == NULL) { |
| 63 | warn("Cluster creation failure, no memory\n"); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 64 | return NULL; |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 65 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 66 | |
| 67 | c_ptr->addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0); |
| 68 | if (in_own_cluster(addr)) |
| 69 | max_nodes = LOWEST_SLAVE + tipc_max_slaves; |
| 70 | else |
| 71 | max_nodes = tipc_max_nodes + 1; |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 72 | |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 73 | c_ptr->nodes = kcalloc(max_nodes + 1, sizeof(void*), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 74 | if (c_ptr->nodes == NULL) { |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 75 | warn("Cluster creation failure, no memory for node area\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 76 | kfree(c_ptr); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 77 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 78 | } |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 79 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 80 | if (in_own_cluster(addr)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 81 | tipc_local_nodes = c_ptr->nodes; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 82 | c_ptr->highest_slave = LOWEST_SLAVE - 1; |
| 83 | c_ptr->highest_node = 0; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 84 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 85 | z_ptr = tipc_zone_find(tipc_zone(addr)); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 86 | if (!z_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 87 | z_ptr = tipc_zone_create(addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 88 | } |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 89 | if (!z_ptr) { |
| 90 | kfree(c_ptr->nodes); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 91 | kfree(c_ptr); |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 92 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 93 | } |
| 94 | |
Allan Stephens | a10bd92 | 2006-06-25 23:52:17 -0700 | [diff] [blame] | 95 | tipc_zone_attach_cluster(z_ptr, c_ptr); |
| 96 | c_ptr->owner = z_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 97 | return c_ptr; |
| 98 | } |
| 99 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 100 | void tipc_cltr_delete(struct cluster *c_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 101 | { |
| 102 | u32 n_num; |
| 103 | |
| 104 | if (!c_ptr) |
| 105 | return; |
| 106 | for (n_num = 1; n_num <= c_ptr->highest_node; n_num++) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 107 | tipc_node_delete(c_ptr->nodes[n_num]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 108 | } |
| 109 | for (n_num = LOWEST_SLAVE; n_num <= c_ptr->highest_slave; n_num++) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 110 | tipc_node_delete(c_ptr->nodes[n_num]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 111 | } |
| 112 | kfree(c_ptr->nodes); |
| 113 | kfree(c_ptr); |
| 114 | } |
| 115 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 116 | |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 117 | void tipc_cltr_attach_node(struct cluster *c_ptr, struct tipc_node *n_ptr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 118 | { |
| 119 | u32 n_num = tipc_node(n_ptr->addr); |
| 120 | u32 max_n_num = tipc_max_nodes; |
| 121 | |
| 122 | if (in_own_cluster(n_ptr->addr)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 123 | max_n_num = tipc_highest_allowed_slave; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 124 | assert(n_num > 0); |
| 125 | assert(n_num <= max_n_num); |
Harvey Harrison | 5f2f40a | 2008-02-24 18:38:31 -0800 | [diff] [blame] | 126 | assert(c_ptr->nodes[n_num] == NULL); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 127 | c_ptr->nodes[n_num] = n_ptr; |
| 128 | if (n_num > c_ptr->highest_node) |
| 129 | c_ptr->highest_node = n_num; |
| 130 | } |
| 131 | |
| 132 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 133 | * tipc_cltr_select_router - select router to a cluster |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 134 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 135 | * Uses deterministic and fair algorithm. |
| 136 | */ |
| 137 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 138 | u32 tipc_cltr_select_router(struct cluster *c_ptr, u32 ref) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 139 | { |
| 140 | u32 n_num; |
| 141 | u32 ulim = c_ptr->highest_node; |
| 142 | u32 mask; |
| 143 | u32 tstart; |
| 144 | |
| 145 | assert(!in_own_cluster(c_ptr->addr)); |
| 146 | if (!ulim) |
| 147 | return 0; |
| 148 | |
| 149 | /* Start entry must be random */ |
| 150 | mask = tipc_max_nodes; |
| 151 | while (mask > ulim) |
| 152 | mask >>= 1; |
| 153 | tstart = ref & mask; |
| 154 | n_num = tstart; |
| 155 | |
| 156 | /* Lookup upwards with wrap-around */ |
| 157 | do { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 158 | if (tipc_node_is_up(c_ptr->nodes[n_num])) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 159 | break; |
| 160 | } while (++n_num <= ulim); |
| 161 | if (n_num > ulim) { |
| 162 | n_num = 1; |
| 163 | do { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 164 | if (tipc_node_is_up(c_ptr->nodes[n_num])) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 165 | break; |
| 166 | } while (++n_num < tstart); |
| 167 | if (n_num == tstart) |
| 168 | return 0; |
| 169 | } |
| 170 | assert(n_num <= ulim); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 171 | return tipc_node_select_router(c_ptr->nodes[n_num], ref); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 175 | * tipc_cltr_select_node - select destination node within a remote cluster |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 176 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 177 | * Uses deterministic and fair algorithm. |
| 178 | */ |
| 179 | |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 180 | struct tipc_node *tipc_cltr_select_node(struct cluster *c_ptr, u32 selector) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 181 | { |
| 182 | u32 n_num; |
| 183 | u32 mask = tipc_max_nodes; |
| 184 | u32 start_entry; |
| 185 | |
| 186 | assert(!in_own_cluster(c_ptr->addr)); |
| 187 | if (!c_ptr->highest_node) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 188 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 189 | |
| 190 | /* Start entry must be random */ |
| 191 | while (mask > c_ptr->highest_node) { |
| 192 | mask >>= 1; |
| 193 | } |
| 194 | start_entry = (selector & mask) ? selector & mask : 1u; |
| 195 | assert(start_entry <= c_ptr->highest_node); |
| 196 | |
| 197 | /* Lookup upwards with wrap-around */ |
| 198 | for (n_num = start_entry; n_num <= c_ptr->highest_node; n_num++) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 199 | if (tipc_node_has_active_links(c_ptr->nodes[n_num])) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 200 | return c_ptr->nodes[n_num]; |
| 201 | } |
| 202 | for (n_num = 1; n_num < start_entry; n_num++) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 203 | if (tipc_node_has_active_links(c_ptr->nodes[n_num])) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 204 | return c_ptr->nodes[n_num]; |
| 205 | } |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 206 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Routing table management: See description in node.c |
| 211 | */ |
| 212 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 213 | static struct sk_buff *tipc_cltr_prepare_routing_msg(u32 data_size, u32 dest) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 214 | { |
| 215 | u32 size = INT_H_SIZE + data_size; |
stephen hemminger | 31e3c3f | 2010-10-13 13:20:35 +0000 | [diff] [blame] | 216 | struct sk_buff *buf = tipc_buf_acquire(size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 217 | struct tipc_msg *msg; |
| 218 | |
| 219 | if (buf) { |
| 220 | msg = buf_msg(buf); |
| 221 | memset((char *)msg, 0, size); |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 222 | tipc_msg_init(msg, ROUTE_DISTRIBUTOR, 0, INT_H_SIZE, dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 223 | } |
| 224 | return buf; |
| 225 | } |
| 226 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 227 | void tipc_cltr_bcast_new_route(struct cluster *c_ptr, u32 dest, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 228 | u32 lower, u32 upper) |
| 229 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 230 | struct sk_buff *buf = tipc_cltr_prepare_routing_msg(0, c_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 231 | struct tipc_msg *msg; |
| 232 | |
| 233 | if (buf) { |
| 234 | msg = buf_msg(buf); |
| 235 | msg_set_remote_node(msg, dest); |
| 236 | msg_set_type(msg, ROUTE_ADDITION); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 237 | tipc_cltr_multicast(c_ptr, buf, lower, upper); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 238 | } else { |
| 239 | warn("Memory squeeze: broadcast of new route failed\n"); |
| 240 | } |
| 241 | } |
| 242 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 243 | void tipc_cltr_bcast_lost_route(struct cluster *c_ptr, u32 dest, |
| 244 | u32 lower, u32 upper) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 245 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 246 | struct sk_buff *buf = tipc_cltr_prepare_routing_msg(0, c_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 247 | struct tipc_msg *msg; |
| 248 | |
| 249 | if (buf) { |
| 250 | msg = buf_msg(buf); |
| 251 | msg_set_remote_node(msg, dest); |
| 252 | msg_set_type(msg, ROUTE_REMOVAL); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 253 | tipc_cltr_multicast(c_ptr, buf, lower, upper); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 254 | } else { |
| 255 | warn("Memory squeeze: broadcast of lost route failed\n"); |
| 256 | } |
| 257 | } |
| 258 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 259 | void tipc_cltr_send_slave_routes(struct cluster *c_ptr, u32 dest) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 260 | { |
| 261 | struct sk_buff *buf; |
| 262 | struct tipc_msg *msg; |
| 263 | u32 highest = c_ptr->highest_slave; |
| 264 | u32 n_num; |
| 265 | int send = 0; |
| 266 | |
| 267 | assert(!is_slave(dest)); |
| 268 | assert(in_own_cluster(dest)); |
| 269 | assert(in_own_cluster(c_ptr->addr)); |
| 270 | if (highest <= LOWEST_SLAVE) |
| 271 | return; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 272 | buf = tipc_cltr_prepare_routing_msg(highest - LOWEST_SLAVE + 1, |
| 273 | c_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 274 | if (buf) { |
| 275 | msg = buf_msg(buf); |
| 276 | msg_set_remote_node(msg, c_ptr->addr); |
| 277 | msg_set_type(msg, SLAVE_ROUTING_TABLE); |
| 278 | for (n_num = LOWEST_SLAVE; n_num <= highest; n_num++) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 279 | if (c_ptr->nodes[n_num] && |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 280 | tipc_node_has_active_links(c_ptr->nodes[n_num])) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 281 | send = 1; |
| 282 | msg_set_dataoctet(msg, n_num); |
| 283 | } |
| 284 | } |
| 285 | if (send) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 286 | tipc_link_send(buf, dest, dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 287 | else |
| 288 | buf_discard(buf); |
| 289 | } else { |
| 290 | warn("Memory squeeze: broadcast of lost route failed\n"); |
| 291 | } |
| 292 | } |
| 293 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 294 | void tipc_cltr_send_ext_routes(struct cluster *c_ptr, u32 dest) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 295 | { |
| 296 | struct sk_buff *buf; |
| 297 | struct tipc_msg *msg; |
| 298 | u32 highest = c_ptr->highest_node; |
| 299 | u32 n_num; |
| 300 | int send = 0; |
| 301 | |
| 302 | if (in_own_cluster(c_ptr->addr)) |
| 303 | return; |
| 304 | assert(!is_slave(dest)); |
| 305 | assert(in_own_cluster(dest)); |
| 306 | highest = c_ptr->highest_node; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 307 | buf = tipc_cltr_prepare_routing_msg(highest + 1, c_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 308 | if (buf) { |
| 309 | msg = buf_msg(buf); |
| 310 | msg_set_remote_node(msg, c_ptr->addr); |
| 311 | msg_set_type(msg, EXT_ROUTING_TABLE); |
| 312 | for (n_num = 1; n_num <= highest; n_num++) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 313 | if (c_ptr->nodes[n_num] && |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 314 | tipc_node_has_active_links(c_ptr->nodes[n_num])) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 315 | send = 1; |
| 316 | msg_set_dataoctet(msg, n_num); |
| 317 | } |
| 318 | } |
| 319 | if (send) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 320 | tipc_link_send(buf, dest, dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 321 | else |
| 322 | buf_discard(buf); |
| 323 | } else { |
| 324 | warn("Memory squeeze: broadcast of external route failed\n"); |
| 325 | } |
| 326 | } |
| 327 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 328 | void tipc_cltr_send_local_routes(struct cluster *c_ptr, u32 dest) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 329 | { |
| 330 | struct sk_buff *buf; |
| 331 | struct tipc_msg *msg; |
| 332 | u32 highest = c_ptr->highest_node; |
| 333 | u32 n_num; |
| 334 | int send = 0; |
| 335 | |
| 336 | assert(is_slave(dest)); |
| 337 | assert(in_own_cluster(c_ptr->addr)); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 338 | buf = tipc_cltr_prepare_routing_msg(highest, c_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 339 | if (buf) { |
| 340 | msg = buf_msg(buf); |
| 341 | msg_set_remote_node(msg, c_ptr->addr); |
| 342 | msg_set_type(msg, LOCAL_ROUTING_TABLE); |
| 343 | for (n_num = 1; n_num <= highest; n_num++) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 344 | if (c_ptr->nodes[n_num] && |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 345 | tipc_node_has_active_links(c_ptr->nodes[n_num])) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | send = 1; |
| 347 | msg_set_dataoctet(msg, n_num); |
| 348 | } |
| 349 | } |
| 350 | if (send) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 351 | tipc_link_send(buf, dest, dest); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 352 | else |
| 353 | buf_discard(buf); |
| 354 | } else { |
| 355 | warn("Memory squeeze: broadcast of local route failed\n"); |
| 356 | } |
| 357 | } |
| 358 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 359 | void tipc_cltr_recv_routing_table(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 360 | { |
| 361 | struct tipc_msg *msg = buf_msg(buf); |
| 362 | struct cluster *c_ptr; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 363 | struct tipc_node *n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 364 | unchar *node_table; |
| 365 | u32 table_size; |
| 366 | u32 router; |
| 367 | u32 rem_node = msg_remote_node(msg); |
| 368 | u32 z_num; |
| 369 | u32 c_num; |
| 370 | u32 n_num; |
| 371 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 372 | c_ptr = tipc_cltr_find(rem_node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 373 | if (!c_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 374 | c_ptr = tipc_cltr_create(rem_node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 375 | if (!c_ptr) { |
| 376 | buf_discard(buf); |
| 377 | return; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | node_table = buf->data + msg_hdr_sz(msg); |
| 382 | table_size = msg_size(msg) - msg_hdr_sz(msg); |
| 383 | router = msg_prevnode(msg); |
| 384 | z_num = tipc_zone(rem_node); |
| 385 | c_num = tipc_cluster(rem_node); |
| 386 | |
| 387 | switch (msg_type(msg)) { |
| 388 | case LOCAL_ROUTING_TABLE: |
| 389 | assert(is_slave(tipc_own_addr)); |
| 390 | case EXT_ROUTING_TABLE: |
| 391 | for (n_num = 1; n_num < table_size; n_num++) { |
| 392 | if (node_table[n_num]) { |
| 393 | u32 addr = tipc_addr(z_num, c_num, n_num); |
| 394 | n_ptr = c_ptr->nodes[n_num]; |
| 395 | if (!n_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 396 | n_ptr = tipc_node_create(addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 397 | } |
| 398 | if (n_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 399 | tipc_node_add_router(n_ptr, router); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | break; |
| 403 | case SLAVE_ROUTING_TABLE: |
| 404 | assert(!is_slave(tipc_own_addr)); |
| 405 | assert(in_own_cluster(c_ptr->addr)); |
| 406 | for (n_num = 1; n_num < table_size; n_num++) { |
| 407 | if (node_table[n_num]) { |
| 408 | u32 slave_num = n_num + LOWEST_SLAVE; |
| 409 | u32 addr = tipc_addr(z_num, c_num, slave_num); |
| 410 | n_ptr = c_ptr->nodes[slave_num]; |
| 411 | if (!n_ptr) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 412 | n_ptr = tipc_node_create(addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 413 | } |
| 414 | if (n_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 415 | tipc_node_add_router(n_ptr, router); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | break; |
| 419 | case ROUTE_ADDITION: |
| 420 | if (!is_slave(tipc_own_addr)) { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 421 | assert(!in_own_cluster(c_ptr->addr) || |
| 422 | is_slave(rem_node)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 423 | } else { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 424 | assert(in_own_cluster(c_ptr->addr) && |
| 425 | !is_slave(rem_node)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 426 | } |
| 427 | n_ptr = c_ptr->nodes[tipc_node(rem_node)]; |
| 428 | if (!n_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 429 | n_ptr = tipc_node_create(rem_node); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 430 | if (n_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 431 | tipc_node_add_router(n_ptr, router); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 432 | break; |
| 433 | case ROUTE_REMOVAL: |
| 434 | if (!is_slave(tipc_own_addr)) { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 435 | assert(!in_own_cluster(c_ptr->addr) || |
| 436 | is_slave(rem_node)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 437 | } else { |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 438 | assert(in_own_cluster(c_ptr->addr) && |
| 439 | !is_slave(rem_node)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 440 | } |
| 441 | n_ptr = c_ptr->nodes[tipc_node(rem_node)]; |
| 442 | if (n_ptr) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 443 | tipc_node_remove_router(n_ptr, router); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 444 | break; |
| 445 | default: |
| 446 | assert(!"Illegal routing manager message received\n"); |
| 447 | } |
| 448 | buf_discard(buf); |
| 449 | } |
| 450 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 451 | void tipc_cltr_remove_as_router(struct cluster *c_ptr, u32 router) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 452 | { |
| 453 | u32 start_entry; |
| 454 | u32 tstop; |
| 455 | u32 n_num; |
| 456 | |
| 457 | if (is_slave(router)) |
| 458 | return; /* Slave nodes can not be routers */ |
| 459 | |
| 460 | if (in_own_cluster(c_ptr->addr)) { |
| 461 | start_entry = LOWEST_SLAVE; |
| 462 | tstop = c_ptr->highest_slave; |
| 463 | } else { |
| 464 | start_entry = 1; |
| 465 | tstop = c_ptr->highest_node; |
| 466 | } |
| 467 | |
| 468 | for (n_num = start_entry; n_num <= tstop; n_num++) { |
| 469 | if (c_ptr->nodes[n_num]) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 470 | tipc_node_remove_router(c_ptr->nodes[n_num], router); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | /** |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 476 | * tipc_cltr_multicast - multicast message to local nodes |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 477 | */ |
| 478 | |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 479 | static void tipc_cltr_multicast(struct cluster *c_ptr, struct sk_buff *buf, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 480 | u32 lower, u32 upper) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 481 | { |
| 482 | struct sk_buff *buf_copy; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 483 | struct tipc_node *n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 484 | u32 n_num; |
| 485 | u32 tstop; |
| 486 | |
| 487 | assert(lower <= upper); |
| 488 | assert(((lower >= 1) && (lower <= tipc_max_nodes)) || |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 489 | ((lower >= LOWEST_SLAVE) && (lower <= tipc_highest_allowed_slave))); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 490 | assert(((upper >= 1) && (upper <= tipc_max_nodes)) || |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 491 | ((upper >= LOWEST_SLAVE) && (upper <= tipc_highest_allowed_slave))); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 492 | assert(in_own_cluster(c_ptr->addr)); |
| 493 | |
| 494 | tstop = is_slave(upper) ? c_ptr->highest_slave : c_ptr->highest_node; |
| 495 | if (tstop > upper) |
| 496 | tstop = upper; |
| 497 | for (n_num = lower; n_num <= tstop; n_num++) { |
| 498 | n_ptr = c_ptr->nodes[n_num]; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 499 | if (n_ptr && tipc_node_has_active_links(n_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 500 | buf_copy = skb_copy(buf, GFP_ATOMIC); |
| 501 | if (buf_copy == NULL) |
| 502 | break; |
| 503 | msg_set_destnode(buf_msg(buf_copy), n_ptr->addr); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 504 | tipc_link_send(buf_copy, n_ptr->addr, n_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | buf_discard(buf); |
| 508 | } |
| 509 | |
| 510 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 511 | * tipc_cltr_broadcast - broadcast message to all nodes within cluster |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 512 | */ |
| 513 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 514 | void tipc_cltr_broadcast(struct sk_buff *buf) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 515 | { |
| 516 | struct sk_buff *buf_copy; |
| 517 | struct cluster *c_ptr; |
David S. Miller | 6c00055 | 2008-09-02 23:38:32 -0700 | [diff] [blame] | 518 | struct tipc_node *n_ptr; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 519 | u32 n_num; |
| 520 | u32 tstart; |
| 521 | u32 tstop; |
| 522 | u32 node_type; |
| 523 | |
| 524 | if (tipc_mode == TIPC_NET_MODE) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 525 | c_ptr = tipc_cltr_find(tipc_own_addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 526 | assert(in_own_cluster(c_ptr->addr)); /* For now */ |
| 527 | |
| 528 | /* Send to standard nodes, then repeat loop sending to slaves */ |
| 529 | tstart = 1; |
| 530 | tstop = c_ptr->highest_node; |
| 531 | for (node_type = 1; node_type <= 2; node_type++) { |
| 532 | for (n_num = tstart; n_num <= tstop; n_num++) { |
| 533 | n_ptr = c_ptr->nodes[n_num]; |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 534 | if (n_ptr && tipc_node_has_active_links(n_ptr)) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 535 | buf_copy = skb_copy(buf, GFP_ATOMIC); |
| 536 | if (buf_copy == NULL) |
| 537 | goto exit; |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 538 | msg_set_destnode(buf_msg(buf_copy), |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 539 | n_ptr->addr); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 540 | tipc_link_send(buf_copy, n_ptr->addr, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 541 | n_ptr->addr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | tstart = LOWEST_SLAVE; |
| 545 | tstop = c_ptr->highest_slave; |
| 546 | } |
| 547 | } |
| 548 | exit: |
| 549 | buf_discard(buf); |
| 550 | } |
| 551 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 552 | int tipc_cltr_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 553 | { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 554 | tipc_highest_allowed_slave = LOWEST_SLAVE + tipc_max_slaves; |
Allan Stephens | 0e35fd5 | 2008-07-14 22:44:01 -0700 | [diff] [blame] | 555 | return tipc_cltr_create(tipc_own_addr) ? 0 : -ENOMEM; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 556 | } |
| 557 | |