18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * net/tipc/name_distr.c: TIPC name distribution code
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 2000-2006, 2014, Ericsson AB
58c2ecf20Sopenharmony_ci * Copyright (c) 2005, 2010-2011, Wind River Systems
68c2ecf20Sopenharmony_ci * All rights reserved.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
98c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
128c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
138c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
148c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
158c2ecf20Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
168c2ecf20Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its
178c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived from
188c2ecf20Sopenharmony_ci *    this software without specific prior written permission.
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
218c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
228c2ecf20Sopenharmony_ci * Software Foundation.
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
258c2ecf20Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
268c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
278c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
288c2ecf20Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
298c2ecf20Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
308c2ecf20Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
318c2ecf20Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
328c2ecf20Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
338c2ecf20Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
348c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
358c2ecf20Sopenharmony_ci */
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include "core.h"
388c2ecf20Sopenharmony_ci#include "link.h"
398c2ecf20Sopenharmony_ci#include "name_distr.h"
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciint sysctl_tipc_named_timeout __read_mostly = 2000;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct distr_queue_item {
448c2ecf20Sopenharmony_ci	struct distr_item i;
458c2ecf20Sopenharmony_ci	u32 dtype;
468c2ecf20Sopenharmony_ci	u32 node;
478c2ecf20Sopenharmony_ci	unsigned long expires;
488c2ecf20Sopenharmony_ci	struct list_head next;
498c2ecf20Sopenharmony_ci};
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/**
528c2ecf20Sopenharmony_ci * publ_to_item - add publication info to a publication message
538c2ecf20Sopenharmony_ci */
548c2ecf20Sopenharmony_cistatic void publ_to_item(struct distr_item *i, struct publication *p)
558c2ecf20Sopenharmony_ci{
568c2ecf20Sopenharmony_ci	i->type = htonl(p->type);
578c2ecf20Sopenharmony_ci	i->lower = htonl(p->lower);
588c2ecf20Sopenharmony_ci	i->upper = htonl(p->upper);
598c2ecf20Sopenharmony_ci	i->port = htonl(p->port);
608c2ecf20Sopenharmony_ci	i->key = htonl(p->key);
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci/**
648c2ecf20Sopenharmony_ci * named_prepare_buf - allocate & initialize a publication message
658c2ecf20Sopenharmony_ci *
668c2ecf20Sopenharmony_ci * The buffer returned is of size INT_H_SIZE + payload size
678c2ecf20Sopenharmony_ci */
688c2ecf20Sopenharmony_cistatic struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size,
698c2ecf20Sopenharmony_ci					 u32 dest)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC);
728c2ecf20Sopenharmony_ci	u32 self = tipc_own_addr(net);
738c2ecf20Sopenharmony_ci	struct tipc_msg *msg;
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci	if (buf != NULL) {
768c2ecf20Sopenharmony_ci		msg = buf_msg(buf);
778c2ecf20Sopenharmony_ci		tipc_msg_init(self, msg, NAME_DISTRIBUTOR,
788c2ecf20Sopenharmony_ci			      type, INT_H_SIZE, dest);
798c2ecf20Sopenharmony_ci		msg_set_size(msg, INT_H_SIZE + size);
808c2ecf20Sopenharmony_ci	}
818c2ecf20Sopenharmony_ci	return buf;
828c2ecf20Sopenharmony_ci}
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci/**
858c2ecf20Sopenharmony_ci * tipc_named_publish - tell other nodes about a new publication by this node
868c2ecf20Sopenharmony_ci */
878c2ecf20Sopenharmony_cistruct sk_buff *tipc_named_publish(struct net *net, struct publication *publ)
888c2ecf20Sopenharmony_ci{
898c2ecf20Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
908c2ecf20Sopenharmony_ci	struct distr_item *item;
918c2ecf20Sopenharmony_ci	struct sk_buff *skb;
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	if (publ->scope == TIPC_NODE_SCOPE) {
948c2ecf20Sopenharmony_ci		list_add_tail_rcu(&publ->binding_node, &nt->node_scope);
958c2ecf20Sopenharmony_ci		return NULL;
968c2ecf20Sopenharmony_ci	}
978c2ecf20Sopenharmony_ci	write_lock_bh(&nt->cluster_scope_lock);
988c2ecf20Sopenharmony_ci	list_add_tail(&publ->binding_node, &nt->cluster_scope);
998c2ecf20Sopenharmony_ci	write_unlock_bh(&nt->cluster_scope_lock);
1008c2ecf20Sopenharmony_ci	skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0);
1018c2ecf20Sopenharmony_ci	if (!skb) {
1028c2ecf20Sopenharmony_ci		pr_warn("Publication distribution failure\n");
1038c2ecf20Sopenharmony_ci		return NULL;
1048c2ecf20Sopenharmony_ci	}
1058c2ecf20Sopenharmony_ci	msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
1068c2ecf20Sopenharmony_ci	msg_set_non_legacy(buf_msg(skb));
1078c2ecf20Sopenharmony_ci	item = (struct distr_item *)msg_data(buf_msg(skb));
1088c2ecf20Sopenharmony_ci	publ_to_item(item, publ);
1098c2ecf20Sopenharmony_ci	return skb;
1108c2ecf20Sopenharmony_ci}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci/**
1138c2ecf20Sopenharmony_ci * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node
1148c2ecf20Sopenharmony_ci */
1158c2ecf20Sopenharmony_cistruct sk_buff *tipc_named_withdraw(struct net *net, struct publication *publ)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
1188c2ecf20Sopenharmony_ci	struct distr_item *item;
1198c2ecf20Sopenharmony_ci	struct sk_buff *skb;
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci	write_lock_bh(&nt->cluster_scope_lock);
1228c2ecf20Sopenharmony_ci	list_del(&publ->binding_node);
1238c2ecf20Sopenharmony_ci	write_unlock_bh(&nt->cluster_scope_lock);
1248c2ecf20Sopenharmony_ci	if (publ->scope == TIPC_NODE_SCOPE)
1258c2ecf20Sopenharmony_ci		return NULL;
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci	skb = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0);
1288c2ecf20Sopenharmony_ci	if (!skb) {
1298c2ecf20Sopenharmony_ci		pr_warn("Withdrawal distribution failure\n");
1308c2ecf20Sopenharmony_ci		return NULL;
1318c2ecf20Sopenharmony_ci	}
1328c2ecf20Sopenharmony_ci	msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
1338c2ecf20Sopenharmony_ci	msg_set_non_legacy(buf_msg(skb));
1348c2ecf20Sopenharmony_ci	item = (struct distr_item *)msg_data(buf_msg(skb));
1358c2ecf20Sopenharmony_ci	publ_to_item(item, publ);
1368c2ecf20Sopenharmony_ci	return skb;
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci/**
1408c2ecf20Sopenharmony_ci * named_distribute - prepare name info for bulk distribution to another node
1418c2ecf20Sopenharmony_ci * @list: list of messages (buffers) to be returned from this function
1428c2ecf20Sopenharmony_ci * @dnode: node to be updated
1438c2ecf20Sopenharmony_ci * @pls: linked list of publication items to be packed into buffer chain
1448c2ecf20Sopenharmony_ci */
1458c2ecf20Sopenharmony_cistatic void named_distribute(struct net *net, struct sk_buff_head *list,
1468c2ecf20Sopenharmony_ci			     u32 dnode, struct list_head *pls, u16 seqno)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	struct publication *publ;
1498c2ecf20Sopenharmony_ci	struct sk_buff *skb = NULL;
1508c2ecf20Sopenharmony_ci	struct distr_item *item = NULL;
1518c2ecf20Sopenharmony_ci	u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0, false) - INT_H_SIZE) /
1528c2ecf20Sopenharmony_ci			ITEM_SIZE) * ITEM_SIZE;
1538c2ecf20Sopenharmony_ci	u32 msg_rem = msg_dsz;
1548c2ecf20Sopenharmony_ci	struct tipc_msg *hdr;
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci	list_for_each_entry(publ, pls, binding_node) {
1578c2ecf20Sopenharmony_ci		/* Prepare next buffer: */
1588c2ecf20Sopenharmony_ci		if (!skb) {
1598c2ecf20Sopenharmony_ci			skb = named_prepare_buf(net, PUBLICATION, msg_rem,
1608c2ecf20Sopenharmony_ci						dnode);
1618c2ecf20Sopenharmony_ci			if (!skb) {
1628c2ecf20Sopenharmony_ci				pr_warn("Bulk publication failure\n");
1638c2ecf20Sopenharmony_ci				return;
1648c2ecf20Sopenharmony_ci			}
1658c2ecf20Sopenharmony_ci			hdr = buf_msg(skb);
1668c2ecf20Sopenharmony_ci			msg_set_bc_ack_invalid(hdr, true);
1678c2ecf20Sopenharmony_ci			msg_set_bulk(hdr);
1688c2ecf20Sopenharmony_ci			msg_set_non_legacy(hdr);
1698c2ecf20Sopenharmony_ci			item = (struct distr_item *)msg_data(hdr);
1708c2ecf20Sopenharmony_ci		}
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci		/* Pack publication into message: */
1738c2ecf20Sopenharmony_ci		publ_to_item(item, publ);
1748c2ecf20Sopenharmony_ci		item++;
1758c2ecf20Sopenharmony_ci		msg_rem -= ITEM_SIZE;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci		/* Append full buffer to list: */
1788c2ecf20Sopenharmony_ci		if (!msg_rem) {
1798c2ecf20Sopenharmony_ci			__skb_queue_tail(list, skb);
1808c2ecf20Sopenharmony_ci			skb = NULL;
1818c2ecf20Sopenharmony_ci			msg_rem = msg_dsz;
1828c2ecf20Sopenharmony_ci		}
1838c2ecf20Sopenharmony_ci	}
1848c2ecf20Sopenharmony_ci	if (skb) {
1858c2ecf20Sopenharmony_ci		hdr = buf_msg(skb);
1868c2ecf20Sopenharmony_ci		msg_set_size(hdr, INT_H_SIZE + (msg_dsz - msg_rem));
1878c2ecf20Sopenharmony_ci		skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem));
1888c2ecf20Sopenharmony_ci		__skb_queue_tail(list, skb);
1898c2ecf20Sopenharmony_ci	}
1908c2ecf20Sopenharmony_ci	hdr = buf_msg(skb_peek_tail(list));
1918c2ecf20Sopenharmony_ci	msg_set_last_bulk(hdr);
1928c2ecf20Sopenharmony_ci	msg_set_named_seqno(hdr, seqno);
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/**
1968c2ecf20Sopenharmony_ci * tipc_named_node_up - tell specified node about all publications by this node
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_civoid tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
1998c2ecf20Sopenharmony_ci{
2008c2ecf20Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
2018c2ecf20Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
2028c2ecf20Sopenharmony_ci	struct sk_buff_head head;
2038c2ecf20Sopenharmony_ci	u16 seqno;
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci	__skb_queue_head_init(&head);
2068c2ecf20Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
2078c2ecf20Sopenharmony_ci	if (!(capabilities & TIPC_NAMED_BCAST))
2088c2ecf20Sopenharmony_ci		nt->rc_dests++;
2098c2ecf20Sopenharmony_ci	seqno = nt->snd_nxt;
2108c2ecf20Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci	read_lock_bh(&nt->cluster_scope_lock);
2138c2ecf20Sopenharmony_ci	named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);
2148c2ecf20Sopenharmony_ci	tipc_node_xmit(net, &head, dnode, 0);
2158c2ecf20Sopenharmony_ci	read_unlock_bh(&nt->cluster_scope_lock);
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ci/**
2198c2ecf20Sopenharmony_ci * tipc_publ_purge - remove publication associated with a failed node
2208c2ecf20Sopenharmony_ci *
2218c2ecf20Sopenharmony_ci * Invoked for each publication issued by a newly failed node.
2228c2ecf20Sopenharmony_ci * Removes publication structure from name table & deletes it.
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_cistatic void tipc_publ_purge(struct net *net, struct publication *publ, u32 addr)
2258c2ecf20Sopenharmony_ci{
2268c2ecf20Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
2278c2ecf20Sopenharmony_ci	struct publication *p;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
2308c2ecf20Sopenharmony_ci	p = tipc_nametbl_remove_publ(net, publ->type, publ->lower, publ->upper,
2318c2ecf20Sopenharmony_ci				     publ->node, publ->key);
2328c2ecf20Sopenharmony_ci	if (p)
2338c2ecf20Sopenharmony_ci		tipc_node_unsubscribe(net, &p->binding_node, addr);
2348c2ecf20Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	if (p != publ) {
2378c2ecf20Sopenharmony_ci		pr_err("Unable to remove publication from failed node\n"
2388c2ecf20Sopenharmony_ci		       " (type=%u, lower=%u, node=0x%x, port=%u, key=%u)\n",
2398c2ecf20Sopenharmony_ci		       publ->type, publ->lower, publ->node, publ->port,
2408c2ecf20Sopenharmony_ci		       publ->key);
2418c2ecf20Sopenharmony_ci	}
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci	if (p)
2448c2ecf20Sopenharmony_ci		kfree_rcu(p, rcu);
2458c2ecf20Sopenharmony_ci}
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci/**
2488c2ecf20Sopenharmony_ci * tipc_dist_queue_purge - remove deferred updates from a node that went down
2498c2ecf20Sopenharmony_ci */
2508c2ecf20Sopenharmony_cistatic void tipc_dist_queue_purge(struct net *net, u32 addr)
2518c2ecf20Sopenharmony_ci{
2528c2ecf20Sopenharmony_ci	struct tipc_net *tn = net_generic(net, tipc_net_id);
2538c2ecf20Sopenharmony_ci	struct distr_queue_item *e, *tmp;
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
2568c2ecf20Sopenharmony_ci	list_for_each_entry_safe(e, tmp, &tn->dist_queue, next) {
2578c2ecf20Sopenharmony_ci		if (e->node != addr)
2588c2ecf20Sopenharmony_ci			continue;
2598c2ecf20Sopenharmony_ci		list_del(&e->next);
2608c2ecf20Sopenharmony_ci		kfree(e);
2618c2ecf20Sopenharmony_ci	}
2628c2ecf20Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
2638c2ecf20Sopenharmony_ci}
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_civoid tipc_publ_notify(struct net *net, struct list_head *nsub_list,
2668c2ecf20Sopenharmony_ci		      u32 addr, u16 capabilities)
2678c2ecf20Sopenharmony_ci{
2688c2ecf20Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
2698c2ecf20Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	struct publication *publ, *tmp;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	list_for_each_entry_safe(publ, tmp, nsub_list, binding_node)
2748c2ecf20Sopenharmony_ci		tipc_publ_purge(net, publ, addr);
2758c2ecf20Sopenharmony_ci	tipc_dist_queue_purge(net, addr);
2768c2ecf20Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
2778c2ecf20Sopenharmony_ci	if (!(capabilities & TIPC_NAMED_BCAST))
2788c2ecf20Sopenharmony_ci		nt->rc_dests--;
2798c2ecf20Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
2808c2ecf20Sopenharmony_ci}
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci/**
2838c2ecf20Sopenharmony_ci * tipc_update_nametbl - try to process a nametable update and notify
2848c2ecf20Sopenharmony_ci *			 subscribers
2858c2ecf20Sopenharmony_ci *
2868c2ecf20Sopenharmony_ci * tipc_nametbl_lock must be held.
2878c2ecf20Sopenharmony_ci * Returns the publication item if successful, otherwise NULL.
2888c2ecf20Sopenharmony_ci */
2898c2ecf20Sopenharmony_cistatic bool tipc_update_nametbl(struct net *net, struct distr_item *i,
2908c2ecf20Sopenharmony_ci				u32 node, u32 dtype)
2918c2ecf20Sopenharmony_ci{
2928c2ecf20Sopenharmony_ci	struct publication *p = NULL;
2938c2ecf20Sopenharmony_ci	u32 lower = ntohl(i->lower);
2948c2ecf20Sopenharmony_ci	u32 upper = ntohl(i->upper);
2958c2ecf20Sopenharmony_ci	u32 type = ntohl(i->type);
2968c2ecf20Sopenharmony_ci	u32 port = ntohl(i->port);
2978c2ecf20Sopenharmony_ci	u32 key = ntohl(i->key);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_ci	if (dtype == PUBLICATION) {
3008c2ecf20Sopenharmony_ci		p = tipc_nametbl_insert_publ(net, type, lower, upper,
3018c2ecf20Sopenharmony_ci					     TIPC_CLUSTER_SCOPE, node,
3028c2ecf20Sopenharmony_ci					     port, key);
3038c2ecf20Sopenharmony_ci		if (p) {
3048c2ecf20Sopenharmony_ci			tipc_node_subscribe(net, &p->binding_node, node);
3058c2ecf20Sopenharmony_ci			return true;
3068c2ecf20Sopenharmony_ci		}
3078c2ecf20Sopenharmony_ci	} else if (dtype == WITHDRAWAL) {
3088c2ecf20Sopenharmony_ci		p = tipc_nametbl_remove_publ(net, type, lower,
3098c2ecf20Sopenharmony_ci					     upper, node, key);
3108c2ecf20Sopenharmony_ci		if (p) {
3118c2ecf20Sopenharmony_ci			tipc_node_unsubscribe(net, &p->binding_node, node);
3128c2ecf20Sopenharmony_ci			kfree_rcu(p, rcu);
3138c2ecf20Sopenharmony_ci			return true;
3148c2ecf20Sopenharmony_ci		}
3158c2ecf20Sopenharmony_ci		pr_warn_ratelimited("Failed to remove binding %u,%u from %x\n",
3168c2ecf20Sopenharmony_ci				    type, lower, node);
3178c2ecf20Sopenharmony_ci	} else {
3188c2ecf20Sopenharmony_ci		pr_warn("Unrecognized name table message received\n");
3198c2ecf20Sopenharmony_ci	}
3208c2ecf20Sopenharmony_ci	return false;
3218c2ecf20Sopenharmony_ci}
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_cistatic struct sk_buff *tipc_named_dequeue(struct sk_buff_head *namedq,
3248c2ecf20Sopenharmony_ci					  u16 *rcv_nxt, bool *open)
3258c2ecf20Sopenharmony_ci{
3268c2ecf20Sopenharmony_ci	struct sk_buff *skb, *tmp;
3278c2ecf20Sopenharmony_ci	struct tipc_msg *hdr;
3288c2ecf20Sopenharmony_ci	u16 seqno;
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	spin_lock_bh(&namedq->lock);
3318c2ecf20Sopenharmony_ci	skb_queue_walk_safe(namedq, skb, tmp) {
3328c2ecf20Sopenharmony_ci		if (unlikely(skb_linearize(skb))) {
3338c2ecf20Sopenharmony_ci			__skb_unlink(skb, namedq);
3348c2ecf20Sopenharmony_ci			kfree_skb(skb);
3358c2ecf20Sopenharmony_ci			continue;
3368c2ecf20Sopenharmony_ci		}
3378c2ecf20Sopenharmony_ci		hdr = buf_msg(skb);
3388c2ecf20Sopenharmony_ci		seqno = msg_named_seqno(hdr);
3398c2ecf20Sopenharmony_ci		if (msg_is_last_bulk(hdr)) {
3408c2ecf20Sopenharmony_ci			*rcv_nxt = seqno;
3418c2ecf20Sopenharmony_ci			*open = true;
3428c2ecf20Sopenharmony_ci		}
3438c2ecf20Sopenharmony_ci
3448c2ecf20Sopenharmony_ci		if (msg_is_bulk(hdr) || msg_is_legacy(hdr)) {
3458c2ecf20Sopenharmony_ci			__skb_unlink(skb, namedq);
3468c2ecf20Sopenharmony_ci			spin_unlock_bh(&namedq->lock);
3478c2ecf20Sopenharmony_ci			return skb;
3488c2ecf20Sopenharmony_ci		}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci		if (*open && (*rcv_nxt == seqno)) {
3518c2ecf20Sopenharmony_ci			(*rcv_nxt)++;
3528c2ecf20Sopenharmony_ci			__skb_unlink(skb, namedq);
3538c2ecf20Sopenharmony_ci			spin_unlock_bh(&namedq->lock);
3548c2ecf20Sopenharmony_ci			return skb;
3558c2ecf20Sopenharmony_ci		}
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci		if (less(seqno, *rcv_nxt)) {
3588c2ecf20Sopenharmony_ci			__skb_unlink(skb, namedq);
3598c2ecf20Sopenharmony_ci			kfree_skb(skb);
3608c2ecf20Sopenharmony_ci			continue;
3618c2ecf20Sopenharmony_ci		}
3628c2ecf20Sopenharmony_ci	}
3638c2ecf20Sopenharmony_ci	spin_unlock_bh(&namedq->lock);
3648c2ecf20Sopenharmony_ci	return NULL;
3658c2ecf20Sopenharmony_ci}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci/**
3688c2ecf20Sopenharmony_ci * tipc_named_rcv - process name table update messages sent by another node
3698c2ecf20Sopenharmony_ci */
3708c2ecf20Sopenharmony_civoid tipc_named_rcv(struct net *net, struct sk_buff_head *namedq,
3718c2ecf20Sopenharmony_ci		    u16 *rcv_nxt, bool *open)
3728c2ecf20Sopenharmony_ci{
3738c2ecf20Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
3748c2ecf20Sopenharmony_ci	struct distr_item *item;
3758c2ecf20Sopenharmony_ci	struct tipc_msg *hdr;
3768c2ecf20Sopenharmony_ci	struct sk_buff *skb;
3778c2ecf20Sopenharmony_ci	u32 count, node;
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
3808c2ecf20Sopenharmony_ci	while ((skb = tipc_named_dequeue(namedq, rcv_nxt, open))) {
3818c2ecf20Sopenharmony_ci		hdr = buf_msg(skb);
3828c2ecf20Sopenharmony_ci		node = msg_orignode(hdr);
3838c2ecf20Sopenharmony_ci		item = (struct distr_item *)msg_data(hdr);
3848c2ecf20Sopenharmony_ci		count = msg_data_sz(hdr) / ITEM_SIZE;
3858c2ecf20Sopenharmony_ci		while (count--) {
3868c2ecf20Sopenharmony_ci			tipc_update_nametbl(net, item, node, msg_type(hdr));
3878c2ecf20Sopenharmony_ci			item++;
3888c2ecf20Sopenharmony_ci		}
3898c2ecf20Sopenharmony_ci		kfree_skb(skb);
3908c2ecf20Sopenharmony_ci	}
3918c2ecf20Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
3928c2ecf20Sopenharmony_ci}
3938c2ecf20Sopenharmony_ci
3948c2ecf20Sopenharmony_ci/**
3958c2ecf20Sopenharmony_ci * tipc_named_reinit - re-initialize local publications
3968c2ecf20Sopenharmony_ci *
3978c2ecf20Sopenharmony_ci * This routine is called whenever TIPC networking is enabled.
3988c2ecf20Sopenharmony_ci * All name table entries published by this node are updated to reflect
3998c2ecf20Sopenharmony_ci * the node's new network address.
4008c2ecf20Sopenharmony_ci */
4018c2ecf20Sopenharmony_civoid tipc_named_reinit(struct net *net)
4028c2ecf20Sopenharmony_ci{
4038c2ecf20Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
4048c2ecf20Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
4058c2ecf20Sopenharmony_ci	struct publication *publ;
4068c2ecf20Sopenharmony_ci	u32 self = tipc_own_addr(net);
4078c2ecf20Sopenharmony_ci
4088c2ecf20Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(publ, &nt->node_scope, binding_node)
4118c2ecf20Sopenharmony_ci		publ->node = self;
4128c2ecf20Sopenharmony_ci	list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node)
4138c2ecf20Sopenharmony_ci		publ->node = self;
4148c2ecf20Sopenharmony_ci	nt->rc_dests = 0;
4158c2ecf20Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
4168c2ecf20Sopenharmony_ci}
417