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

📄 node.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
		return;	}	if (n_ptr->bclink.supported) {		tipc_nmap_add(&tipc_cltr_bcast_nodes, n_ptr->addr);		if (n_ptr->addr < tipc_own_addr)			tipc_own_tag++;	}	/* Case 3 (see above) */	tipc_net_send_external_routes(n_ptr->addr);	tipc_cltr_send_slave_routes(c_ptr, n_ptr->addr);	tipc_cltr_bcast_new_route(c_ptr, n_ptr->addr, LOWEST_SLAVE,				  tipc_highest_allowed_slave);}static void node_lost_contact(struct node *n_ptr){	struct cluster *c_ptr;	struct node_subscr *ns, *tns;	char addr_string[16];	u32 i;	/* Clean up broadcast reception remains */	n_ptr->bclink.gap_after = n_ptr->bclink.gap_to = 0;	while (n_ptr->bclink.deferred_head) {		struct sk_buff* buf = n_ptr->bclink.deferred_head;		n_ptr->bclink.deferred_head = buf->next;		buf_discard(buf);	}	if (n_ptr->bclink.defragm) {		buf_discard(n_ptr->bclink.defragm);		n_ptr->bclink.defragm = NULL;	}	if (in_own_cluster(n_ptr->addr) && n_ptr->bclink.supported) {		tipc_bclink_acknowledge(n_ptr, mod(n_ptr->bclink.acked + 10000));	}	/* Update routing tables */	if (is_slave(tipc_own_addr)) {		tipc_net_remove_as_router(n_ptr->addr);	} else {		if (!in_own_cluster(n_ptr->addr)) {			/* Case 4 (see above) */			c_ptr = tipc_cltr_find(tipc_own_addr);			tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,						   tipc_max_nodes);		} else {			/* Case 5 (see above) */			c_ptr = tipc_cltr_find(n_ptr->addr);			if (is_slave(n_ptr->addr)) {				tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr, 1,							   tipc_max_nodes);			} else {				if (n_ptr->bclink.supported) {					tipc_nmap_remove(&tipc_cltr_bcast_nodes,							 n_ptr->addr);					if (n_ptr->addr < tipc_own_addr)						tipc_own_tag--;				}				tipc_net_remove_as_router(n_ptr->addr);				tipc_cltr_bcast_lost_route(c_ptr, n_ptr->addr,							   LOWEST_SLAVE,							   tipc_highest_allowed_slave);			}		}	}	if (tipc_node_has_active_routes(n_ptr))		return;	info("Lost contact with %s\n",	     addr_string_fill(addr_string, n_ptr->addr));	/* Abort link changeover */	for (i = 0; i < MAX_BEARERS; i++) {		struct link *l_ptr = n_ptr->links[i];		if (!l_ptr)			continue;		l_ptr->reset_checkpoint = l_ptr->next_in_no;		l_ptr->exp_msg_count = 0;		tipc_link_reset_fragments(l_ptr);	}	/* Notify subscribers */	list_for_each_entry_safe(ns, tns, &n_ptr->nsub, nodesub_list) {		ns->node = NULL;		list_del_init(&ns->nodesub_list);		tipc_k_signal((Handler)ns->handle_node_down,			      (unsigned long)ns->usr_handle);	}}/** * tipc_node_select_next_hop - find the next-hop node for a message * * Called by when cluster local lookup has failed. */struct node *tipc_node_select_next_hop(u32 addr, u32 selector){	struct node *n_ptr;	u32 router_addr;	if (!tipc_addr_domain_valid(addr))		return NULL;	/* Look for direct link to destination processsor */	n_ptr = tipc_node_find(addr);	if (n_ptr && tipc_node_has_active_links(n_ptr))		return n_ptr;	/* Cluster local system nodes *must* have direct links */	if (!is_slave(addr) && in_own_cluster(addr))		return NULL;	/* Look for cluster local router with direct link to node */	router_addr = tipc_node_select_router(n_ptr, selector);	if (router_addr)		return tipc_node_select(router_addr, selector);	/* Slave nodes can only be accessed within own cluster via a	   known router with direct link -- if no router was found,give up */	if (is_slave(addr))		return NULL;	/* Inter zone/cluster -- find any direct link to remote cluster */	addr = tipc_addr(tipc_zone(addr), tipc_cluster(addr), 0);	n_ptr = tipc_net_select_remote_node(addr, selector);	if (n_ptr && tipc_node_has_active_links(n_ptr))		return n_ptr;	/* Last resort -- look for any router to anywhere in remote zone */	router_addr =  tipc_net_select_router(addr, selector);	if (router_addr)		return tipc_node_select(router_addr, selector);	return NULL;}/** * tipc_node_select_router - select router to reach specified node * * Uses a deterministic and fair algorithm for selecting router node. */u32 tipc_node_select_router(struct node *n_ptr, u32 ref){	u32 ulim;	u32 mask;	u32 start;	u32 r;	if (!n_ptr)		return 0;	if (n_ptr->last_router < 0)		return 0;	ulim = ((n_ptr->last_router + 1) * 32) - 1;	/* Start entry must be random */	mask = tipc_max_nodes;	while (mask > ulim)		mask >>= 1;	start = ref & mask;	r = start;	/* Lookup upwards with wrap-around */	do {		if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)			break;	} while (++r <= ulim);	if (r > ulim) {		r = 1;		do {			if (((n_ptr->routers[r / 32]) >> (r % 32)) & 1)				break;		} while (++r < start);		assert(r != start);	}	assert(r && (r <= ulim));	return tipc_addr(own_zone(), own_cluster(), r);}void tipc_node_add_router(struct node *n_ptr, u32 router){	u32 r_num = tipc_node(router);	n_ptr->routers[r_num / 32] =		((1 << (r_num % 32)) | n_ptr->routers[r_num / 32]);	n_ptr->last_router = tipc_max_nodes / 32;	while ((--n_ptr->last_router >= 0) &&	       !n_ptr->routers[n_ptr->last_router]);}void tipc_node_remove_router(struct node *n_ptr, u32 router){	u32 r_num = tipc_node(router);	if (n_ptr->last_router < 0)		return;		/* No routes */	n_ptr->routers[r_num / 32] =		((~(1 << (r_num % 32))) & (n_ptr->routers[r_num / 32]));	n_ptr->last_router = tipc_max_nodes / 32;	while ((--n_ptr->last_router >= 0) &&	       !n_ptr->routers[n_ptr->last_router]);	if (!tipc_node_is_up(n_ptr))		node_lost_contact(n_ptr);}#if 0void node_print(struct print_buf *buf, struct node *n_ptr, char *str){	u32 i;	tipc_printf(buf, "\n\n%s", str);	for (i = 0; i < MAX_BEARERS; i++) {		if (!n_ptr->links[i])			continue;		tipc_printf(buf, "Links[%u]: %x, ", i, n_ptr->links[i]);	}	tipc_printf(buf, "Active links: [%x,%x]\n",		    n_ptr->active_links[0], n_ptr->active_links[1]);}#endifu32 tipc_available_nodes(const u32 domain){	struct node *n_ptr;	u32 cnt = 0;	for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {		if (!in_scope(domain, n_ptr->addr))			continue;		if (tipc_node_is_up(n_ptr))			cnt++;	}	return cnt;}struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space){	u32 domain;	struct sk_buff *buf;	struct node *n_ptr;	struct tipc_node_info node_info;	u32 payload_size;	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);	domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));	if (!tipc_addr_domain_valid(domain))		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE						   " (network address)");	if (!tipc_nodes)		return tipc_cfg_reply_none();	/* For now, get space for all other nodes	   (will need to modify this when slave nodes are supported */	payload_size = TLV_SPACE(sizeof(node_info)) * (tipc_max_nodes - 1);	if (payload_size > 32768u)		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED						   " (too many nodes)");	buf = tipc_cfg_reply_alloc(payload_size);	if (!buf)		return NULL;	/* Add TLVs for all nodes in scope */	for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {		if (!in_scope(domain, n_ptr->addr))			continue;		node_info.addr = htonl(n_ptr->addr);		node_info.up = htonl(tipc_node_is_up(n_ptr));		tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,				    &node_info, sizeof(node_info));	}	return buf;}struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space){	u32 domain;	struct sk_buff *buf;	struct node *n_ptr;	struct tipc_link_info link_info;	u32 payload_size;	if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))		return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);	domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));	if (!tipc_addr_domain_valid(domain))		return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE						   " (network address)");	if (tipc_mode != TIPC_NET_MODE)		return tipc_cfg_reply_none();	/* Get space for all unicast links + multicast link */	payload_size = TLV_SPACE(sizeof(link_info)) *		(tipc_net.zones[tipc_zone(tipc_own_addr)]->links + 1);	if (payload_size > 32768u)		return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED						   " (too many links)");	buf = tipc_cfg_reply_alloc(payload_size);	if (!buf)		return NULL;	/* Add TLV for broadcast link */	link_info.dest = htonl(tipc_own_addr & 0xfffff00);	link_info.up = htonl(1);	sprintf(link_info.str, tipc_bclink_name);	tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));	/* Add TLVs for any other links in scope */	for (n_ptr = tipc_nodes; n_ptr; n_ptr = n_ptr->next) {		u32 i;		if (!in_scope(domain, n_ptr->addr))			continue;		for (i = 0; i < MAX_BEARERS; i++) {			if (!n_ptr->links[i])				continue;			link_info.dest = htonl(n_ptr->addr);			link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));			strcpy(link_info.str, n_ptr->links[i]->name);			tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,					    &link_info, sizeof(link_info));		}	}	return buf;}

⌨️ 快捷键说明

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