aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/bcast.c
diff options
context:
space:
mode:
authorPer Liden <per.liden@nospam.ericsson.com>2006-01-02 13:04:38 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-01-12 17:06:31 -0500
commitb97bf3fd8f6a16966d4f18983b2c40993ff937d4 (patch)
tree59959f8a0f3087455efdcb430846686f303c5991 /net/tipc/bcast.c
parent58cba4650a7a414eabd2b40cc9d8e45fcdf192d9 (diff)
[TIPC] Initial merge
TIPC (Transparent Inter Process Communication) is a protocol designed for intra cluster communication. For more information see http://tipc.sourceforge.net Signed-off-by: Per Liden <per.liden@nospam.ericsson.com>
Diffstat (limited to 'net/tipc/bcast.c')
-rw-r--r--net/tipc/bcast.c803
1 files changed, 803 insertions, 0 deletions
diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c
new file mode 100644
index 000000000000..35ca90667a59
--- /dev/null
+++ b/net/tipc/bcast.c
@@ -0,0 +1,803 @@
1/*
2 * net/tipc/bcast.c: TIPC broadcast code
3 *
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2004, Intel Corporation.
6 * Copyright (c) 2005, Wind River Systems
7 * Copyright (c) 2005-2006, Ericsson AB
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 *
13 * Redistributions of source code must retain the above copyright notice, this
14 * list of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * Neither the names of the copyright holders nor the names of its
19 * contributors may be used to endorse or promote products derived from this
20 * software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include "core.h"
36#include "msg.h"
37#include "dbg.h"
38#include "link.h"
39#include "net.h"
40#include "node.h"
41#include "port.h"
42#include "addr.h"
43#include "node_subscr.h"
44#include "name_distr.h"
45#include "bearer.h"
46#include "name_table.h"
47#include "bcast.h"
48
49
50#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */
51
52#define BCLINK_WIN_DEFAULT 20 /* bcast link window size (default) */
53
54#define BCLINK_LOG_BUF_SIZE 0
55
56/**
57 * struct bcbearer_pair - a pair of bearers used by broadcast link
58 * @primary: pointer to primary bearer
59 * @secondary: pointer to secondary bearer
60 *
61 * Bearers must have same priority and same set of reachable destinations
62 * to be paired.
63 */
64
65struct bcbearer_pair {
66 struct bearer *primary;
67 struct bearer *secondary;
68};
69
70/**
71 * struct bcbearer - bearer used by broadcast link
72 * @bearer: (non-standard) broadcast bearer structure
73 * @media: (non-standard) broadcast media structure
74 * @bpairs: array of bearer pairs
75 * @bpairs_temp: array of bearer pairs used during creation of "bpairs"
76 */
77
78struct bcbearer {
79 struct bearer bearer;
80 struct media media;
81 struct bcbearer_pair bpairs[MAX_BEARERS];
82 struct bcbearer_pair bpairs_temp[TIPC_NUM_LINK_PRI];
83};
84
85/**
86 * struct bclink - link used for broadcast messages
87 * @link: (non-standard) broadcast link structure
88 * @node: (non-standard) node structure representing b'cast link's peer node
89 *
90 * Handles sequence numbering, fragmentation, bundling, etc.
91 */
92
93struct bclink {
94 struct link link;
95 struct node node;
96};
97
98
99static struct bcbearer *bcbearer = NULL;
100static struct bclink *bclink = NULL;
101static struct link *bcl = NULL;
102static spinlock_t bc_lock = SPIN_LOCK_UNLOCKED;
103
104char bc_link_name[] = "multicast-link";
105
106
107static inline u32 buf_seqno(struct sk_buff *buf)
108{
109 return msg_seqno(buf_msg(buf));
110}
111
112static inline u32 bcbuf_acks(struct sk_buff *buf)
113{
114 return (u32)TIPC_SKB_CB(buf)->handle;
115}
116
117static inline void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
118{
119 TIPC_SKB_CB(buf)->handle = (void *)acks;
120}
121
122static inline void bcbuf_decr_acks(struct sk_buff *buf)
123{
124 bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
125}
126
127
128/**
129 * bclink_set_gap - set gap according to contents of current deferred pkt queue
130 *
131 * Called with 'node' locked, bc_lock unlocked
132 */
133
134static inline void bclink_set_gap(struct node *n_ptr)
135{
136 struct sk_buff *buf = n_ptr->bclink.deferred_head;
137
138 n_ptr->bclink.gap_after = n_ptr->bclink.gap_to =
139 mod(n_ptr->bclink.last_in);
140 if (unlikely(buf != NULL))
141 n_ptr->bclink.gap_to = mod(buf_seqno(buf) - 1);
142}
143
144/**
145 * bclink_ack_allowed - test if ACK or NACK message can be sent at this moment
146 *
147 * This mechanism endeavours to prevent all nodes in network from trying
148 * to ACK or NACK at the same time.
149 *
150 * Note: TIPC uses a different trigger to distribute ACKs than it does to
151 * distribute NACKs, but tries to use the same spacing (divide by 16).
152 */
153
154static inline int bclink_ack_allowed(u32 n)
155{
156 return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag);
157}
158
159
160/**
161 * bclink_retransmit_pkt - retransmit broadcast packets
162 * @after: sequence number of last packet to *not* retransmit
163 * @to: sequence number of last packet to retransmit
164 *
165 * Called with 'node' locked, bc_lock unlocked
166 */
167
168static void bclink_retransmit_pkt(u32 after, u32 to)
169{
170 struct sk_buff *buf;
171
172 spin_lock_bh(&bc_lock);
173 buf = bcl->first_out;
174 while (buf && less_eq(buf_seqno(buf), after)) {
175 buf = buf->next;
176 }
177 if (buf != NULL)
178 link_retransmit(bcl, buf, mod(to - after));
179 spin_unlock_bh(&bc_lock);
180}
181
182/**
183 * bclink_acknowledge - handle acknowledgement of broadcast packets
184 * @n_ptr: node that sent acknowledgement info
185 * @acked: broadcast sequence # that has been acknowledged
186 *
187 * Node is locked, bc_lock unlocked.
188 */
189
190void bclink_acknowledge(struct node *n_ptr, u32 acked)
191{
192 struct sk_buff *crs;
193 struct sk_buff *next;
194 unsigned int released = 0;
195
196 if (less_eq(acked, n_ptr->bclink.acked))
197 return;
198
199 spin_lock_bh(&bc_lock);
200
201 /* Skip over packets that node has previously acknowledged */
202
203 crs = bcl->first_out;
204 while (crs && less_eq(buf_seqno(crs), n_ptr->bclink.acked)) {
205 crs = crs->next;
206 }
207
208 /* Update packets that node is now acknowledging */
209
210 while (crs && less_eq(buf_seqno(crs), acked)) {
211 next = crs->next;
212 bcbuf_decr_acks(crs);
213 if (bcbuf_acks(crs) == 0) {
214 bcl->first_out = next;
215 bcl->out_queue_size--;
216 buf_discard(crs);
217 released = 1;
218 }
219 crs = next;
220 }
221 n_ptr->bclink.acked = acked;
222
223 /* Try resolving broadcast link congestion, if necessary */
224
225 if (unlikely(bcl->next_out))
226 link_push_queue(bcl);
227 if (unlikely(released && !list_empty(&bcl->waiting_ports)))
228 link_wakeup_ports(bcl, 0);
229 spin_unlock_bh(&bc_lock);
230}
231
232/**
233 * bclink_send_ack - unicast an ACK msg
234 *
235 * net_lock and node lock set
236 */
237
238static void bclink_send_ack(struct node *n_ptr)
239{
240 struct link *l_ptr = n_ptr->active_links[n_ptr->addr & 1];
241
242 if (l_ptr != NULL)
243 link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);
244}
245
246/**
247 * bclink_send_nack- broadcast a NACK msg
248 *
249 * net_lock and node lock set
250 */
251
252static void bclink_send_nack(struct node *n_ptr)
253{
254 struct sk_buff *buf;
255 struct tipc_msg *msg;
256
257 if (!less(n_ptr->bclink.gap_after, n_ptr->bclink.gap_to))
258 return;
259
260 buf = buf_acquire(INT_H_SIZE);
261 if (buf) {
262 msg = buf_msg(buf);
263 msg_init(msg, BCAST_PROTOCOL, STATE_MSG,
264 TIPC_OK, INT_H_SIZE, n_ptr->addr);
265 msg_set_mc_netid(msg, tipc_net_id);
266 msg_set_bcast_ack(msg, mod(n_ptr->bclink.last_in));
267 msg_set_bcgap_after(msg, n_ptr->bclink.gap_after);
268 msg_set_bcgap_to(msg, n_ptr->bclink.gap_to);
269 msg_set_bcast_tag(msg, tipc_own_tag);
270
271 if (bearer_send(&bcbearer->bearer, buf, 0)) {
272 bcl->stats.sent_nacks++;
273 buf_discard(buf);
274 } else {
275 bearer_schedule(bcl->b_ptr, bcl);
276 bcl->proto_msg_queue = buf;
277 bcl->stats.bearer_congs++;
278 }
279
280 /*
281 * Ensure we doesn't send another NACK msg to the node
282 * until 16 more deferred messages arrive from it
283 * (i.e. helps prevent all nodes from NACK'ing at same time)
284 */
285
286 n_ptr->bclink.nack_sync = tipc_own_tag;
287 }
288}
289
290/**
291 * bclink_check_gap - send a NACK if a sequence gap exists
292 *
293 * net_lock and node lock set
294 */
295
296void bclink_check_gap(struct node *n_ptr, u32 last_sent)
297{
298 if (!n_ptr->bclink.supported ||
299 less_eq(last_sent, mod(n_ptr->bclink.last_in)))
300 return;
301
302 bclink_set_gap(n_ptr);
303 if (n_ptr->bclink.gap_after == n_ptr->bclink.gap_to)
304 n_ptr->bclink.gap_to = last_sent;
305 bclink_send_nack(n_ptr);
306}
307
308/**
309 * bclink_peek_nack - process a NACK msg meant for another node
310 *
311 * Only net_lock set.
312 */
313
314void bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to)
315{
316 struct node *n_ptr = node_find(dest);
317 u32 my_after, my_to;
318
319 if (unlikely(!n_ptr || !node_is_up(n_ptr)))
320 return;
321 node_lock(n_ptr);
322 /*
323 * Modify gap to suppress unnecessary NACKs from this node
324 */
325 my_after = n_ptr->bclink.gap_after;
326 my_to = n_ptr->bclink.gap_to;
327
328 if (less_eq(gap_after, my_after)) {
329 if (less(my_after, gap_to) && less(gap_to, my_to))
330 n_ptr->bclink.gap_after = gap_to;
331 else if (less_eq(my_to, gap_to))
332 n_ptr->bclink.gap_to = n_ptr->bclink.gap_after;
333 } else if (less_eq(gap_after, my_to)) {
334 if (less_eq(my_to, gap_to))
335 n_ptr->bclink.gap_to = gap_after;
336 } else {
337 /*
338 * Expand gap if missing bufs not in deferred queue:
339 */
340 struct sk_buff *buf = n_ptr->bclink.deferred_head;
341 u32 prev = n_ptr->bclink.gap_to;
342
343 for (; buf; buf = buf->next) {
344 u32 seqno = buf_seqno(buf);
345
346 if (mod(seqno - prev) != 1)
347 buf = NULL;
348 if (seqno == gap_after)
349 break;
350 prev = seqno;
351 }
352 if (buf == NULL)
353 n_ptr->bclink.gap_to = gap_after;
354 }
355 /*
356 * Some nodes may send a complementary NACK now:
357 */
358 if (bclink_ack_allowed(sender_tag + 1)) {
359 if (n_ptr->bclink.gap_to != n_ptr->bclink.gap_after) {
360 bclink_send_nack(n_ptr);
361 bclink_set_gap(n_ptr);
362 }
363 }
364 node_unlock(n_ptr);
365}
366
367/**
368 * bclink_send_msg - broadcast a packet to all nodes in cluster
369 */
370
371int bclink_send_msg(struct sk_buff *buf)
372{
373 int res;
374
375 spin_lock_bh(&bc_lock);
376
377 res = link_send_buf(bcl, buf);
378 if (unlikely(res == -ELINKCONG))
379 buf_discard(buf);
380 else
381 bcl->stats.sent_info++;
382
383 if (bcl->out_queue_size > bcl->stats.max_queue_sz)
384 bcl->stats.max_queue_sz = bcl->out_queue_size;
385 bcl->stats.queue_sz_counts++;
386 bcl->stats.accu_queue_sz += bcl->out_queue_size;
387
388 spin_unlock_bh(&bc_lock);
389 return res;
390}
391
392/**
393 * bclink_recv_pkt - receive a broadcast packet, and deliver upwards
394 *
395 * net_lock is read_locked, no other locks set
396 */
397
398void bclink_recv_pkt(struct sk_buff *buf)
399{
400 struct tipc_msg *msg = buf_msg(buf);
401 struct node* node = node_find(msg_prevnode(msg));
402 u32 next_in;
403 u32 seqno;
404 struct sk_buff *deferred;
405
406 msg_dbg(msg, "<BC<<<");
407
408 if (unlikely(!node || !node_is_up(node) || !node->bclink.supported ||
409 (msg_mc_netid(msg) != tipc_net_id))) {
410 buf_discard(buf);
411 return;
412 }
413
414 if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) {
415 msg_dbg(msg, "<BCNACK<<<");
416 if (msg_destnode(msg) == tipc_own_addr) {
417 node_lock(node);
418 bclink_acknowledge(node, msg_bcast_ack(msg));
419 node_unlock(node);
420 bcl->stats.recv_nacks++;
421 bclink_retransmit_pkt(msg_bcgap_after(msg),
422 msg_bcgap_to(msg));
423 } else {
424 bclink_peek_nack(msg_destnode(msg),
425 msg_bcast_tag(msg),
426 msg_bcgap_after(msg),
427 msg_bcgap_to(msg));
428 }
429 buf_discard(buf);
430 return;
431 }
432
433 node_lock(node);
434receive:
435 deferred = node->bclink.deferred_head;
436 next_in = mod(node->bclink.last_in + 1);
437 seqno = msg_seqno(msg);
438
439 if (likely(seqno == next_in)) {
440 bcl->stats.recv_info++;
441 node->bclink.last_in++;
442 bclink_set_gap(node);
443 if (unlikely(bclink_ack_allowed(seqno))) {
444 bclink_send_ack(node);
445 bcl->stats.sent_acks++;
446 }
447 if (likely(msg_isdata(msg))) {
448 node_unlock(node);
449 port_recv_mcast(buf, NULL);
450 } else if (msg_user(msg) == MSG_BUNDLER) {
451 bcl->stats.recv_bundles++;
452 bcl->stats.recv_bundled += msg_msgcnt(msg);
453 node_unlock(node);
454 link_recv_bundle(buf);
455 } else if (msg_user(msg) == MSG_FRAGMENTER) {
456 bcl->stats.recv_fragments++;
457 if (link_recv_fragment(&node->bclink.defragm,
458 &buf, &msg))
459 bcl->stats.recv_fragmented++;
460 node_unlock(node);
461 net_route_msg(buf);
462 } else {
463 node_unlock(node);
464 net_route_msg(buf);
465 }
466 if (deferred && (buf_seqno(deferred) == mod(next_in + 1))) {
467 node_lock(node);
468 buf = deferred;
469 msg = buf_msg(buf);
470 node->bclink.deferred_head = deferred->next;
471 goto receive;
472 }
473 return;
474 } else if (less(next_in, seqno)) {
475 u32 gap_after = node->bclink.gap_after;
476 u32 gap_to = node->bclink.gap_to;
477
478 if (link_defer_pkt(&node->bclink.deferred_head,
479 &node->bclink.deferred_tail,
480 buf)) {
481 node->bclink.nack_sync++;
482 bcl->stats.deferred_recv++;
483 if (seqno == mod(gap_after + 1))
484 node->bclink.gap_after = seqno;
485 else if (less(gap_after, seqno) && less(seqno, gap_to))
486 node->bclink.gap_to = seqno;
487 }
488 if (bclink_ack_allowed(node->bclink.nack_sync)) {
489 if (gap_to != gap_after)
490 bclink_send_nack(node);
491 bclink_set_gap(node);
492 }
493 } else {
494 bcl->stats.duplicates++;
495 buf_discard(buf);
496 }
497 node_unlock(node);
498}
499
500u32 bclink_get_last_sent(void)
501{
502 u32 last_sent = mod(bcl->next_out_no - 1);
503
504 if (bcl->next_out)
505 last_sent = mod(buf_seqno(bcl->next_out) - 1);
506 return last_sent;
507}
508
509u32 bclink_acks_missing(struct node *n_ptr)
510{
511 return (n_ptr->bclink.supported &&
512 (bclink_get_last_sent() != n_ptr->bclink.acked));
513}
514
515
516/**
517 * bcbearer_send - send a packet through the broadcast pseudo-bearer
518 *
519 * Send through as many bearers as necessary to reach all nodes
520 * that support TIPC multicasting.
521 *
522 * Returns 0 if packet sent successfully, non-zero if not
523 */
524
525int bcbearer_send(struct sk_buff *buf,
526 struct tipc_bearer *unused1,
527 struct tipc_media_addr *unused2)
528{
529 static int send_count = 0;
530
531 struct node_map remains;
532 struct node_map remains_new;
533 int bp_index;
534 int swap_time;
535
536 /* Prepare buffer for broadcasting (if first time trying to send it) */
537
538 if (likely(!msg_non_seq(buf_msg(buf)))) {
539 struct tipc_msg *msg;
540
541 assert(cluster_bcast_nodes.count != 0);
542 bcbuf_set_acks(buf, cluster_bcast_nodes.count);
543 msg = buf_msg(buf);
544 msg_set_non_seq(msg);
545 msg_set_mc_netid(msg, tipc_net_id);
546 }
547
548 /* Determine if bearer pairs should be swapped following this attempt */
549
550 if ((swap_time = (++send_count >= 10)))
551 send_count = 0;
552
553 /* Send buffer over bearers until all targets reached */
554
555 remains = cluster_bcast_nodes;
556
557 for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
558 struct bearer *p = bcbearer->bpairs[bp_index].primary;
559 struct bearer *s = bcbearer->bpairs[bp_index].secondary;
560
561 if (!p)
562 break; /* no more bearers to try */
563
564 nmap_diff(&remains, &p->nodes, &remains_new);
565 if (remains_new.count == remains.count)
566 continue; /* bearer pair doesn't add anything */
567
568 if (!p->publ.blocked &&
569 !p->media->send_msg(buf, &p->publ, &p->media->bcast_addr)) {
570 if (swap_time && s && !s->publ.blocked)
571 goto swap;
572 else
573 goto update;
574 }
575
576 if (!s || s->publ.blocked ||
577 s->media->send_msg(buf, &s->publ, &s->media->bcast_addr))
578 continue; /* unable to send using bearer pair */
579swap:
580 bcbearer->bpairs[bp_index].primary = s;
581 bcbearer->bpairs[bp_index].secondary = p;
582update:
583 if (remains_new.count == 0)
584 return TIPC_OK;
585
586 remains = remains_new;
587 }
588
589 /* Unable to reach all targets */
590
591 bcbearer->bearer.publ.blocked = 1;
592 bcl->stats.bearer_congs++;
593 return ~TIPC_OK;
594}
595
596/**
597 * bcbearer_sort - create sets of bearer pairs used by broadcast bearer
598 */
599
600void bcbearer_sort(void)
601{
602 struct bcbearer_pair *bp_temp = bcbearer->bpairs_temp;
603 struct bcbearer_pair *bp_curr;
604 int b_index;
605 int pri;
606
607 spin_lock_bh(&bc_lock);
608
609 /* Group bearers by priority (can assume max of two per priority) */
610
611 memset(bp_temp, 0, sizeof(bcbearer->bpairs_temp));
612
613 for (b_index = 0; b_index < MAX_BEARERS; b_index++) {
614 struct bearer *b = &bearers[b_index];
615
616 if (!b->active || !b->nodes.count)
617 continue;
618
619 if (!bp_temp[b->priority].primary)
620 bp_temp[b->priority].primary = b;
621 else
622 bp_temp[b->priority].secondary = b;
623 }
624
625 /* Create array of bearer pairs for broadcasting */
626
627 bp_curr = bcbearer->bpairs;
628 memset(bcbearer->bpairs, 0, sizeof(bcbearer->bpairs));
629
630 for (pri = (TIPC_NUM_LINK_PRI - 1); pri >= 0; pri--) {
631
632 if (!bp_temp[pri].primary)
633 continue;
634
635 bp_curr->primary = bp_temp[pri].primary;
636
637 if (bp_temp[pri].secondary) {
638 if (nmap_equal(&bp_temp[pri].primary->nodes,
639 &bp_temp[pri].secondary->nodes)) {
640 bp_curr->secondary = bp_temp[pri].secondary;
641 } else {
642 bp_curr++;
643 bp_curr->primary = bp_temp[pri].secondary;
644 }
645 }
646
647 bp_curr++;
648 }
649
650 spin_unlock_bh(&bc_lock);
651}
652
653/**
654 * bcbearer_push - resolve bearer congestion
655 *
656 * Forces bclink to push out any unsent packets, until all packets are gone
657 * or congestion reoccurs.
658 * No locks set when function called
659 */
660
661void bcbearer_push(void)
662{
663 struct bearer *b_ptr;
664
665 spin_lock_bh(&bc_lock);
666 b_ptr = &bcbearer->bearer;
667 if (b_ptr->publ.blocked) {
668 b_ptr->publ.blocked = 0;
669 bearer_lock_push(b_ptr);
670 }
671 spin_unlock_bh(&bc_lock);
672}
673
674
675int bclink_stats(char *buf, const u32 buf_size)
676{
677 struct print_buf pb;
678
679 if (!bcl)
680 return 0;
681
682 printbuf_init(&pb, buf, buf_size);
683
684 spin_lock_bh(&bc_lock);
685
686 tipc_printf(&pb, "Link <%s>\n"
687 " Window:%u packets\n",
688 bcl->name, bcl->queue_limit[0]);
689 tipc_printf(&pb, " RX packets:%u fragments:%u/%u bundles:%u/%u\n",
690 bcl->stats.recv_info,
691 bcl->stats.recv_fragments,
692 bcl->stats.recv_fragmented,
693 bcl->stats.recv_bundles,
694 bcl->stats.recv_bundled);
695 tipc_printf(&pb, " TX packets:%u fragments:%u/%u bundles:%u/%u\n",
696 bcl->stats.sent_info,
697 bcl->stats.sent_fragments,
698 bcl->stats.sent_fragmented,
699 bcl->stats.sent_bundles,
700 bcl->stats.sent_bundled);
701 tipc_printf(&pb, " RX naks:%u defs:%u dups:%u\n",
702 bcl->stats.recv_nacks,
703 bcl->stats.deferred_recv,
704 bcl->stats.duplicates);
705 tipc_printf(&pb, " TX naks:%u acks:%u dups:%u\n",
706 bcl->stats.sent_nacks,
707 bcl->stats.sent_acks,
708 bcl->stats.retransmitted);
709 tipc_printf(&pb, " Congestion bearer:%u link:%u Send queue max:%u avg:%u\n",
710 bcl->stats.bearer_congs,
711 bcl->stats.link_congs,
712 bcl->stats.max_queue_sz,
713 bcl->stats.queue_sz_counts
714 ? (bcl->stats.accu_queue_sz / bcl->stats.queue_sz_counts)
715 : 0);
716
717 spin_unlock_bh(&bc_lock);
718 return printbuf_validate(&pb);
719}
720
721int bclink_reset_stats(void)
722{
723 if (!bcl)
724 return -ENOPROTOOPT;
725
726 spin_lock_bh(&bc_lock);
727 memset(&bcl->stats, 0, sizeof(bcl->stats));
728 spin_unlock_bh(&bc_lock);
729 return TIPC_OK;
730}
731
732int bclink_set_queue_limits(u32 limit)
733{
734 if (!bcl)
735 return -ENOPROTOOPT;
736 if ((limit < TIPC_MIN_LINK_WIN) || (limit > TIPC_MAX_LINK_WIN))
737 return -EINVAL;
738
739 spin_lock_bh(&bc_lock);
740 link_set_queue_limits(bcl, limit);
741 spin_unlock_bh(&bc_lock);
742 return TIPC_OK;
743}
744
745int bclink_init(void)
746{
747 bcbearer = kmalloc(sizeof(*bcbearer), GFP_ATOMIC);
748 bclink = kmalloc(sizeof(*bclink), GFP_ATOMIC);
749 if (!bcbearer || !bclink) {
750 nomem:
751 warn("Memory squeeze; Failed to create multicast link\n");
752 kfree(bcbearer);
753 bcbearer = NULL;
754 kfree(bclink);
755 bclink = NULL;
756 return -ENOMEM;
757 }
758
759 memset(bcbearer, 0, sizeof(struct bcbearer));
760 INIT_LIST_HEAD(&bcbearer->bearer.cong_links);
761 bcbearer->bearer.media = &bcbearer->media;
762 bcbearer->media.send_msg = bcbearer_send;
763 sprintf(bcbearer->media.name, "tipc-multicast");
764
765 bcl = &bclink->link;
766 memset(bclink, 0, sizeof(struct bclink));
767 INIT_LIST_HEAD(&bcl->waiting_ports);
768 bcl->next_out_no = 1;
769 bclink->node.lock = SPIN_LOCK_UNLOCKED;
770 bcl->owner = &bclink->node;
771 bcl->max_pkt = MAX_PKT_DEFAULT_MCAST;
772 link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);
773 bcl->b_ptr = &bcbearer->bearer;
774 bcl->state = WORKING_WORKING;
775 sprintf(bcl->name, bc_link_name);
776
777 if (BCLINK_LOG_BUF_SIZE) {
778 char *pb = kmalloc(BCLINK_LOG_BUF_SIZE, GFP_ATOMIC);
779
780 if (!pb)
781 goto nomem;
782 printbuf_init(&bcl->print_buf, pb, BCLINK_LOG_BUF_SIZE);
783 }
784
785 return TIPC_OK;
786}
787
788void bclink_stop(void)
789{
790 spin_lock_bh(&bc_lock);
791 if (bcbearer) {
792 link_stop(bcl);
793 if (BCLINK_LOG_BUF_SIZE)
794 kfree(bcl->print_buf.buf);
795 bcl = NULL;
796 kfree(bclink);
797 bclink = NULL;
798 kfree(bcbearer);
799 bcbearer = NULL;
800 }
801 spin_unlock_bh(&bc_lock);
802}
803