18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * net/tipc/bcast.c: TIPC broadcast code 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2004-2006, 2014-2017, Ericsson AB 58c2ecf20Sopenharmony_ci * Copyright (c) 2004, Intel Corporation. 68c2ecf20Sopenharmony_ci * Copyright (c) 2005, 2010-2011, Wind River Systems 78c2ecf20Sopenharmony_ci * All rights reserved. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 108c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 138c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer. 148c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright 158c2ecf20Sopenharmony_ci * notice, this list of conditions and the following disclaimer in the 168c2ecf20Sopenharmony_ci * documentation and/or other materials provided with the distribution. 178c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its 188c2ecf20Sopenharmony_ci * contributors may be used to endorse or promote products derived from 198c2ecf20Sopenharmony_ci * this software without specific prior written permission. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the 228c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free 238c2ecf20Sopenharmony_ci * Software Foundation. 248c2ecf20Sopenharmony_ci * 258c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 268c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 278c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 288c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 298c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 308c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 318c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 328c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 338c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 348c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 358c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE. 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/tipc_config.h> 398c2ecf20Sopenharmony_ci#include "socket.h" 408c2ecf20Sopenharmony_ci#include "msg.h" 418c2ecf20Sopenharmony_ci#include "bcast.h" 428c2ecf20Sopenharmony_ci#include "link.h" 438c2ecf20Sopenharmony_ci#include "name_table.h" 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */ 468c2ecf20Sopenharmony_ci#define BCLINK_WIN_MIN 32 /* bcast minimum link window size */ 478c2ecf20Sopenharmony_ci 488c2ecf20Sopenharmony_ciconst char tipc_bclink_name[] = "broadcast-link"; 498c2ecf20Sopenharmony_ciunsigned long sysctl_tipc_bc_retruni __read_mostly; 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/** 528c2ecf20Sopenharmony_ci * struct tipc_bc_base - base structure for keeping broadcast send state 538c2ecf20Sopenharmony_ci * @link: broadcast send link structure 548c2ecf20Sopenharmony_ci * @inputq: data input queue; will only carry SOCK_WAKEUP messages 558c2ecf20Sopenharmony_ci * @dests: array keeping number of reachable destinations per bearer 568c2ecf20Sopenharmony_ci * @primary_bearer: a bearer having links to all broadcast destinations, if any 578c2ecf20Sopenharmony_ci * @bcast_support: indicates if primary bearer, if any, supports broadcast 588c2ecf20Sopenharmony_ci * @force_bcast: forces broadcast for multicast traffic 598c2ecf20Sopenharmony_ci * @rcast_support: indicates if all peer nodes support replicast 608c2ecf20Sopenharmony_ci * @force_rcast: forces replicast for multicast traffic 618c2ecf20Sopenharmony_ci * @rc_ratio: dest count as percentage of cluster size where send method changes 628c2ecf20Sopenharmony_ci * @bc_threshold: calculated from rc_ratio; if dests > threshold use broadcast 638c2ecf20Sopenharmony_ci */ 648c2ecf20Sopenharmony_cistruct tipc_bc_base { 658c2ecf20Sopenharmony_ci struct tipc_link *link; 668c2ecf20Sopenharmony_ci struct sk_buff_head inputq; 678c2ecf20Sopenharmony_ci int dests[MAX_BEARERS]; 688c2ecf20Sopenharmony_ci int primary_bearer; 698c2ecf20Sopenharmony_ci bool bcast_support; 708c2ecf20Sopenharmony_ci bool force_bcast; 718c2ecf20Sopenharmony_ci bool rcast_support; 728c2ecf20Sopenharmony_ci bool force_rcast; 738c2ecf20Sopenharmony_ci int rc_ratio; 748c2ecf20Sopenharmony_ci int bc_threshold; 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_cistatic struct tipc_bc_base *tipc_bc_base(struct net *net) 788c2ecf20Sopenharmony_ci{ 798c2ecf20Sopenharmony_ci return tipc_net(net)->bcbase; 808c2ecf20Sopenharmony_ci} 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci/* tipc_bcast_get_mtu(): -get the MTU currently used by broadcast link 838c2ecf20Sopenharmony_ci * Note: the MTU is decremented to give room for a tunnel header, in 848c2ecf20Sopenharmony_ci * case the message needs to be sent as replicast 858c2ecf20Sopenharmony_ci */ 868c2ecf20Sopenharmony_ciint tipc_bcast_get_mtu(struct net *net) 878c2ecf20Sopenharmony_ci{ 888c2ecf20Sopenharmony_ci return tipc_link_mss(tipc_bc_sndlink(net)); 898c2ecf20Sopenharmony_ci} 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid tipc_bcast_toggle_rcast(struct net *net, bool supp) 928c2ecf20Sopenharmony_ci{ 938c2ecf20Sopenharmony_ci tipc_bc_base(net)->rcast_support = supp; 948c2ecf20Sopenharmony_ci} 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_cistatic void tipc_bcbase_calc_bc_threshold(struct net *net) 978c2ecf20Sopenharmony_ci{ 988c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 998c2ecf20Sopenharmony_ci int cluster_size = tipc_link_bc_peers(tipc_bc_sndlink(net)); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci bb->bc_threshold = 1 + (cluster_size * bb->rc_ratio / 100); 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* tipc_bcbase_select_primary(): find a bearer with links to all destinations, 1058c2ecf20Sopenharmony_ci * if any, and make it primary bearer 1068c2ecf20Sopenharmony_ci */ 1078c2ecf20Sopenharmony_cistatic void tipc_bcbase_select_primary(struct net *net) 1088c2ecf20Sopenharmony_ci{ 1098c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 1108c2ecf20Sopenharmony_ci int all_dests = tipc_link_bc_peers(bb->link); 1118c2ecf20Sopenharmony_ci int max_win = tipc_link_max_win(bb->link); 1128c2ecf20Sopenharmony_ci int min_win = tipc_link_min_win(bb->link); 1138c2ecf20Sopenharmony_ci int i, mtu, prim; 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci bb->primary_bearer = INVALID_BEARER_ID; 1168c2ecf20Sopenharmony_ci bb->bcast_support = true; 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci if (!all_dests) 1198c2ecf20Sopenharmony_ci return; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci for (i = 0; i < MAX_BEARERS; i++) { 1228c2ecf20Sopenharmony_ci if (!bb->dests[i]) 1238c2ecf20Sopenharmony_ci continue; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci mtu = tipc_bearer_mtu(net, i); 1268c2ecf20Sopenharmony_ci if (mtu < tipc_link_mtu(bb->link)) { 1278c2ecf20Sopenharmony_ci tipc_link_set_mtu(bb->link, mtu); 1288c2ecf20Sopenharmony_ci tipc_link_set_queue_limits(bb->link, 1298c2ecf20Sopenharmony_ci min_win, 1308c2ecf20Sopenharmony_ci max_win); 1318c2ecf20Sopenharmony_ci } 1328c2ecf20Sopenharmony_ci bb->bcast_support &= tipc_bearer_bcast_support(net, i); 1338c2ecf20Sopenharmony_ci if (bb->dests[i] < all_dests) 1348c2ecf20Sopenharmony_ci continue; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci bb->primary_bearer = i; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ci /* Reduce risk that all nodes select same primary */ 1398c2ecf20Sopenharmony_ci if ((i ^ tipc_own_addr(net)) & 1) 1408c2ecf20Sopenharmony_ci break; 1418c2ecf20Sopenharmony_ci } 1428c2ecf20Sopenharmony_ci prim = bb->primary_bearer; 1438c2ecf20Sopenharmony_ci if (prim != INVALID_BEARER_ID) 1448c2ecf20Sopenharmony_ci bb->bcast_support = tipc_bearer_bcast_support(net, prim); 1458c2ecf20Sopenharmony_ci} 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_civoid tipc_bcast_inc_bearer_dst_cnt(struct net *net, int bearer_id) 1488c2ecf20Sopenharmony_ci{ 1498c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 1528c2ecf20Sopenharmony_ci bb->dests[bearer_id]++; 1538c2ecf20Sopenharmony_ci tipc_bcbase_select_primary(net); 1548c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 1558c2ecf20Sopenharmony_ci} 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_civoid tipc_bcast_dec_bearer_dst_cnt(struct net *net, int bearer_id) 1588c2ecf20Sopenharmony_ci{ 1598c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 1628c2ecf20Sopenharmony_ci bb->dests[bearer_id]--; 1638c2ecf20Sopenharmony_ci tipc_bcbase_select_primary(net); 1648c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 1658c2ecf20Sopenharmony_ci} 1668c2ecf20Sopenharmony_ci 1678c2ecf20Sopenharmony_ci/* tipc_bcbase_xmit - broadcast a packet queue across one or more bearers 1688c2ecf20Sopenharmony_ci * 1698c2ecf20Sopenharmony_ci * Note that number of reachable destinations, as indicated in the dests[] 1708c2ecf20Sopenharmony_ci * array, may transitionally differ from the number of destinations indicated 1718c2ecf20Sopenharmony_ci * in each sent buffer. We can sustain this. Excess destination nodes will 1728c2ecf20Sopenharmony_ci * drop and never acknowledge the unexpected packets, and missing destinations 1738c2ecf20Sopenharmony_ci * will either require retransmission (if they are just about to be added to 1748c2ecf20Sopenharmony_ci * the bearer), or be removed from the buffer's 'ackers' counter (if they 1758c2ecf20Sopenharmony_ci * just went down) 1768c2ecf20Sopenharmony_ci */ 1778c2ecf20Sopenharmony_cistatic void tipc_bcbase_xmit(struct net *net, struct sk_buff_head *xmitq) 1788c2ecf20Sopenharmony_ci{ 1798c2ecf20Sopenharmony_ci int bearer_id; 1808c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 1818c2ecf20Sopenharmony_ci struct sk_buff *skb, *_skb; 1828c2ecf20Sopenharmony_ci struct sk_buff_head _xmitq; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci if (skb_queue_empty(xmitq)) 1858c2ecf20Sopenharmony_ci return; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* The typical case: at least one bearer has links to all nodes */ 1888c2ecf20Sopenharmony_ci bearer_id = bb->primary_bearer; 1898c2ecf20Sopenharmony_ci if (bearer_id >= 0) { 1908c2ecf20Sopenharmony_ci tipc_bearer_bc_xmit(net, bearer_id, xmitq); 1918c2ecf20Sopenharmony_ci return; 1928c2ecf20Sopenharmony_ci } 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci /* We have to transmit across all bearers */ 1958c2ecf20Sopenharmony_ci __skb_queue_head_init(&_xmitq); 1968c2ecf20Sopenharmony_ci for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) { 1978c2ecf20Sopenharmony_ci if (!bb->dests[bearer_id]) 1988c2ecf20Sopenharmony_ci continue; 1998c2ecf20Sopenharmony_ci 2008c2ecf20Sopenharmony_ci skb_queue_walk(xmitq, skb) { 2018c2ecf20Sopenharmony_ci _skb = pskb_copy_for_clone(skb, GFP_ATOMIC); 2028c2ecf20Sopenharmony_ci if (!_skb) 2038c2ecf20Sopenharmony_ci break; 2048c2ecf20Sopenharmony_ci __skb_queue_tail(&_xmitq, _skb); 2058c2ecf20Sopenharmony_ci } 2068c2ecf20Sopenharmony_ci tipc_bearer_bc_xmit(net, bearer_id, &_xmitq); 2078c2ecf20Sopenharmony_ci } 2088c2ecf20Sopenharmony_ci __skb_queue_purge(xmitq); 2098c2ecf20Sopenharmony_ci __skb_queue_purge(&_xmitq); 2108c2ecf20Sopenharmony_ci} 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_cistatic void tipc_bcast_select_xmit_method(struct net *net, int dests, 2138c2ecf20Sopenharmony_ci struct tipc_mc_method *method) 2148c2ecf20Sopenharmony_ci{ 2158c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 2168c2ecf20Sopenharmony_ci unsigned long exp = method->expires; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci /* Broadcast supported by used bearer/bearers? */ 2198c2ecf20Sopenharmony_ci if (!bb->bcast_support) { 2208c2ecf20Sopenharmony_ci method->rcast = true; 2218c2ecf20Sopenharmony_ci return; 2228c2ecf20Sopenharmony_ci } 2238c2ecf20Sopenharmony_ci /* Any destinations which don't support replicast ? */ 2248c2ecf20Sopenharmony_ci if (!bb->rcast_support) { 2258c2ecf20Sopenharmony_ci method->rcast = false; 2268c2ecf20Sopenharmony_ci return; 2278c2ecf20Sopenharmony_ci } 2288c2ecf20Sopenharmony_ci /* Can current method be changed ? */ 2298c2ecf20Sopenharmony_ci method->expires = jiffies + TIPC_METHOD_EXPIRE; 2308c2ecf20Sopenharmony_ci if (method->mandatory) 2318c2ecf20Sopenharmony_ci return; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci if (!(tipc_net(net)->capabilities & TIPC_MCAST_RBCTL) && 2348c2ecf20Sopenharmony_ci time_before(jiffies, exp)) 2358c2ecf20Sopenharmony_ci return; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci /* Configuration as force 'broadcast' method */ 2388c2ecf20Sopenharmony_ci if (bb->force_bcast) { 2398c2ecf20Sopenharmony_ci method->rcast = false; 2408c2ecf20Sopenharmony_ci return; 2418c2ecf20Sopenharmony_ci } 2428c2ecf20Sopenharmony_ci /* Configuration as force 'replicast' method */ 2438c2ecf20Sopenharmony_ci if (bb->force_rcast) { 2448c2ecf20Sopenharmony_ci method->rcast = true; 2458c2ecf20Sopenharmony_ci return; 2468c2ecf20Sopenharmony_ci } 2478c2ecf20Sopenharmony_ci /* Configuration as 'autoselect' or default method */ 2488c2ecf20Sopenharmony_ci /* Determine method to use now */ 2498c2ecf20Sopenharmony_ci method->rcast = dests <= bb->bc_threshold; 2508c2ecf20Sopenharmony_ci} 2518c2ecf20Sopenharmony_ci 2528c2ecf20Sopenharmony_ci/* tipc_bcast_xmit - broadcast the buffer chain to all external nodes 2538c2ecf20Sopenharmony_ci * @net: the applicable net namespace 2548c2ecf20Sopenharmony_ci * @pkts: chain of buffers containing message 2558c2ecf20Sopenharmony_ci * @cong_link_cnt: set to 1 if broadcast link is congested, otherwise 0 2568c2ecf20Sopenharmony_ci * Consumes the buffer chain. 2578c2ecf20Sopenharmony_ci * Returns 0 if success, otherwise errno: -EHOSTUNREACH,-EMSGSIZE 2588c2ecf20Sopenharmony_ci */ 2598c2ecf20Sopenharmony_ciint tipc_bcast_xmit(struct net *net, struct sk_buff_head *pkts, 2608c2ecf20Sopenharmony_ci u16 *cong_link_cnt) 2618c2ecf20Sopenharmony_ci{ 2628c2ecf20Sopenharmony_ci struct tipc_link *l = tipc_bc_sndlink(net); 2638c2ecf20Sopenharmony_ci struct sk_buff_head xmitq; 2648c2ecf20Sopenharmony_ci int rc = 0; 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci __skb_queue_head_init(&xmitq); 2678c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 2688c2ecf20Sopenharmony_ci if (tipc_link_bc_peers(l)) 2698c2ecf20Sopenharmony_ci rc = tipc_link_xmit(l, pkts, &xmitq); 2708c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 2718c2ecf20Sopenharmony_ci tipc_bcbase_xmit(net, &xmitq); 2728c2ecf20Sopenharmony_ci __skb_queue_purge(pkts); 2738c2ecf20Sopenharmony_ci if (rc == -ELINKCONG) { 2748c2ecf20Sopenharmony_ci *cong_link_cnt = 1; 2758c2ecf20Sopenharmony_ci rc = 0; 2768c2ecf20Sopenharmony_ci } 2778c2ecf20Sopenharmony_ci return rc; 2788c2ecf20Sopenharmony_ci} 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci/* tipc_rcast_xmit - replicate and send a message to given destination nodes 2818c2ecf20Sopenharmony_ci * @net: the applicable net namespace 2828c2ecf20Sopenharmony_ci * @pkts: chain of buffers containing message 2838c2ecf20Sopenharmony_ci * @dests: list of destination nodes 2848c2ecf20Sopenharmony_ci * @cong_link_cnt: returns number of congested links 2858c2ecf20Sopenharmony_ci * @cong_links: returns identities of congested links 2868c2ecf20Sopenharmony_ci * Returns 0 if success, otherwise errno 2878c2ecf20Sopenharmony_ci */ 2888c2ecf20Sopenharmony_cistatic int tipc_rcast_xmit(struct net *net, struct sk_buff_head *pkts, 2898c2ecf20Sopenharmony_ci struct tipc_nlist *dests, u16 *cong_link_cnt) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci struct tipc_dest *dst, *tmp; 2928c2ecf20Sopenharmony_ci struct sk_buff_head _pkts; 2938c2ecf20Sopenharmony_ci u32 dnode, selector; 2948c2ecf20Sopenharmony_ci 2958c2ecf20Sopenharmony_ci selector = msg_link_selector(buf_msg(skb_peek(pkts))); 2968c2ecf20Sopenharmony_ci __skb_queue_head_init(&_pkts); 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci list_for_each_entry_safe(dst, tmp, &dests->list, list) { 2998c2ecf20Sopenharmony_ci dnode = dst->node; 3008c2ecf20Sopenharmony_ci if (!tipc_msg_pskb_copy(dnode, pkts, &_pkts)) 3018c2ecf20Sopenharmony_ci return -ENOMEM; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci /* Any other return value than -ELINKCONG is ignored */ 3048c2ecf20Sopenharmony_ci if (tipc_node_xmit(net, &_pkts, dnode, selector) == -ELINKCONG) 3058c2ecf20Sopenharmony_ci (*cong_link_cnt)++; 3068c2ecf20Sopenharmony_ci } 3078c2ecf20Sopenharmony_ci return 0; 3088c2ecf20Sopenharmony_ci} 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci/* tipc_mcast_send_sync - deliver a dummy message with SYN bit 3118c2ecf20Sopenharmony_ci * @net: the applicable net namespace 3128c2ecf20Sopenharmony_ci * @skb: socket buffer to copy 3138c2ecf20Sopenharmony_ci * @method: send method to be used 3148c2ecf20Sopenharmony_ci * @dests: destination nodes for message. 3158c2ecf20Sopenharmony_ci * Returns 0 if success, otherwise errno 3168c2ecf20Sopenharmony_ci */ 3178c2ecf20Sopenharmony_cistatic int tipc_mcast_send_sync(struct net *net, struct sk_buff *skb, 3188c2ecf20Sopenharmony_ci struct tipc_mc_method *method, 3198c2ecf20Sopenharmony_ci struct tipc_nlist *dests) 3208c2ecf20Sopenharmony_ci{ 3218c2ecf20Sopenharmony_ci struct tipc_msg *hdr, *_hdr; 3228c2ecf20Sopenharmony_ci struct sk_buff_head tmpq; 3238c2ecf20Sopenharmony_ci struct sk_buff *_skb; 3248c2ecf20Sopenharmony_ci u16 cong_link_cnt; 3258c2ecf20Sopenharmony_ci int rc = 0; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci /* Is a cluster supporting with new capabilities ? */ 3288c2ecf20Sopenharmony_ci if (!(tipc_net(net)->capabilities & TIPC_MCAST_RBCTL)) 3298c2ecf20Sopenharmony_ci return 0; 3308c2ecf20Sopenharmony_ci 3318c2ecf20Sopenharmony_ci hdr = buf_msg(skb); 3328c2ecf20Sopenharmony_ci if (msg_user(hdr) == MSG_FRAGMENTER) 3338c2ecf20Sopenharmony_ci hdr = msg_inner_hdr(hdr); 3348c2ecf20Sopenharmony_ci if (msg_type(hdr) != TIPC_MCAST_MSG) 3358c2ecf20Sopenharmony_ci return 0; 3368c2ecf20Sopenharmony_ci 3378c2ecf20Sopenharmony_ci /* Allocate dummy message */ 3388c2ecf20Sopenharmony_ci _skb = tipc_buf_acquire(MCAST_H_SIZE, GFP_KERNEL); 3398c2ecf20Sopenharmony_ci if (!_skb) 3408c2ecf20Sopenharmony_ci return -ENOMEM; 3418c2ecf20Sopenharmony_ci 3428c2ecf20Sopenharmony_ci /* Preparing for 'synching' header */ 3438c2ecf20Sopenharmony_ci msg_set_syn(hdr, 1); 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci /* Copy skb's header into a dummy header */ 3468c2ecf20Sopenharmony_ci skb_copy_to_linear_data(_skb, hdr, MCAST_H_SIZE); 3478c2ecf20Sopenharmony_ci skb_orphan(_skb); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci /* Reverse method for dummy message */ 3508c2ecf20Sopenharmony_ci _hdr = buf_msg(_skb); 3518c2ecf20Sopenharmony_ci msg_set_size(_hdr, MCAST_H_SIZE); 3528c2ecf20Sopenharmony_ci msg_set_is_rcast(_hdr, !msg_is_rcast(hdr)); 3538c2ecf20Sopenharmony_ci msg_set_errcode(_hdr, TIPC_ERR_NO_PORT); 3548c2ecf20Sopenharmony_ci 3558c2ecf20Sopenharmony_ci __skb_queue_head_init(&tmpq); 3568c2ecf20Sopenharmony_ci __skb_queue_tail(&tmpq, _skb); 3578c2ecf20Sopenharmony_ci if (method->rcast) 3588c2ecf20Sopenharmony_ci rc = tipc_bcast_xmit(net, &tmpq, &cong_link_cnt); 3598c2ecf20Sopenharmony_ci else 3608c2ecf20Sopenharmony_ci rc = tipc_rcast_xmit(net, &tmpq, dests, &cong_link_cnt); 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci /* This queue should normally be empty by now */ 3638c2ecf20Sopenharmony_ci __skb_queue_purge(&tmpq); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci return rc; 3668c2ecf20Sopenharmony_ci} 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci/* tipc_mcast_xmit - deliver message to indicated destination nodes 3698c2ecf20Sopenharmony_ci * and to identified node local sockets 3708c2ecf20Sopenharmony_ci * @net: the applicable net namespace 3718c2ecf20Sopenharmony_ci * @pkts: chain of buffers containing message 3728c2ecf20Sopenharmony_ci * @method: send method to be used 3738c2ecf20Sopenharmony_ci * @dests: destination nodes for message. 3748c2ecf20Sopenharmony_ci * @cong_link_cnt: returns number of encountered congested destination links 3758c2ecf20Sopenharmony_ci * Consumes buffer chain. 3768c2ecf20Sopenharmony_ci * Returns 0 if success, otherwise errno 3778c2ecf20Sopenharmony_ci */ 3788c2ecf20Sopenharmony_ciint tipc_mcast_xmit(struct net *net, struct sk_buff_head *pkts, 3798c2ecf20Sopenharmony_ci struct tipc_mc_method *method, struct tipc_nlist *dests, 3808c2ecf20Sopenharmony_ci u16 *cong_link_cnt) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci struct sk_buff_head inputq, localq; 3838c2ecf20Sopenharmony_ci bool rcast = method->rcast; 3848c2ecf20Sopenharmony_ci struct tipc_msg *hdr; 3858c2ecf20Sopenharmony_ci struct sk_buff *skb; 3868c2ecf20Sopenharmony_ci int rc = 0; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci skb_queue_head_init(&inputq); 3898c2ecf20Sopenharmony_ci __skb_queue_head_init(&localq); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci /* Clone packets before they are consumed by next call */ 3928c2ecf20Sopenharmony_ci if (dests->local && !tipc_msg_reassemble(pkts, &localq)) { 3938c2ecf20Sopenharmony_ci rc = -ENOMEM; 3948c2ecf20Sopenharmony_ci goto exit; 3958c2ecf20Sopenharmony_ci } 3968c2ecf20Sopenharmony_ci /* Send according to determined transmit method */ 3978c2ecf20Sopenharmony_ci if (dests->remote) { 3988c2ecf20Sopenharmony_ci tipc_bcast_select_xmit_method(net, dests->remote, method); 3998c2ecf20Sopenharmony_ci 4008c2ecf20Sopenharmony_ci skb = skb_peek(pkts); 4018c2ecf20Sopenharmony_ci hdr = buf_msg(skb); 4028c2ecf20Sopenharmony_ci if (msg_user(hdr) == MSG_FRAGMENTER) 4038c2ecf20Sopenharmony_ci hdr = msg_inner_hdr(hdr); 4048c2ecf20Sopenharmony_ci msg_set_is_rcast(hdr, method->rcast); 4058c2ecf20Sopenharmony_ci 4068c2ecf20Sopenharmony_ci /* Switch method ? */ 4078c2ecf20Sopenharmony_ci if (rcast != method->rcast) { 4088c2ecf20Sopenharmony_ci rc = tipc_mcast_send_sync(net, skb, method, dests); 4098c2ecf20Sopenharmony_ci if (unlikely(rc)) { 4108c2ecf20Sopenharmony_ci pr_err("Unable to send SYN: method %d, rc %d\n", 4118c2ecf20Sopenharmony_ci rcast, rc); 4128c2ecf20Sopenharmony_ci goto exit; 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci } 4158c2ecf20Sopenharmony_ci 4168c2ecf20Sopenharmony_ci if (method->rcast) 4178c2ecf20Sopenharmony_ci rc = tipc_rcast_xmit(net, pkts, dests, cong_link_cnt); 4188c2ecf20Sopenharmony_ci else 4198c2ecf20Sopenharmony_ci rc = tipc_bcast_xmit(net, pkts, cong_link_cnt); 4208c2ecf20Sopenharmony_ci } 4218c2ecf20Sopenharmony_ci 4228c2ecf20Sopenharmony_ci if (dests->local) { 4238c2ecf20Sopenharmony_ci tipc_loopback_trace(net, &localq); 4248c2ecf20Sopenharmony_ci tipc_sk_mcast_rcv(net, &localq, &inputq); 4258c2ecf20Sopenharmony_ci } 4268c2ecf20Sopenharmony_ciexit: 4278c2ecf20Sopenharmony_ci /* This queue should normally be empty by now */ 4288c2ecf20Sopenharmony_ci __skb_queue_purge(pkts); 4298c2ecf20Sopenharmony_ci return rc; 4308c2ecf20Sopenharmony_ci} 4318c2ecf20Sopenharmony_ci 4328c2ecf20Sopenharmony_ci/* tipc_bcast_rcv - receive a broadcast packet, and deliver to rcv link 4338c2ecf20Sopenharmony_ci * 4348c2ecf20Sopenharmony_ci * RCU is locked, no other locks set 4358c2ecf20Sopenharmony_ci */ 4368c2ecf20Sopenharmony_ciint tipc_bcast_rcv(struct net *net, struct tipc_link *l, struct sk_buff *skb) 4378c2ecf20Sopenharmony_ci{ 4388c2ecf20Sopenharmony_ci struct tipc_msg *hdr = buf_msg(skb); 4398c2ecf20Sopenharmony_ci struct sk_buff_head *inputq = &tipc_bc_base(net)->inputq; 4408c2ecf20Sopenharmony_ci struct sk_buff_head xmitq; 4418c2ecf20Sopenharmony_ci int rc; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci __skb_queue_head_init(&xmitq); 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci if (msg_mc_netid(hdr) != tipc_netid(net) || !tipc_link_is_up(l)) { 4468c2ecf20Sopenharmony_ci kfree_skb(skb); 4478c2ecf20Sopenharmony_ci return 0; 4488c2ecf20Sopenharmony_ci } 4498c2ecf20Sopenharmony_ci 4508c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 4518c2ecf20Sopenharmony_ci if (msg_user(hdr) == BCAST_PROTOCOL) 4528c2ecf20Sopenharmony_ci rc = tipc_link_bc_nack_rcv(l, skb, &xmitq); 4538c2ecf20Sopenharmony_ci else 4548c2ecf20Sopenharmony_ci rc = tipc_link_rcv(l, skb, NULL); 4558c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_ci tipc_bcbase_xmit(net, &xmitq); 4588c2ecf20Sopenharmony_ci 4598c2ecf20Sopenharmony_ci /* Any socket wakeup messages ? */ 4608c2ecf20Sopenharmony_ci if (!skb_queue_empty(inputq)) 4618c2ecf20Sopenharmony_ci tipc_sk_rcv(net, inputq); 4628c2ecf20Sopenharmony_ci 4638c2ecf20Sopenharmony_ci return rc; 4648c2ecf20Sopenharmony_ci} 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci/* tipc_bcast_ack_rcv - receive and handle a broadcast acknowledge 4678c2ecf20Sopenharmony_ci * 4688c2ecf20Sopenharmony_ci * RCU is locked, no other locks set 4698c2ecf20Sopenharmony_ci */ 4708c2ecf20Sopenharmony_civoid tipc_bcast_ack_rcv(struct net *net, struct tipc_link *l, 4718c2ecf20Sopenharmony_ci struct tipc_msg *hdr) 4728c2ecf20Sopenharmony_ci{ 4738c2ecf20Sopenharmony_ci struct sk_buff_head *inputq = &tipc_bc_base(net)->inputq; 4748c2ecf20Sopenharmony_ci u16 acked = msg_bcast_ack(hdr); 4758c2ecf20Sopenharmony_ci struct sk_buff_head xmitq; 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci /* Ignore bc acks sent by peer before bcast synch point was received */ 4788c2ecf20Sopenharmony_ci if (msg_bc_ack_invalid(hdr)) 4798c2ecf20Sopenharmony_ci return; 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci __skb_queue_head_init(&xmitq); 4828c2ecf20Sopenharmony_ci 4838c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 4848c2ecf20Sopenharmony_ci tipc_link_bc_ack_rcv(l, acked, 0, NULL, &xmitq, NULL); 4858c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci tipc_bcbase_xmit(net, &xmitq); 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci /* Any socket wakeup messages ? */ 4908c2ecf20Sopenharmony_ci if (!skb_queue_empty(inputq)) 4918c2ecf20Sopenharmony_ci tipc_sk_rcv(net, inputq); 4928c2ecf20Sopenharmony_ci} 4938c2ecf20Sopenharmony_ci 4948c2ecf20Sopenharmony_ci/* tipc_bcast_synch_rcv - check and update rcv link with peer's send state 4958c2ecf20Sopenharmony_ci * 4968c2ecf20Sopenharmony_ci * RCU is locked, no other locks set 4978c2ecf20Sopenharmony_ci */ 4988c2ecf20Sopenharmony_ciint tipc_bcast_sync_rcv(struct net *net, struct tipc_link *l, 4998c2ecf20Sopenharmony_ci struct tipc_msg *hdr, 5008c2ecf20Sopenharmony_ci struct sk_buff_head *retrq) 5018c2ecf20Sopenharmony_ci{ 5028c2ecf20Sopenharmony_ci struct sk_buff_head *inputq = &tipc_bc_base(net)->inputq; 5038c2ecf20Sopenharmony_ci struct tipc_gap_ack_blks *ga; 5048c2ecf20Sopenharmony_ci struct sk_buff_head xmitq; 5058c2ecf20Sopenharmony_ci int rc = 0; 5068c2ecf20Sopenharmony_ci 5078c2ecf20Sopenharmony_ci __skb_queue_head_init(&xmitq); 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 5108c2ecf20Sopenharmony_ci if (msg_type(hdr) != STATE_MSG) { 5118c2ecf20Sopenharmony_ci tipc_link_bc_init_rcv(l, hdr); 5128c2ecf20Sopenharmony_ci } else if (!msg_bc_ack_invalid(hdr)) { 5138c2ecf20Sopenharmony_ci tipc_get_gap_ack_blks(&ga, l, hdr, false); 5148c2ecf20Sopenharmony_ci if (!sysctl_tipc_bc_retruni) 5158c2ecf20Sopenharmony_ci retrq = &xmitq; 5168c2ecf20Sopenharmony_ci rc = tipc_link_bc_ack_rcv(l, msg_bcast_ack(hdr), 5178c2ecf20Sopenharmony_ci msg_bc_gap(hdr), ga, &xmitq, 5188c2ecf20Sopenharmony_ci retrq); 5198c2ecf20Sopenharmony_ci rc |= tipc_link_bc_sync_rcv(l, hdr, &xmitq); 5208c2ecf20Sopenharmony_ci } 5218c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci tipc_bcbase_xmit(net, &xmitq); 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci /* Any socket wakeup messages ? */ 5268c2ecf20Sopenharmony_ci if (!skb_queue_empty(inputq)) 5278c2ecf20Sopenharmony_ci tipc_sk_rcv(net, inputq); 5288c2ecf20Sopenharmony_ci return rc; 5298c2ecf20Sopenharmony_ci} 5308c2ecf20Sopenharmony_ci 5318c2ecf20Sopenharmony_ci/* tipc_bcast_add_peer - add a peer node to broadcast link and bearer 5328c2ecf20Sopenharmony_ci * 5338c2ecf20Sopenharmony_ci * RCU is locked, node lock is set 5348c2ecf20Sopenharmony_ci */ 5358c2ecf20Sopenharmony_civoid tipc_bcast_add_peer(struct net *net, struct tipc_link *uc_l, 5368c2ecf20Sopenharmony_ci struct sk_buff_head *xmitq) 5378c2ecf20Sopenharmony_ci{ 5388c2ecf20Sopenharmony_ci struct tipc_link *snd_l = tipc_bc_sndlink(net); 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 5418c2ecf20Sopenharmony_ci tipc_link_add_bc_peer(snd_l, uc_l, xmitq); 5428c2ecf20Sopenharmony_ci tipc_bcbase_select_primary(net); 5438c2ecf20Sopenharmony_ci tipc_bcbase_calc_bc_threshold(net); 5448c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 5458c2ecf20Sopenharmony_ci} 5468c2ecf20Sopenharmony_ci 5478c2ecf20Sopenharmony_ci/* tipc_bcast_remove_peer - remove a peer node from broadcast link and bearer 5488c2ecf20Sopenharmony_ci * 5498c2ecf20Sopenharmony_ci * RCU is locked, node lock is set 5508c2ecf20Sopenharmony_ci */ 5518c2ecf20Sopenharmony_civoid tipc_bcast_remove_peer(struct net *net, struct tipc_link *rcv_l) 5528c2ecf20Sopenharmony_ci{ 5538c2ecf20Sopenharmony_ci struct tipc_link *snd_l = tipc_bc_sndlink(net); 5548c2ecf20Sopenharmony_ci struct sk_buff_head *inputq = &tipc_bc_base(net)->inputq; 5558c2ecf20Sopenharmony_ci struct sk_buff_head xmitq; 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci __skb_queue_head_init(&xmitq); 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 5608c2ecf20Sopenharmony_ci tipc_link_remove_bc_peer(snd_l, rcv_l, &xmitq); 5618c2ecf20Sopenharmony_ci tipc_bcbase_select_primary(net); 5628c2ecf20Sopenharmony_ci tipc_bcbase_calc_bc_threshold(net); 5638c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 5648c2ecf20Sopenharmony_ci 5658c2ecf20Sopenharmony_ci tipc_bcbase_xmit(net, &xmitq); 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* Any socket wakeup messages ? */ 5688c2ecf20Sopenharmony_ci if (!skb_queue_empty(inputq)) 5698c2ecf20Sopenharmony_ci tipc_sk_rcv(net, inputq); 5708c2ecf20Sopenharmony_ci} 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ciint tipc_bclink_reset_stats(struct net *net, struct tipc_link *l) 5738c2ecf20Sopenharmony_ci{ 5748c2ecf20Sopenharmony_ci if (!l) 5758c2ecf20Sopenharmony_ci return -ENOPROTOOPT; 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 5788c2ecf20Sopenharmony_ci tipc_link_reset_stats(l); 5798c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 5808c2ecf20Sopenharmony_ci return 0; 5818c2ecf20Sopenharmony_ci} 5828c2ecf20Sopenharmony_ci 5838c2ecf20Sopenharmony_cistatic int tipc_bc_link_set_queue_limits(struct net *net, u32 max_win) 5848c2ecf20Sopenharmony_ci{ 5858c2ecf20Sopenharmony_ci struct tipc_link *l = tipc_bc_sndlink(net); 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci if (!l) 5888c2ecf20Sopenharmony_ci return -ENOPROTOOPT; 5898c2ecf20Sopenharmony_ci if (max_win < BCLINK_WIN_MIN) 5908c2ecf20Sopenharmony_ci max_win = BCLINK_WIN_MIN; 5918c2ecf20Sopenharmony_ci if (max_win > TIPC_MAX_LINK_WIN) 5928c2ecf20Sopenharmony_ci return -EINVAL; 5938c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 5948c2ecf20Sopenharmony_ci tipc_link_set_queue_limits(l, tipc_link_min_win(l), max_win); 5958c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 5968c2ecf20Sopenharmony_ci return 0; 5978c2ecf20Sopenharmony_ci} 5988c2ecf20Sopenharmony_ci 5998c2ecf20Sopenharmony_cistatic int tipc_bc_link_set_broadcast_mode(struct net *net, u32 bc_mode) 6008c2ecf20Sopenharmony_ci{ 6018c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci switch (bc_mode) { 6048c2ecf20Sopenharmony_ci case BCLINK_MODE_BCAST: 6058c2ecf20Sopenharmony_ci if (!bb->bcast_support) 6068c2ecf20Sopenharmony_ci return -ENOPROTOOPT; 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci bb->force_bcast = true; 6098c2ecf20Sopenharmony_ci bb->force_rcast = false; 6108c2ecf20Sopenharmony_ci break; 6118c2ecf20Sopenharmony_ci case BCLINK_MODE_RCAST: 6128c2ecf20Sopenharmony_ci if (!bb->rcast_support) 6138c2ecf20Sopenharmony_ci return -ENOPROTOOPT; 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci bb->force_bcast = false; 6168c2ecf20Sopenharmony_ci bb->force_rcast = true; 6178c2ecf20Sopenharmony_ci break; 6188c2ecf20Sopenharmony_ci case BCLINK_MODE_SEL: 6198c2ecf20Sopenharmony_ci if (!bb->bcast_support || !bb->rcast_support) 6208c2ecf20Sopenharmony_ci return -ENOPROTOOPT; 6218c2ecf20Sopenharmony_ci 6228c2ecf20Sopenharmony_ci bb->force_bcast = false; 6238c2ecf20Sopenharmony_ci bb->force_rcast = false; 6248c2ecf20Sopenharmony_ci break; 6258c2ecf20Sopenharmony_ci default: 6268c2ecf20Sopenharmony_ci return -EINVAL; 6278c2ecf20Sopenharmony_ci } 6288c2ecf20Sopenharmony_ci 6298c2ecf20Sopenharmony_ci return 0; 6308c2ecf20Sopenharmony_ci} 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_cistatic int tipc_bc_link_set_broadcast_ratio(struct net *net, u32 bc_ratio) 6338c2ecf20Sopenharmony_ci{ 6348c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci if (!bb->bcast_support || !bb->rcast_support) 6378c2ecf20Sopenharmony_ci return -ENOPROTOOPT; 6388c2ecf20Sopenharmony_ci 6398c2ecf20Sopenharmony_ci if (bc_ratio > 100 || bc_ratio <= 0) 6408c2ecf20Sopenharmony_ci return -EINVAL; 6418c2ecf20Sopenharmony_ci 6428c2ecf20Sopenharmony_ci bb->rc_ratio = bc_ratio; 6438c2ecf20Sopenharmony_ci tipc_bcast_lock(net); 6448c2ecf20Sopenharmony_ci tipc_bcbase_calc_bc_threshold(net); 6458c2ecf20Sopenharmony_ci tipc_bcast_unlock(net); 6468c2ecf20Sopenharmony_ci 6478c2ecf20Sopenharmony_ci return 0; 6488c2ecf20Sopenharmony_ci} 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ciint tipc_nl_bc_link_set(struct net *net, struct nlattr *attrs[]) 6518c2ecf20Sopenharmony_ci{ 6528c2ecf20Sopenharmony_ci int err; 6538c2ecf20Sopenharmony_ci u32 win; 6548c2ecf20Sopenharmony_ci u32 bc_mode; 6558c2ecf20Sopenharmony_ci u32 bc_ratio; 6568c2ecf20Sopenharmony_ci struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci if (!attrs[TIPC_NLA_LINK_PROP]) 6598c2ecf20Sopenharmony_ci return -EINVAL; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_LINK_PROP], props); 6628c2ecf20Sopenharmony_ci if (err) 6638c2ecf20Sopenharmony_ci return err; 6648c2ecf20Sopenharmony_ci 6658c2ecf20Sopenharmony_ci if (!props[TIPC_NLA_PROP_WIN] && 6668c2ecf20Sopenharmony_ci !props[TIPC_NLA_PROP_BROADCAST] && 6678c2ecf20Sopenharmony_ci !props[TIPC_NLA_PROP_BROADCAST_RATIO]) { 6688c2ecf20Sopenharmony_ci return -EOPNOTSUPP; 6698c2ecf20Sopenharmony_ci } 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci if (props[TIPC_NLA_PROP_BROADCAST]) { 6728c2ecf20Sopenharmony_ci bc_mode = nla_get_u32(props[TIPC_NLA_PROP_BROADCAST]); 6738c2ecf20Sopenharmony_ci err = tipc_bc_link_set_broadcast_mode(net, bc_mode); 6748c2ecf20Sopenharmony_ci } 6758c2ecf20Sopenharmony_ci 6768c2ecf20Sopenharmony_ci if (!err && props[TIPC_NLA_PROP_BROADCAST_RATIO]) { 6778c2ecf20Sopenharmony_ci bc_ratio = nla_get_u32(props[TIPC_NLA_PROP_BROADCAST_RATIO]); 6788c2ecf20Sopenharmony_ci err = tipc_bc_link_set_broadcast_ratio(net, bc_ratio); 6798c2ecf20Sopenharmony_ci } 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ci if (!err && props[TIPC_NLA_PROP_WIN]) { 6828c2ecf20Sopenharmony_ci win = nla_get_u32(props[TIPC_NLA_PROP_WIN]); 6838c2ecf20Sopenharmony_ci err = tipc_bc_link_set_queue_limits(net, win); 6848c2ecf20Sopenharmony_ci } 6858c2ecf20Sopenharmony_ci 6868c2ecf20Sopenharmony_ci return err; 6878c2ecf20Sopenharmony_ci} 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ciint tipc_bcast_init(struct net *net) 6908c2ecf20Sopenharmony_ci{ 6918c2ecf20Sopenharmony_ci struct tipc_net *tn = tipc_net(net); 6928c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = NULL; 6938c2ecf20Sopenharmony_ci struct tipc_link *l = NULL; 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci bb = kzalloc(sizeof(*bb), GFP_KERNEL); 6968c2ecf20Sopenharmony_ci if (!bb) 6978c2ecf20Sopenharmony_ci goto enomem; 6988c2ecf20Sopenharmony_ci tn->bcbase = bb; 6998c2ecf20Sopenharmony_ci spin_lock_init(&tipc_net(net)->bclock); 7008c2ecf20Sopenharmony_ci 7018c2ecf20Sopenharmony_ci if (!tipc_link_bc_create(net, 0, 0, NULL, 7028c2ecf20Sopenharmony_ci one_page_mtu, 7038c2ecf20Sopenharmony_ci BCLINK_WIN_DEFAULT, 7048c2ecf20Sopenharmony_ci BCLINK_WIN_DEFAULT, 7058c2ecf20Sopenharmony_ci 0, 7068c2ecf20Sopenharmony_ci &bb->inputq, 7078c2ecf20Sopenharmony_ci NULL, 7088c2ecf20Sopenharmony_ci NULL, 7098c2ecf20Sopenharmony_ci &l)) 7108c2ecf20Sopenharmony_ci goto enomem; 7118c2ecf20Sopenharmony_ci bb->link = l; 7128c2ecf20Sopenharmony_ci tn->bcl = l; 7138c2ecf20Sopenharmony_ci bb->rc_ratio = 10; 7148c2ecf20Sopenharmony_ci bb->rcast_support = true; 7158c2ecf20Sopenharmony_ci return 0; 7168c2ecf20Sopenharmony_cienomem: 7178c2ecf20Sopenharmony_ci kfree(bb); 7188c2ecf20Sopenharmony_ci kfree(l); 7198c2ecf20Sopenharmony_ci return -ENOMEM; 7208c2ecf20Sopenharmony_ci} 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_civoid tipc_bcast_stop(struct net *net) 7238c2ecf20Sopenharmony_ci{ 7248c2ecf20Sopenharmony_ci struct tipc_net *tn = net_generic(net, tipc_net_id); 7258c2ecf20Sopenharmony_ci 7268c2ecf20Sopenharmony_ci synchronize_net(); 7278c2ecf20Sopenharmony_ci kfree(tn->bcbase); 7288c2ecf20Sopenharmony_ci kfree(tn->bcl); 7298c2ecf20Sopenharmony_ci} 7308c2ecf20Sopenharmony_ci 7318c2ecf20Sopenharmony_civoid tipc_nlist_init(struct tipc_nlist *nl, u32 self) 7328c2ecf20Sopenharmony_ci{ 7338c2ecf20Sopenharmony_ci memset(nl, 0, sizeof(*nl)); 7348c2ecf20Sopenharmony_ci INIT_LIST_HEAD(&nl->list); 7358c2ecf20Sopenharmony_ci nl->self = self; 7368c2ecf20Sopenharmony_ci} 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_civoid tipc_nlist_add(struct tipc_nlist *nl, u32 node) 7398c2ecf20Sopenharmony_ci{ 7408c2ecf20Sopenharmony_ci if (node == nl->self) 7418c2ecf20Sopenharmony_ci nl->local = true; 7428c2ecf20Sopenharmony_ci else if (tipc_dest_push(&nl->list, node, 0)) 7438c2ecf20Sopenharmony_ci nl->remote++; 7448c2ecf20Sopenharmony_ci} 7458c2ecf20Sopenharmony_ci 7468c2ecf20Sopenharmony_civoid tipc_nlist_del(struct tipc_nlist *nl, u32 node) 7478c2ecf20Sopenharmony_ci{ 7488c2ecf20Sopenharmony_ci if (node == nl->self) 7498c2ecf20Sopenharmony_ci nl->local = false; 7508c2ecf20Sopenharmony_ci else if (tipc_dest_del(&nl->list, node, 0)) 7518c2ecf20Sopenharmony_ci nl->remote--; 7528c2ecf20Sopenharmony_ci} 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_civoid tipc_nlist_purge(struct tipc_nlist *nl) 7558c2ecf20Sopenharmony_ci{ 7568c2ecf20Sopenharmony_ci tipc_dest_list_purge(&nl->list); 7578c2ecf20Sopenharmony_ci nl->remote = 0; 7588c2ecf20Sopenharmony_ci nl->local = false; 7598c2ecf20Sopenharmony_ci} 7608c2ecf20Sopenharmony_ci 7618c2ecf20Sopenharmony_ciu32 tipc_bcast_get_mode(struct net *net) 7628c2ecf20Sopenharmony_ci{ 7638c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 7648c2ecf20Sopenharmony_ci 7658c2ecf20Sopenharmony_ci if (bb->force_bcast) 7668c2ecf20Sopenharmony_ci return BCLINK_MODE_BCAST; 7678c2ecf20Sopenharmony_ci 7688c2ecf20Sopenharmony_ci if (bb->force_rcast) 7698c2ecf20Sopenharmony_ci return BCLINK_MODE_RCAST; 7708c2ecf20Sopenharmony_ci 7718c2ecf20Sopenharmony_ci if (bb->bcast_support && bb->rcast_support) 7728c2ecf20Sopenharmony_ci return BCLINK_MODE_SEL; 7738c2ecf20Sopenharmony_ci 7748c2ecf20Sopenharmony_ci return 0; 7758c2ecf20Sopenharmony_ci} 7768c2ecf20Sopenharmony_ci 7778c2ecf20Sopenharmony_ciu32 tipc_bcast_get_broadcast_ratio(struct net *net) 7788c2ecf20Sopenharmony_ci{ 7798c2ecf20Sopenharmony_ci struct tipc_bc_base *bb = tipc_bc_base(net); 7808c2ecf20Sopenharmony_ci 7818c2ecf20Sopenharmony_ci return bb->rc_ratio; 7828c2ecf20Sopenharmony_ci} 7838c2ecf20Sopenharmony_ci 7848c2ecf20Sopenharmony_civoid tipc_mcast_filter_msg(struct net *net, struct sk_buff_head *defq, 7858c2ecf20Sopenharmony_ci struct sk_buff_head *inputq) 7868c2ecf20Sopenharmony_ci{ 7878c2ecf20Sopenharmony_ci struct sk_buff *skb, *_skb, *tmp; 7888c2ecf20Sopenharmony_ci struct tipc_msg *hdr, *_hdr; 7898c2ecf20Sopenharmony_ci bool match = false; 7908c2ecf20Sopenharmony_ci u32 node, port; 7918c2ecf20Sopenharmony_ci 7928c2ecf20Sopenharmony_ci skb = skb_peek(inputq); 7938c2ecf20Sopenharmony_ci if (!skb) 7948c2ecf20Sopenharmony_ci return; 7958c2ecf20Sopenharmony_ci 7968c2ecf20Sopenharmony_ci hdr = buf_msg(skb); 7978c2ecf20Sopenharmony_ci 7988c2ecf20Sopenharmony_ci if (likely(!msg_is_syn(hdr) && skb_queue_empty(defq))) 7998c2ecf20Sopenharmony_ci return; 8008c2ecf20Sopenharmony_ci 8018c2ecf20Sopenharmony_ci node = msg_orignode(hdr); 8028c2ecf20Sopenharmony_ci if (node == tipc_own_addr(net)) 8038c2ecf20Sopenharmony_ci return; 8048c2ecf20Sopenharmony_ci 8058c2ecf20Sopenharmony_ci port = msg_origport(hdr); 8068c2ecf20Sopenharmony_ci 8078c2ecf20Sopenharmony_ci /* Has the twin SYN message already arrived ? */ 8088c2ecf20Sopenharmony_ci skb_queue_walk(defq, _skb) { 8098c2ecf20Sopenharmony_ci _hdr = buf_msg(_skb); 8108c2ecf20Sopenharmony_ci if (msg_orignode(_hdr) != node) 8118c2ecf20Sopenharmony_ci continue; 8128c2ecf20Sopenharmony_ci if (msg_origport(_hdr) != port) 8138c2ecf20Sopenharmony_ci continue; 8148c2ecf20Sopenharmony_ci match = true; 8158c2ecf20Sopenharmony_ci break; 8168c2ecf20Sopenharmony_ci } 8178c2ecf20Sopenharmony_ci 8188c2ecf20Sopenharmony_ci if (!match) { 8198c2ecf20Sopenharmony_ci if (!msg_is_syn(hdr)) 8208c2ecf20Sopenharmony_ci return; 8218c2ecf20Sopenharmony_ci __skb_dequeue(inputq); 8228c2ecf20Sopenharmony_ci __skb_queue_tail(defq, skb); 8238c2ecf20Sopenharmony_ci return; 8248c2ecf20Sopenharmony_ci } 8258c2ecf20Sopenharmony_ci 8268c2ecf20Sopenharmony_ci /* Deliver non-SYN message from other link, otherwise queue it */ 8278c2ecf20Sopenharmony_ci if (!msg_is_syn(hdr)) { 8288c2ecf20Sopenharmony_ci if (msg_is_rcast(hdr) != msg_is_rcast(_hdr)) 8298c2ecf20Sopenharmony_ci return; 8308c2ecf20Sopenharmony_ci __skb_dequeue(inputq); 8318c2ecf20Sopenharmony_ci __skb_queue_tail(defq, skb); 8328c2ecf20Sopenharmony_ci return; 8338c2ecf20Sopenharmony_ci } 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci /* Queue non-SYN/SYN message from same link */ 8368c2ecf20Sopenharmony_ci if (msg_is_rcast(hdr) == msg_is_rcast(_hdr)) { 8378c2ecf20Sopenharmony_ci __skb_dequeue(inputq); 8388c2ecf20Sopenharmony_ci __skb_queue_tail(defq, skb); 8398c2ecf20Sopenharmony_ci return; 8408c2ecf20Sopenharmony_ci } 8418c2ecf20Sopenharmony_ci 8428c2ecf20Sopenharmony_ci /* Matching SYN messages => return the one with data, if any */ 8438c2ecf20Sopenharmony_ci __skb_unlink(_skb, defq); 8448c2ecf20Sopenharmony_ci if (msg_data_sz(hdr)) { 8458c2ecf20Sopenharmony_ci kfree_skb(_skb); 8468c2ecf20Sopenharmony_ci } else { 8478c2ecf20Sopenharmony_ci __skb_dequeue(inputq); 8488c2ecf20Sopenharmony_ci kfree_skb(skb); 8498c2ecf20Sopenharmony_ci __skb_queue_tail(inputq, _skb); 8508c2ecf20Sopenharmony_ci } 8518c2ecf20Sopenharmony_ci 8528c2ecf20Sopenharmony_ci /* Deliver subsequent non-SYN messages from same peer */ 8538c2ecf20Sopenharmony_ci skb_queue_walk_safe(defq, _skb, tmp) { 8548c2ecf20Sopenharmony_ci _hdr = buf_msg(_skb); 8558c2ecf20Sopenharmony_ci if (msg_orignode(_hdr) != node) 8568c2ecf20Sopenharmony_ci continue; 8578c2ecf20Sopenharmony_ci if (msg_origport(_hdr) != port) 8588c2ecf20Sopenharmony_ci continue; 8598c2ecf20Sopenharmony_ci if (msg_is_syn(_hdr)) 8608c2ecf20Sopenharmony_ci break; 8618c2ecf20Sopenharmony_ci __skb_unlink(_skb, defq); 8628c2ecf20Sopenharmony_ci __skb_queue_tail(inputq, _skb); 8638c2ecf20Sopenharmony_ci } 8648c2ecf20Sopenharmony_ci} 865