blob: eadba62afa85dcd9463f5eddd08704539fa63488 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/bcast.c: TIPC broadcast code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Jon Paul Maloy3c724ac2015-02-05 08:36:43 -05004 * Copyright (c) 2004-2006, 2014-2015, Ericsson AB
Per Lidenb97bf3f2006-01-02 19:04:38 +01005 * Copyright (c) 2004, Intel Corporation.
Allan Stephens2d627b92011-01-07 13:00:11 -05006 * Copyright (c) 2005, 2010-2011, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01007 * All rights reserved.
8 *
Per Liden9ea1fd32006-01-11 13:30:43 +01009 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +010010 * modification, are permitted provided that the following conditions are met:
11 *
Per Liden9ea1fd32006-01-11 13:30:43 +010012 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
Per Lidenb97bf3f2006-01-02 19:04:38 +010020 *
Per Liden9ea1fd32006-01-11 13:30:43 +010021 * Alternatively, this software may be distributed under the terms of the
22 * GNU General Public License ("GPL") version 2 as published by the Free
23 * Software Foundation.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Per Lidenb97bf3f2006-01-02 19:04:38 +010035 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
Jon Paul Maloy078bec82014-07-16 20:41:00 -040038#include "socket.h"
39#include "msg.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040#include "bcast.h"
Allan Stephens9f6bdcd42011-04-07 14:57:53 -040041#include "name_distr.h"
Ying Xue1da46562015-01-09 15:27:07 +080042#include "core.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010043
Ying Xue987b58b2014-03-27 12:54:35 +080044#define MAX_PKT_DEFAULT_MCAST 1500 /* bcast link max packet size (fixed) */
Jon Paul Maloy53387c42015-10-19 09:21:37 -040045#define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */
46#define BCLINK_WIN_MIN 32 /* bcast minimum link window size */
Allan Stephensc47e9b92011-10-24 10:29:26 -040047
Allan Stephens3aec9cc2010-05-11 14:30:07 +000048const char tipc_bclink_name[] = "broadcast-link";
Per Lidenb97bf3f2006-01-02 19:04:38 +010049
stephen hemminger31e3c3f2010-10-13 13:20:35 +000050static void tipc_nmap_diff(struct tipc_node_map *nm_a,
51 struct tipc_node_map *nm_b,
52 struct tipc_node_map *nm_diff);
Ying Xue28dd9412014-04-21 10:55:51 +080053static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node);
54static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node);
Per Lidenb97bf3f2006-01-02 19:04:38 +010055
Ying Xue1da46562015-01-09 15:27:07 +080056static void tipc_bclink_lock(struct net *net)
Ying Xued69afc92014-05-05 08:56:15 +080057{
Ying Xue1da46562015-01-09 15:27:07 +080058 struct tipc_net *tn = net_generic(net, tipc_net_id);
59
60 spin_lock_bh(&tn->bclink->lock);
Ying Xued69afc92014-05-05 08:56:15 +080061}
62
Ying Xue1da46562015-01-09 15:27:07 +080063static void tipc_bclink_unlock(struct net *net)
Ying Xued69afc92014-05-05 08:56:15 +080064{
Ying Xue1da46562015-01-09 15:27:07 +080065 struct tipc_net *tn = net_generic(net, tipc_net_id);
Ying Xue3f5a12b2014-05-05 08:56:17 +080066
Ying Xue1da46562015-01-09 15:27:07 +080067 spin_unlock_bh(&tn->bclink->lock);
Ying Xue3f5a12b2014-05-05 08:56:17 +080068}
69
Jon Paul Maloycb1b7282015-02-05 08:36:44 -050070void tipc_bclink_input(struct net *net)
71{
72 struct tipc_net *tn = net_generic(net, tipc_net_id);
73
74 tipc_sk_mcast_rcv(net, &tn->bclink->arrvq, &tn->bclink->inputq);
75}
76
Jon Paul Maloy078bec82014-07-16 20:41:00 -040077uint tipc_bclink_get_mtu(void)
78{
79 return MAX_PKT_DEFAULT_MCAST;
80}
81
Sam Ravnborg05790c62006-03-20 22:37:04 -080082static u32 bcbuf_acks(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +010083{
David S. Miller880b0052006-01-12 13:22:32 -080084 return (u32)(unsigned long)TIPC_SKB_CB(buf)->handle;
Per Lidenb97bf3f2006-01-02 19:04:38 +010085}
86
Sam Ravnborg05790c62006-03-20 22:37:04 -080087static void bcbuf_set_acks(struct sk_buff *buf, u32 acks)
Per Lidenb97bf3f2006-01-02 19:04:38 +010088{
David S. Miller880b0052006-01-12 13:22:32 -080089 TIPC_SKB_CB(buf)->handle = (void *)(unsigned long)acks;
Per Lidenb97bf3f2006-01-02 19:04:38 +010090}
91
Sam Ravnborg05790c62006-03-20 22:37:04 -080092static void bcbuf_decr_acks(struct sk_buff *buf)
Per Lidenb97bf3f2006-01-02 19:04:38 +010093{
94 bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);
95}
96
Ying Xue1da46562015-01-09 15:27:07 +080097void tipc_bclink_add_node(struct net *net, u32 addr)
Allan Stephenscd3decd2011-10-24 11:18:12 -040098{
Ying Xue1da46562015-01-09 15:27:07 +080099 struct tipc_net *tn = net_generic(net, tipc_net_id);
100
101 tipc_bclink_lock(net);
102 tipc_nmap_add(&tn->bclink->bcast_nodes, addr);
103 tipc_bclink_unlock(net);
Allan Stephenscd3decd2011-10-24 11:18:12 -0400104}
105
Ying Xue1da46562015-01-09 15:27:07 +0800106void tipc_bclink_remove_node(struct net *net, u32 addr)
Allan Stephenscd3decd2011-10-24 11:18:12 -0400107{
Ying Xue1da46562015-01-09 15:27:07 +0800108 struct tipc_net *tn = net_generic(net, tipc_net_id);
109
110 tipc_bclink_lock(net);
111 tipc_nmap_remove(&tn->bclink->bcast_nodes, addr);
Jon Paul Maloy7d967b62015-06-28 09:44:44 -0400112
113 /* Last node? => reset backlog queue */
114 if (!tn->bclink->bcast_nodes.count)
115 tipc_link_purge_backlog(&tn->bclink->link);
116
Ying Xue1da46562015-01-09 15:27:07 +0800117 tipc_bclink_unlock(net);
Allan Stephenscd3decd2011-10-24 11:18:12 -0400118}
Per Lidenb97bf3f2006-01-02 19:04:38 +0100119
Ying Xue1da46562015-01-09 15:27:07 +0800120static void bclink_set_last_sent(struct net *net)
Allan Stephens5b1f7bd2010-08-17 11:00:09 +0000121{
Ying Xue1da46562015-01-09 15:27:07 +0800122 struct tipc_net *tn = net_generic(net, tipc_net_id);
123 struct tipc_link *bcl = tn->bcl;
124
Jon Paul Maloydd3f9e72015-05-14 10:46:18 -0400125 bcl->silent_intv_cnt = mod(bcl->snd_nxt - 1);
Allan Stephens5b1f7bd2010-08-17 11:00:09 +0000126}
127
Ying Xue1da46562015-01-09 15:27:07 +0800128u32 tipc_bclink_get_last_sent(struct net *net)
Allan Stephens5b1f7bd2010-08-17 11:00:09 +0000129{
Ying Xue1da46562015-01-09 15:27:07 +0800130 struct tipc_net *tn = net_generic(net, tipc_net_id);
131
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400132 return tn->bcl->silent_intv_cnt;
Allan Stephens5b1f7bd2010-08-17 11:00:09 +0000133}
134
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400135static void bclink_update_last_sent(struct tipc_node *node, u32 seqno)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100136{
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400137 node->bclink.last_sent = less_eq(node->bclink.last_sent, seqno) ?
138 seqno : node->bclink.last_sent;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100139}
140
Ben Hutchings2c530402012-07-10 10:55:09 +0000141/**
Allan Stephens01d83ed2011-01-18 13:53:16 -0500142 * tipc_bclink_retransmit_to - get most recent node to request retransmission
143 *
Ying Xued69afc92014-05-05 08:56:15 +0800144 * Called with bclink_lock locked
Allan Stephens01d83ed2011-01-18 13:53:16 -0500145 */
Ying Xue1da46562015-01-09 15:27:07 +0800146struct tipc_node *tipc_bclink_retransmit_to(struct net *net)
Allan Stephens01d83ed2011-01-18 13:53:16 -0500147{
Ying Xue1da46562015-01-09 15:27:07 +0800148 struct tipc_net *tn = net_generic(net, tipc_net_id);
149
150 return tn->bclink->retransmit_to;
Allan Stephens01d83ed2011-01-18 13:53:16 -0500151}
152
153/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100154 * bclink_retransmit_pkt - retransmit broadcast packets
155 * @after: sequence number of last packet to *not* retransmit
156 * @to: sequence number of last packet to retransmit
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900157 *
Ying Xued69afc92014-05-05 08:56:15 +0800158 * Called with bclink_lock locked
Per Lidenb97bf3f2006-01-02 19:04:38 +0100159 */
Ying Xue1da46562015-01-09 15:27:07 +0800160static void bclink_retransmit_pkt(struct tipc_net *tn, u32 after, u32 to)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100161{
Ying Xue58dc55f2014-11-26 11:41:52 +0800162 struct sk_buff *skb;
Ying Xue1da46562015-01-09 15:27:07 +0800163 struct tipc_link *bcl = tn->bcl;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100164
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400165 skb_queue_walk(&bcl->transmq, skb) {
Jon Maloy703068e2015-01-09 15:26:58 +0800166 if (more(buf_seqno(skb), after)) {
167 tipc_link_retransmit(bcl, skb, mod(to - after));
Ying Xue58dc55f2014-11-26 11:41:52 +0800168 break;
Jon Maloy703068e2015-01-09 15:26:58 +0800169 }
Ying Xue58dc55f2014-11-26 11:41:52 +0800170 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100171}
172
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900173/**
Kolmakov Dmitriy78459892015-09-07 09:05:48 +0000174 * bclink_prepare_wakeup - prepare users for wakeup after congestion
175 * @bcl: broadcast link
176 * @resultq: queue for users which can be woken up
177 * Move a number of waiting users, as permitted by available space in
178 * the send queue, from link wait queue to specified queue for wakeup
179 */
180static void bclink_prepare_wakeup(struct tipc_link *bcl, struct sk_buff_head *resultq)
181{
182 int pnd[TIPC_SYSTEM_IMPORTANCE + 1] = {0,};
183 int imp, lim;
184 struct sk_buff *skb, *tmp;
185
186 skb_queue_walk_safe(&bcl->wakeupq, skb, tmp) {
187 imp = TIPC_SKB_CB(skb)->chain_imp;
188 lim = bcl->window + bcl->backlog[imp].limit;
189 pnd[imp] += TIPC_SKB_CB(skb)->chain_sz;
190 if ((pnd[imp] + bcl->backlog[imp].len) >= lim)
191 continue;
192 skb_unlink(skb, &bcl->wakeupq);
193 skb_queue_tail(resultq, skb);
194 }
195}
196
197/**
Jon Maloy908344c2014-10-07 14:12:34 -0400198 * tipc_bclink_wakeup_users - wake up pending users
199 *
200 * Called with no locks taken
201 */
Ying Xuef2f98002015-01-09 15:27:05 +0800202void tipc_bclink_wakeup_users(struct net *net)
Jon Maloy908344c2014-10-07 14:12:34 -0400203{
Ying Xue1da46562015-01-09 15:27:07 +0800204 struct tipc_net *tn = net_generic(net, tipc_net_id);
Kolmakov Dmitriy78459892015-09-07 09:05:48 +0000205 struct tipc_link *bcl = tn->bcl;
206 struct sk_buff_head resultq;
Erik Hugne4988bb42014-12-03 16:58:40 +0100207
Kolmakov Dmitriy78459892015-09-07 09:05:48 +0000208 skb_queue_head_init(&resultq);
209 bclink_prepare_wakeup(bcl, &resultq);
210 tipc_sk_rcv(net, &resultq);
Jon Maloy908344c2014-10-07 14:12:34 -0400211}
212
213/**
Per Liden4323add2006-01-18 00:38:21 +0100214 * tipc_bclink_acknowledge - handle acknowledgement of broadcast packets
Per Lidenb97bf3f2006-01-02 19:04:38 +0100215 * @n_ptr: node that sent acknowledgement info
216 * @acked: broadcast sequence # that has been acknowledged
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900217 *
Ying Xued69afc92014-05-05 08:56:15 +0800218 * Node is locked, bclink_lock unlocked.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100219 */
David S. Miller6c000552008-09-02 23:38:32 -0700220void tipc_bclink_acknowledge(struct tipc_node *n_ptr, u32 acked)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100221{
Ying Xue58dc55f2014-11-26 11:41:52 +0800222 struct sk_buff *skb, *tmp;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100223 unsigned int released = 0;
Ying Xue1da46562015-01-09 15:27:07 +0800224 struct net *net = n_ptr->net;
225 struct tipc_net *tn = net_generic(net, tipc_net_id);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100226
Jon Paul Maloy2cdf3912015-03-13 16:08:09 -0400227 if (unlikely(!n_ptr->bclink.recv_permitted))
228 return;
229
Ying Xue1da46562015-01-09 15:27:07 +0800230 tipc_bclink_lock(net);
Jon Paul Maloy2cdf3912015-03-13 16:08:09 -0400231
Allan Stephens365595912011-10-24 15:26:24 -0400232 /* Bail out if tx queue is empty (no clean up is required) */
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400233 skb = skb_peek(&tn->bcl->transmq);
Ying Xue58dc55f2014-11-26 11:41:52 +0800234 if (!skb)
Allan Stephens365595912011-10-24 15:26:24 -0400235 goto exit;
236
237 /* Determine which messages need to be acknowledged */
238 if (acked == INVALID_LINK_SEQ) {
239 /*
240 * Contact with specified node has been lost, so need to
241 * acknowledge sent messages only (if other nodes still exist)
242 * or both sent and unsent messages (otherwise)
243 */
Ying Xue1da46562015-01-09 15:27:07 +0800244 if (tn->bclink->bcast_nodes.count)
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400245 acked = tn->bcl->silent_intv_cnt;
Allan Stephens365595912011-10-24 15:26:24 -0400246 else
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400247 acked = tn->bcl->snd_nxt;
Allan Stephens365595912011-10-24 15:26:24 -0400248 } else {
249 /*
250 * Bail out if specified sequence number does not correspond
251 * to a message that has been sent and not yet acknowledged
252 */
Ying Xue58dc55f2014-11-26 11:41:52 +0800253 if (less(acked, buf_seqno(skb)) ||
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400254 less(tn->bcl->silent_intv_cnt, acked) ||
Allan Stephens365595912011-10-24 15:26:24 -0400255 less_eq(acked, n_ptr->bclink.acked))
256 goto exit;
257 }
258
259 /* Skip over packets that node has previously acknowledged */
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400260 skb_queue_walk(&tn->bcl->transmq, skb) {
Ying Xue58dc55f2014-11-26 11:41:52 +0800261 if (more(buf_seqno(skb), n_ptr->bclink.acked))
262 break;
263 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100264
265 /* Update packets that node is now acknowledging */
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400266 skb_queue_walk_from_safe(&tn->bcl->transmq, skb, tmp) {
Ying Xue58dc55f2014-11-26 11:41:52 +0800267 if (more(buf_seqno(skb), acked))
268 break;
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400269 bcbuf_decr_acks(skb);
270 bclink_set_last_sent(net);
Ying Xue58dc55f2014-11-26 11:41:52 +0800271 if (bcbuf_acks(skb) == 0) {
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400272 __skb_unlink(skb, &tn->bcl->transmq);
Ying Xue58dc55f2014-11-26 11:41:52 +0800273 kfree_skb(skb);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100274 released = 1;
275 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100276 }
277 n_ptr->bclink.acked = acked;
278
279 /* Try resolving broadcast link congestion, if necessary */
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400280 if (unlikely(skb_peek(&tn->bcl->backlogq))) {
Ying Xue1da46562015-01-09 15:27:07 +0800281 tipc_link_push_packets(tn->bcl);
282 bclink_set_last_sent(net);
Allan Stephens5b1f7bd2010-08-17 11:00:09 +0000283 }
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500284 if (unlikely(released && !skb_queue_empty(&tn->bcl->wakeupq)))
Jon Maloy908344c2014-10-07 14:12:34 -0400285 n_ptr->action_flags |= TIPC_WAKEUP_BCAST_USERS;
Allan Stephens365595912011-10-24 15:26:24 -0400286exit:
Ying Xue1da46562015-01-09 15:27:07 +0800287 tipc_bclink_unlock(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100288}
289
Ben Hutchings2c530402012-07-10 10:55:09 +0000290/**
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400291 * tipc_bclink_update_link_state - update broadcast link state
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900292 *
Ying Xue7216cd92014-04-21 10:55:48 +0800293 * RCU and node lock set
Per Lidenb97bf3f2006-01-02 19:04:38 +0100294 */
Jon Paul Maloyc5898632015-02-05 08:36:36 -0500295void tipc_bclink_update_link_state(struct tipc_node *n_ptr,
Ying Xuec93d3ba2015-01-09 15:27:04 +0800296 u32 last_sent)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100297{
298 struct sk_buff *buf;
Jon Paul Maloyc5898632015-02-05 08:36:36 -0500299 struct net *net = n_ptr->net;
Ying Xuec93d3ba2015-01-09 15:27:04 +0800300 struct tipc_net *tn = net_generic(net, tipc_net_id);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100301
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400302 /* Ignore "stale" link state info */
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400303 if (less_eq(last_sent, n_ptr->bclink.last_in))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100304 return;
305
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400306 /* Update link synchronization state; quit if in sync */
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400307 bclink_update_last_sent(n_ptr, last_sent);
308
309 if (n_ptr->bclink.last_sent == n_ptr->bclink.last_in)
310 return;
311
312 /* Update out-of-sync state; quit if loss is still unconfirmed */
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400313 if ((++n_ptr->bclink.oos_state) == 1) {
314 if (n_ptr->bclink.deferred_size < (TIPC_MIN_LINK_WIN / 2))
315 return;
316 n_ptr->bclink.oos_state++;
317 }
318
319 /* Don't NACK if one has been recently sent (or seen) */
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400320 if (n_ptr->bclink.oos_state & 0x1)
321 return;
322
323 /* Send NACK */
stephen hemminger31e3c3f2010-10-13 13:20:35 +0000324 buf = tipc_buf_acquire(INT_H_SIZE);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100325 if (buf) {
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400326 struct tipc_msg *msg = buf_msg(buf);
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400327 struct sk_buff *skb = skb_peek(&n_ptr->bclink.deferdq);
Ying Xuebc6fecd2014-11-26 11:41:53 +0800328 u32 to = skb ? buf_seqno(skb) - 1 : n_ptr->bclink.last_sent;
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400329
Jon Paul Maloyc5898632015-02-05 08:36:36 -0500330 tipc_msg_init(tn->own_addr, msg, BCAST_PROTOCOL, STATE_MSG,
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400331 INT_H_SIZE, n_ptr->addr);
Allan Stephensbf781ec2011-01-25 16:12:39 -0500332 msg_set_non_seq(msg, 1);
Ying Xuec93d3ba2015-01-09 15:27:04 +0800333 msg_set_mc_netid(msg, tn->net_id);
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400334 msg_set_bcast_ack(msg, n_ptr->bclink.last_in);
335 msg_set_bcgap_after(msg, n_ptr->bclink.last_in);
Ying Xuebc6fecd2014-11-26 11:41:53 +0800336 msg_set_bcgap_to(msg, to);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100337
Ying Xue1da46562015-01-09 15:27:07 +0800338 tipc_bclink_lock(net);
Ying Xue7f9f95d2015-01-09 15:27:06 +0800339 tipc_bearer_send(net, MAX_BEARERS, buf, NULL);
Ying Xue1da46562015-01-09 15:27:07 +0800340 tn->bcl->stats.sent_nacks++;
341 tipc_bclink_unlock(net);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400342 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100343
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400344 n_ptr->bclink.oos_state++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100345 }
346}
347
Jon Paul Maloyd9992972015-07-16 16:54:31 -0400348void tipc_bclink_sync_state(struct tipc_node *n, struct tipc_msg *hdr)
349{
350 u16 last = msg_last_bcast(hdr);
351 int mtyp = msg_type(hdr);
352
353 if (unlikely(msg_user(hdr) != LINK_PROTOCOL))
354 return;
355 if (mtyp == STATE_MSG) {
356 tipc_bclink_update_link_state(n, last);
357 return;
358 }
359 /* Compatibility: older nodes don't know BCAST_PROTOCOL synchronization,
360 * and transfer synch info in LINK_PROTOCOL messages.
361 */
362 if (tipc_node_is_up(n))
363 return;
364 if ((mtyp != RESET_MSG) && (mtyp != ACTIVATE_MSG))
365 return;
366 n->bclink.last_sent = last;
367 n->bclink.last_in = last;
368 n->bclink.oos_state = 0;
369}
370
Ben Hutchings2c530402012-07-10 10:55:09 +0000371/**
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400372 * bclink_peek_nack - monitor retransmission requests sent by other nodes
Per Lidenb97bf3f2006-01-02 19:04:38 +0100373 *
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400374 * Delay any upcoming NACK by this node if another node has already
375 * requested the first message this node is going to ask for.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100376 */
Ying Xuef2f98002015-01-09 15:27:05 +0800377static void bclink_peek_nack(struct net *net, struct tipc_msg *msg)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100378{
Ying Xuef2f98002015-01-09 15:27:05 +0800379 struct tipc_node *n_ptr = tipc_node_find(net, msg_destnode(msg));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100380
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400381 if (unlikely(!n_ptr))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100382 return;
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400383
Per Liden4323add2006-01-18 00:38:21 +0100384 tipc_node_lock(n_ptr);
Ying Xue389dd9b2012-11-16 13:51:30 +0800385 if (n_ptr->bclink.recv_permitted &&
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400386 (n_ptr->bclink.last_in != n_ptr->bclink.last_sent) &&
387 (n_ptr->bclink.last_in == msg_bcgap_after(msg)))
388 n_ptr->bclink.oos_state = 2;
Per Liden4323add2006-01-18 00:38:21 +0100389 tipc_node_unlock(n_ptr);
Ying Xue8a0f6eb2015-03-26 18:10:24 +0800390 tipc_node_put(n_ptr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100391}
392
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500393/* tipc_bclink_xmit - deliver buffer chain to all nodes in cluster
Jon Paul Maloy9fbfb8b2014-07-16 20:41:03 -0400394 * and to identified node local sockets
Ying Xuef2f98002015-01-09 15:27:05 +0800395 * @net: the applicable net namespace
Ying Xuea6ca1092014-11-26 11:41:55 +0800396 * @list: chain of buffers containing message
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400397 * Consumes the buffer chain, except when returning -ELINKCONG
398 * Returns 0 if success, otherwise errno: -ELINKCONG,-EHOSTUNREACH,-EMSGSIZE
399 */
Ying Xuef2f98002015-01-09 15:27:05 +0800400int tipc_bclink_xmit(struct net *net, struct sk_buff_head *list)
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400401{
Ying Xue1da46562015-01-09 15:27:07 +0800402 struct tipc_net *tn = net_generic(net, tipc_net_id);
403 struct tipc_link *bcl = tn->bcl;
404 struct tipc_bclink *bclink = tn->bclink;
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400405 int rc = 0;
406 int bc = 0;
Ying Xuea6ca1092014-11-26 11:41:55 +0800407 struct sk_buff *skb;
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500408 struct sk_buff_head arrvq;
409 struct sk_buff_head inputq;
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400410
411 /* Prepare clone of message for local node */
Ying Xuea6ca1092014-11-26 11:41:55 +0800412 skb = tipc_msg_reassemble(list);
Jon Paul Maloy22d85c72015-07-16 16:54:23 -0400413 if (unlikely(!skb))
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400414 return -EHOSTUNREACH;
Jon Paul Maloy22d85c72015-07-16 16:54:23 -0400415
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500416 /* Broadcast to all nodes */
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400417 if (likely(bclink)) {
Ying Xue1da46562015-01-09 15:27:07 +0800418 tipc_bclink_lock(net);
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400419 if (likely(bclink->bcast_nodes.count)) {
Ying Xue7f9f95d2015-01-09 15:27:06 +0800420 rc = __tipc_link_xmit(net, bcl, list);
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400421 if (likely(!rc)) {
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400422 u32 len = skb_queue_len(&bcl->transmq);
Ying Xue58dc55f2014-11-26 11:41:52 +0800423
Ying Xue1da46562015-01-09 15:27:07 +0800424 bclink_set_last_sent(net);
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400425 bcl->stats.queue_sz_counts++;
Ying Xue58dc55f2014-11-26 11:41:52 +0800426 bcl->stats.accu_queue_sz += len;
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400427 }
428 bc = 1;
429 }
Ying Xue1da46562015-01-09 15:27:07 +0800430 tipc_bclink_unlock(net);
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400431 }
432
433 if (unlikely(!bc))
Ying Xuea6ca1092014-11-26 11:41:55 +0800434 __skb_queue_purge(list);
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400435
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500436 if (unlikely(rc)) {
Ying Xuea6ca1092014-11-26 11:41:55 +0800437 kfree_skb(skb);
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500438 return rc;
439 }
440 /* Deliver message clone */
441 __skb_queue_head_init(&arrvq);
442 skb_queue_head_init(&inputq);
443 __skb_queue_tail(&arrvq, skb);
444 tipc_sk_mcast_rcv(net, &arrvq, &inputq);
Jon Paul Maloy078bec82014-07-16 20:41:00 -0400445 return rc;
446}
447
Ben Hutchings2c530402012-07-10 10:55:09 +0000448/**
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400449 * bclink_accept_pkt - accept an incoming, in-sequence broadcast packet
450 *
Ying Xued69afc92014-05-05 08:56:15 +0800451 * Called with both sending node's lock and bclink_lock taken.
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400452 */
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400453static void bclink_accept_pkt(struct tipc_node *node, u32 seqno)
454{
Ying Xue1da46562015-01-09 15:27:07 +0800455 struct tipc_net *tn = net_generic(node->net, tipc_net_id);
456
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400457 bclink_update_last_sent(node, seqno);
458 node->bclink.last_in = seqno;
459 node->bclink.oos_state = 0;
Ying Xue1da46562015-01-09 15:27:07 +0800460 tn->bcl->stats.recv_info++;
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400461
462 /*
463 * Unicast an ACK periodically, ensuring that
464 * all nodes in the cluster don't ACK at the same time
465 */
Ying Xue34747532015-01-09 15:27:10 +0800466 if (((seqno - tn->own_addr) % TIPC_MIN_LINK_WIN) == 0) {
Jon Paul Maloy9d13ec62015-07-16 16:54:19 -0400467 tipc_link_proto_xmit(node_active_link(node, node->addr),
Jon Paul Maloyed193ec2015-04-02 09:33:02 -0400468 STATE_MSG, 0, 0, 0, 0);
Ying Xue1da46562015-01-09 15:27:07 +0800469 tn->bcl->stats.sent_acks++;
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400470 }
471}
472
Ben Hutchings2c530402012-07-10 10:55:09 +0000473/**
Ying Xue247f0f32014-02-18 16:06:46 +0800474 * tipc_bclink_rcv - receive a broadcast packet, and deliver upwards
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900475 *
Ying Xue7216cd92014-04-21 10:55:48 +0800476 * RCU is locked, no other locks set
Per Lidenb97bf3f2006-01-02 19:04:38 +0100477 */
Ying Xuec93d3ba2015-01-09 15:27:04 +0800478void tipc_bclink_rcv(struct net *net, struct sk_buff *buf)
Allan Stephensd356eeb2006-06-25 23:40:01 -0700479{
Ying Xuec93d3ba2015-01-09 15:27:04 +0800480 struct tipc_net *tn = net_generic(net, tipc_net_id);
Ying Xue1da46562015-01-09 15:27:07 +0800481 struct tipc_link *bcl = tn->bcl;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100482 struct tipc_msg *msg = buf_msg(buf);
Allan Stephens5d3c4882011-04-07 13:57:25 -0400483 struct tipc_node *node;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100484 u32 next_in;
485 u32 seqno;
Jon Paul Maloy0abd8ff2014-07-16 20:41:01 -0400486 int deferred = 0;
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500487 int pos = 0;
488 struct sk_buff *iskb;
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500489 struct sk_buff_head *arrvq, *inputq;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100490
Allan Stephens5d3c4882011-04-07 13:57:25 -0400491 /* Screen out unwanted broadcast messages */
Ying Xuec93d3ba2015-01-09 15:27:04 +0800492 if (msg_mc_netid(msg) != tn->net_id)
Allan Stephens5d3c4882011-04-07 13:57:25 -0400493 goto exit;
494
Ying Xuef2f98002015-01-09 15:27:05 +0800495 node = tipc_node_find(net, msg_prevnode(msg));
Allan Stephens5d3c4882011-04-07 13:57:25 -0400496 if (unlikely(!node))
497 goto exit;
498
499 tipc_node_lock(node);
Ying Xue389dd9b2012-11-16 13:51:30 +0800500 if (unlikely(!node->bclink.recv_permitted))
Allan Stephens5d3c4882011-04-07 13:57:25 -0400501 goto unlock;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100502
Allan Stephens8a275a62011-10-26 15:33:44 -0400503 /* Handle broadcast protocol message */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100504 if (unlikely(msg_user(msg) == BCAST_PROTOCOL)) {
Allan Stephens9f6bdcd42011-04-07 14:57:53 -0400505 if (msg_type(msg) != STATE_MSG)
506 goto unlock;
Ying Xue34747532015-01-09 15:27:10 +0800507 if (msg_destnode(msg) == tn->own_addr) {
Per Liden4323add2006-01-18 00:38:21 +0100508 tipc_bclink_acknowledge(node, msg_bcast_ack(msg));
Ying Xue1da46562015-01-09 15:27:07 +0800509 tipc_bclink_lock(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100510 bcl->stats.recv_nacks++;
Ying Xue1da46562015-01-09 15:27:07 +0800511 tn->bclink->retransmit_to = node;
512 bclink_retransmit_pkt(tn, msg_bcgap_after(msg),
Per Lidenb97bf3f2006-01-02 19:04:38 +0100513 msg_bcgap_to(msg));
Ying Xue1da46562015-01-09 15:27:07 +0800514 tipc_bclink_unlock(net);
Ying Xueb952b2b2015-03-26 18:10:23 +0800515 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100516 } else {
Allan Stephens5d3c4882011-04-07 13:57:25 -0400517 tipc_node_unlock(node);
Ying Xuef2f98002015-01-09 15:27:05 +0800518 bclink_peek_nack(net, msg);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100519 }
Ying Xue8a0f6eb2015-03-26 18:10:24 +0800520 tipc_node_put(node);
Allan Stephens5d3c4882011-04-07 13:57:25 -0400521 goto exit;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100522 }
523
Allan Stephens5d3c4882011-04-07 13:57:25 -0400524 /* Handle in-sequence broadcast message */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100525 seqno = msg_seqno(msg);
Allan Stephens8a275a62011-10-26 15:33:44 -0400526 next_in = mod(node->bclink.last_in + 1);
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500527 arrvq = &tn->bclink->arrvq;
528 inputq = &tn->bclink->inputq;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100529
530 if (likely(seqno == next_in)) {
Allan Stephens8a275a62011-10-26 15:33:44 -0400531receive:
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400532 /* Deliver message to destination */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100533 if (likely(msg_isdata(msg))) {
Ying Xue1da46562015-01-09 15:27:07 +0800534 tipc_bclink_lock(net);
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400535 bclink_accept_pkt(node, seqno);
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500536 spin_lock_bh(&inputq->lock);
537 __skb_queue_tail(arrvq, buf);
538 spin_unlock_bh(&inputq->lock);
539 node->action_flags |= TIPC_BCAST_MSG_EVT;
Ying Xue1da46562015-01-09 15:27:07 +0800540 tipc_bclink_unlock(net);
Per Liden4323add2006-01-18 00:38:21 +0100541 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100542 } else if (msg_user(msg) == MSG_BUNDLER) {
Ying Xue1da46562015-01-09 15:27:07 +0800543 tipc_bclink_lock(net);
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400544 bclink_accept_pkt(node, seqno);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100545 bcl->stats.recv_bundles++;
546 bcl->stats.recv_bundled += msg_msgcnt(msg);
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500547 pos = 0;
548 while (tipc_msg_extract(buf, &iskb, &pos)) {
549 spin_lock_bh(&inputq->lock);
550 __skb_queue_tail(arrvq, iskb);
551 spin_unlock_bh(&inputq->lock);
552 }
553 node->action_flags |= TIPC_BCAST_MSG_EVT;
Ying Xue1da46562015-01-09 15:27:07 +0800554 tipc_bclink_unlock(net);
Per Liden4323add2006-01-18 00:38:21 +0100555 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100556 } else if (msg_user(msg) == MSG_FRAGMENTER) {
Ying Xue1da46562015-01-09 15:27:07 +0800557 tipc_bclink_lock(net);
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400558 bclink_accept_pkt(node, seqno);
Ying Xuebc14b8d2015-03-25 18:09:40 +0800559 tipc_buf_append(&node->bclink.reasm_buf, &buf);
560 if (unlikely(!buf && !node->bclink.reasm_buf)) {
561 tipc_bclink_unlock(net);
562 goto unlock;
563 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100564 bcl->stats.recv_fragments++;
Jon Paul Maloy37e22162014-05-14 05:39:12 -0400565 if (buf) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100566 bcl->stats.recv_fragmented++;
Erik Hugne40ba3cd2013-11-06 09:28:06 +0100567 msg = buf_msg(buf);
Ying Xue1da46562015-01-09 15:27:07 +0800568 tipc_bclink_unlock(net);
Erik Hugne528f6f42013-11-06 09:28:05 +0100569 goto receive;
570 }
Ying Xue1da46562015-01-09 15:27:07 +0800571 tipc_bclink_unlock(net);
Per Liden4323add2006-01-18 00:38:21 +0100572 tipc_node_unlock(node);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100573 } else {
Ying Xue1da46562015-01-09 15:27:07 +0800574 tipc_bclink_lock(net);
Allan Stephens63e7f1a2011-10-27 16:43:09 -0400575 bclink_accept_pkt(node, seqno);
Ying Xue1da46562015-01-09 15:27:07 +0800576 tipc_bclink_unlock(net);
Per Liden4323add2006-01-18 00:38:21 +0100577 tipc_node_unlock(node);
Allan Stephens5f6d9122011-11-04 13:24:29 -0400578 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100579 }
Allan Stephens5d3c4882011-04-07 13:57:25 -0400580 buf = NULL;
Allan Stephens8a275a62011-10-26 15:33:44 -0400581
582 /* Determine new synchronization state */
Allan Stephens5d3c4882011-04-07 13:57:25 -0400583 tipc_node_lock(node);
Allan Stephens8a275a62011-10-26 15:33:44 -0400584 if (unlikely(!tipc_node_is_up(node)))
585 goto unlock;
586
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400587 if (node->bclink.last_in == node->bclink.last_sent)
Allan Stephens8a275a62011-10-26 15:33:44 -0400588 goto unlock;
589
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400590 if (skb_queue_empty(&node->bclink.deferdq)) {
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400591 node->bclink.oos_state = 1;
592 goto unlock;
593 }
594
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400595 msg = buf_msg(skb_peek(&node->bclink.deferdq));
Allan Stephens8a275a62011-10-26 15:33:44 -0400596 seqno = msg_seqno(msg);
597 next_in = mod(next_in + 1);
598 if (seqno != next_in)
599 goto unlock;
600
601 /* Take in-sequence message from deferred queue & deliver it */
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400602 buf = __skb_dequeue(&node->bclink.deferdq);
Allan Stephens8a275a62011-10-26 15:33:44 -0400603 goto receive;
604 }
605
606 /* Handle out-of-sequence broadcast message */
Allan Stephens8a275a62011-10-26 15:33:44 -0400607 if (less(next_in, seqno)) {
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400608 deferred = tipc_link_defer_pkt(&node->bclink.deferdq,
Allan Stephens8a275a62011-10-26 15:33:44 -0400609 buf);
Allan Stephens7a54d4a2011-10-27 14:17:53 -0400610 bclink_update_last_sent(node, seqno);
Allan Stephens5d3c4882011-04-07 13:57:25 -0400611 buf = NULL;
Jon Paul Maloy0abd8ff2014-07-16 20:41:01 -0400612 }
Allan Stephens8a275a62011-10-26 15:33:44 -0400613
Ying Xue1da46562015-01-09 15:27:07 +0800614 tipc_bclink_lock(net);
Allan Stephensb98158e2011-10-26 16:13:35 -0400615
Allan Stephens8a275a62011-10-26 15:33:44 -0400616 if (deferred)
617 bcl->stats.deferred_recv++;
Allan Stephens0232c5a2011-10-26 15:57:26 -0400618 else
619 bcl->stats.duplicates++;
Allan Stephens8a275a62011-10-26 15:33:44 -0400620
Ying Xue1da46562015-01-09 15:27:07 +0800621 tipc_bclink_unlock(net);
Allan Stephensb98158e2011-10-26 16:13:35 -0400622
Allan Stephens5d3c4882011-04-07 13:57:25 -0400623unlock:
Per Liden4323add2006-01-18 00:38:21 +0100624 tipc_node_unlock(node);
Ying Xue8a0f6eb2015-03-26 18:10:24 +0800625 tipc_node_put(node);
Allan Stephens5d3c4882011-04-07 13:57:25 -0400626exit:
Allan Stephens5f6d9122011-11-04 13:24:29 -0400627 kfree_skb(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100628}
629
David S. Miller6c000552008-09-02 23:38:32 -0700630u32 tipc_bclink_acks_missing(struct tipc_node *n_ptr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100631{
Ying Xue389dd9b2012-11-16 13:51:30 +0800632 return (n_ptr->bclink.recv_permitted &&
Ying Xue1da46562015-01-09 15:27:07 +0800633 (tipc_bclink_get_last_sent(n_ptr->net) != n_ptr->bclink.acked));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100634}
635
636
637/**
Per Liden4323add2006-01-18 00:38:21 +0100638 * tipc_bcbearer_send - send a packet through the broadcast pseudo-bearer
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900639 *
Allan Stephens2ff9f922011-04-07 10:44:54 -0400640 * Send packet over as many bearers as necessary to reach all nodes
641 * that have joined the broadcast link.
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900642 *
Allan Stephens2ff9f922011-04-07 10:44:54 -0400643 * Returns 0 (packet sent successfully) under all circumstances,
644 * since the broadcast link's pseudo-bearer never blocks
Per Lidenb97bf3f2006-01-02 19:04:38 +0100645 */
Ying Xue1da46562015-01-09 15:27:07 +0800646static int tipc_bcbearer_send(struct net *net, struct sk_buff *buf,
647 struct tipc_bearer *unused1,
Adrian Bunk988f0882006-03-20 22:37:52 -0800648 struct tipc_media_addr *unused2)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100649{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100650 int bp_index;
Jon Paul Maloy6f92ee52014-07-16 20:41:04 -0400651 struct tipc_msg *msg = buf_msg(buf);
Ying Xuec93d3ba2015-01-09 15:27:04 +0800652 struct tipc_net *tn = net_generic(net, tipc_net_id);
Ying Xue1da46562015-01-09 15:27:07 +0800653 struct tipc_bcbearer *bcbearer = tn->bcbearer;
654 struct tipc_bclink *bclink = tn->bclink;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100655
Gerlando Falautoe6160712013-05-01 12:04:44 +0000656 /* Prepare broadcast link message for reliable transmission,
Allan Stephens2ff9f922011-04-07 10:44:54 -0400657 * if first time trying to send it;
658 * preparation is skipped for broadcast link protocol messages
659 * since they are sent in an unreliable manner and don't need it
660 */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100661 if (likely(!msg_non_seq(buf_msg(buf)))) {
Allan Stephenscd3decd2011-10-24 11:18:12 -0400662 bcbuf_set_acks(buf, bclink->bcast_nodes.count);
Allan Stephens40aecb12008-06-04 17:54:48 -0700663 msg_set_non_seq(msg, 1);
Ying Xuec93d3ba2015-01-09 15:27:04 +0800664 msg_set_mc_netid(msg, tn->net_id);
Ying Xue1da46562015-01-09 15:27:07 +0800665 tn->bcl->stats.sent_info++;
Allan Stephenscd3decd2011-10-24 11:18:12 -0400666 if (WARN_ON(!bclink->bcast_nodes.count)) {
Allan Stephens5e726902011-05-23 13:14:18 -0400667 dump_stack();
668 return 0;
669 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100670 }
671
Per Lidenb97bf3f2006-01-02 19:04:38 +0100672 /* Send buffer over bearers until all targets reached */
Allan Stephenscd3decd2011-10-24 11:18:12 -0400673 bcbearer->remains = bclink->bcast_nodes;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100674
675 for (bp_index = 0; bp_index < MAX_BEARERS; bp_index++) {
Allan Stephens2d627b92011-01-07 13:00:11 -0500676 struct tipc_bearer *p = bcbearer->bpairs[bp_index].primary;
677 struct tipc_bearer *s = bcbearer->bpairs[bp_index].secondary;
Jon Paul Maloy6f92ee52014-07-16 20:41:04 -0400678 struct tipc_bearer *bp[2] = {p, s};
679 struct tipc_bearer *b = bp[msg_link_selector(msg)];
Gerlando Falauto488fc9a2013-05-01 12:04:46 +0000680 struct sk_buff *tbuf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100681
682 if (!p)
Gerlando Falautoe6160712013-05-01 12:04:44 +0000683 break; /* No more bearers to try */
Jon Paul Maloy6f92ee52014-07-16 20:41:04 -0400684 if (!b)
685 b = p;
Gerlando Falauto77861d92013-05-01 12:04:45 +0000686 tipc_nmap_diff(&bcbearer->remains, &b->nodes,
Gerlando Falautoe6160712013-05-01 12:04:44 +0000687 &bcbearer->remains_new);
Allan Stephens65f51ef2006-06-25 23:53:20 -0700688 if (bcbearer->remains_new.count == bcbearer->remains.count)
Gerlando Falautoe6160712013-05-01 12:04:44 +0000689 continue; /* Nothing added by bearer pair */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100690
Gerlando Falauto488fc9a2013-05-01 12:04:46 +0000691 if (bp_index == 0) {
692 /* Use original buffer for first bearer */
Ying Xue7f9f95d2015-01-09 15:27:06 +0800693 tipc_bearer_send(net, b->identity, buf, &b->bcast_addr);
Gerlando Falauto488fc9a2013-05-01 12:04:46 +0000694 } else {
695 /* Avoid concurrent buffer access */
Octavian Purdilabad93e92014-06-12 01:36:26 +0300696 tbuf = pskb_copy_for_clone(buf, GFP_ATOMIC);
Gerlando Falauto488fc9a2013-05-01 12:04:46 +0000697 if (!tbuf)
698 break;
Ying Xue7f9f95d2015-01-09 15:27:06 +0800699 tipc_bearer_send(net, b->identity, tbuf,
700 &b->bcast_addr);
Gerlando Falauto488fc9a2013-05-01 12:04:46 +0000701 kfree_skb(tbuf); /* Bearer keeps a clone */
702 }
Allan Stephens65f51ef2006-06-25 23:53:20 -0700703 if (bcbearer->remains_new.count == 0)
Gerlando Falautoe6160712013-05-01 12:04:44 +0000704 break; /* All targets reached */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100705
Allan Stephens65f51ef2006-06-25 23:53:20 -0700706 bcbearer->remains = bcbearer->remains_new;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100707 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900708
Allan Stephens2ff9f922011-04-07 10:44:54 -0400709 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100710}
711
712/**
Per Liden4323add2006-01-18 00:38:21 +0100713 * tipc_bcbearer_sort - create sets of bearer pairs used by broadcast bearer
Per Lidenb97bf3f2006-01-02 19:04:38 +0100714 */
Ying Xue7f9f95d2015-01-09 15:27:06 +0800715void tipc_bcbearer_sort(struct net *net, struct tipc_node_map *nm_ptr,
716 u32 node, bool action)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100717{
Ying Xue7f9f95d2015-01-09 15:27:06 +0800718 struct tipc_net *tn = net_generic(net, tipc_net_id);
Ying Xue1da46562015-01-09 15:27:07 +0800719 struct tipc_bcbearer *bcbearer = tn->bcbearer;
Paul Gortmaker7f9ab6a2011-12-29 20:55:27 -0500720 struct tipc_bcbearer_pair *bp_temp = bcbearer->bpairs_temp;
721 struct tipc_bcbearer_pair *bp_curr;
Ying Xuef8322df2014-04-21 10:55:45 +0800722 struct tipc_bearer *b;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100723 int b_index;
724 int pri;
725
Ying Xue1da46562015-01-09 15:27:07 +0800726 tipc_bclink_lock(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100727
Ying Xue28dd9412014-04-21 10:55:51 +0800728 if (action)
729 tipc_nmap_add(nm_ptr, node);
730 else
731 tipc_nmap_remove(nm_ptr, node);
732
Per Lidenb97bf3f2006-01-02 19:04:38 +0100733 /* Group bearers by priority (can assume max of two per priority) */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100734 memset(bp_temp, 0, sizeof(bcbearer->bpairs_temp));
735
Ying Xuef8322df2014-04-21 10:55:45 +0800736 rcu_read_lock();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100737 for (b_index = 0; b_index < MAX_BEARERS; b_index++) {
Ying Xue7f9f95d2015-01-09 15:27:06 +0800738 b = rcu_dereference_rtnl(tn->bearer_list[b_index]);
Ying Xuef47de122014-03-27 12:54:34 +0800739 if (!b || !b->nodes.count)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100740 continue;
741
742 if (!bp_temp[b->priority].primary)
743 bp_temp[b->priority].primary = b;
744 else
745 bp_temp[b->priority].secondary = b;
746 }
Ying Xuef8322df2014-04-21 10:55:45 +0800747 rcu_read_unlock();
Per Lidenb97bf3f2006-01-02 19:04:38 +0100748
749 /* Create array of bearer pairs for broadcasting */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100750 bp_curr = bcbearer->bpairs;
751 memset(bcbearer->bpairs, 0, sizeof(bcbearer->bpairs));
752
Per Liden16cb4b32006-01-13 22:22:22 +0100753 for (pri = TIPC_MAX_LINK_PRI; pri >= 0; pri--) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100754
755 if (!bp_temp[pri].primary)
756 continue;
757
758 bp_curr->primary = bp_temp[pri].primary;
759
760 if (bp_temp[pri].secondary) {
Per Liden4323add2006-01-18 00:38:21 +0100761 if (tipc_nmap_equal(&bp_temp[pri].primary->nodes,
762 &bp_temp[pri].secondary->nodes)) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100763 bp_curr->secondary = bp_temp[pri].secondary;
764 } else {
765 bp_curr++;
766 bp_curr->primary = bp_temp[pri].secondary;
767 }
768 }
769
770 bp_curr++;
771 }
772
Ying Xue1da46562015-01-09 15:27:07 +0800773 tipc_bclink_unlock(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100774}
775
Richard Alped8182802014-11-24 11:10:29 +0100776static int __tipc_nl_add_bc_link_stat(struct sk_buff *skb,
777 struct tipc_stats *stats)
Richard Alpe7be57fc2014-11-20 10:29:12 +0100778{
779 int i;
780 struct nlattr *nest;
781
782 struct nla_map {
783 __u32 key;
784 __u32 val;
785 };
786
787 struct nla_map map[] = {
788 {TIPC_NLA_STATS_RX_INFO, stats->recv_info},
789 {TIPC_NLA_STATS_RX_FRAGMENTS, stats->recv_fragments},
790 {TIPC_NLA_STATS_RX_FRAGMENTED, stats->recv_fragmented},
791 {TIPC_NLA_STATS_RX_BUNDLES, stats->recv_bundles},
792 {TIPC_NLA_STATS_RX_BUNDLED, stats->recv_bundled},
793 {TIPC_NLA_STATS_TX_INFO, stats->sent_info},
794 {TIPC_NLA_STATS_TX_FRAGMENTS, stats->sent_fragments},
795 {TIPC_NLA_STATS_TX_FRAGMENTED, stats->sent_fragmented},
796 {TIPC_NLA_STATS_TX_BUNDLES, stats->sent_bundles},
797 {TIPC_NLA_STATS_TX_BUNDLED, stats->sent_bundled},
798 {TIPC_NLA_STATS_RX_NACKS, stats->recv_nacks},
799 {TIPC_NLA_STATS_RX_DEFERRED, stats->deferred_recv},
800 {TIPC_NLA_STATS_TX_NACKS, stats->sent_nacks},
801 {TIPC_NLA_STATS_TX_ACKS, stats->sent_acks},
802 {TIPC_NLA_STATS_RETRANSMITTED, stats->retransmitted},
803 {TIPC_NLA_STATS_DUPLICATES, stats->duplicates},
804 {TIPC_NLA_STATS_LINK_CONGS, stats->link_congs},
805 {TIPC_NLA_STATS_MAX_QUEUE, stats->max_queue_sz},
806 {TIPC_NLA_STATS_AVG_QUEUE, stats->queue_sz_counts ?
807 (stats->accu_queue_sz / stats->queue_sz_counts) : 0}
808 };
809
810 nest = nla_nest_start(skb, TIPC_NLA_LINK_STATS);
811 if (!nest)
812 return -EMSGSIZE;
813
814 for (i = 0; i < ARRAY_SIZE(map); i++)
815 if (nla_put_u32(skb, map[i].key, map[i].val))
816 goto msg_full;
817
818 nla_nest_end(skb, nest);
819
820 return 0;
821msg_full:
822 nla_nest_cancel(skb, nest);
823
824 return -EMSGSIZE;
825}
826
Ying Xue1da46562015-01-09 15:27:07 +0800827int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
Richard Alpe7be57fc2014-11-20 10:29:12 +0100828{
829 int err;
830 void *hdr;
831 struct nlattr *attrs;
832 struct nlattr *prop;
Ying Xue1da46562015-01-09 15:27:07 +0800833 struct tipc_net *tn = net_generic(net, tipc_net_id);
834 struct tipc_link *bcl = tn->bcl;
Richard Alpe7be57fc2014-11-20 10:29:12 +0100835
836 if (!bcl)
837 return 0;
838
Ying Xue1da46562015-01-09 15:27:07 +0800839 tipc_bclink_lock(net);
Richard Alpe7be57fc2014-11-20 10:29:12 +0100840
Richard Alpebfb3e5d2015-02-09 09:50:03 +0100841 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
Richard Alpe7be57fc2014-11-20 10:29:12 +0100842 NLM_F_MULTI, TIPC_NL_LINK_GET);
843 if (!hdr)
844 return -EMSGSIZE;
845
846 attrs = nla_nest_start(msg->skb, TIPC_NLA_LINK);
847 if (!attrs)
848 goto msg_full;
849
850 /* The broadcast link is always up */
851 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_UP))
852 goto attr_msg_full;
853
854 if (nla_put_flag(msg->skb, TIPC_NLA_LINK_BROADCAST))
855 goto attr_msg_full;
856 if (nla_put_string(msg->skb, TIPC_NLA_LINK_NAME, bcl->name))
857 goto attr_msg_full;
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400858 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_RX, bcl->rcv_nxt))
Richard Alpe7be57fc2014-11-20 10:29:12 +0100859 goto attr_msg_full;
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400860 if (nla_put_u32(msg->skb, TIPC_NLA_LINK_TX, bcl->snd_nxt))
Richard Alpe7be57fc2014-11-20 10:29:12 +0100861 goto attr_msg_full;
862
863 prop = nla_nest_start(msg->skb, TIPC_NLA_LINK_PROP);
864 if (!prop)
865 goto attr_msg_full;
Jon Paul Maloy1f66d162015-03-25 12:07:24 -0400866 if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, bcl->window))
Richard Alpe7be57fc2014-11-20 10:29:12 +0100867 goto prop_msg_full;
868 nla_nest_end(msg->skb, prop);
869
870 err = __tipc_nl_add_bc_link_stat(msg->skb, &bcl->stats);
871 if (err)
872 goto attr_msg_full;
873
Ying Xue1da46562015-01-09 15:27:07 +0800874 tipc_bclink_unlock(net);
Richard Alpe7be57fc2014-11-20 10:29:12 +0100875 nla_nest_end(msg->skb, attrs);
876 genlmsg_end(msg->skb, hdr);
877
878 return 0;
879
880prop_msg_full:
881 nla_nest_cancel(msg->skb, prop);
882attr_msg_full:
883 nla_nest_cancel(msg->skb, attrs);
884msg_full:
Ying Xue1da46562015-01-09 15:27:07 +0800885 tipc_bclink_unlock(net);
Richard Alpe7be57fc2014-11-20 10:29:12 +0100886 genlmsg_cancel(msg->skb, hdr);
887
888 return -EMSGSIZE;
889}
Per Lidenb97bf3f2006-01-02 19:04:38 +0100890
Ying Xue1da46562015-01-09 15:27:07 +0800891int tipc_bclink_reset_stats(struct net *net)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100892{
Ying Xue1da46562015-01-09 15:27:07 +0800893 struct tipc_net *tn = net_generic(net, tipc_net_id);
894 struct tipc_link *bcl = tn->bcl;
895
Per Lidenb97bf3f2006-01-02 19:04:38 +0100896 if (!bcl)
897 return -ENOPROTOOPT;
898
Ying Xue1da46562015-01-09 15:27:07 +0800899 tipc_bclink_lock(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100900 memset(&bcl->stats, 0, sizeof(bcl->stats));
Ying Xue1da46562015-01-09 15:27:07 +0800901 tipc_bclink_unlock(net);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700902 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100903}
904
Ying Xue1da46562015-01-09 15:27:07 +0800905int tipc_bclink_set_queue_limits(struct net *net, u32 limit)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100906{
Ying Xue1da46562015-01-09 15:27:07 +0800907 struct tipc_net *tn = net_generic(net, tipc_net_id);
908 struct tipc_link *bcl = tn->bcl;
909
Per Lidenb97bf3f2006-01-02 19:04:38 +0100910 if (!bcl)
911 return -ENOPROTOOPT;
Jon Paul Maloy53387c42015-10-19 09:21:37 -0400912 if (limit < BCLINK_WIN_MIN)
913 limit = BCLINK_WIN_MIN;
914 if (limit > TIPC_MAX_LINK_WIN)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100915 return -EINVAL;
Ying Xue1da46562015-01-09 15:27:07 +0800916 tipc_bclink_lock(net);
Per Liden4323add2006-01-18 00:38:21 +0100917 tipc_link_set_queue_limits(bcl, limit);
Ying Xue1da46562015-01-09 15:27:07 +0800918 tipc_bclink_unlock(net);
Allan Stephens0e35fd52008-07-14 22:44:01 -0700919 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100920}
921
Richard Alpe670f4f82015-05-06 13:58:55 +0200922int tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[])
923{
924 int err;
925 u32 win;
926 struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
927
928 if (!attrs[TIPC_NLA_LINK_PROP])
929 return -EINVAL;
930
931 err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP], props);
932 if (err)
933 return err;
934
935 if (!props[TIPC_NLA_PROP_WIN])
936 return -EOPNOTSUPP;
937
938 win = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
939
940 return tipc_bclink_set_queue_limits(net, win);
941}
942
Ying Xue7f9f95d2015-01-09 15:27:06 +0800943int tipc_bclink_init(struct net *net)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100944{
Ying Xue7f9f95d2015-01-09 15:27:06 +0800945 struct tipc_net *tn = net_generic(net, tipc_net_id);
Ying Xue1da46562015-01-09 15:27:07 +0800946 struct tipc_bcbearer *bcbearer;
947 struct tipc_bclink *bclink;
948 struct tipc_link *bcl;
Ying Xue7f9f95d2015-01-09 15:27:06 +0800949
Ying Xueeb8b00f2014-05-05 08:56:16 +0800950 bcbearer = kzalloc(sizeof(*bcbearer), GFP_ATOMIC);
951 if (!bcbearer)
952 return -ENOMEM;
953
954 bclink = kzalloc(sizeof(*bclink), GFP_ATOMIC);
955 if (!bclink) {
956 kfree(bcbearer);
957 return -ENOMEM;
958 }
959
960 bcl = &bclink->link;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100961 bcbearer->bearer.media = &bcbearer->media;
Per Liden4323add2006-01-18 00:38:21 +0100962 bcbearer->media.send_msg = tipc_bcbearer_send;
Allan Stephens2e2d9be2011-04-07 10:22:31 -0400963 sprintf(bcbearer->media.name, "tipc-broadcast");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100964
Ying Xued69afc92014-05-05 08:56:15 +0800965 spin_lock_init(&bclink->lock);
Jon Paul Maloy05dcc5a2015-03-13 16:08:10 -0400966 __skb_queue_head_init(&bcl->transmq);
967 __skb_queue_head_init(&bcl->backlogq);
968 __skb_queue_head_init(&bcl->deferdq);
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500969 skb_queue_head_init(&bcl->wakeupq);
Jon Paul Maloya97b9d32015-05-14 10:46:15 -0400970 bcl->snd_nxt = 1;
Ingo Molnar34af9462006-06-27 02:53:55 -0700971 spin_lock_init(&bclink->node.lock);
Jon Paul Maloycb1b7282015-02-05 08:36:44 -0500972 __skb_queue_head_init(&bclink->arrvq);
973 skb_queue_head_init(&bclink->inputq);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100974 bcl->owner = &bclink->node;
Ying Xue1da46562015-01-09 15:27:07 +0800975 bcl->owner->net = net;
Jon Paul Maloyed193ec2015-04-02 09:33:02 -0400976 bcl->mtu = MAX_PKT_DEFAULT_MCAST;
Per Liden4323add2006-01-18 00:38:21 +0100977 tipc_link_set_queue_limits(bcl, BCLINK_WIN_DEFAULT);
Ying Xue7a2f7d12014-04-21 10:55:46 +0800978 bcl->bearer_id = MAX_BEARERS;
Ying Xue7f9f95d2015-01-09 15:27:06 +0800979 rcu_assign_pointer(tn->bearer_list[MAX_BEARERS], &bcbearer->bearer);
Jon Paul Maloyc5898632015-02-05 08:36:36 -0500980 bcl->pmsg = (struct tipc_msg *)&bcl->proto_msg;
981 msg_set_prevnode(bcl->pmsg, tn->own_addr);
Stephen Hemminger4b704d52009-03-18 19:11:29 -0700982 strlcpy(bcl->name, tipc_bclink_name, TIPC_MAX_LINK_NAME);
Ying Xue1da46562015-01-09 15:27:07 +0800983 tn->bcbearer = bcbearer;
984 tn->bclink = bclink;
985 tn->bcl = bcl;
Ying Xueeb8b00f2014-05-05 08:56:16 +0800986 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100987}
988
Ying Xue7f9f95d2015-01-09 15:27:06 +0800989void tipc_bclink_stop(struct net *net)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100990{
Ying Xue7f9f95d2015-01-09 15:27:06 +0800991 struct tipc_net *tn = net_generic(net, tipc_net_id);
992
Ying Xue1da46562015-01-09 15:27:07 +0800993 tipc_bclink_lock(net);
994 tipc_link_purge_queues(tn->bcl);
995 tipc_bclink_unlock(net);
Allan Stephensc47e9b92011-10-24 10:29:26 -0400996
Ying Xue7f9f95d2015-01-09 15:27:06 +0800997 RCU_INIT_POINTER(tn->bearer_list[BCBEARER], NULL);
Ying Xueeb8b00f2014-05-05 08:56:16 +0800998 synchronize_net();
Ying Xue1da46562015-01-09 15:27:07 +0800999 kfree(tn->bcbearer);
1000 kfree(tn->bclink);
Per Lidenb97bf3f2006-01-02 19:04:38 +01001001}
1002
Allan Stephens3e22e622010-05-11 14:30:14 +00001003/**
1004 * tipc_nmap_add - add a node to a node map
1005 */
Ying Xue28dd9412014-04-21 10:55:51 +08001006static void tipc_nmap_add(struct tipc_node_map *nm_ptr, u32 node)
Allan Stephens3e22e622010-05-11 14:30:14 +00001007{
1008 int n = tipc_node(node);
1009 int w = n / WSIZE;
1010 u32 mask = (1 << (n % WSIZE));
1011
1012 if ((nm_ptr->map[w] & mask) == 0) {
1013 nm_ptr->count++;
1014 nm_ptr->map[w] |= mask;
1015 }
1016}
1017
1018/**
1019 * tipc_nmap_remove - remove a node from a node map
1020 */
Ying Xue28dd9412014-04-21 10:55:51 +08001021static void tipc_nmap_remove(struct tipc_node_map *nm_ptr, u32 node)
Allan Stephens3e22e622010-05-11 14:30:14 +00001022{
1023 int n = tipc_node(node);
1024 int w = n / WSIZE;
1025 u32 mask = (1 << (n % WSIZE));
1026
1027 if ((nm_ptr->map[w] & mask) != 0) {
1028 nm_ptr->map[w] &= ~mask;
1029 nm_ptr->count--;
1030 }
1031}
1032
1033/**
1034 * tipc_nmap_diff - find differences between node maps
1035 * @nm_a: input node map A
1036 * @nm_b: input node map B
1037 * @nm_diff: output node map A-B (i.e. nodes of A that are not in B)
1038 */
stephen hemminger31e3c3f2010-10-13 13:20:35 +00001039static void tipc_nmap_diff(struct tipc_node_map *nm_a,
1040 struct tipc_node_map *nm_b,
1041 struct tipc_node_map *nm_diff)
Allan Stephens3e22e622010-05-11 14:30:14 +00001042{
1043 int stop = ARRAY_SIZE(nm_a->map);
1044 int w;
1045 int b;
1046 u32 map;
1047
1048 memset(nm_diff, 0, sizeof(*nm_diff));
1049 for (w = 0; w < stop; w++) {
1050 map = nm_a->map[w] ^ (nm_a->map[w] & nm_b->map[w]);
1051 nm_diff->map[w] = map;
1052 if (map != 0) {
1053 for (b = 0 ; b < WSIZE; b++) {
1054 if (map & (1 << b))
1055 nm_diff->count++;
1056 }
1057 }
1058 }
1059}