1b97bf3fdSPer Liden /*
2b97bf3fdSPer Liden * net/tipc/name_distr.c: TIPC name distribution code
3b97bf3fdSPer Liden *
4998d3907SJon Maloy * Copyright (c) 2000-2006, 2014-2019, Ericsson AB
5431697ebSAllan Stephens * Copyright (c) 2005, 2010-2011, Wind River Systems
6998d3907SJon Maloy * Copyright (c) 2020-2021, Red Hat Inc
7b97bf3fdSPer Liden * All rights reserved.
8b97bf3fdSPer Liden *
9b97bf3fdSPer Liden * Redistribution and use in source and binary forms, with or without
10b97bf3fdSPer Liden * modification, are permitted provided that the following conditions are met:
11b97bf3fdSPer Liden *
129ea1fd3cSPer Liden * 1. Redistributions of source code must retain the above copyright
139ea1fd3cSPer Liden * notice, this list of conditions and the following disclaimer.
149ea1fd3cSPer Liden * 2. Redistributions in binary form must reproduce the above copyright
159ea1fd3cSPer Liden * notice, this list of conditions and the following disclaimer in the
169ea1fd3cSPer Liden * documentation and/or other materials provided with the distribution.
179ea1fd3cSPer Liden * 3. Neither the names of the copyright holders nor the names of its
189ea1fd3cSPer Liden * contributors may be used to endorse or promote products derived from
199ea1fd3cSPer Liden * this software without specific prior written permission.
209ea1fd3cSPer Liden *
219ea1fd3cSPer Liden * Alternatively, this software may be distributed under the terms of the
229ea1fd3cSPer Liden * GNU General Public License ("GPL") version 2 as published by the Free
239ea1fd3cSPer Liden * Software Foundation.
24b97bf3fdSPer Liden *
25b97bf3fdSPer Liden * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26b97bf3fdSPer Liden * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27b97bf3fdSPer Liden * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28b97bf3fdSPer Liden * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29b97bf3fdSPer Liden * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30b97bf3fdSPer Liden * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31b97bf3fdSPer Liden * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32b97bf3fdSPer Liden * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33b97bf3fdSPer Liden * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34b97bf3fdSPer Liden * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35b97bf3fdSPer Liden * POSSIBILITY OF SUCH DAMAGE.
36b97bf3fdSPer Liden */
37b97bf3fdSPer Liden
38b97bf3fdSPer Liden #include "core.h"
39b97bf3fdSPer Liden #include "link.h"
40b97bf3fdSPer Liden #include "name_distr.h"
41b97bf3fdSPer Liden
42a5325ae5SErik Hugne int sysctl_tipc_named_timeout __read_mostly = 2000;
43a5325ae5SErik Hugne
44b97bf3fdSPer Liden /**
45b97bf3fdSPer Liden * publ_to_item - add publication info to a publication message
46cb67296eSRandy Dunlap * @p: publication info
47cb67296eSRandy Dunlap * @i: location of item in the message
48b97bf3fdSPer Liden */
publ_to_item(struct distr_item * i,struct publication * p)49b97bf3fdSPer Liden static void publ_to_item(struct distr_item *i, struct publication *p)
50b97bf3fdSPer Liden {
51998d3907SJon Maloy i->type = htonl(p->sr.type);
52998d3907SJon Maloy i->lower = htonl(p->sr.lower);
53998d3907SJon Maloy i->upper = htonl(p->sr.upper);
54998d3907SJon Maloy i->port = htonl(p->sk.ref);
55b97bf3fdSPer Liden i->key = htonl(p->key);
56b97bf3fdSPer Liden }
57b97bf3fdSPer Liden
58b97bf3fdSPer Liden /**
59b97bf3fdSPer Liden * named_prepare_buf - allocate & initialize a publication message
60cb67296eSRandy Dunlap * @net: the associated network namespace
61cb67296eSRandy Dunlap * @type: message type
62cb67296eSRandy Dunlap * @size: payload size
63cb67296eSRandy Dunlap * @dest: destination node
64d2f394dcSParthasarathy Bhuvaragan *
65d2f394dcSParthasarathy Bhuvaragan * The buffer returned is of size INT_H_SIZE + payload size
66b97bf3fdSPer Liden */
named_prepare_buf(struct net * net,u32 type,u32 size,u32 dest)6734747539SYing Xue static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size,
6834747539SYing Xue u32 dest)
69b97bf3fdSPer Liden {
7057d5f64dSParthasarathy Bhuvaragan struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC);
7123fd3eacSJon Maloy u32 self = tipc_own_addr(net);
72b97bf3fdSPer Liden struct tipc_msg *msg;
73b97bf3fdSPer Liden
74b97bf3fdSPer Liden if (buf != NULL) {
75b97bf3fdSPer Liden msg = buf_msg(buf);
7623fd3eacSJon Maloy tipc_msg_init(self, msg, NAME_DISTRIBUTOR,
7723fd3eacSJon Maloy type, INT_H_SIZE, dest);
78741d9eb7SAllan Stephens msg_set_size(msg, INT_H_SIZE + size);
79b97bf3fdSPer Liden }
80b97bf3fdSPer Liden return buf;
81b97bf3fdSPer Liden }
82b97bf3fdSPer Liden
83b97bf3fdSPer Liden /**
844323add6SPer Liden * tipc_named_publish - tell other nodes about a new publication by this node
85cb67296eSRandy Dunlap * @net: the associated network namespace
86998d3907SJon Maloy * @p: the new publication
87b97bf3fdSPer Liden */
tipc_named_publish(struct net * net,struct publication * p)88998d3907SJon Maloy struct sk_buff *tipc_named_publish(struct net *net, struct publication *p)
89b97bf3fdSPer Liden {
9064a52b26SJon Maloy struct name_table *nt = tipc_name_table(net);
91b97bf3fdSPer Liden struct distr_item *item;
9264a52b26SJon Maloy struct sk_buff *skb;
93b97bf3fdSPer Liden
94998d3907SJon Maloy if (p->scope == TIPC_NODE_SCOPE) {
95998d3907SJon Maloy list_add_tail_rcu(&p->binding_node, &nt->node_scope);
96eab8c045SYing Xue return NULL;
9764a52b26SJon Maloy }
98988f3f16SJon Maloy write_lock_bh(&nt->cluster_scope_lock);
99998d3907SJon Maloy list_add_tail(&p->binding_node, &nt->cluster_scope);
100988f3f16SJon Maloy write_unlock_bh(&nt->cluster_scope_lock);
10164a52b26SJon Maloy skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0);
10264a52b26SJon Maloy if (!skb) {
1032cf8aa19SErik Hugne pr_warn("Publication distribution failure\n");
104eab8c045SYing Xue return NULL;
105b97bf3fdSPer Liden }
106cad2929dSHoang Huu Le msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
107cad2929dSHoang Huu Le msg_set_non_legacy(buf_msg(skb));
10864a52b26SJon Maloy item = (struct distr_item *)msg_data(buf_msg(skb));
109998d3907SJon Maloy publ_to_item(item, p);
11064a52b26SJon Maloy return skb;
111b97bf3fdSPer Liden }
112b97bf3fdSPer Liden
113b97bf3fdSPer Liden /**
1144323add6SPer Liden * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node
115cb67296eSRandy Dunlap * @net: the associated network namespace
116998d3907SJon Maloy * @p: the withdrawn publication
117b97bf3fdSPer Liden */
tipc_named_withdraw(struct net * net,struct publication * p)118998d3907SJon Maloy struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *p)
119b97bf3fdSPer Liden {
120988f3f16SJon Maloy struct name_table *nt = tipc_name_table(net);
121b97bf3fdSPer Liden struct distr_item *item;
122cad2929dSHoang Huu Le struct sk_buff *skb;
123b97bf3fdSPer Liden
124988f3f16SJon Maloy write_lock_bh(&nt->cluster_scope_lock);
125998d3907SJon Maloy list_del(&p->binding_node);
126988f3f16SJon Maloy write_unlock_bh(&nt->cluster_scope_lock);
127998d3907SJon Maloy if (p->scope == TIPC_NODE_SCOPE)
128eab8c045SYing Xue return NULL;
1291110b8d3SAllan Stephens
130cad2929dSHoang Huu Le skb = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0);
131cad2929dSHoang Huu Le if (!skb) {
1322cf8aa19SErik Hugne pr_warn("Withdrawal distribution failure\n");
133eab8c045SYing Xue return NULL;
134b97bf3fdSPer Liden }
135cad2929dSHoang Huu Le msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
136cad2929dSHoang Huu Le msg_set_non_legacy(buf_msg(skb));
137cad2929dSHoang Huu Le item = (struct distr_item *)msg_data(buf_msg(skb));
138998d3907SJon Maloy publ_to_item(item, p);
139cad2929dSHoang Huu Le return skb;
140b97bf3fdSPer Liden }
141b97bf3fdSPer Liden
142dbdf6d24SJon Paul Maloy /**
143e11aa059SAllan Stephens * named_distribute - prepare name info for bulk distribution to another node
144cb67296eSRandy Dunlap * @net: the associated network namespace
145a6ca1094SYing Xue * @list: list of messages (buffers) to be returned from this function
146dbdf6d24SJon Paul Maloy * @dnode: node to be updated
147dbdf6d24SJon Paul Maloy * @pls: linked list of publication items to be packed into buffer chain
148cb67296eSRandy Dunlap * @seqno: sequence number for this message
149e11aa059SAllan Stephens */
named_distribute(struct net * net,struct sk_buff_head * list,u32 dnode,struct list_head * pls,u16 seqno)150f2f9800dSYing Xue static void named_distribute(struct net *net, struct sk_buff_head *list,
151cad2929dSHoang Huu Le u32 dnode, struct list_head *pls, u16 seqno)
152e11aa059SAllan Stephens {
153e11aa059SAllan Stephens struct publication *publ;
154a6ca1094SYing Xue struct sk_buff *skb = NULL;
155e11aa059SAllan Stephens struct distr_item *item = NULL;
156f73b1281SHoang Le u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0, false) - INT_H_SIZE) /
157d2f394dcSParthasarathy Bhuvaragan ITEM_SIZE) * ITEM_SIZE;
158d2f394dcSParthasarathy Bhuvaragan u32 msg_rem = msg_dsz;
159cad2929dSHoang Huu Le struct tipc_msg *hdr;
160e11aa059SAllan Stephens
161988f3f16SJon Maloy list_for_each_entry(publ, pls, binding_node) {
162dbdf6d24SJon Paul Maloy /* Prepare next buffer: */
163a6ca1094SYing Xue if (!skb) {
16434747539SYing Xue skb = named_prepare_buf(net, PUBLICATION, msg_rem,
16534747539SYing Xue dnode);
166a6ca1094SYing Xue if (!skb) {
1672cf8aa19SErik Hugne pr_warn("Bulk publication failure\n");
168e11aa059SAllan Stephens return;
169e11aa059SAllan Stephens }
170cad2929dSHoang Huu Le hdr = buf_msg(skb);
171cad2929dSHoang Huu Le msg_set_bc_ack_invalid(hdr, true);
172cad2929dSHoang Huu Le msg_set_bulk(hdr);
173cad2929dSHoang Huu Le msg_set_non_legacy(hdr);
174cad2929dSHoang Huu Le item = (struct distr_item *)msg_data(hdr);
175e11aa059SAllan Stephens }
176dbdf6d24SJon Paul Maloy
177dbdf6d24SJon Paul Maloy /* Pack publication into message: */
178e11aa059SAllan Stephens publ_to_item(item, publ);
179e11aa059SAllan Stephens item++;
180dbdf6d24SJon Paul Maloy msg_rem -= ITEM_SIZE;
181dbdf6d24SJon Paul Maloy
182dbdf6d24SJon Paul Maloy /* Append full buffer to list: */
183dbdf6d24SJon Paul Maloy if (!msg_rem) {
184a6ca1094SYing Xue __skb_queue_tail(list, skb);
185a6ca1094SYing Xue skb = NULL;
1861b61e70aSYing Xue msg_rem = msg_dsz;
187e11aa059SAllan Stephens }
188e11aa059SAllan Stephens }
1891b61e70aSYing Xue if (skb) {
190cad2929dSHoang Huu Le hdr = buf_msg(skb);
191cad2929dSHoang Huu Le msg_set_size(hdr, INT_H_SIZE + (msg_dsz - msg_rem));
1921b61e70aSYing Xue skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem));
1931b61e70aSYing Xue __skb_queue_tail(list, skb);
1941b61e70aSYing Xue }
195cad2929dSHoang Huu Le hdr = buf_msg(skb_peek_tail(list));
196cad2929dSHoang Huu Le msg_set_last_bulk(hdr);
197cad2929dSHoang Huu Le msg_set_named_seqno(hdr, seqno);
198e11aa059SAllan Stephens }
199e11aa059SAllan Stephens
200b97bf3fdSPer Liden /**
2014323add6SPer Liden * tipc_named_node_up - tell specified node about all publications by this node
202cb67296eSRandy Dunlap * @net: the associated network namespace
203cb67296eSRandy Dunlap * @dnode: destination node
204cb67296eSRandy Dunlap * @capabilities: peer node's capabilities
205b97bf3fdSPer Liden */
tipc_named_node_up(struct net * net,u32 dnode,u16 capabilities)206cad2929dSHoang Huu Le void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
207b97bf3fdSPer Liden {
20864a52b26SJon Maloy struct name_table *nt = tipc_name_table(net);
209cad2929dSHoang Huu Le struct tipc_net *tn = tipc_net(net);
210a6ca1094SYing Xue struct sk_buff_head head;
211cad2929dSHoang Huu Le u16 seqno;
212a6ca1094SYing Xue
213e654f9f5SJon Maloy __skb_queue_head_init(&head);
214cad2929dSHoang Huu Le spin_lock_bh(&tn->nametbl_lock);
215cad2929dSHoang Huu Le if (!(capabilities & TIPC_NAMED_BCAST))
216cad2929dSHoang Huu Le nt->rc_dests++;
217cad2929dSHoang Huu Le seqno = nt->snd_nxt;
218cad2929dSHoang Huu Le spin_unlock_bh(&tn->nametbl_lock);
2199aa88c2aSAllan Stephens
220988f3f16SJon Maloy read_lock_bh(&nt->cluster_scope_lock);
221cad2929dSHoang Huu Le named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);
222c49a0a84SJon Paul Maloy tipc_node_xmit(net, &head, dnode, 0);
223988f3f16SJon Maloy read_unlock_bh(&nt->cluster_scope_lock);
224b97bf3fdSPer Liden }
225b97bf3fdSPer Liden
226b97bf3fdSPer Liden /**
227a8f48af5SYing Xue * tipc_publ_purge - remove publication associated with a failed node
228cb67296eSRandy Dunlap * @net: the associated network namespace
229998d3907SJon Maloy * @p: the publication to remove
230cb67296eSRandy Dunlap * @addr: failed node's address
231b97bf3fdSPer Liden *
232b97bf3fdSPer Liden * Invoked for each publication issued by a newly failed node.
233b97bf3fdSPer Liden * Removes publication structure from name table & deletes it.
234b97bf3fdSPer Liden */
tipc_publ_purge(struct net * net,struct publication * p,u32 addr)235998d3907SJon Maloy static void tipc_publ_purge(struct net *net, struct publication *p, u32 addr)
236b97bf3fdSPer Liden {
23737922ea4SJon Maloy struct tipc_net *tn = tipc_net(net);
238998d3907SJon Maloy struct publication *_p;
2392c98da07SJon Maloy struct tipc_uaddr ua;
240f131072cSAllan Stephens
2412c98da07SJon Maloy tipc_uaddr(&ua, TIPC_SERVICE_RANGE, p->scope, p->sr.type,
2422c98da07SJon Maloy p->sr.lower, p->sr.upper);
2434ac1c8d0SYing Xue spin_lock_bh(&tn->nametbl_lock);
2442c98da07SJon Maloy _p = tipc_nametbl_remove_publ(net, &ua, &p->sk, p->key);
245998d3907SJon Maloy if (_p)
246998d3907SJon Maloy tipc_node_unsubscribe(net, &_p->binding_node, addr);
2474ac1c8d0SYing Xue spin_unlock_bh(&tn->nametbl_lock);
248998d3907SJon Maloy if (_p)
249998d3907SJon Maloy kfree_rcu(_p, rcu);
250f131072cSAllan Stephens }
251b97bf3fdSPer Liden
tipc_publ_notify(struct net * net,struct list_head * nsub_list,u32 addr,u16 capabilities)252cad2929dSHoang Huu Le void tipc_publ_notify(struct net *net, struct list_head *nsub_list,
253cad2929dSHoang Huu Le u32 addr, u16 capabilities)
254a8f48af5SYing Xue {
255cad2929dSHoang Huu Le struct name_table *nt = tipc_name_table(net);
256cad2929dSHoang Huu Le struct tipc_net *tn = tipc_net(net);
257cad2929dSHoang Huu Le
258a8f48af5SYing Xue struct publication *publ, *tmp;
259a8f48af5SYing Xue
260935439ccSJon Maloy list_for_each_entry_safe(publ, tmp, nsub_list, binding_node)
261f2f9800dSYing Xue tipc_publ_purge(net, publ, addr);
262cad2929dSHoang Huu Le spin_lock_bh(&tn->nametbl_lock);
263cad2929dSHoang Huu Le if (!(capabilities & TIPC_NAMED_BCAST))
264cad2929dSHoang Huu Le nt->rc_dests--;
265cad2929dSHoang Huu Le spin_unlock_bh(&tn->nametbl_lock);
266a8f48af5SYing Xue }
267a8f48af5SYing Xue
268b97bf3fdSPer Liden /**
269f4ad8a4bSErik Hugne * tipc_update_nametbl - try to process a nametable update and notify
270f4ad8a4bSErik Hugne * subscribers
271cb67296eSRandy Dunlap * @net: the associated network namespace
272cb67296eSRandy Dunlap * @i: location of item in the message
273cb67296eSRandy Dunlap * @node: node address
274cb67296eSRandy Dunlap * @dtype: name distributor message type
275f4ad8a4bSErik Hugne *
276f4ad8a4bSErik Hugne * tipc_nametbl_lock must be held.
277637b77fdSRandy Dunlap * Return: the publication item if successful, otherwise NULL.
278f4ad8a4bSErik Hugne */
tipc_update_nametbl(struct net * net,struct distr_item * i,u32 node,u32 dtype)279f2f9800dSYing Xue static bool tipc_update_nametbl(struct net *net, struct distr_item *i,
280f2f9800dSYing Xue u32 node, u32 dtype)
281f4ad8a4bSErik Hugne {
28237922ea4SJon Maloy struct publication *p = NULL;
283a45ffa68SJon Maloy struct tipc_socket_addr sk;
284a45ffa68SJon Maloy struct tipc_uaddr ua;
28537922ea4SJon Maloy u32 key = ntohl(i->key);
286f4ad8a4bSErik Hugne
287a45ffa68SJon Maloy tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_CLUSTER_SCOPE,
288a45ffa68SJon Maloy ntohl(i->type), ntohl(i->lower), ntohl(i->upper));
289a45ffa68SJon Maloy sk.ref = ntohl(i->port);
290a45ffa68SJon Maloy sk.node = node;
291a45ffa68SJon Maloy
292f4ad8a4bSErik Hugne if (dtype == PUBLICATION) {
293a45ffa68SJon Maloy p = tipc_nametbl_insert_publ(net, &ua, &sk, key);
29437922ea4SJon Maloy if (p) {
29537922ea4SJon Maloy tipc_node_subscribe(net, &p->binding_node, node);
2960fc4dffaSErik Hugne return true;
297f4ad8a4bSErik Hugne }
298f4ad8a4bSErik Hugne } else if (dtype == WITHDRAWAL) {
2992c98da07SJon Maloy p = tipc_nametbl_remove_publ(net, &ua, &sk, key);
30037922ea4SJon Maloy if (p) {
30137922ea4SJon Maloy tipc_node_unsubscribe(net, &p->binding_node, node);
30237922ea4SJon Maloy kfree_rcu(p, rcu);
3030fc4dffaSErik Hugne return true;
304f4ad8a4bSErik Hugne }
305a45ffa68SJon Maloy pr_warn_ratelimited("Failed to remove binding %u,%u from %u\n",
306a45ffa68SJon Maloy ua.sr.type, ua.sr.lower, node);
307f4ad8a4bSErik Hugne } else {
308*c7223d68SJon Maloy pr_warn_ratelimited("Unknown name table message received\n");
309f4ad8a4bSErik Hugne }
3100fc4dffaSErik Hugne return false;
311f4ad8a4bSErik Hugne }
312f4ad8a4bSErik Hugne
tipc_named_dequeue(struct sk_buff_head * namedq,u16 * rcv_nxt,bool * open)313cad2929dSHoang Huu Le static struct sk_buff *tipc_named_dequeue(struct sk_buff_head *namedq,
314cad2929dSHoang Huu Le u16 *rcv_nxt, bool *open)
315cad2929dSHoang Huu Le {
316cad2929dSHoang Huu Le struct sk_buff *skb, *tmp;
317cad2929dSHoang Huu Le struct tipc_msg *hdr;
318cad2929dSHoang Huu Le u16 seqno;
319cad2929dSHoang Huu Le
3207b50ee3dSHoang Huu Le spin_lock_bh(&namedq->lock);
321cad2929dSHoang Huu Le skb_queue_walk_safe(namedq, skb, tmp) {
3227b50ee3dSHoang Huu Le if (unlikely(skb_linearize(skb))) {
3237b50ee3dSHoang Huu Le __skb_unlink(skb, namedq);
3247b50ee3dSHoang Huu Le kfree_skb(skb);
3257b50ee3dSHoang Huu Le continue;
3267b50ee3dSHoang Huu Le }
327cad2929dSHoang Huu Le hdr = buf_msg(skb);
328cad2929dSHoang Huu Le seqno = msg_named_seqno(hdr);
329cad2929dSHoang Huu Le if (msg_is_last_bulk(hdr)) {
330cad2929dSHoang Huu Le *rcv_nxt = seqno;
331cad2929dSHoang Huu Le *open = true;
332cad2929dSHoang Huu Le }
333cad2929dSHoang Huu Le
334cad2929dSHoang Huu Le if (msg_is_bulk(hdr) || msg_is_legacy(hdr)) {
335cad2929dSHoang Huu Le __skb_unlink(skb, namedq);
3367b50ee3dSHoang Huu Le spin_unlock_bh(&namedq->lock);
337cad2929dSHoang Huu Le return skb;
338cad2929dSHoang Huu Le }
339cad2929dSHoang Huu Le
340cad2929dSHoang Huu Le if (*open && (*rcv_nxt == seqno)) {
341cad2929dSHoang Huu Le (*rcv_nxt)++;
342cad2929dSHoang Huu Le __skb_unlink(skb, namedq);
3437b50ee3dSHoang Huu Le spin_unlock_bh(&namedq->lock);
344cad2929dSHoang Huu Le return skb;
345cad2929dSHoang Huu Le }
346cad2929dSHoang Huu Le
347cad2929dSHoang Huu Le if (less(seqno, *rcv_nxt)) {
348cad2929dSHoang Huu Le __skb_unlink(skb, namedq);
349cad2929dSHoang Huu Le kfree_skb(skb);
350cad2929dSHoang Huu Le continue;
351cad2929dSHoang Huu Le }
352cad2929dSHoang Huu Le }
3537b50ee3dSHoang Huu Le spin_unlock_bh(&namedq->lock);
354cad2929dSHoang Huu Le return NULL;
355cad2929dSHoang Huu Le }
356cad2929dSHoang Huu Le
357f4ad8a4bSErik Hugne /**
358c637c103SJon Paul Maloy * tipc_named_rcv - process name table update messages sent by another node
359cb67296eSRandy Dunlap * @net: the associated network namespace
360cb67296eSRandy Dunlap * @namedq: queue to receive from
361cb67296eSRandy Dunlap * @rcv_nxt: store last received seqno here
362cb67296eSRandy Dunlap * @open: last bulk msg was received (FIXME)
363b97bf3fdSPer Liden */
tipc_named_rcv(struct net * net,struct sk_buff_head * namedq,u16 * rcv_nxt,bool * open)364cad2929dSHoang Huu Le void tipc_named_rcv(struct net *net, struct sk_buff_head *namedq,
365cad2929dSHoang Huu Le u16 *rcv_nxt, bool *open)
366b97bf3fdSPer Liden {
367cad2929dSHoang Huu Le struct tipc_net *tn = tipc_net(net);
368c637c103SJon Paul Maloy struct distr_item *item;
369cad2929dSHoang Huu Le struct tipc_msg *hdr;
370c637c103SJon Paul Maloy struct sk_buff *skb;
371cad2929dSHoang Huu Le u32 count, node;
372b97bf3fdSPer Liden
3734ac1c8d0SYing Xue spin_lock_bh(&tn->nametbl_lock);
374cad2929dSHoang Huu Le while ((skb = tipc_named_dequeue(namedq, rcv_nxt, open))) {
375cad2929dSHoang Huu Le hdr = buf_msg(skb);
376cad2929dSHoang Huu Le node = msg_orignode(hdr);
377cad2929dSHoang Huu Le item = (struct distr_item *)msg_data(hdr);
378cad2929dSHoang Huu Le count = msg_data_sz(hdr) / ITEM_SIZE;
379b97bf3fdSPer Liden while (count--) {
380cad2929dSHoang Huu Le tipc_update_nametbl(net, item, node, msg_type(hdr));
381b97bf3fdSPer Liden item++;
382b97bf3fdSPer Liden }
383c637c103SJon Paul Maloy kfree_skb(skb);
384c637c103SJon Paul Maloy }
3854ac1c8d0SYing Xue spin_unlock_bh(&tn->nametbl_lock);
386b97bf3fdSPer Liden }
387b97bf3fdSPer Liden
388b97bf3fdSPer Liden /**
3891110b8d3SAllan Stephens * tipc_named_reinit - re-initialize local publications
390cb67296eSRandy Dunlap * @net: the associated network namespace
391b97bf3fdSPer Liden *
392945af1c3SAllan Stephens * This routine is called whenever TIPC networking is enabled.
3931110b8d3SAllan Stephens * All name table entries published by this node are updated to reflect
3941110b8d3SAllan Stephens * the node's new network address.
395b97bf3fdSPer Liden */
tipc_named_reinit(struct net * net)3964ac1c8d0SYing Xue void tipc_named_reinit(struct net *net)
397b97bf3fdSPer Liden {
39864a52b26SJon Maloy struct name_table *nt = tipc_name_table(net);
39964a52b26SJon Maloy struct tipc_net *tn = tipc_net(net);
400998d3907SJon Maloy struct publication *p;
40123fd3eacSJon Maloy u32 self = tipc_own_addr(net);
402b97bf3fdSPer Liden
4034ac1c8d0SYing Xue spin_lock_bh(&tn->nametbl_lock);
404945af1c3SAllan Stephens
405998d3907SJon Maloy list_for_each_entry_rcu(p, &nt->node_scope, binding_node)
406998d3907SJon Maloy p->sk.node = self;
407998d3907SJon Maloy list_for_each_entry_rcu(p, &nt->cluster_scope, binding_node)
408998d3907SJon Maloy p->sk.node = self;
409cad2929dSHoang Huu Le nt->rc_dests = 0;
4104ac1c8d0SYing Xue spin_unlock_bh(&tn->nametbl_lock);
411b97bf3fdSPer Liden }
412