162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * net/tipc/name_distr.c: TIPC name distribution code
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2000-2006, 2014-2019, Ericsson AB
562306a36Sopenharmony_ci * Copyright (c) 2005, 2010-2011, Wind River Systems
662306a36Sopenharmony_ci * Copyright (c) 2020-2021, Red Hat Inc
762306a36Sopenharmony_ci * All rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
1062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1362306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
1462306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
1562306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
1662306a36Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
1762306a36Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its
1862306a36Sopenharmony_ci *    contributors may be used to endorse or promote products derived from
1962306a36Sopenharmony_ci *    this software without specific prior written permission.
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2262306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2362306a36Sopenharmony_ci * Software Foundation.
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2662306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2762306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2862306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2962306a36Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3062306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3162306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3262306a36Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3362306a36Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3462306a36Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3562306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#include "core.h"
3962306a36Sopenharmony_ci#include "link.h"
4062306a36Sopenharmony_ci#include "name_distr.h"
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ciint sysctl_tipc_named_timeout __read_mostly = 2000;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/**
4562306a36Sopenharmony_ci * publ_to_item - add publication info to a publication message
4662306a36Sopenharmony_ci * @p: publication info
4762306a36Sopenharmony_ci * @i: location of item in the message
4862306a36Sopenharmony_ci */
4962306a36Sopenharmony_cistatic void publ_to_item(struct distr_item *i, struct publication *p)
5062306a36Sopenharmony_ci{
5162306a36Sopenharmony_ci	i->type = htonl(p->sr.type);
5262306a36Sopenharmony_ci	i->lower = htonl(p->sr.lower);
5362306a36Sopenharmony_ci	i->upper = htonl(p->sr.upper);
5462306a36Sopenharmony_ci	i->port = htonl(p->sk.ref);
5562306a36Sopenharmony_ci	i->key = htonl(p->key);
5662306a36Sopenharmony_ci}
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci/**
5962306a36Sopenharmony_ci * named_prepare_buf - allocate & initialize a publication message
6062306a36Sopenharmony_ci * @net: the associated network namespace
6162306a36Sopenharmony_ci * @type: message type
6262306a36Sopenharmony_ci * @size: payload size
6362306a36Sopenharmony_ci * @dest: destination node
6462306a36Sopenharmony_ci *
6562306a36Sopenharmony_ci * The buffer returned is of size INT_H_SIZE + payload size
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_cistatic struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size,
6862306a36Sopenharmony_ci					 u32 dest)
6962306a36Sopenharmony_ci{
7062306a36Sopenharmony_ci	struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC);
7162306a36Sopenharmony_ci	u32 self = tipc_own_addr(net);
7262306a36Sopenharmony_ci	struct tipc_msg *msg;
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	if (buf != NULL) {
7562306a36Sopenharmony_ci		msg = buf_msg(buf);
7662306a36Sopenharmony_ci		tipc_msg_init(self, msg, NAME_DISTRIBUTOR,
7762306a36Sopenharmony_ci			      type, INT_H_SIZE, dest);
7862306a36Sopenharmony_ci		msg_set_size(msg, INT_H_SIZE + size);
7962306a36Sopenharmony_ci	}
8062306a36Sopenharmony_ci	return buf;
8162306a36Sopenharmony_ci}
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci/**
8462306a36Sopenharmony_ci * tipc_named_publish - tell other nodes about a new publication by this node
8562306a36Sopenharmony_ci * @net: the associated network namespace
8662306a36Sopenharmony_ci * @p: the new publication
8762306a36Sopenharmony_ci */
8862306a36Sopenharmony_cistruct sk_buff *tipc_named_publish(struct net *net, struct publication *p)
8962306a36Sopenharmony_ci{
9062306a36Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
9162306a36Sopenharmony_ci	struct distr_item *item;
9262306a36Sopenharmony_ci	struct sk_buff *skb;
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci	if (p->scope == TIPC_NODE_SCOPE) {
9562306a36Sopenharmony_ci		list_add_tail_rcu(&p->binding_node, &nt->node_scope);
9662306a36Sopenharmony_ci		return NULL;
9762306a36Sopenharmony_ci	}
9862306a36Sopenharmony_ci	write_lock_bh(&nt->cluster_scope_lock);
9962306a36Sopenharmony_ci	list_add_tail(&p->binding_node, &nt->cluster_scope);
10062306a36Sopenharmony_ci	write_unlock_bh(&nt->cluster_scope_lock);
10162306a36Sopenharmony_ci	skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0);
10262306a36Sopenharmony_ci	if (!skb) {
10362306a36Sopenharmony_ci		pr_warn("Publication distribution failure\n");
10462306a36Sopenharmony_ci		return NULL;
10562306a36Sopenharmony_ci	}
10662306a36Sopenharmony_ci	msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
10762306a36Sopenharmony_ci	msg_set_non_legacy(buf_msg(skb));
10862306a36Sopenharmony_ci	item = (struct distr_item *)msg_data(buf_msg(skb));
10962306a36Sopenharmony_ci	publ_to_item(item, p);
11062306a36Sopenharmony_ci	return skb;
11162306a36Sopenharmony_ci}
11262306a36Sopenharmony_ci
11362306a36Sopenharmony_ci/**
11462306a36Sopenharmony_ci * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node
11562306a36Sopenharmony_ci * @net: the associated network namespace
11662306a36Sopenharmony_ci * @p: the withdrawn publication
11762306a36Sopenharmony_ci */
11862306a36Sopenharmony_cistruct sk_buff *tipc_named_withdraw(struct net *net, struct publication *p)
11962306a36Sopenharmony_ci{
12062306a36Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
12162306a36Sopenharmony_ci	struct distr_item *item;
12262306a36Sopenharmony_ci	struct sk_buff *skb;
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	write_lock_bh(&nt->cluster_scope_lock);
12562306a36Sopenharmony_ci	list_del(&p->binding_node);
12662306a36Sopenharmony_ci	write_unlock_bh(&nt->cluster_scope_lock);
12762306a36Sopenharmony_ci	if (p->scope == TIPC_NODE_SCOPE)
12862306a36Sopenharmony_ci		return NULL;
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ci	skb = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0);
13162306a36Sopenharmony_ci	if (!skb) {
13262306a36Sopenharmony_ci		pr_warn("Withdrawal distribution failure\n");
13362306a36Sopenharmony_ci		return NULL;
13462306a36Sopenharmony_ci	}
13562306a36Sopenharmony_ci	msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
13662306a36Sopenharmony_ci	msg_set_non_legacy(buf_msg(skb));
13762306a36Sopenharmony_ci	item = (struct distr_item *)msg_data(buf_msg(skb));
13862306a36Sopenharmony_ci	publ_to_item(item, p);
13962306a36Sopenharmony_ci	return skb;
14062306a36Sopenharmony_ci}
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/**
14362306a36Sopenharmony_ci * named_distribute - prepare name info for bulk distribution to another node
14462306a36Sopenharmony_ci * @net: the associated network namespace
14562306a36Sopenharmony_ci * @list: list of messages (buffers) to be returned from this function
14662306a36Sopenharmony_ci * @dnode: node to be updated
14762306a36Sopenharmony_ci * @pls: linked list of publication items to be packed into buffer chain
14862306a36Sopenharmony_ci * @seqno: sequence number for this message
14962306a36Sopenharmony_ci */
15062306a36Sopenharmony_cistatic void named_distribute(struct net *net, struct sk_buff_head *list,
15162306a36Sopenharmony_ci			     u32 dnode, struct list_head *pls, u16 seqno)
15262306a36Sopenharmony_ci{
15362306a36Sopenharmony_ci	struct publication *publ;
15462306a36Sopenharmony_ci	struct sk_buff *skb = NULL;
15562306a36Sopenharmony_ci	struct distr_item *item = NULL;
15662306a36Sopenharmony_ci	u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0, false) - INT_H_SIZE) /
15762306a36Sopenharmony_ci			ITEM_SIZE) * ITEM_SIZE;
15862306a36Sopenharmony_ci	u32 msg_rem = msg_dsz;
15962306a36Sopenharmony_ci	struct tipc_msg *hdr;
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci	list_for_each_entry(publ, pls, binding_node) {
16262306a36Sopenharmony_ci		/* Prepare next buffer: */
16362306a36Sopenharmony_ci		if (!skb) {
16462306a36Sopenharmony_ci			skb = named_prepare_buf(net, PUBLICATION, msg_rem,
16562306a36Sopenharmony_ci						dnode);
16662306a36Sopenharmony_ci			if (!skb) {
16762306a36Sopenharmony_ci				pr_warn("Bulk publication failure\n");
16862306a36Sopenharmony_ci				return;
16962306a36Sopenharmony_ci			}
17062306a36Sopenharmony_ci			hdr = buf_msg(skb);
17162306a36Sopenharmony_ci			msg_set_bc_ack_invalid(hdr, true);
17262306a36Sopenharmony_ci			msg_set_bulk(hdr);
17362306a36Sopenharmony_ci			msg_set_non_legacy(hdr);
17462306a36Sopenharmony_ci			item = (struct distr_item *)msg_data(hdr);
17562306a36Sopenharmony_ci		}
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci		/* Pack publication into message: */
17862306a36Sopenharmony_ci		publ_to_item(item, publ);
17962306a36Sopenharmony_ci		item++;
18062306a36Sopenharmony_ci		msg_rem -= ITEM_SIZE;
18162306a36Sopenharmony_ci
18262306a36Sopenharmony_ci		/* Append full buffer to list: */
18362306a36Sopenharmony_ci		if (!msg_rem) {
18462306a36Sopenharmony_ci			__skb_queue_tail(list, skb);
18562306a36Sopenharmony_ci			skb = NULL;
18662306a36Sopenharmony_ci			msg_rem = msg_dsz;
18762306a36Sopenharmony_ci		}
18862306a36Sopenharmony_ci	}
18962306a36Sopenharmony_ci	if (skb) {
19062306a36Sopenharmony_ci		hdr = buf_msg(skb);
19162306a36Sopenharmony_ci		msg_set_size(hdr, INT_H_SIZE + (msg_dsz - msg_rem));
19262306a36Sopenharmony_ci		skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem));
19362306a36Sopenharmony_ci		__skb_queue_tail(list, skb);
19462306a36Sopenharmony_ci	}
19562306a36Sopenharmony_ci	hdr = buf_msg(skb_peek_tail(list));
19662306a36Sopenharmony_ci	msg_set_last_bulk(hdr);
19762306a36Sopenharmony_ci	msg_set_named_seqno(hdr, seqno);
19862306a36Sopenharmony_ci}
19962306a36Sopenharmony_ci
20062306a36Sopenharmony_ci/**
20162306a36Sopenharmony_ci * tipc_named_node_up - tell specified node about all publications by this node
20262306a36Sopenharmony_ci * @net: the associated network namespace
20362306a36Sopenharmony_ci * @dnode: destination node
20462306a36Sopenharmony_ci * @capabilities: peer node's capabilities
20562306a36Sopenharmony_ci */
20662306a36Sopenharmony_civoid tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
20762306a36Sopenharmony_ci{
20862306a36Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
20962306a36Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
21062306a36Sopenharmony_ci	struct sk_buff_head head;
21162306a36Sopenharmony_ci	u16 seqno;
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	__skb_queue_head_init(&head);
21462306a36Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
21562306a36Sopenharmony_ci	if (!(capabilities & TIPC_NAMED_BCAST))
21662306a36Sopenharmony_ci		nt->rc_dests++;
21762306a36Sopenharmony_ci	seqno = nt->snd_nxt;
21862306a36Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
21962306a36Sopenharmony_ci
22062306a36Sopenharmony_ci	read_lock_bh(&nt->cluster_scope_lock);
22162306a36Sopenharmony_ci	named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);
22262306a36Sopenharmony_ci	tipc_node_xmit(net, &head, dnode, 0);
22362306a36Sopenharmony_ci	read_unlock_bh(&nt->cluster_scope_lock);
22462306a36Sopenharmony_ci}
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci/**
22762306a36Sopenharmony_ci * tipc_publ_purge - remove publication associated with a failed node
22862306a36Sopenharmony_ci * @net: the associated network namespace
22962306a36Sopenharmony_ci * @p: the publication to remove
23062306a36Sopenharmony_ci * @addr: failed node's address
23162306a36Sopenharmony_ci *
23262306a36Sopenharmony_ci * Invoked for each publication issued by a newly failed node.
23362306a36Sopenharmony_ci * Removes publication structure from name table & deletes it.
23462306a36Sopenharmony_ci */
23562306a36Sopenharmony_cistatic void tipc_publ_purge(struct net *net, struct publication *p, u32 addr)
23662306a36Sopenharmony_ci{
23762306a36Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
23862306a36Sopenharmony_ci	struct publication *_p;
23962306a36Sopenharmony_ci	struct tipc_uaddr ua;
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci	tipc_uaddr(&ua, TIPC_SERVICE_RANGE, p->scope, p->sr.type,
24262306a36Sopenharmony_ci		   p->sr.lower, p->sr.upper);
24362306a36Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
24462306a36Sopenharmony_ci	_p = tipc_nametbl_remove_publ(net, &ua, &p->sk, p->key);
24562306a36Sopenharmony_ci	if (_p)
24662306a36Sopenharmony_ci		tipc_node_unsubscribe(net, &_p->binding_node, addr);
24762306a36Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
24862306a36Sopenharmony_ci	if (_p)
24962306a36Sopenharmony_ci		kfree_rcu(_p, rcu);
25062306a36Sopenharmony_ci}
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_civoid tipc_publ_notify(struct net *net, struct list_head *nsub_list,
25362306a36Sopenharmony_ci		      u32 addr, u16 capabilities)
25462306a36Sopenharmony_ci{
25562306a36Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
25662306a36Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
25762306a36Sopenharmony_ci
25862306a36Sopenharmony_ci	struct publication *publ, *tmp;
25962306a36Sopenharmony_ci
26062306a36Sopenharmony_ci	list_for_each_entry_safe(publ, tmp, nsub_list, binding_node)
26162306a36Sopenharmony_ci		tipc_publ_purge(net, publ, addr);
26262306a36Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
26362306a36Sopenharmony_ci	if (!(capabilities & TIPC_NAMED_BCAST))
26462306a36Sopenharmony_ci		nt->rc_dests--;
26562306a36Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
26662306a36Sopenharmony_ci}
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_ci/**
26962306a36Sopenharmony_ci * tipc_update_nametbl - try to process a nametable update and notify
27062306a36Sopenharmony_ci *			 subscribers
27162306a36Sopenharmony_ci * @net: the associated network namespace
27262306a36Sopenharmony_ci * @i: location of item in the message
27362306a36Sopenharmony_ci * @node: node address
27462306a36Sopenharmony_ci * @dtype: name distributor message type
27562306a36Sopenharmony_ci *
27662306a36Sopenharmony_ci * tipc_nametbl_lock must be held.
27762306a36Sopenharmony_ci * Return: the publication item if successful, otherwise NULL.
27862306a36Sopenharmony_ci */
27962306a36Sopenharmony_cistatic bool tipc_update_nametbl(struct net *net, struct distr_item *i,
28062306a36Sopenharmony_ci				u32 node, u32 dtype)
28162306a36Sopenharmony_ci{
28262306a36Sopenharmony_ci	struct publication *p = NULL;
28362306a36Sopenharmony_ci	struct tipc_socket_addr sk;
28462306a36Sopenharmony_ci	struct tipc_uaddr ua;
28562306a36Sopenharmony_ci	u32 key = ntohl(i->key);
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_ci	tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_CLUSTER_SCOPE,
28862306a36Sopenharmony_ci		   ntohl(i->type), ntohl(i->lower), ntohl(i->upper));
28962306a36Sopenharmony_ci	sk.ref = ntohl(i->port);
29062306a36Sopenharmony_ci	sk.node = node;
29162306a36Sopenharmony_ci
29262306a36Sopenharmony_ci	if (dtype == PUBLICATION) {
29362306a36Sopenharmony_ci		p = tipc_nametbl_insert_publ(net, &ua, &sk, key);
29462306a36Sopenharmony_ci		if (p) {
29562306a36Sopenharmony_ci			tipc_node_subscribe(net, &p->binding_node, node);
29662306a36Sopenharmony_ci			return true;
29762306a36Sopenharmony_ci		}
29862306a36Sopenharmony_ci	} else if (dtype == WITHDRAWAL) {
29962306a36Sopenharmony_ci		p = tipc_nametbl_remove_publ(net, &ua, &sk, key);
30062306a36Sopenharmony_ci		if (p) {
30162306a36Sopenharmony_ci			tipc_node_unsubscribe(net, &p->binding_node, node);
30262306a36Sopenharmony_ci			kfree_rcu(p, rcu);
30362306a36Sopenharmony_ci			return true;
30462306a36Sopenharmony_ci		}
30562306a36Sopenharmony_ci		pr_warn_ratelimited("Failed to remove binding %u,%u from %u\n",
30662306a36Sopenharmony_ci				    ua.sr.type, ua.sr.lower, node);
30762306a36Sopenharmony_ci	} else {
30862306a36Sopenharmony_ci		pr_warn_ratelimited("Unknown name table message received\n");
30962306a36Sopenharmony_ci	}
31062306a36Sopenharmony_ci	return false;
31162306a36Sopenharmony_ci}
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_cistatic struct sk_buff *tipc_named_dequeue(struct sk_buff_head *namedq,
31462306a36Sopenharmony_ci					  u16 *rcv_nxt, bool *open)
31562306a36Sopenharmony_ci{
31662306a36Sopenharmony_ci	struct sk_buff *skb, *tmp;
31762306a36Sopenharmony_ci	struct tipc_msg *hdr;
31862306a36Sopenharmony_ci	u16 seqno;
31962306a36Sopenharmony_ci
32062306a36Sopenharmony_ci	spin_lock_bh(&namedq->lock);
32162306a36Sopenharmony_ci	skb_queue_walk_safe(namedq, skb, tmp) {
32262306a36Sopenharmony_ci		if (unlikely(skb_linearize(skb))) {
32362306a36Sopenharmony_ci			__skb_unlink(skb, namedq);
32462306a36Sopenharmony_ci			kfree_skb(skb);
32562306a36Sopenharmony_ci			continue;
32662306a36Sopenharmony_ci		}
32762306a36Sopenharmony_ci		hdr = buf_msg(skb);
32862306a36Sopenharmony_ci		seqno = msg_named_seqno(hdr);
32962306a36Sopenharmony_ci		if (msg_is_last_bulk(hdr)) {
33062306a36Sopenharmony_ci			*rcv_nxt = seqno;
33162306a36Sopenharmony_ci			*open = true;
33262306a36Sopenharmony_ci		}
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci		if (msg_is_bulk(hdr) || msg_is_legacy(hdr)) {
33562306a36Sopenharmony_ci			__skb_unlink(skb, namedq);
33662306a36Sopenharmony_ci			spin_unlock_bh(&namedq->lock);
33762306a36Sopenharmony_ci			return skb;
33862306a36Sopenharmony_ci		}
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci		if (*open && (*rcv_nxt == seqno)) {
34162306a36Sopenharmony_ci			(*rcv_nxt)++;
34262306a36Sopenharmony_ci			__skb_unlink(skb, namedq);
34362306a36Sopenharmony_ci			spin_unlock_bh(&namedq->lock);
34462306a36Sopenharmony_ci			return skb;
34562306a36Sopenharmony_ci		}
34662306a36Sopenharmony_ci
34762306a36Sopenharmony_ci		if (less(seqno, *rcv_nxt)) {
34862306a36Sopenharmony_ci			__skb_unlink(skb, namedq);
34962306a36Sopenharmony_ci			kfree_skb(skb);
35062306a36Sopenharmony_ci			continue;
35162306a36Sopenharmony_ci		}
35262306a36Sopenharmony_ci	}
35362306a36Sopenharmony_ci	spin_unlock_bh(&namedq->lock);
35462306a36Sopenharmony_ci	return NULL;
35562306a36Sopenharmony_ci}
35662306a36Sopenharmony_ci
35762306a36Sopenharmony_ci/**
35862306a36Sopenharmony_ci * tipc_named_rcv - process name table update messages sent by another node
35962306a36Sopenharmony_ci * @net: the associated network namespace
36062306a36Sopenharmony_ci * @namedq: queue to receive from
36162306a36Sopenharmony_ci * @rcv_nxt: store last received seqno here
36262306a36Sopenharmony_ci * @open: last bulk msg was received (FIXME)
36362306a36Sopenharmony_ci */
36462306a36Sopenharmony_civoid tipc_named_rcv(struct net *net, struct sk_buff_head *namedq,
36562306a36Sopenharmony_ci		    u16 *rcv_nxt, bool *open)
36662306a36Sopenharmony_ci{
36762306a36Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
36862306a36Sopenharmony_ci	struct distr_item *item;
36962306a36Sopenharmony_ci	struct tipc_msg *hdr;
37062306a36Sopenharmony_ci	struct sk_buff *skb;
37162306a36Sopenharmony_ci	u32 count, node;
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
37462306a36Sopenharmony_ci	while ((skb = tipc_named_dequeue(namedq, rcv_nxt, open))) {
37562306a36Sopenharmony_ci		hdr = buf_msg(skb);
37662306a36Sopenharmony_ci		node = msg_orignode(hdr);
37762306a36Sopenharmony_ci		item = (struct distr_item *)msg_data(hdr);
37862306a36Sopenharmony_ci		count = msg_data_sz(hdr) / ITEM_SIZE;
37962306a36Sopenharmony_ci		while (count--) {
38062306a36Sopenharmony_ci			tipc_update_nametbl(net, item, node, msg_type(hdr));
38162306a36Sopenharmony_ci			item++;
38262306a36Sopenharmony_ci		}
38362306a36Sopenharmony_ci		kfree_skb(skb);
38462306a36Sopenharmony_ci	}
38562306a36Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
38662306a36Sopenharmony_ci}
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci/**
38962306a36Sopenharmony_ci * tipc_named_reinit - re-initialize local publications
39062306a36Sopenharmony_ci * @net: the associated network namespace
39162306a36Sopenharmony_ci *
39262306a36Sopenharmony_ci * This routine is called whenever TIPC networking is enabled.
39362306a36Sopenharmony_ci * All name table entries published by this node are updated to reflect
39462306a36Sopenharmony_ci * the node's new network address.
39562306a36Sopenharmony_ci */
39662306a36Sopenharmony_civoid tipc_named_reinit(struct net *net)
39762306a36Sopenharmony_ci{
39862306a36Sopenharmony_ci	struct name_table *nt = tipc_name_table(net);
39962306a36Sopenharmony_ci	struct tipc_net *tn = tipc_net(net);
40062306a36Sopenharmony_ci	struct publication *p;
40162306a36Sopenharmony_ci	u32 self = tipc_own_addr(net);
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci	spin_lock_bh(&tn->nametbl_lock);
40462306a36Sopenharmony_ci
40562306a36Sopenharmony_ci	list_for_each_entry_rcu(p, &nt->node_scope, binding_node)
40662306a36Sopenharmony_ci		p->sk.node = self;
40762306a36Sopenharmony_ci	list_for_each_entry_rcu(p, &nt->cluster_scope, binding_node)
40862306a36Sopenharmony_ci		p->sk.node = self;
40962306a36Sopenharmony_ci	nt->rc_dests = 0;
41062306a36Sopenharmony_ci	spin_unlock_bh(&tn->nametbl_lock);
41162306a36Sopenharmony_ci}
412