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