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