aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bcast.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/bcast.c')
-rw-r--r--net/tipc/bcast.c504
1 files changed, 214 insertions, 290 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
index 96ceefeb9daf..3e41704832de 100644
--- a/net/tipc/bcast.c
+++ b/net/tipc/bcast.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * net/tipc/bcast.c: TIPC broadcast code 2 * net/tipc/bcast.c: TIPC broadcast code
3 * 3 *
4 * Copyright (c) 2004-2006, 2014, Ericsson AB 4 * Copyright (c) 2004-2006, 2014-2015, Ericsson AB
5 * Copyright (c) 2004, Intel Corporation. 5 * Copyright (c) 2004, Intel Corporation.
6 * Copyright (c) 2005, 2010-2011, Wind River Systems 6 * Copyright (c) 2005, 2010-2011, Wind River Systems
7 * All rights reserved. 7 * All rights reserved.
@@ -35,77 +35,14 @@
35 * POSSIBILITY OF SUCH DAMAGE. 35 * POSSIBILITY OF SUCH DAMAGE.
36 */ 36 */
37 37
38#include "core.h"
39#include "link.h"
40#include "socket.h" 38#include "socket.h"
41#include "msg.h" 39#include "msg.h"
42#include "bcast.h" 40#include "bcast.h"
43#include "name_distr.h" 41#include "name_distr.h"
42#include "core.h"
44 43
45#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */ 44#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */
46#define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */ 45#define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */
47#define BCBEARER MAX_BEARERS
48
49/**
50 * struct tipc_bcbearer_pair - a pair of bearers used by broadcast link
51 * @primary: pointer to primary bearer
52 * @secondary: pointer to secondary bearer
53 *
54 * Bearers must have same priority and same set of reachable destinations
55 * to be paired.
56 */
57
58struct tipc_bcbearer_pair {
59 struct tipc_bearer *primary;
60 struct tipc_bearer *secondary;
61};
62
63/**
64 * struct tipc_bcbearer - bearer used by broadcast link
65 * @bearer: (non-standard) broadcast bearer structure
66 * @media: (non-standard) broadcast media structure
67 * @bpairs: array of bearer pairs
68 * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort()
69 * @remains: temporary node map used by tipc_bcbearer_send()
70 * @remains_new: temporary node map used tipc_bcbearer_send()
71 *
72 * Note: The fields labelled "temporary" are incorporated into the bearer
73 * to avoid consuming potentially limited stack space through the use of
74 * large local variables within multicast routines. Concurrent access is
75 * prevented through use of the spinlock "bclink_lock".
76 */
77struct tipc_bcbearer {
78 struct tipc_bearer bearer;
79 struct tipc_media media;
80 struct tipc_bcbearer_pair bpairs[MAX_BEARERS];
81 struct tipc_bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1];
82 struct tipc_node_map remains;
83 struct tipc_node_map remains_new;
84};
85
86/**
87 * struct tipc_bclink - link used for broadcast messages
88 * @lock: spinlock governing access to structure
89 * @link: (non-standard) broadcast link structure
90 * @node: (non-standard) node structure representing b'cast link's peer node
91 * @flags: represent bclink states
92 * @bcast_nodes: map of broadcast-capable nodes
93 * @retransmit_to: node that most recently requested a retransmit
94 *
95 * Handles sequence numbering, fragmentation, bundling, etc.
96 */
97struct tipc_bclink {
98 spinlock_t lock;
99 struct tipc_link link;
100 struct tipc_node node;
101 unsigned int flags;
102 struct tipc_node_map bcast_nodes;
103 struct tipc_node *retransmit_to;
104};
105
106static struct tipc_bcbearer *bcbearer;
107static struct tipc_bclink *bclink;
108static struct tipc_link *bcl;
109 46
110const char tipc_bclink_name[] = "broadcast-link"; 47const char tipc_bclink_name[] = "broadcast-link";
111 48
@@ -115,38 +52,50 @@ static void tipc_nmap_diff(struct tipc_node_map *nm_a,
115static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node); 52static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node);
116static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node); 53static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node);
117 54
118static void tipc_bclink_lock(void) 55static void tipc_bclink_lock(struct net *net)
119{ 56{
120 spin_lock_bh(&bclink->lock); 57 struct tipc_net *tn = net_generic(net, tipc_net_id);
58
59 spin_lock_bh(&tn->bclink->lock);
121} 60}
122 61
123static void tipc_bclink_unlock(void) 62static void tipc_bclink_unlock(struct net *net)
124{ 63{
64 struct tipc_net *tn = net_generic(net, tipc_net_id);
125 struct tipc_node *node = NULL; 65 struct tipc_node *node = NULL;
126 66
127 if (likely(!bclink->flags)) { 67 if (likely(!tn->bclink->flags)) {
128 spin_unlock_bh(&bclink->lock); 68 spin_unlock_bh(&tn->bclink->lock);
129 return; 69 return;
130 } 70 }
131 71
132 if (bclink->flags & TIPC_BCLINK_RESET) { 72 if (tn->bclink->flags & TIPC_BCLINK_RESET) {
133 bclink->flags &= ~TIPC_BCLINK_RESET; 73 tn->bclink->flags &= ~TIPC_BCLINK_RESET;
134 node = tipc_bclink_retransmit_to(); 74 node = tipc_bclink_retransmit_to(net);
135 } 75 }
136 spin_unlock_bh(&bclink->lock); 76 spin_unlock_bh(&tn->bclink->lock);
137 77
138 if (node) 78 if (node)
139 tipc_link_reset_all(node); 79 tipc_link_reset_all(node);
140} 80}
141 81
82void tipc_bclink_input(struct net *net)
83{
84 struct tipc_net *tn = net_generic(net, tipc_net_id);
85
86 tipc_sk_mcast_rcv(net, &tn->bclink->arrvq, &tn->bclink->inputq);
87}
88
142uint tipc_bclink_get_mtu(void) 89uint tipc_bclink_get_mtu(void)
143{ 90{
144 return MAX_PKT_DEFAULT_MCAST; 91 return MAX_PKT_DEFAULT_MCAST;
145} 92}
146 93
147void tipc_bclink_set_flags(unsigned int flags) 94void tipc_bclink_set_flags(struct net *net, unsigned int flags)
148{ 95{
149 bclink->flags |= flags; 96 struct tipc_net *tn = net_generic(net, tipc_net_id);
97
98 tn->bclink->flags |= flags;
150} 99}
151 100
152static u32 bcbuf_acks(struct sk_buff *buf) 101static u32 bcbuf_acks(struct sk_buff *buf)
@@ -164,31 +113,40 @@ static void bcbuf_decr_acks(struct sk_buff *buf)
164 bcbuf_set_acks(buf, bcbuf_acks(buf) - 1); 113 bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
165} 114}
166 115
167void tipc_bclink_add_node(u32 addr) 116void tipc_bclink_add_node(struct net *net, u32 addr)
168{ 117{
169 tipc_bclink_lock(); 118 struct tipc_net *tn = net_generic(net, tipc_net_id);
170 tipc_nmap_add(&bclink->bcast_nodes, addr); 119
171 tipc_bclink_unlock(); 120 tipc_bclink_lock(net);
121 tipc_nmap_add(&tn->bclink->bcast_nodes, addr);
122 tipc_bclink_unlock(net);
172} 123}
173 124
174void tipc_bclink_remove_node(u32 addr) 125void tipc_bclink_remove_node(struct net *net, u32 addr)
175{ 126{
176 tipc_bclink_lock(); 127 struct tipc_net *tn = net_generic(net, tipc_net_id);
177 tipc_nmap_remove(&bclink->bcast_nodes, addr); 128
178 tipc_bclink_unlock(); 129 tipc_bclink_lock(net);
130 tipc_nmap_remove(&tn->bclink->bcast_nodes, addr);
131 tipc_bclink_unlock(net);
179} 132}
180 133
181static void bclink_set_last_sent(void) 134static void bclink_set_last_sent(struct net *net)
182{ 135{
136 struct tipc_net *tn = net_generic(net, tipc_net_id);
137 struct tipc_link *bcl = tn->bcl;
138
183 if (bcl->next_out) 139 if (bcl->next_out)
184 bcl->fsm_msg_cnt = mod(buf_seqno(bcl->next_out) - 1); 140 bcl->fsm_msg_cnt = mod(buf_seqno(bcl->next_out) - 1);
185 else 141 else
186 bcl->fsm_msg_cnt = mod(bcl->next_out_no - 1); 142 bcl->fsm_msg_cnt = mod(bcl->next_out_no - 1);
187} 143}
188 144
189u32 tipc_bclink_get_last_sent(void) 145u32 tipc_bclink_get_last_sent(struct net *net)
190{ 146{
191 return bcl->fsm_msg_cnt; 147 struct tipc_net *tn = net_generic(net, tipc_net_id);
148
149 return tn->bcl->fsm_msg_cnt;
192} 150}
193 151
194static void bclink_update_last_sent(struct tipc_node *node, u32 seqno) 152static void bclink_update_last_sent(struct tipc_node *node, u32 seqno)
@@ -203,9 +161,11 @@ static void bclink_update_last_sent(struct tipc_node *node, u32 seqno)
203 * 161 *
204 * Called with bclink_lock locked 162 * Called with bclink_lock locked
205 */ 163 */
206struct tipc_node *tipc_bclink_retransmit_to(void) 164struct tipc_node *tipc_bclink_retransmit_to(struct net *net)
207{ 165{
208 return bclink->retransmit_to; 166 struct tipc_net *tn = net_generic(net, tipc_net_id);
167
168 return tn->bclink->retransmit_to;
209} 169}
210 170
211/** 171/**
@@ -215,15 +175,17 @@ struct tipc_node *tipc_bclink_retransmit_to(void)
215 * 175 *
216 * Called with bclink_lock locked 176 * Called with bclink_lock locked
217 */ 177 */
218static void bclink_retransmit_pkt(u32 after, u32 to) 178static void bclink_retransmit_pkt(struct tipc_net *tn, u32 after, u32 to)
219{ 179{
220 struct sk_buff *skb; 180 struct sk_buff *skb;
181 struct tipc_link *bcl = tn->bcl;
221 182
222 skb_queue_walk(&bcl->outqueue, skb) { 183 skb_queue_walk(&bcl->outqueue, skb) {
223 if (more(buf_seqno(skb), after)) 184 if (more(buf_seqno(skb), after)) {
185 tipc_link_retransmit(bcl, skb, mod(to - after));
224 break; 186 break;
187 }
225 } 188 }
226 tipc_link_retransmit(bcl, skb, mod(to - after));
227} 189}
228 190
229/** 191/**
@@ -231,13 +193,11 @@ static void bclink_retransmit_pkt(u32 after, u32 to)
231 * 193 *
232 * Called with no locks taken 194 * Called with no locks taken
233 */ 195 */
234void tipc_bclink_wakeup_users(void) 196void tipc_bclink_wakeup_users(struct net *net)
235{ 197{
236 struct sk_buff *skb; 198 struct tipc_net *tn = net_generic(net, tipc_net_id);
237
238 while ((skb = skb_dequeue(&bclink->link.waiting_sks)))
239 tipc_sk_rcv(skb);
240 199
200 tipc_sk_rcv(net, &tn->bclink->link.wakeupq);
241} 201}
242 202
243/** 203/**
@@ -252,10 +212,12 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
252 struct sk_buff *skb, *tmp; 212 struct sk_buff *skb, *tmp;
253 struct sk_buff *next; 213 struct sk_buff *next;
254 unsigned int released = 0; 214 unsigned int released = 0;
215 struct net *net = n_ptr->net;
216 struct tipc_net *tn = net_generic(net, tipc_net_id);
255 217
256 tipc_bclink_lock(); 218 tipc_bclink_lock(net);
257 /* Bail out if tx queue is empty (no clean up is required) */ 219 /* Bail out if tx queue is empty (no clean up is required) */
258 skb = skb_peek(&bcl->outqueue); 220 skb = skb_peek(&tn->bcl->outqueue);
259 if (!skb) 221 if (!skb)
260 goto exit; 222 goto exit;
261 223
@@ -266,43 +228,43 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
266 * acknowledge sent messages only (if other nodes still exist) 228 * acknowledge sent messages only (if other nodes still exist)
267 * or both sent and unsent messages (otherwise) 229 * or both sent and unsent messages (otherwise)
268 */ 230 */
269 if (bclink->bcast_nodes.count) 231 if (tn->bclink->bcast_nodes.count)
270 acked = bcl->fsm_msg_cnt; 232 acked = tn->bcl->fsm_msg_cnt;
271 else 233 else
272 acked = bcl->next_out_no; 234 acked = tn->bcl->next_out_no;
273 } else { 235 } else {
274 /* 236 /*
275 * Bail out if specified sequence number does not correspond 237 * Bail out if specified sequence number does not correspond
276 * to a message that has been sent and not yet acknowledged 238 * to a message that has been sent and not yet acknowledged
277 */ 239 */
278 if (less(acked, buf_seqno(skb)) || 240 if (less(acked, buf_seqno(skb)) ||
279 less(bcl->fsm_msg_cnt, acked) || 241 less(tn->bcl->fsm_msg_cnt, acked) ||
280 less_eq(acked, n_ptr->bclink.acked)) 242 less_eq(acked, n_ptr->bclink.acked))
281 goto exit; 243 goto exit;
282 } 244 }
283 245
284 /* Skip over packets that node has previously acknowledged */ 246 /* Skip over packets that node has previously acknowledged */
285 skb_queue_walk(&bcl->outqueue, skb) { 247 skb_queue_walk(&tn->bcl->outqueue, skb) {
286 if (more(buf_seqno(skb), n_ptr->bclink.acked)) 248 if (more(buf_seqno(skb), n_ptr->bclink.acked))
287 break; 249 break;
288 } 250 }
289 251
290 /* Update packets that node is now acknowledging */ 252 /* Update packets that node is now acknowledging */
291 skb_queue_walk_from_safe(&bcl->outqueue, skb, tmp) { 253 skb_queue_walk_from_safe(&tn->bcl->outqueue, skb, tmp) {
292 if (more(buf_seqno(skb), acked)) 254 if (more(buf_seqno(skb), acked))
293 break; 255 break;
294 256
295 next = tipc_skb_queue_next(&bcl->outqueue, skb); 257 next = tipc_skb_queue_next(&tn->bcl->outqueue, skb);
296 if (skb != bcl->next_out) { 258 if (skb != tn->bcl->next_out) {
297 bcbuf_decr_acks(skb); 259 bcbuf_decr_acks(skb);
298 } else { 260 } else {
299 bcbuf_set_acks(skb, 0); 261 bcbuf_set_acks(skb, 0);
300 bcl->next_out = next; 262 tn->bcl->next_out = next;
301 bclink_set_last_sent(); 263 bclink_set_last_sent(net);
302 } 264 }
303 265
304 if (bcbuf_acks(skb) == 0) { 266 if (bcbuf_acks(skb) == 0) {
305 __skb_unlink(skb, &bcl->outqueue); 267 __skb_unlink(skb, &tn->bcl->outqueue);
306 kfree_skb(skb); 268 kfree_skb(skb);
307 released = 1; 269 released = 1;
308 } 270 }
@@ -310,15 +272,14 @@ void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
310 n_ptr->bclink.acked = acked; 272 n_ptr->bclink.acked = acked;
311 273
312 /* Try resolving broadcast link congestion, if necessary */ 274 /* Try resolving broadcast link congestion, if necessary */
313 if (unlikely(bcl->next_out)) { 275 if (unlikely(tn->bcl->next_out)) {
314 tipc_link_push_packets(bcl); 276 tipc_link_push_packets(tn->bcl);
315 bclink_set_last_sent(); 277 bclink_set_last_sent(net);
316 } 278 }
317 if (unlikely(released && !skb_queue_empty(&bcl->waiting_sks))) 279 if (unlikely(released && !skb_queue_empty(&tn->bcl->wakeupq)))
318 n_ptr->action_flags |= TIPC_WAKEUP_BCAST_USERS; 280 n_ptr->action_flags |= TIPC_WAKEUP_BCAST_USERS;
319
320exit: 281exit:
321 tipc_bclink_unlock(); 282 tipc_bclink_unlock(net);
322} 283}
323 284
324/** 285/**
@@ -326,9 +287,12 @@ exit:
326 * 287 *
327 * RCU and node lock set 288 * RCU and node lock set
328 */ 289 */
329void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent) 290void tipc_bclink_update_link_state(struct tipc_node *n_ptr,
291 u32 last_sent)
330{ 292{
331 struct sk_buff *buf; 293 struct sk_buff *buf;
294 struct net *net = n_ptr->net;
295 struct tipc_net *tn = net_generic(net, tipc_net_id);
332 296
333 /* Ignore "stale" link state info */ 297 /* Ignore "stale" link state info */
334 if (less_eq(last_sent, n_ptr->bclink.last_in)) 298 if (less_eq(last_sent, n_ptr->bclink.last_in))
@@ -358,18 +322,18 @@ void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent)
358 struct sk_buff *skb = skb_peek(&n_ptr->bclink.deferred_queue); 322 struct sk_buff *skb = skb_peek(&n_ptr->bclink.deferred_queue);
359 u32 to = skb ? buf_seqno(skb) - 1 : n_ptr->bclink.last_sent; 323 u32 to = skb ? buf_seqno(skb) - 1 : n_ptr->bclink.last_sent;
360 324
361 tipc_msg_init(msg, BCAST_PROTOCOL, STATE_MSG, 325 tipc_msg_init(tn->own_addr, msg, BCAST_PROTOCOL, STATE_MSG,
362 INT_H_SIZE, n_ptr->addr); 326 INT_H_SIZE, n_ptr->addr);
363 msg_set_non_seq(msg, 1); 327 msg_set_non_seq(msg, 1);
364 msg_set_mc_netid(msg, tipc_net_id); 328 msg_set_mc_netid(msg, tn->net_id);
365 msg_set_bcast_ack(msg, n_ptr->bclink.last_in); 329 msg_set_bcast_ack(msg, n_ptr->bclink.last_in);
366 msg_set_bcgap_after(msg, n_ptr->bclink.last_in); 330 msg_set_bcgap_after(msg, n_ptr->bclink.last_in);
367 msg_set_bcgap_to(msg, to); 331 msg_set_bcgap_to(msg, to);
368 332
369 tipc_bclink_lock(); 333 tipc_bclink_lock(net);
370 tipc_bearer_send(MAX_BEARERS, buf, NULL); 334 tipc_bearer_send(net, MAX_BEARERS, buf, NULL);
371 bcl->stats.sent_nacks++; 335 tn->bcl->stats.sent_nacks++;
372 tipc_bclink_unlock(); 336 tipc_bclink_unlock(net);
373 kfree_skb(buf); 337 kfree_skb(buf);
374 338
375 n_ptr->bclink.oos_state++; 339 n_ptr->bclink.oos_state++;
@@ -382,9 +346,9 @@ void tipc_bclink_update_link_state(struct tipc_node *n_ptr, u32 last_sent)
382 * Delay any upcoming NACK by this node if another node has already 346 * Delay any upcoming NACK by this node if another node has already
383 * requested the first message this node is going to ask for. 347 * requested the first message this node is going to ask for.
384 */ 348 */
385static void bclink_peek_nack(struct tipc_msg *msg) 349static void bclink_peek_nack(struct net *net, struct tipc_msg *msg)
386{ 350{
387 struct tipc_node *n_ptr = tipc_node_find(msg_destnode(msg)); 351 struct tipc_node *n_ptr = tipc_node_find(net, msg_destnode(msg));
388 352
389 if (unlikely(!n_ptr)) 353 if (unlikely(!n_ptr))
390 return; 354 return;
@@ -399,17 +363,23 @@ static void bclink_peek_nack(struct tipc_msg *msg)
399 tipc_node_unlock(n_ptr); 363 tipc_node_unlock(n_ptr);
400} 364}
401 365
402/* tipc_bclink_xmit - broadcast buffer chain to all nodes in cluster 366/* tipc_bclink_xmit - deliver buffer chain to all nodes in cluster
403 * and to identified node local sockets 367 * and to identified node local sockets
368 * @net: the applicable net namespace
404 * @list: chain of buffers containing message 369 * @list: chain of buffers containing message
405 * Consumes the buffer chain, except when returning -ELINKCONG 370 * Consumes the buffer chain, except when returning -ELINKCONG
406 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE 371 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
407 */ 372 */
408int tipc_bclink_xmit(struct sk_buff_head *list) 373int tipc_bclink_xmit(struct net *net, struct sk_buff_head *list)
409{ 374{
375 struct tipc_net *tn = net_generic(net, tipc_net_id);
376 struct tipc_link *bcl = tn->bcl;
377 struct tipc_bclink *bclink = tn->bclink;
410 int rc = 0; 378 int rc = 0;
411 int bc = 0; 379 int bc = 0;
412 struct sk_buff *skb; 380 struct sk_buff *skb;
381 struct sk_buff_head arrvq;
382 struct sk_buff_head inputq;
413 383
414 /* Prepare clone of message for local node */ 384 /* Prepare clone of message for local node */
415 skb = tipc_msg_reassemble(list); 385 skb = tipc_msg_reassemble(list);
@@ -418,32 +388,35 @@ int tipc_bclink_xmit(struct sk_buff_head *list)
418 return -EHOSTUNREACH; 388 return -EHOSTUNREACH;
419 } 389 }
420 390
421 /* Broadcast to all other nodes */ 391 /* Broadcast to all nodes */
422 if (likely(bclink)) { 392 if (likely(bclink)) {
423 tipc_bclink_lock(); 393 tipc_bclink_lock(net);
424 if (likely(bclink->bcast_nodes.count)) { 394 if (likely(bclink->bcast_nodes.count)) {
425 rc = __tipc_link_xmit(bcl, list); 395 rc = __tipc_link_xmit(net, bcl, list);
426 if (likely(!rc)) { 396 if (likely(!rc)) {
427 u32 len = skb_queue_len(&bcl->outqueue); 397 u32 len = skb_queue_len(&bcl->outqueue);
428 398
429 bclink_set_last_sent(); 399 bclink_set_last_sent(net);
430 bcl->stats.queue_sz_counts++; 400 bcl->stats.queue_sz_counts++;
431 bcl->stats.accu_queue_sz += len; 401 bcl->stats.accu_queue_sz += len;
432 } 402 }
433 bc = 1; 403 bc = 1;
434 } 404 }
435 tipc_bclink_unlock(); 405 tipc_bclink_unlock(net);
436 } 406 }
437 407
438 if (unlikely(!bc)) 408 if (unlikely(!bc))
439 __skb_queue_purge(list); 409 __skb_queue_purge(list);
440 410
441 /* Deliver message clone */ 411 if (unlikely(rc)) {
442 if (likely(!rc))
443 tipc_sk_mcast_rcv(skb);
444 else
445 kfree_skb(skb); 412 kfree_skb(skb);
446 413 return rc;
414 }
415 /* Deliver message clone */
416 __skb_queue_head_init(&arrvq);
417 skb_queue_head_init(&inputq);
418 __skb_queue_tail(&arrvq, skb);
419 tipc_sk_mcast_rcv(net, &arrvq, &inputq);
447 return rc; 420 return rc;
448} 421}
449 422
@@ -454,19 +427,21 @@ int tipc_bclink_xmit(struct sk_buff_head *list)
454 */ 427 */
455static void bclink_accept_pkt(struct tipc_node *node, u32 seqno) 428static void bclink_accept_pkt(struct tipc_node *node, u32 seqno)
456{ 429{
430 struct tipc_net *tn = net_generic(node->net, tipc_net_id);
431
457 bclink_update_last_sent(node, seqno); 432 bclink_update_last_sent(node, seqno);
458 node->bclink.last_in = seqno; 433 node->bclink.last_in = seqno;
459 node->bclink.oos_state = 0; 434 node->bclink.oos_state = 0;
460 bcl->stats.recv_info++; 435 tn->bcl->stats.recv_info++;
461 436
462 /* 437 /*
463 * Unicast an ACK periodically, ensuring that 438 * Unicast an ACK periodically, ensuring that
464 * all nodes in the cluster don't ACK at the same time 439 * all nodes in the cluster don't ACK at the same time
465 */ 440 */
466 if (((seqno - tipc_own_addr) % TIPC_MIN_LINK_WIN) == 0) { 441 if (((seqno - tn->own_addr) % TIPC_MIN_LINK_WIN) == 0) {
467 tipc_link_proto_xmit(node->active_links[node->addr & 1], 442 tipc_link_proto_xmit(node->active_links[node->addr & 1],
468 STATE_MSG, 0, 0, 0, 0, 0); 443 STATE_MSG, 0, 0, 0, 0, 0);
469 bcl->stats.sent_acks++; 444 tn->bcl->stats.sent_acks++;
470 } 445 }
471} 446}
472 447
@@ -475,19 +450,24 @@ static void bclink_accept_pkt(struct tipc_node *node, u32 seqno)
475 * 450 *
476 * RCU is locked, no other locks set 451 * RCU is locked, no other locks set
477 */ 452 */
478void tipc_bclink_rcv(struct sk_buff *buf) 453void tipc_bclink_rcv(struct net *net, struct sk_buff *buf)
479{ 454{
455 struct tipc_net *tn = net_generic(net, tipc_net_id);
456 struct tipc_link *bcl = tn->bcl;
480 struct tipc_msg *msg = buf_msg(buf); 457 struct tipc_msg *msg = buf_msg(buf);
481 struct tipc_node *node; 458 struct tipc_node *node;
482 u32 next_in; 459 u32 next_in;
483 u32 seqno; 460 u32 seqno;
484 int deferred = 0; 461 int deferred = 0;
462 int pos = 0;
463 struct sk_buff *iskb;
464 struct sk_buff_head *arrvq, *inputq;
485 465
486 /* Screen out unwanted broadcast messages */ 466 /* Screen out unwanted broadcast messages */
487 if (msg_mc_netid(msg) != tipc_net_id) 467 if (msg_mc_netid(msg) != tn->net_id)
488 goto exit; 468 goto exit;
489 469
490 node = tipc_node_find(msg_prevnode(msg)); 470 node = tipc_node_find(net, msg_prevnode(msg));
491 if (unlikely(!node)) 471 if (unlikely(!node))
492 goto exit; 472 goto exit;
493 473
@@ -499,18 +479,18 @@ void tipc_bclink_rcv(struct sk_buff *buf)
499 if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) { 479 if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) {
500 if (msg_type(msg) != STATE_MSG) 480 if (msg_type(msg) != STATE_MSG)
501 goto unlock; 481 goto unlock;
502 if (msg_destnode(msg) == tipc_own_addr) { 482 if (msg_destnode(msg) == tn->own_addr) {
503 tipc_bclink_acknowledge(node, msg_bcast_ack(msg)); 483 tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
504 tipc_node_unlock(node); 484 tipc_node_unlock(node);
505 tipc_bclink_lock(); 485 tipc_bclink_lock(net);
506 bcl->stats.recv_nacks++; 486 bcl->stats.recv_nacks++;
507 bclink->retransmit_to = node; 487 tn->bclink->retransmit_to = node;
508 bclink_retransmit_pkt(msg_bcgap_after(msg), 488 bclink_retransmit_pkt(tn, msg_bcgap_after(msg),
509 msg_bcgap_to(msg)); 489 msg_bcgap_to(msg));
510 tipc_bclink_unlock(); 490 tipc_bclink_unlock(net);
511 } else { 491 } else {
512 tipc_node_unlock(node); 492 tipc_node_unlock(node);
513 bclink_peek_nack(msg); 493 bclink_peek_nack(net, msg);
514 } 494 }
515 goto exit; 495 goto exit;
516 } 496 }
@@ -518,52 +498,54 @@ void tipc_bclink_rcv(struct sk_buff *buf)
518 /* Handle in-sequence broadcast message */ 498 /* Handle in-sequence broadcast message */
519 seqno = msg_seqno(msg); 499 seqno = msg_seqno(msg);
520 next_in = mod(node->bclink.last_in + 1); 500 next_in = mod(node->bclink.last_in + 1);
501 arrvq = &tn->bclink->arrvq;
502 inputq = &tn->bclink->inputq;
521 503
522 if (likely(seqno == next_in)) { 504 if (likely(seqno == next_in)) {
523receive: 505receive:
524 /* Deliver message to destination */ 506 /* Deliver message to destination */
525 if (likely(msg_isdata(msg))) { 507 if (likely(msg_isdata(msg))) {
526 tipc_bclink_lock(); 508 tipc_bclink_lock(net);
527 bclink_accept_pkt(node, seqno); 509 bclink_accept_pkt(node, seqno);
528 tipc_bclink_unlock(); 510 spin_lock_bh(&inputq->lock);
511 __skb_queue_tail(arrvq, buf);
512 spin_unlock_bh(&inputq->lock);
513 node->action_flags |= TIPC_BCAST_MSG_EVT;
514 tipc_bclink_unlock(net);
529 tipc_node_unlock(node); 515 tipc_node_unlock(node);
530 if (likely(msg_mcast(msg)))
531 tipc_sk_mcast_rcv(buf);
532 else
533 kfree_skb(buf);
534 } else if (msg_user(msg) == MSG_BUNDLER) { 516 } else if (msg_user(msg) == MSG_BUNDLER) {
535 tipc_bclink_lock(); 517 tipc_bclink_lock(net);
536 bclink_accept_pkt(node, seqno); 518 bclink_accept_pkt(node, seqno);
537 bcl->stats.recv_bundles++; 519 bcl->stats.recv_bundles++;
538 bcl->stats.recv_bundled += msg_msgcnt(msg); 520 bcl->stats.recv_bundled += msg_msgcnt(msg);
539 tipc_bclink_unlock(); 521 pos = 0;
522 while (tipc_msg_extract(buf, &iskb, &pos)) {
523 spin_lock_bh(&inputq->lock);
524 __skb_queue_tail(arrvq, iskb);
525 spin_unlock_bh(&inputq->lock);
526 }
527 node->action_flags |= TIPC_BCAST_MSG_EVT;
528 tipc_bclink_unlock(net);
540 tipc_node_unlock(node); 529 tipc_node_unlock(node);
541 tipc_link_bundle_rcv(buf);
542 } else if (msg_user(msg) == MSG_FRAGMENTER) { 530 } else if (msg_user(msg) == MSG_FRAGMENTER) {
543 tipc_buf_append(&node->bclink.reasm_buf, &buf); 531 tipc_buf_append(&node->bclink.reasm_buf, &buf);
544 if (unlikely(!buf && !node->bclink.reasm_buf)) 532 if (unlikely(!buf && !node->bclink.reasm_buf))
545 goto unlock; 533 goto unlock;
546 tipc_bclink_lock(); 534 tipc_bclink_lock(net);
547 bclink_accept_pkt(node, seqno); 535 bclink_accept_pkt(node, seqno);
548 bcl->stats.recv_fragments++; 536 bcl->stats.recv_fragments++;
549 if (buf) { 537 if (buf) {
550 bcl->stats.recv_fragmented++; 538 bcl->stats.recv_fragmented++;
551 msg = buf_msg(buf); 539 msg = buf_msg(buf);
552 tipc_bclink_unlock(); 540 tipc_bclink_unlock(net);
553 goto receive; 541 goto receive;
554 } 542 }
555 tipc_bclink_unlock(); 543 tipc_bclink_unlock(net);
556 tipc_node_unlock(node); 544 tipc_node_unlock(node);
557 } else if (msg_user(msg) == NAME_DISTRIBUTOR) {
558 tipc_bclink_lock();
559 bclink_accept_pkt(node, seqno);
560 tipc_bclink_unlock();
561 tipc_node_unlock(node);
562 tipc_named_rcv(buf);
563 } else { 545 } else {
564 tipc_bclink_lock(); 546 tipc_bclink_lock(net);
565 bclink_accept_pkt(node, seqno); 547 bclink_accept_pkt(node, seqno);
566 tipc_bclink_unlock(); 548 tipc_bclink_unlock(net);
567 tipc_node_unlock(node); 549 tipc_node_unlock(node);
568 kfree_skb(buf); 550 kfree_skb(buf);
569 } 551 }
@@ -601,14 +583,14 @@ receive:
601 buf = NULL; 583 buf = NULL;
602 } 584 }
603 585
604 tipc_bclink_lock(); 586 tipc_bclink_lock(net);
605 587
606 if (deferred) 588 if (deferred)
607 bcl->stats.deferred_recv++; 589 bcl->stats.deferred_recv++;
608 else 590 else
609 bcl->stats.duplicates++; 591 bcl->stats.duplicates++;
610 592
611 tipc_bclink_unlock(); 593 tipc_bclink_unlock(net);
612 594
613unlock: 595unlock:
614 tipc_node_unlock(node); 596 tipc_node_unlock(node);
@@ -619,7 +601,7 @@ exit:
619u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr) 601u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr)
620{ 602{
621 return (n_ptr->bclink.recv_permitted && 603 return (n_ptr->bclink.recv_permitted &&
622 (tipc_bclink_get_last_sent() != n_ptr->bclink.acked)); 604 (tipc_bclink_get_last_sent(n_ptr->net) != n_ptr->bclink.acked));
623} 605}
624 606
625 607
@@ -632,11 +614,15 @@ u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr)
632 * Returns 0 (packet sent successfully) under all circumstances, 614 * Returns 0 (packet sent successfully) under all circumstances,
633 * since the broadcast link's pseudo-bearer never blocks 615 * since the broadcast link's pseudo-bearer never blocks
634 */ 616 */
635static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1, 617static int tipc_bcbearer_send(struct net *net, struct sk_buff *buf,
618 struct tipc_bearer *unused1,
636 struct tipc_media_addr *unused2) 619 struct tipc_media_addr *unused2)
637{ 620{
638 int bp_index; 621 int bp_index;
639 struct tipc_msg *msg = buf_msg(buf); 622 struct tipc_msg *msg = buf_msg(buf);
623 struct tipc_net *tn = net_generic(net, tipc_net_id);
624 struct tipc_bcbearer *bcbearer = tn->bcbearer;
625 struct tipc_bclink *bclink = tn->bclink;
640 626
641 /* Prepare broadcast link message for reliable transmission, 627 /* Prepare broadcast link message for reliable transmission,
642 * if first time trying to send it; 628 * if first time trying to send it;
@@ -646,8 +632,8 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
646 if (likely(!msg_non_seq(buf_msg(buf)))) { 632 if (likely(!msg_non_seq(buf_msg(buf)))) {
647 bcbuf_set_acks(buf, bclink->bcast_nodes.count); 633 bcbuf_set_acks(buf, bclink->bcast_nodes.count);
648 msg_set_non_seq(msg, 1); 634 msg_set_non_seq(msg, 1);
649 msg_set_mc_netid(msg, tipc_net_id); 635 msg_set_mc_netid(msg, tn->net_id);
650 bcl->stats.sent_info++; 636 tn->bcl->stats.sent_info++;
651 637
652 if (WARN_ON(!bclink->bcast_nodes.count)) { 638 if (WARN_ON(!bclink->bcast_nodes.count)) {
653 dump_stack(); 639 dump_stack();
@@ -676,13 +662,14 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
676 662
677 if (bp_index == 0) { 663 if (bp_index == 0) {
678 /* Use original buffer for first bearer */ 664 /* Use original buffer for first bearer */
679 tipc_bearer_send(b->identity, buf, &b->bcast_addr); 665 tipc_bearer_send(net, b->identity, buf, &b->bcast_addr);
680 } else { 666 } else {
681 /* Avoid concurrent buffer access */ 667 /* Avoid concurrent buffer access */
682 tbuf = pskb_copy_for_clone(buf, GFP_ATOMIC); 668 tbuf = pskb_copy_for_clone(buf, GFP_ATOMIC);
683 if (!tbuf) 669 if (!tbuf)
684 break; 670 break;
685 tipc_bearer_send(b->identity, tbuf, &b->bcast_addr); 671 tipc_bearer_send(net, b->identity, tbuf,
672 &b->bcast_addr);
686 kfree_skb(tbuf); /* Bearer keeps a clone */ 673 kfree_skb(tbuf); /* Bearer keeps a clone */
687 } 674 }
688 if (bcbearer->remains_new.count == 0) 675 if (bcbearer->remains_new.count == 0)
@@ -697,15 +684,18 @@ static int tipc_bcbearer_send(struct sk_buff *buf, struct tipc_bearer *unused1,
697/** 684/**
698 * tipc_bcbearer_sort - create sets of bearer pairs used by broadcast bearer 685 * tipc_bcbearer_sort - create sets of bearer pairs used by broadcast bearer
699 */ 686 */
700void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action) 687void tipc_bcbearer_sort(struct net *net, struct tipc_node_map *nm_ptr,
688 u32 node, bool action)
701{ 689{
690 struct tipc_net *tn = net_generic(net, tipc_net_id);
691 struct tipc_bcbearer *bcbearer = tn->bcbearer;
702 struct tipc_bcbearer_pair *bp_temp = bcbearer->bpairs_temp; 692 struct tipc_bcbearer_pair *bp_temp = bcbearer->bpairs_temp;
703 struct tipc_bcbearer_pair *bp_curr; 693 struct tipc_bcbearer_pair *bp_curr;
704 struct tipc_bearer *b; 694 struct tipc_bearer *b;
705 int b_index; 695 int b_index;
706 int pri; 696 int pri;
707 697
708 tipc_bclink_lock(); 698 tipc_bclink_lock(net);
709 699
710 if (action) 700 if (action)
711 tipc_nmap_add(nm_ptr, node); 701 tipc_nmap_add(nm_ptr, node);
@@ -717,7 +707,7 @@ void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action)
717 707
718 rcu_read_lock(); 708 rcu_read_lock();
719 for (b_index = 0; b_index < MAX_BEARERS; b_index++) { 709 for (b_index = 0; b_index < MAX_BEARERS; b_index++) {
720 b = rcu_dereference_rtnl(bearer_list[b_index]); 710 b = rcu_dereference_rtnl(tn->bearer_list[b_index]);
721 if (!b || !b->nodes.count) 711 if (!b || !b->nodes.count)
722 continue; 712 continue;
723 713
@@ -752,7 +742,7 @@ void tipc_bcbearer_sort(struct tipc_node_map *nm_ptr, u32 node, bool action)
752 bp_curr++; 742 bp_curr++;
753 } 743 }
754 744
755 tipc_bclink_unlock(); 745 tipc_bclink_unlock(net);
756} 746}
757 747
758static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb, 748static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
@@ -806,19 +796,21 @@ msg_full:
806 return -EMSGSIZE; 796 return -EMSGSIZE;
807} 797}
808 798
809int tipc_nl_add_bc_link(struct tipc_nl_msg *msg) 799int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
810{ 800{
811 int err; 801 int err;
812 void *hdr; 802 void *hdr;
813 struct nlattr *attrs; 803 struct nlattr *attrs;
814 struct nlattr *prop; 804 struct nlattr *prop;
805 struct tipc_net *tn = net_generic(net, tipc_net_id);
806 struct tipc_link *bcl = tn->bcl;
815 807
816 if (!bcl) 808 if (!bcl)
817 return 0; 809 return 0;
818 810
819 tipc_bclink_lock(); 811 tipc_bclink_lock(net);
820 812
821 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, 813 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
822 NLM_F_MULTI, TIPC_NL_LINK_GET); 814 NLM_F_MULTI, TIPC_NL_LINK_GET);
823 if (!hdr) 815 if (!hdr)
824 return -EMSGSIZE; 816 return -EMSGSIZE;
@@ -851,7 +843,7 @@ int tipc_nl_add_bc_link(struct tipc_nl_msg *msg)
851 if (err) 843 if (err)
852 goto attr_msg_full; 844 goto attr_msg_full;
853 845
854 tipc_bclink_unlock(); 846 tipc_bclink_unlock(net);
855 nla_nest_end(msg->skb, attrs); 847 nla_nest_end(msg->skb, attrs);
856 genlmsg_end(msg->skb, hdr); 848 genlmsg_end(msg->skb, hdr);
857 849
@@ -862,79 +854,49 @@ prop_msg_full:
862attr_msg_full: 854attr_msg_full:
863 nla_nest_cancel(msg->skb, attrs); 855 nla_nest_cancel(msg->skb, attrs);
864msg_full: 856msg_full:
865 tipc_bclink_unlock(); 857 tipc_bclink_unlock(net);
866 genlmsg_cancel(msg->skb, hdr); 858 genlmsg_cancel(msg->skb, hdr);
867 859
868 return -EMSGSIZE; 860 return -EMSGSIZE;
869} 861}
870 862
871int tipc_bclink_stats(char *buf, const u32 buf_size) 863int tipc_bclink_reset_stats(struct net *net)
872{ 864{
873 int ret; 865 struct tipc_net *tn = net_generic(net, tipc_net_id);
874 struct tipc_stats *s; 866 struct tipc_link *bcl = tn->bcl;
875 867
876 if (!bcl) 868 if (!bcl)
877 return 0;
878
879 tipc_bclink_lock();
880
881 s = &bcl->stats;
882
883 ret = tipc_snprintf(buf, buf_size, "Link <%s>\n"
884 " Window:%u packets\n",
885 bcl->name, bcl->queue_limit[0]);
886 ret += tipc_snprintf(buf + ret, buf_size - ret,
887 " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
888 s->recv_info, s->recv_fragments,
889 s->recv_fragmented, s->recv_bundles,
890 s->recv_bundled);
891 ret += tipc_snprintf(buf + ret, buf_size - ret,
892 " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
893 s->sent_info, s->sent_fragments,
894 s->sent_fragmented, s->sent_bundles,
895 s->sent_bundled);
896 ret += tipc_snprintf(buf + ret, buf_size - ret,
897 " RX naks:%u defs:%u dups:%u\n",
898 s->recv_nacks, s->deferred_recv, s->duplicates);
899 ret += tipc_snprintf(buf + ret, buf_size - ret,
900 " TX naks:%u acks:%u dups:%u\n",
901 s->sent_nacks, s->sent_acks, s->retransmitted);
902 ret += tipc_snprintf(buf + ret, buf_size - ret,
903 " Congestion link:%u Send queue max:%u avg:%u\n",
904 s->link_congs, s->max_queue_sz,
905 s->queue_sz_counts ?
906 (s->accu_queue_sz / s->queue_sz_counts) : 0);
907
908 tipc_bclink_unlock();
909 return ret;
910}
911
912int tipc_bclink_reset_stats(void)
913{
914 if (!bcl)
915 return -ENOPROTOOPT; 869 return -ENOPROTOOPT;
916 870
917 tipc_bclink_lock(); 871 tipc_bclink_lock(net);
918 memset(&bcl->stats, 0, sizeof(bcl->stats)); 872 memset(&bcl->stats, 0, sizeof(bcl->stats));
919 tipc_bclink_unlock(); 873 tipc_bclink_unlock(net);
920 return 0; 874 return 0;
921} 875}
922 876
923int tipc_bclink_set_queue_limits(u32 limit) 877int tipc_bclink_set_queue_limits(struct net *net, u32 limit)
924{ 878{
879 struct tipc_net *tn = net_generic(net, tipc_net_id);
880 struct tipc_link *bcl = tn->bcl;
881
925 if (!bcl) 882 if (!bcl)
926 return -ENOPROTOOPT; 883 return -ENOPROTOOPT;
927 if ((limit < TIPC_MIN_LINK_WIN) || (limit > TIPC_MAX_LINK_WIN)) 884 if ((limit < TIPC_MIN_LINK_WIN) || (limit > TIPC_MAX_LINK_WIN))
928 return -EINVAL; 885 return -EINVAL;
929 886
930 tipc_bclink_lock(); 887 tipc_bclink_lock(net);
931 tipc_link_set_queue_limits(bcl, limit); 888 tipc_link_set_queue_limits(bcl, limit);
932 tipc_bclink_unlock(); 889 tipc_bclink_unlock(net);
933 return 0; 890 return 0;
934} 891}
935 892
936int tipc_bclink_init(void) 893int tipc_bclink_init(struct net *net)
937{ 894{
895 struct tipc_net *tn = net_generic(net, tipc_net_id);
896 struct tipc_bcbearer *bcbearer;
897 struct tipc_bclink *bclink;
898 struct tipc_link *bcl;
899
938 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC); 900 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC);
939 if (!bcbearer) 901 if (!bcbearer)
940 return -ENOMEM; 902 return -ENOMEM;
@@ -953,30 +915,39 @@ int tipc_bclink_init(void)
953 spin_lock_init(&bclink->lock); 915 spin_lock_init(&bclink->lock);
954 __skb_queue_head_init(&bcl->outqueue); 916 __skb_queue_head_init(&bcl->outqueue);
955 __skb_queue_head_init(&bcl->deferred_queue); 917 __skb_queue_head_init(&bcl->deferred_queue);
956 skb_queue_head_init(&bcl->waiting_sks); 918 skb_queue_head_init(&bcl->wakeupq);
957 bcl->next_out_no = 1; 919 bcl->next_out_no = 1;
958 spin_lock_init(&bclink->node.lock); 920 spin_lock_init(&bclink->node.lock);
959 __skb_queue_head_init(&bclink->node.waiting_sks); 921 __skb_queue_head_init(&bclink->arrvq);
922 skb_queue_head_init(&bclink->inputq);
960 bcl->owner = &bclink->node; 923 bcl->owner = &bclink->node;
924 bcl->owner->net = net;
961 bcl->max_pkt = MAX_PKT_DEFAULT_MCAST; 925 bcl->max_pkt = MAX_PKT_DEFAULT_MCAST;
962 tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT); 926 tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);
963 bcl->bearer_id = MAX_BEARERS; 927 bcl->bearer_id = MAX_BEARERS;
964 rcu_assign_pointer(bearer_list[MAX_BEARERS], &bcbearer->bearer); 928 rcu_assign_pointer(tn->bearer_list[MAX_BEARERS], &bcbearer->bearer);
965 bcl->state = WORKING_WORKING; 929 bcl->state = WORKING_WORKING;
930 bcl->pmsg = (struct tipc_msg *)&bcl->proto_msg;
931 msg_set_prevnode(bcl->pmsg, tn->own_addr);
966 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME); 932 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME);
933 tn->bcbearer = bcbearer;
934 tn->bclink = bclink;
935 tn->bcl = bcl;
967 return 0; 936 return 0;
968} 937}
969 938
970void tipc_bclink_stop(void) 939void tipc_bclink_stop(struct net *net)
971{ 940{
972 tipc_bclink_lock(); 941 struct tipc_net *tn = net_generic(net, tipc_net_id);
973 tipc_link_purge_queues(bcl); 942
974 tipc_bclink_unlock(); 943 tipc_bclink_lock(net);
944 tipc_link_purge_queues(tn->bcl);
945 tipc_bclink_unlock(net);
975 946
976 RCU_INIT_POINTER(bearer_list[BCBEARER], NULL); 947 RCU_INIT_POINTER(tn->bearer_list[BCBEARER], NULL);
977 synchronize_net(); 948 synchronize_net();
978 kfree(bcbearer); 949 kfree(tn->bcbearer);
979 kfree(bclink); 950 kfree(tn->bclink);
980} 951}
981 952
982/** 953/**
@@ -1036,50 +1007,3 @@ static void tipc_nmap_diff(struct tipc_node_map *nm_a,
1036 } 1007 }
1037 } 1008 }
1038} 1009}
1039
1040/**
1041 * tipc_port_list_add - add a port to a port list, ensuring no duplicates
1042 */
1043void tipc_port_list_add(struct tipc_port_list *pl_ptr, u32 port)
1044{
1045 struct tipc_port_list *item = pl_ptr;
1046 int i;
1047 int item_sz = PLSIZE;
1048 int cnt = pl_ptr->count;
1049
1050 for (; ; cnt -= item_sz, item = item->next) {
1051 if (cnt < PLSIZE)
1052 item_sz = cnt;
1053 for (i = 0; i < item_sz; i++)
1054 if (item->ports[i] == port)
1055 return;
1056 if (i < PLSIZE) {
1057 item->ports[i] = port;
1058 pl_ptr->count++;
1059 return;
1060 }
1061 if (!item->next) {
1062 item->next = kmalloc(sizeof(*item), GFP_ATOMIC);
1063 if (!item->next) {
1064 pr_warn("Incomplete multicast delivery, no memory\n");
1065 return;
1066 }
1067 item->next->next = NULL;
1068 }
1069 }
1070}
1071
1072/**
1073 * tipc_port_list_free - free dynamically created entries in port_list chain
1074 *
1075 */
1076void tipc_port_list_free(struct tipc_port_list *pl_ptr)
1077{
1078 struct tipc_port_list *item;
1079 struct tipc_port_list *next;
1080
1081 for (item = pl_ptr->next; item; item = next) {
1082 next = item->next;
1083 kfree(item);
1084 }
1085}