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

📄 node.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * net/tipc/node.c: TIPC node management routines * * Copyright (c) 2000-2006, Ericsson AB * Copyright (c) 2005-2006, 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 "config.h"#include "node.h"#include "cluster.h"#include "net.h"#include "addr.h"#include "node_subscr.h"#include "link.h"#include "port.h"#include "bearer.h"#include "name_distr.h"void node_print(struct print_buf *buf, struct node *n_ptr, char *str);static void node_lost_contact(struct node *n_ptr);static void node_established_contact(struct node *n_ptr);struct node *tipc_nodes = NULL;	/* sorted list of nodes within cluster */u32 tipc_own_tag = 0;struct node *tipc_node_create(u32 addr){	struct cluster *c_ptr;	struct node *n_ptr;	struct node **curr_node;	n_ptr = kzalloc(sizeof(*n_ptr),GFP_ATOMIC);	if (!n_ptr) {		warn("Node creation failed, no memory\n");		return NULL;	}	c_ptr = tipc_cltr_find(addr);	if (!c_ptr) {		c_ptr = tipc_cltr_create(addr);	}	if (!c_ptr) {		kfree(n_ptr);		return NULL;	}	n_ptr->addr = addr;		spin_lock_init(&n_ptr->lock);	INIT_LIST_HEAD(&n_ptr->nsub);	n_ptr->owner = c_ptr;	tipc_cltr_attach_node(c_ptr, n_ptr);	n_ptr->last_router = -1;	/* Insert node into ordered list */	for (curr_node = &tipc_nodes; *curr_node;	     curr_node = &(*curr_node)->next) {		if (addr < (*curr_node)->addr) {			n_ptr->next = *curr_node;			break;		}	}	(*curr_node) = n_ptr;	return n_ptr;}void tipc_node_delete(struct node *n_ptr){	if (!n_ptr)		return;#if 0	/* Not needed because links are already deleted via tipc_bearer_stop() */	u32 l_num;	for (l_num = 0; l_num < MAX_BEARERS; l_num++) {		link_delete(n_ptr->links[l_num]);	}#endif	dbg("node %x deleted\n", n_ptr->addr);	kfree(n_ptr);}/** * tipc_node_link_up - handle addition of link * * Link becomes active (alone or shared) or standby, depending on its priority. */void tipc_node_link_up(struct node *n_ptr, struct link *l_ptr){	struct link **active = &n_ptr->active_links[0];	n_ptr->working_links++;	info("Established link <%s> on network plane %c\n",	     l_ptr->name, l_ptr->b_ptr->net_plane);	if (!active[0]) {		dbg(" link %x into %x/%x\n", l_ptr, &active[0], &active[1]);		active[0] = active[1] = l_ptr;		node_established_contact(n_ptr);		return;	}	if (l_ptr->priority < active[0]->priority) {		info("New link <%s> becomes standby\n", l_ptr->name);		return;	}	tipc_link_send_duplicate(active[0], l_ptr);	if (l_ptr->priority == active[0]->priority) {		active[0] = l_ptr;		return;	}	info("Old link <%s> becomes standby\n", active[0]->name);	if (active[1] != active[0])		info("Old link <%s> becomes standby\n", active[1]->name);	active[0] = active[1] = l_ptr;}/** * node_select_active_links - select active link */static void node_select_active_links(struct node *n_ptr){	struct link **active = &n_ptr->active_links[0];	u32 i;	u32 highest_prio = 0;	active[0] = active[1] = NULL;	for (i = 0; i < MAX_BEARERS; i++) {		struct link *l_ptr = n_ptr->links[i];		if (!l_ptr || !tipc_link_is_up(l_ptr) ||		    (l_ptr->priority < highest_prio))			continue;		if (l_ptr->priority > highest_prio) {			highest_prio = l_ptr->priority;			active[0] = active[1] = l_ptr;		} else {			active[1] = l_ptr;		}	}}/** * tipc_node_link_down - handle loss of link */void tipc_node_link_down(struct node *n_ptr, struct link *l_ptr){	struct link **active;	n_ptr->working_links--;	if (!tipc_link_is_active(l_ptr)) {		info("Lost standby link <%s> on network plane %c\n",		     l_ptr->name, l_ptr->b_ptr->net_plane);		return;	}	info("Lost link <%s> on network plane %c\n",		l_ptr->name, l_ptr->b_ptr->net_plane);	active = &n_ptr->active_links[0];	if (active[0] == l_ptr)		active[0] = active[1];	if (active[1] == l_ptr)		active[1] = active[0];	if (active[0] == l_ptr)		node_select_active_links(n_ptr);	if (tipc_node_is_up(n_ptr))		tipc_link_changeover(l_ptr);	else		node_lost_contact(n_ptr);}int tipc_node_has_active_links(struct node *n_ptr){	return (n_ptr &&		((n_ptr->active_links[0]) || (n_ptr->active_links[1])));}int tipc_node_has_redundant_links(struct node *n_ptr){	return (n_ptr->working_links > 1);}static int tipc_node_has_active_routes(struct node *n_ptr){	return (n_ptr && (n_ptr->last_router >= 0));}int tipc_node_is_up(struct node *n_ptr){	return (tipc_node_has_active_links(n_ptr) || tipc_node_has_active_routes(n_ptr));}struct node *tipc_node_attach_link(struct link *l_ptr){	struct node *n_ptr = tipc_node_find(l_ptr->addr);	if (!n_ptr)		n_ptr = tipc_node_create(l_ptr->addr);	if (n_ptr) {		u32 bearer_id = l_ptr->b_ptr->identity;		char addr_string[16];		if (n_ptr->link_cnt >= 2) {			err("Attempt to create third link to %s\n",			    addr_string_fill(addr_string, n_ptr->addr));			return NULL;		}		if (!n_ptr->links[bearer_id]) {			n_ptr->links[bearer_id] = l_ptr;			tipc_net.zones[tipc_zone(l_ptr->addr)]->links++;			n_ptr->link_cnt++;			return n_ptr;		}		err("Attempt to establish second link on <%s> to %s \n",		    l_ptr->b_ptr->publ.name,		    addr_string_fill(addr_string, l_ptr->addr));	}	return NULL;}void tipc_node_detach_link(struct node *n_ptr, struct link *l_ptr){	n_ptr->links[l_ptr->b_ptr->identity] = NULL;	tipc_net.zones[tipc_zone(l_ptr->addr)]->links--;	n_ptr->link_cnt--;}/* * Routing table management - five cases to handle: * * 1: A link towards a zone/cluster external node comes up. *    => Send a multicast message updating routing tables of all *    system nodes within own cluster that the new destination *    can be reached via this node. *    (node.establishedContact()=>cluster.multicastNewRoute()) * * 2: A link towards a slave node comes up. *    => Send a multicast message updating routing tables of all *    system nodes within own cluster that the new destination *    can be reached via this node. *    (node.establishedContact()=>cluster.multicastNewRoute()) *    => Send a  message to the slave node about existence *    of all system nodes within cluster: *    (node.establishedContact()=>cluster.sendLocalRoutes()) * * 3: A new cluster local system node becomes available. *    => Send message(s) to this particular node containing *    information about all cluster external and slave *     nodes which can be reached via this node. *    (node.establishedContact()==>network.sendExternalRoutes()) *    (node.establishedContact()==>network.sendSlaveRoutes()) *    => Send messages to all directly connected slave nodes *    containing information about the existence of the new node *    (node.establishedContact()=>cluster.multicastNewRoute()) * * 4: The link towards a zone/cluster external node or slave *    node goes down. *    => Send a multcast message updating routing tables of all *    nodes within cluster that the new destination can not any *    longer be reached via this node. *    (node.lostAllLinks()=>cluster.bcastLostRoute()) * * 5: A cluster local system node becomes unavailable. *    => Remove all references to this node from the local *    routing tables. Note: This is a completely node *    local operation. *    (node.lostAllLinks()=>network.removeAsRouter()) *    => Send messages to all directly connected slave nodes *    containing information about loss of the node *    (node.establishedContact()=>cluster.multicastLostRoute()) * */static void node_established_contact(struct node *n_ptr){	struct cluster *c_ptr;	dbg("node_established_contact:-> %x\n", n_ptr->addr);	if (!tipc_node_has_active_routes(n_ptr) && in_own_cluster(n_ptr->addr)) {		tipc_k_signal((Handler)tipc_named_node_up, n_ptr->addr);	}	/* Syncronize broadcast acks */	n_ptr->bclink.acked = tipc_bclink_get_last_sent();	if (is_slave(tipc_own_addr))		return;	if (!in_own_cluster(n_ptr->addr)) {		/* Usage case 1 (see above) */		c_ptr = tipc_cltr_find(tipc_own_addr);		if (!c_ptr)			c_ptr = tipc_cltr_create(tipc_own_addr);		if (c_ptr)			tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1,						  tipc_max_nodes);		return;	}	c_ptr = n_ptr->owner;	if (is_slave(n_ptr->addr)) {		/* Usage case 2 (see above) */		tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, 1, tipc_max_nodes);		tipc_cltr_send_local_routes(c_ptr, n_ptr->addr);

⌨️ 快捷键说明

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