/* * net/tipc/bcast.c: TIPC broadcast code * * Copyright (c) 2004-2006, 2014-2017, Ericsson AB * Copyright (c) 2004, Intel Corporation. * Copyright (c) 2005, 2010-2011, Wind River Systems * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the names of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * Alternatively, this software may be distributed under the terms of the * GNU General Public License ("GPL") version 2 as published by the Free * Software Foundation. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE.
*/
/** * struct tipc_bc_base - base structure for keeping broadcast send state * @link: broadcast send link structure * @inputq: data input queue; will only carry SOCK_WAKEUP messages * @dests: array keeping number of reachable destinations per bearer * @primary_bearer: a bearer having links to all broadcast destinations, if any * @bcast_support: indicates if primary bearer, if any, supports broadcast * @force_bcast: forces broadcast for multicast traffic * @rcast_support: indicates if all peer nodes support replicast * @force_rcast: forces replicast for multicast traffic * @rc_ratio: dest count as percentage of cluster size where send method changes * @bc_threshold: calculated from rc_ratio; if dests > threshold use broadcast
*/ struct tipc_bc_base { struct tipc_link *link; struct sk_buff_head inputq; int dests[MAX_BEARERS]; int primary_bearer; bool bcast_support; bool force_bcast; bool rcast_support; bool force_rcast; int rc_ratio; int bc_threshold;
};
staticstruct tipc_bc_base *tipc_bc_base(struct net *net)
{ return tipc_net(net)->bcbase;
}
/* tipc_bcast_get_mtu(): -get the MTU currently used by broadcast link * Note: the MTU is decremented to give room for a tunnel header, in * case the message needs to be sent as replicast
*/ int tipc_bcast_get_mtu(struct net *net)
{ return tipc_link_mss(tipc_bc_sndlink(net));
}
/* tipc_bcbase_select_primary(): find a bearer with links to all destinations, * if any, and make it primary bearer
*/ staticvoid tipc_bcbase_select_primary(struct net *net)
{ struct tipc_bc_base *bb = tipc_bc_base(net); int all_dests = tipc_link_bc_peers(bb->link); int max_win = tipc_link_max_win(bb->link); int min_win = tipc_link_min_win(bb->link); int i, mtu, prim;
for (i = 0; i < MAX_BEARERS; i++) { if (!bb->dests[i]) continue;
mtu = tipc_bearer_mtu(net, i); if (mtu < tipc_link_mtu(bb->link)) {
tipc_link_set_mtu(bb->link, mtu);
tipc_link_set_queue_limits(bb->link,
min_win,
max_win);
}
bb->bcast_support &= tipc_bearer_bcast_support(net, i); if (bb->dests[i] < all_dests) continue;
bb->primary_bearer = i;
/* Reduce risk that all nodes select same primary */ if ((i ^ tipc_own_addr(net)) & 1) break;
}
prim = bb->primary_bearer; if (prim != INVALID_BEARER_ID)
bb->bcast_support = tipc_bearer_bcast_support(net, prim);
}
void tipc_bcast_inc_bearer_dst_cnt(struct net *net, int bearer_id)
{ struct tipc_bc_base *bb = tipc_bc_base(net);
/* tipc_bcbase_xmit - broadcast a packet queue across one or more bearers * * Note that number of reachable destinations, as indicated in the dests[] * array, may transitionally differ from the number of destinations indicated * in each sent buffer. We can sustain this. Excess destination nodes will * drop and never acknowledge the unexpected packets, and missing destinations * will either require retransmission (if they are just about to be added to * the bearer), or be removed from the buffer's 'ackers' counter (if they * just went down)
*/ staticvoid tipc_bcbase_xmit(struct net *net, struct sk_buff_head *xmitq)
{ int bearer_id; struct tipc_bc_base *bb = tipc_bc_base(net); struct sk_buff *skb, *_skb; struct sk_buff_head _xmitq;
if (skb_queue_empty(xmitq)) return;
/* The typical case: at least one bearer has links to all nodes */
bearer_id = bb->primary_bearer; if (bearer_id >= 0) {
tipc_bearer_bc_xmit(net, bearer_id, xmitq); return;
}
/* We have to transmit across all bearers */
__skb_queue_head_init(&_xmitq); for (bearer_id = 0; bearer_id < MAX_BEARERS; bearer_id++) { if (!bb->dests[bearer_id]) continue;
staticvoid tipc_bcast_select_xmit_method(struct net *net, int dests, struct tipc_mc_method *method)
{ struct tipc_bc_base *bb = tipc_bc_base(net); unsignedlong exp = method->expires;
/* Broadcast supported by used bearer/bearers? */ if (!bb->bcast_support) {
method->rcast = true; return;
} /* Any destinations which don't support replicast ? */ if (!bb->rcast_support) {
method->rcast = false; return;
} /* Can current method be changed ? */
method->expires = jiffies + TIPC_METHOD_EXPIRE; if (method->mandatory) return;
if (!(tipc_net(net)->capabilities & TIPC_MCAST_RBCTL) &&
time_before(jiffies, exp)) return;
/* Configuration as force 'broadcast' method */ if (bb->force_bcast) {
method->rcast = false; return;
} /* Configuration as force 'replicast' method */ if (bb->force_rcast) {
method->rcast = true; return;
} /* Configuration as 'autoselect' or default method */ /* Determine method to use now */
method->rcast = dests <= bb->bc_threshold;
}
/* tipc_bcast_xmit - broadcast the buffer chain to all external nodes * @net: the applicable net namespace * @pkts: chain of buffers containing message * @cong_link_cnt: set to 1 if broadcast link is congested, otherwise 0 * Consumes the buffer chain. * Returns 0 if success, otherwise errno: -EHOSTUNREACH,-EMSGSIZE
*/ int tipc_bcast_xmit(struct net *net, struct sk_buff_head *pkts,
u16 *cong_link_cnt)
{ struct tipc_link *l = tipc_bc_sndlink(net); struct sk_buff_head xmitq; int rc = 0;
/* Any other return value than -ELINKCONG is ignored */ if (tipc_node_xmit(net, &_pkts, dnode, selector) == -ELINKCONG)
(*cong_link_cnt)++;
} return 0;
}
/* tipc_mcast_send_sync - deliver a dummy message with SYN bit * @net: the applicable net namespace * @skb: socket buffer to copy * @method: send method to be used * @dests: destination nodes for message. * Returns 0 if success, otherwise errno
*/ staticint tipc_mcast_send_sync(struct net *net, struct sk_buff *skb, struct tipc_mc_method *method, struct tipc_nlist *dests)
{ struct tipc_msg *hdr, *_hdr; struct sk_buff_head tmpq;
u16 cong_link_cnt = 0; struct sk_buff *_skb; int rc = 0;
/* Is a cluster supporting with new capabilities ? */ if (!(tipc_net(net)->capabilities & TIPC_MCAST_RBCTL)) return 0;
hdr = buf_msg(skb); if (msg_user(hdr) == MSG_FRAGMENTER)
hdr = msg_inner_hdr(hdr); if (msg_type(hdr) != TIPC_MCAST_MSG) return 0;
/* Clone packets before they are consumed by next call */ if (dests->local && !tipc_msg_reassemble(pkts, &localq)) {
rc = -ENOMEM; gotoexit;
} /* Send according to determined transmit method */ if (dests->remote) {
tipc_bcast_select_xmit_method(net, dests->remote, method);
if (dests->local) {
tipc_loopback_trace(net, &localq);
tipc_sk_mcast_rcv(net, &localq, &inputq);
} exit: /* This queue should normally be empty by now */
__skb_queue_purge(pkts); return rc;
}
/* tipc_bcast_rcv - receive a broadcast packet, and deliver to rcv link * * RCU is locked, no other locks set
*/ int tipc_bcast_rcv(struct net *net, struct tipc_link *l, struct sk_buff *skb)
{ struct tipc_msg *hdr = buf_msg(skb); struct sk_buff_head *inputq = &tipc_bc_base(net)->inputq; struct sk_buff_head xmitq; int rc;
/* Any socket wakeup messages ? */ if (!skb_queue_empty(inputq))
tipc_sk_rcv(net, inputq);
}
/* tipc_bcast_synch_rcv - check and update rcv link with peer's send state * * RCU is locked, no other locks set
*/ int tipc_bcast_sync_rcv(struct net *net, struct tipc_link *l, struct tipc_msg *hdr, struct sk_buff_head *retrq)
{ struct sk_buff_head *inputq = &tipc_bc_base(net)->inputq; struct tipc_gap_ack_blks *ga; struct sk_buff_head xmitq; int rc = 0;
/* Any socket wakeup messages ? */ if (!skb_queue_empty(inputq))
tipc_sk_rcv(net, inputq); return rc;
}
/* tipc_bcast_add_peer - add a peer node to broadcast link and bearer * * RCU is locked, node lock is set
*/ void tipc_bcast_add_peer(struct net *net, struct tipc_link *uc_l, struct sk_buff_head *xmitq)
{ struct tipc_link *snd_l = tipc_bc_sndlink(net);
if (likely(!msg_is_syn(hdr) && skb_queue_empty(defq))) return;
node = msg_orignode(hdr); if (node == tipc_own_addr(net)) return;
port = msg_origport(hdr);
/* Has the twin SYN message already arrived ? */
skb_queue_walk(defq, _skb) {
_hdr = buf_msg(_skb); if (msg_orignode(_hdr) != node) continue; if (msg_origport(_hdr) != port) continue;
match = true; break;
}
if (!match) { if (!msg_is_syn(hdr)) return;
__skb_dequeue(inputq);
__skb_queue_tail(defq, skb); return;
}
/* Deliver non-SYN message from other link, otherwise queue it */ if (!msg_is_syn(hdr)) { if (msg_is_rcast(hdr) != msg_is_rcast(_hdr)) return;
__skb_dequeue(inputq);
__skb_queue_tail(defq, skb); return;
}
/* Queue non-SYN/SYN message from same link */ if (msg_is_rcast(hdr) == msg_is_rcast(_hdr)) {
__skb_dequeue(inputq);
__skb_queue_tail(defq, skb); return;
}
/* Matching SYN messages => return the one with data, if any */
__skb_unlink(_skb, defq); if (msg_data_sz(hdr)) {
kfree_skb(_skb);
} else {
__skb_dequeue(inputq);
kfree_skb(skb);
__skb_queue_tail(inputq, _skb);
}
/* Deliver subsequent non-SYN messages from same peer */
skb_queue_walk_safe(defq, _skb, tmp) {
_hdr = buf_msg(_skb); if (msg_orignode(_hdr) != node) continue; if (msg_origport(_hdr) != port) continue; if (msg_is_syn(_hdr)) break;
__skb_unlink(_skb, defq);
__skb_queue_tail(inputq, _skb);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.