⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bcast.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * net/tipc/bcast.c: TIPC broadcast code * * Copyright (c) 2004-2006, Ericsson AB * Copyright (c) 2004, Intel Corporation. * Copyright (c) 2005, 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. */#include "core.h"#include "msg.h"#include "dbg.h"#include "link.h"#include "net.h"#include "node.h"#include "port.h"#include "addr.h"#include "node_subscr.h"#include "name_distr.h"#include "bearer.h"#include "name_table.h"#include "bcast.h"#define MAX_PKT_DEFAULT_MCAST 1500	/* bcast link max packet size (fixed) */#define BCLINK_WIN_DEFAULT 20		/* bcast link window size (default) */#define BCLINK_LOG_BUF_SIZE 0/* * Loss rate for incoming broadcast frames; used to test retransmission code. * Set to N to cause every N'th frame to be discarded; 0 => don't discard any. */#define TIPC_BCAST_LOSS_RATE 0/** * struct bcbearer_pair - a pair of bearers used by broadcast link * @primary: pointer to primary bearer * @secondary: pointer to secondary bearer * * Bearers must have same priority and same set of reachable destinations * to be paired. */struct bcbearer_pair {	struct bearer *primary;	struct bearer *secondary;};/** * struct bcbearer - bearer used by broadcast link * @bearer: (non-standard) broadcast bearer structure * @media: (non-standard) broadcast media structure * @bpairs: array of bearer pairs * @bpairs_temp: temporary array of bearer pairs used by tipc_bcbearer_sort() * @remains: temporary node map used by tipc_bcbearer_send() * @remains_new: temporary node map used tipc_bcbearer_send() * * Note: The fields labelled "temporary" are incorporated into the bearer * to avoid consuming potentially limited stack space through the use of * large local variables within multicast routines.  Concurrent access is * prevented through use of the spinlock "bc_lock". */struct bcbearer {	struct bearer bearer;	struct media media;	struct bcbearer_pair bpairs[MAX_BEARERS];	struct bcbearer_pair bpairs_temp[TIPC_MAX_LINK_PRI + 1];	struct node_map remains;	struct node_map remains_new;};/** * struct bclink - link used for broadcast messages * @link: (non-standard) broadcast link structure * @node: (non-standard) node structure representing b'cast link's peer node * * Handles sequence numbering, fragmentation, bundling, etc. */struct bclink {	struct link link;	struct node node;};static struct bcbearer *bcbearer = NULL;static struct bclink *bclink = NULL;static struct link *bcl = NULL;static DEFINE_SPINLOCK(bc_lock);char tipc_bclink_name[] = "multicast-link";static u32 buf_seqno(struct sk_buff *buf){	return msg_seqno(buf_msg(buf));}static u32 bcbuf_acks(struct sk_buff *buf){	return (u32)(unsigned long)TIPC_SKB_CB(buf)->handle;}static void bcbuf_set_acks(struct sk_buff *buf, u32 acks){	TIPC_SKB_CB(buf)->handle = (void *)(unsigned long)acks;}static void bcbuf_decr_acks(struct sk_buff *buf){	bcbuf_set_acks(buf, bcbuf_acks(buf) - 1);}/** * bclink_set_gap - set gap according to contents of current deferred pkt queue * * Called with 'node' locked, bc_lock unlocked */static void bclink_set_gap(struct node *n_ptr){	struct sk_buff *buf = n_ptr->bclink.deferred_head;	n_ptr->bclink.gap_after = n_ptr->bclink.gap_to =		mod(n_ptr->bclink.last_in);	if (unlikely(buf != NULL))		n_ptr->bclink.gap_to = mod(buf_seqno(buf) - 1);}/** * bclink_ack_allowed - test if ACK or NACK message can be sent at this moment * * This mechanism endeavours to prevent all nodes in network from trying * to ACK or NACK at the same time. * * Note: TIPC uses a different trigger to distribute ACKs than it does to *       distribute NACKs, but tries to use the same spacing (divide by 16). */static int bclink_ack_allowed(u32 n){	return((n % TIPC_MIN_LINK_WIN) == tipc_own_tag);}/** * bclink_retransmit_pkt - retransmit broadcast packets * @after: sequence number of last packet to *not* retransmit * @to: sequence number of last packet to retransmit * * Called with bc_lock locked */static void bclink_retransmit_pkt(u32 after, u32 to){	struct sk_buff *buf;	buf = bcl->first_out;	while (buf && less_eq(buf_seqno(buf), after)) {		buf = buf->next;	}	tipc_link_retransmit(bcl, buf, mod(to - after));}/** * tipc_bclink_acknowledge - handle acknowledgement of broadcast packets * @n_ptr: node that sent acknowledgement info * @acked: broadcast sequence # that has been acknowledged * * Node is locked, bc_lock unlocked. */void tipc_bclink_acknowledge(struct node *n_ptr, u32 acked){	struct sk_buff *crs;	struct sk_buff *next;	unsigned int released = 0;	if (less_eq(acked, n_ptr->bclink.acked))		return;	spin_lock_bh(&bc_lock);	/* Skip over packets that node has previously acknowledged */	crs = bcl->first_out;	while (crs && less_eq(buf_seqno(crs), n_ptr->bclink.acked)) {		crs = crs->next;	}	/* Update packets that node is now acknowledging */	while (crs && less_eq(buf_seqno(crs), acked)) {		next = crs->next;		bcbuf_decr_acks(crs);		if (bcbuf_acks(crs) == 0) {			bcl->first_out = next;			bcl->out_queue_size--;			buf_discard(crs);			released = 1;		}		crs = next;	}	n_ptr->bclink.acked = acked;	/* Try resolving broadcast link congestion, if necessary */	if (unlikely(bcl->next_out))		tipc_link_push_queue(bcl);	if (unlikely(released && !list_empty(&bcl->waiting_ports)))		tipc_link_wakeup_ports(bcl, 0);	spin_unlock_bh(&bc_lock);}/** * bclink_send_ack - unicast an ACK msg * * tipc_net_lock and node lock set */static void bclink_send_ack(struct node *n_ptr){	struct link *l_ptr = n_ptr->active_links[n_ptr->addr & 1];	if (l_ptr != NULL)		tipc_link_send_proto_msg(l_ptr, STATE_MSG, 0, 0, 0, 0, 0);}/** * bclink_send_nack- broadcast a NACK msg * * tipc_net_lock and node lock set */static void bclink_send_nack(struct node *n_ptr){	struct sk_buff *buf;	struct tipc_msg *msg;	if (!less(n_ptr->bclink.gap_after, n_ptr->bclink.gap_to))		return;	buf = buf_acquire(INT_H_SIZE);	if (buf) {		msg = buf_msg(buf);		msg_init(msg, BCAST_PROTOCOL, STATE_MSG,			 TIPC_OK, INT_H_SIZE, n_ptr->addr);		msg_set_mc_netid(msg, tipc_net_id);		msg_set_bcast_ack(msg, mod(n_ptr->bclink.last_in));		msg_set_bcgap_after(msg, n_ptr->bclink.gap_after);		msg_set_bcgap_to(msg, n_ptr->bclink.gap_to);		msg_set_bcast_tag(msg, tipc_own_tag);		if (tipc_bearer_send(&bcbearer->bearer, buf, NULL)) {			bcl->stats.sent_nacks++;			buf_discard(buf);		} else {			tipc_bearer_schedule(bcl->b_ptr, bcl);			bcl->proto_msg_queue = buf;			bcl->stats.bearer_congs++;		}		/*		 * Ensure we doesn't send another NACK msg to the node		 * until 16 more deferred messages arrive from it		 * (i.e. helps prevent all nodes from NACK'ing at same time)		 */		n_ptr->bclink.nack_sync = tipc_own_tag;	}}/** * tipc_bclink_check_gap - send a NACK if a sequence gap exists * * tipc_net_lock and node lock set */void tipc_bclink_check_gap(struct node *n_ptr, u32 last_sent){	if (!n_ptr->bclink.supported ||	    less_eq(last_sent, mod(n_ptr->bclink.last_in)))		return;	bclink_set_gap(n_ptr);	if (n_ptr->bclink.gap_after == n_ptr->bclink.gap_to)		n_ptr->bclink.gap_to = last_sent;	bclink_send_nack(n_ptr);}/** * tipc_bclink_peek_nack - process a NACK msg meant for another node * * Only tipc_net_lock set. */static void tipc_bclink_peek_nack(u32 dest, u32 sender_tag, u32 gap_after, u32 gap_to){	struct node *n_ptr = tipc_node_find(dest);	u32 my_after, my_to;	if (unlikely(!n_ptr || !tipc_node_is_up(n_ptr)))		return;	tipc_node_lock(n_ptr);	/*	 * Modify gap to suppress unnecessary NACKs from this node	 */	my_after = n_ptr->bclink.gap_after;	my_to = n_ptr->bclink.gap_to;	if (less_eq(gap_after, my_after)) {		if (less(my_after, gap_to) && less(gap_to, my_to))			n_ptr->bclink.gap_after = gap_to;		else if (less_eq(my_to, gap_to))			n_ptr->bclink.gap_to = n_ptr->bclink.gap_after;	} else if (less_eq(gap_after, my_to)) {		if (less_eq(my_to, gap_to))			n_ptr->bclink.gap_to = gap_after;	} else {		/*		 * Expand gap if missing bufs not in deferred queue:		 */		struct sk_buff *buf = n_ptr->bclink.deferred_head;		u32 prev = n_ptr->bclink.gap_to;		for (; buf; buf = buf->next) {			u32 seqno = buf_seqno(buf);			if (mod(seqno - prev) != 1) {				buf = NULL;				break;			}			if (seqno == gap_after)				break;			prev = seqno;		}		if (buf == NULL)			n_ptr->bclink.gap_to = gap_after;	}	/*	 * Some nodes may send a complementary NACK now:	 */	if (bclink_ack_allowed(sender_tag + 1)) {		if (n_ptr->bclink.gap_to != n_ptr->bclink.gap_after) {			bclink_send_nack(n_ptr);			bclink_set_gap(n_ptr);		}	}	tipc_node_unlock(n_ptr);}/** * tipc_bclink_send_msg - broadcast a packet to all nodes in cluster */int tipc_bclink_send_msg(struct sk_buff *buf){	int res;	spin_lock_bh(&bc_lock);	res = tipc_link_send_buf(bcl, buf);	if (unlikely(res == -ELINKCONG))		buf_discard(buf);	else		bcl->stats.sent_info++;	if (bcl->out_queue_size > bcl->stats.max_queue_sz)		bcl->stats.max_queue_sz = bcl->out_queue_size;	bcl->stats.queue_sz_counts++;	bcl->stats.accu_queue_sz += bcl->out_queue_size;	spin_unlock_bh(&bc_lock);	return res;}/** * tipc_bclink_recv_pkt - receive a broadcast packet, and deliver upwards * * tipc_net_lock is read_locked, no other locks set */void tipc_bclink_recv_pkt(struct sk_buff *buf){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -