xref: /linux/net/tipc/name_distr.c (revision 1b61e70ad13e1c907f143c3b0a1694df640639c0)
1b97bf3fdSPer Liden /*
2b97bf3fdSPer Liden  * net/tipc/name_distr.c: TIPC name distribution code
3b97bf3fdSPer Liden  *
4a5325ae5SErik Hugne  * Copyright (c) 2000-2006, 2014, Ericsson AB
5431697ebSAllan Stephens  * Copyright (c) 2005, 2010-2011, Wind River Systems
6b97bf3fdSPer Liden  * All rights reserved.
7b97bf3fdSPer Liden  *
8b97bf3fdSPer Liden  * Redistribution and use in source and binary forms, with or without
9b97bf3fdSPer Liden  * modification, are permitted provided that the following conditions are met:
10b97bf3fdSPer Liden  *
119ea1fd3cSPer Liden  * 1. Redistributions of source code must retain the above copyright
129ea1fd3cSPer Liden  *    notice, this list of conditions and the following disclaimer.
139ea1fd3cSPer Liden  * 2. Redistributions in binary form must reproduce the above copyright
149ea1fd3cSPer Liden  *    notice, this list of conditions and the following disclaimer in the
159ea1fd3cSPer Liden  *    documentation and/or other materials provided with the distribution.
169ea1fd3cSPer Liden  * 3. Neither the names of the copyright holders nor the names of its
179ea1fd3cSPer Liden  *    contributors may be used to endorse or promote products derived from
189ea1fd3cSPer Liden  *    this software without specific prior written permission.
199ea1fd3cSPer Liden  *
209ea1fd3cSPer Liden  * Alternatively, this software may be distributed under the terms of the
219ea1fd3cSPer Liden  * GNU General Public License ("GPL") version 2 as published by the Free
229ea1fd3cSPer Liden  * Software Foundation.
23b97bf3fdSPer Liden  *
24b97bf3fdSPer Liden  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25b97bf3fdSPer Liden  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26b97bf3fdSPer Liden  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27b97bf3fdSPer Liden  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28b97bf3fdSPer Liden  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29b97bf3fdSPer Liden  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30b97bf3fdSPer Liden  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31b97bf3fdSPer Liden  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32b97bf3fdSPer Liden  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33b97bf3fdSPer Liden  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34b97bf3fdSPer Liden  * POSSIBILITY OF SUCH DAMAGE.
35b97bf3fdSPer Liden  */
36b97bf3fdSPer Liden 
37b97bf3fdSPer Liden #include "core.h"
38b97bf3fdSPer Liden #include "link.h"
39b97bf3fdSPer Liden #include "name_distr.h"
40b97bf3fdSPer Liden 
41b97bf3fdSPer Liden /**
423f8375feSAllan Stephens  * struct publ_list - list of publications made by this node
433f8375feSAllan Stephens  * @list: circular list of publications
44b97bf3fdSPer Liden  */
453f8375feSAllan Stephens struct publ_list {
463f8375feSAllan Stephens 	struct list_head list;
473f8375feSAllan Stephens };
48b97bf3fdSPer Liden 
49a909804fSAllan Stephens static struct publ_list publ_zone = {
50a909804fSAllan Stephens 	.list = LIST_HEAD_INIT(publ_zone.list),
51a909804fSAllan Stephens };
52a909804fSAllan Stephens 
533f8375feSAllan Stephens static struct publ_list publ_cluster = {
543f8375feSAllan Stephens 	.list = LIST_HEAD_INIT(publ_cluster.list),
553f8375feSAllan Stephens };
56b97bf3fdSPer Liden 
57a909804fSAllan Stephens static struct publ_list publ_node = {
58a909804fSAllan Stephens 	.list = LIST_HEAD_INIT(publ_node.list),
59a909804fSAllan Stephens };
60a909804fSAllan Stephens 
61a909804fSAllan Stephens static struct publ_list *publ_lists[] = {
62a909804fSAllan Stephens 	NULL,
63a909804fSAllan Stephens 	&publ_zone,	/* publ_lists[TIPC_ZONE_SCOPE]		*/
64a909804fSAllan Stephens 	&publ_cluster,	/* publ_lists[TIPC_CLUSTER_SCOPE]	*/
65a909804fSAllan Stephens 	&publ_node	/* publ_lists[TIPC_NODE_SCOPE]		*/
66a909804fSAllan Stephens };
67a909804fSAllan Stephens 
68a909804fSAllan Stephens 
69a5325ae5SErik Hugne int sysctl_tipc_named_timeout __read_mostly = 2000;
70a5325ae5SErik Hugne 
71a5325ae5SErik Hugne /**
72a5325ae5SErik Hugne  * struct tipc_dist_queue - queue holding deferred name table updates
73a5325ae5SErik Hugne  */
74a5325ae5SErik Hugne static struct list_head tipc_dist_queue = LIST_HEAD_INIT(tipc_dist_queue);
75a5325ae5SErik Hugne 
76a5325ae5SErik Hugne struct distr_queue_item {
77a5325ae5SErik Hugne 	struct distr_item i;
78a5325ae5SErik Hugne 	u32 dtype;
79a5325ae5SErik Hugne 	u32 node;
80a5325ae5SErik Hugne 	unsigned long expires;
81a5325ae5SErik Hugne 	struct list_head next;
82a5325ae5SErik Hugne };
83a5325ae5SErik Hugne 
84b97bf3fdSPer Liden /**
85b97bf3fdSPer Liden  * publ_to_item - add publication info to a publication message
86b97bf3fdSPer Liden  */
87b97bf3fdSPer Liden static void publ_to_item(struct distr_item *i, struct publication *p)
88b97bf3fdSPer Liden {
89b97bf3fdSPer Liden 	i->type = htonl(p->type);
90b97bf3fdSPer Liden 	i->lower = htonl(p->lower);
91b97bf3fdSPer Liden 	i->upper = htonl(p->upper);
92b97bf3fdSPer Liden 	i->ref = htonl(p->ref);
93b97bf3fdSPer Liden 	i->key = htonl(p->key);
94b97bf3fdSPer Liden }
95b97bf3fdSPer Liden 
96b97bf3fdSPer Liden /**
97b97bf3fdSPer Liden  * named_prepare_buf - allocate & initialize a publication message
98b97bf3fdSPer Liden  */
99b97bf3fdSPer Liden static struct sk_buff *named_prepare_buf(u32 type, u32 size, u32 dest)
100b97bf3fdSPer Liden {
101741d9eb7SAllan Stephens 	struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size);
102b97bf3fdSPer Liden 	struct tipc_msg *msg;
103b97bf3fdSPer Liden 
104b97bf3fdSPer Liden 	if (buf != NULL) {
105b97bf3fdSPer Liden 		msg = buf_msg(buf);
106741d9eb7SAllan Stephens 		tipc_msg_init(msg, NAME_DISTRIBUTOR, type, INT_H_SIZE, dest);
107741d9eb7SAllan Stephens 		msg_set_size(msg, INT_H_SIZE + size);
108b97bf3fdSPer Liden 	}
109b97bf3fdSPer Liden 	return buf;
110b97bf3fdSPer Liden }
111b97bf3fdSPer Liden 
112a6ca1094SYing Xue void named_cluster_distribute(struct sk_buff *skb)
1138f92df6aSAllan Stephens {
114a6ca1094SYing Xue 	struct sk_buff *oskb;
115dbdf6d24SJon Paul Maloy 	struct tipc_node *node;
116dbdf6d24SJon Paul Maloy 	u32 dnode;
1178f92df6aSAllan Stephens 
1186c7a762eSYing Xue 	rcu_read_lock();
119dbdf6d24SJon Paul Maloy 	list_for_each_entry_rcu(node, &tipc_node_list, list) {
120dbdf6d24SJon Paul Maloy 		dnode = node->addr;
121dbdf6d24SJon Paul Maloy 		if (in_own_node(dnode))
122dbdf6d24SJon Paul Maloy 			continue;
123dbdf6d24SJon Paul Maloy 		if (!tipc_node_active_links(node))
124dbdf6d24SJon Paul Maloy 			continue;
125a6ca1094SYing Xue 		oskb = skb_copy(skb, GFP_ATOMIC);
126a6ca1094SYing Xue 		if (!oskb)
1278f92df6aSAllan Stephens 			break;
128a6ca1094SYing Xue 		msg_set_destnode(buf_msg(oskb), dnode);
129a6ca1094SYing Xue 		tipc_link_xmit_skb(oskb, dnode, dnode);
1308f92df6aSAllan Stephens 	}
1316c7a762eSYing Xue 	rcu_read_unlock();
1328f92df6aSAllan Stephens 
133a6ca1094SYing Xue 	kfree_skb(skb);
1348f92df6aSAllan Stephens }
1358f92df6aSAllan Stephens 
136b97bf3fdSPer Liden /**
1374323add6SPer Liden  * tipc_named_publish - tell other nodes about a new publication by this node
138b97bf3fdSPer Liden  */
139eab8c045SYing Xue struct sk_buff *tipc_named_publish(struct publication *publ)
140b97bf3fdSPer Liden {
141b97bf3fdSPer Liden 	struct sk_buff *buf;
142b97bf3fdSPer Liden 	struct distr_item *item;
143b97bf3fdSPer Liden 
144a909804fSAllan Stephens 	list_add_tail(&publ->local_list, &publ_lists[publ->scope]->list);
145b97bf3fdSPer Liden 
1461110b8d3SAllan Stephens 	if (publ->scope == TIPC_NODE_SCOPE)
147eab8c045SYing Xue 		return NULL;
1481110b8d3SAllan Stephens 
149b97bf3fdSPer Liden 	buf = named_prepare_buf(PUBLICATION, ITEM_SIZE, 0);
150b97bf3fdSPer Liden 	if (!buf) {
1512cf8aa19SErik Hugne 		pr_warn("Publication distribution failure\n");
152eab8c045SYing Xue 		return NULL;
153b97bf3fdSPer Liden 	}
154b97bf3fdSPer Liden 
155b97bf3fdSPer Liden 	item = (struct distr_item *)msg_data(buf_msg(buf));
156b97bf3fdSPer Liden 	publ_to_item(item, publ);
157eab8c045SYing Xue 	return buf;
158b97bf3fdSPer Liden }
159b97bf3fdSPer Liden 
160b97bf3fdSPer Liden /**
1614323add6SPer Liden  * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node
162b97bf3fdSPer Liden  */
163eab8c045SYing Xue struct sk_buff *tipc_named_withdraw(struct publication *publ)
164b97bf3fdSPer Liden {
165b97bf3fdSPer Liden 	struct sk_buff *buf;
166b97bf3fdSPer Liden 	struct distr_item *item;
167b97bf3fdSPer Liden 
168b97bf3fdSPer Liden 	list_del(&publ->local_list);
169b97bf3fdSPer Liden 
1701110b8d3SAllan Stephens 	if (publ->scope == TIPC_NODE_SCOPE)
171eab8c045SYing Xue 		return NULL;
1721110b8d3SAllan Stephens 
173b97bf3fdSPer Liden 	buf = named_prepare_buf(WITHDRAWAL, ITEM_SIZE, 0);
174b97bf3fdSPer Liden 	if (!buf) {
1752cf8aa19SErik Hugne 		pr_warn("Withdrawal distribution failure\n");
176eab8c045SYing Xue 		return NULL;
177b97bf3fdSPer Liden 	}
178b97bf3fdSPer Liden 
179b97bf3fdSPer Liden 	item = (struct distr_item *)msg_data(buf_msg(buf));
180b97bf3fdSPer Liden 	publ_to_item(item, publ);
181eab8c045SYing Xue 	return buf;
182b97bf3fdSPer Liden }
183b97bf3fdSPer Liden 
184dbdf6d24SJon Paul Maloy /**
185e11aa059SAllan Stephens  * named_distribute - prepare name info for bulk distribution to another node
186a6ca1094SYing Xue  * @list: list of messages (buffers) to be returned from this function
187dbdf6d24SJon Paul Maloy  * @dnode: node to be updated
188dbdf6d24SJon Paul Maloy  * @pls: linked list of publication items to be packed into buffer chain
189e11aa059SAllan Stephens  */
190a6ca1094SYing Xue static void named_distribute(struct sk_buff_head *list, u32 dnode,
191dbdf6d24SJon Paul Maloy 			     struct publ_list *pls)
192e11aa059SAllan Stephens {
193e11aa059SAllan Stephens 	struct publication *publ;
194a6ca1094SYing Xue 	struct sk_buff *skb = NULL;
195e11aa059SAllan Stephens 	struct distr_item *item = NULL;
196dbdf6d24SJon Paul Maloy 	uint msg_dsz = (tipc_node_get_mtu(dnode, 0) / ITEM_SIZE) * ITEM_SIZE;
197*1b61e70aSYing Xue 	uint msg_rem = msg_dsz;
198e11aa059SAllan Stephens 
199e11aa059SAllan Stephens 	list_for_each_entry(publ, &pls->list, local_list) {
200dbdf6d24SJon Paul Maloy 		/* Prepare next buffer: */
201a6ca1094SYing Xue 		if (!skb) {
202a6ca1094SYing Xue 			skb = named_prepare_buf(PUBLICATION, msg_rem, dnode);
203a6ca1094SYing Xue 			if (!skb) {
2042cf8aa19SErik Hugne 				pr_warn("Bulk publication failure\n");
205e11aa059SAllan Stephens 				return;
206e11aa059SAllan Stephens 			}
207a6ca1094SYing Xue 			item = (struct distr_item *)msg_data(buf_msg(skb));
208e11aa059SAllan Stephens 		}
209dbdf6d24SJon Paul Maloy 
210dbdf6d24SJon Paul Maloy 		/* Pack publication into message: */
211e11aa059SAllan Stephens 		publ_to_item(item, publ);
212e11aa059SAllan Stephens 		item++;
213dbdf6d24SJon Paul Maloy 		msg_rem -= ITEM_SIZE;
214dbdf6d24SJon Paul Maloy 
215dbdf6d24SJon Paul Maloy 		/* Append full buffer to list: */
216dbdf6d24SJon Paul Maloy 		if (!msg_rem) {
217a6ca1094SYing Xue 			__skb_queue_tail(list, skb);
218a6ca1094SYing Xue 			skb = NULL;
219*1b61e70aSYing Xue 			msg_rem = msg_dsz;
220e11aa059SAllan Stephens 		}
221e11aa059SAllan Stephens 	}
222*1b61e70aSYing Xue 	if (skb) {
223*1b61e70aSYing Xue 		msg_set_size(buf_msg(skb), INT_H_SIZE + (msg_dsz - msg_rem));
224*1b61e70aSYing Xue 		skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem));
225*1b61e70aSYing Xue 		__skb_queue_tail(list, skb);
226*1b61e70aSYing Xue 	}
227e11aa059SAllan Stephens }
228e11aa059SAllan Stephens 
229b97bf3fdSPer Liden /**
2304323add6SPer Liden  * tipc_named_node_up - tell specified node about all publications by this node
231b97bf3fdSPer Liden  */
232dbdf6d24SJon Paul Maloy void tipc_named_node_up(u32 dnode)
233b97bf3fdSPer Liden {
234a6ca1094SYing Xue 	struct sk_buff_head head;
235a6ca1094SYing Xue 
236a6ca1094SYing Xue 	__skb_queue_head_init(&head);
2379aa88c2aSAllan Stephens 
2384323add6SPer Liden 	read_lock_bh(&tipc_nametbl_lock);
239a6ca1094SYing Xue 	named_distribute(&head, dnode, &publ_cluster);
240a6ca1094SYing Xue 	named_distribute(&head, dnode, &publ_zone);
2414323add6SPer Liden 	read_unlock_bh(&tipc_nametbl_lock);
2429aa88c2aSAllan Stephens 
243a6ca1094SYing Xue 	tipc_link_xmit(&head, dnode, dnode);
244b97bf3fdSPer Liden }
245b97bf3fdSPer Liden 
246a8f48af5SYing Xue static void tipc_publ_subscribe(struct publication *publ, u32 addr)
247a8f48af5SYing Xue {
248a8f48af5SYing Xue 	struct tipc_node *node;
249a8f48af5SYing Xue 
250a8f48af5SYing Xue 	if (in_own_node(addr))
251a8f48af5SYing Xue 		return;
252a8f48af5SYing Xue 
253a8f48af5SYing Xue 	node = tipc_node_find(addr);
254a8f48af5SYing Xue 	if (!node) {
255a8f48af5SYing Xue 		pr_warn("Node subscription rejected, unknown node 0x%x\n",
256a8f48af5SYing Xue 			addr);
257a8f48af5SYing Xue 		return;
258a8f48af5SYing Xue 	}
259a8f48af5SYing Xue 
260a8f48af5SYing Xue 	tipc_node_lock(node);
261a8f48af5SYing Xue 	list_add_tail(&publ->nodesub_list, &node->publ_list);
262a8f48af5SYing Xue 	tipc_node_unlock(node);
263a8f48af5SYing Xue }
264a8f48af5SYing Xue 
265a8f48af5SYing Xue static void tipc_publ_unsubscribe(struct publication *publ, u32 addr)
266a8f48af5SYing Xue {
267a8f48af5SYing Xue 	struct tipc_node *node;
268a8f48af5SYing Xue 
269a8f48af5SYing Xue 	node = tipc_node_find(addr);
270a8f48af5SYing Xue 	if (!node)
271a8f48af5SYing Xue 		return;
272a8f48af5SYing Xue 
273a8f48af5SYing Xue 	tipc_node_lock(node);
274a8f48af5SYing Xue 	list_del_init(&publ->nodesub_list);
275a8f48af5SYing Xue 	tipc_node_unlock(node);
276a8f48af5SYing Xue }
277a8f48af5SYing Xue 
278b97bf3fdSPer Liden /**
279a8f48af5SYing Xue  * tipc_publ_purge - remove publication associated with a failed node
280b97bf3fdSPer Liden  *
281b97bf3fdSPer Liden  * Invoked for each publication issued by a newly failed node.
282b97bf3fdSPer Liden  * Removes publication structure from name table & deletes it.
283b97bf3fdSPer Liden  */
284a8f48af5SYing Xue static void tipc_publ_purge(struct publication *publ, u32 addr)
285b97bf3fdSPer Liden {
286b97bf3fdSPer Liden 	struct publication *p;
287f131072cSAllan Stephens 
2884323add6SPer Liden 	write_lock_bh(&tipc_nametbl_lock);
2894323add6SPer Liden 	p = tipc_nametbl_remove_publ(publ->type, publ->lower,
290b97bf3fdSPer Liden 				     publ->node, publ->ref, publ->key);
291431697ebSAllan Stephens 	if (p)
292a8f48af5SYing Xue 		tipc_publ_unsubscribe(p, addr);
2934323add6SPer Liden 	write_unlock_bh(&tipc_nametbl_lock);
294f131072cSAllan Stephens 
295f131072cSAllan Stephens 	if (p != publ) {
2962cf8aa19SErik Hugne 		pr_err("Unable to remove publication from failed node\n"
297f131072cSAllan Stephens 		       " (type=%u, lower=%u, node=0x%x, ref=%u, key=%u)\n",
2982cf8aa19SErik Hugne 		       publ->type, publ->lower, publ->node, publ->ref,
2992cf8aa19SErik Hugne 		       publ->key);
300f131072cSAllan Stephens 	}
301f131072cSAllan Stephens 
302f131072cSAllan Stephens 	kfree(p);
303f131072cSAllan Stephens }
304b97bf3fdSPer Liden 
305a8f48af5SYing Xue void tipc_publ_notify(struct list_head *nsub_list, u32 addr)
306a8f48af5SYing Xue {
307a8f48af5SYing Xue 	struct publication *publ, *tmp;
308a8f48af5SYing Xue 
309a8f48af5SYing Xue 	list_for_each_entry_safe(publ, tmp, nsub_list, nodesub_list)
310a8f48af5SYing Xue 		tipc_publ_purge(publ, addr);
311a8f48af5SYing Xue }
312a8f48af5SYing Xue 
313b97bf3fdSPer Liden /**
314f4ad8a4bSErik Hugne  * tipc_update_nametbl - try to process a nametable update and notify
315f4ad8a4bSErik Hugne  *			 subscribers
316f4ad8a4bSErik Hugne  *
317f4ad8a4bSErik Hugne  * tipc_nametbl_lock must be held.
318f4ad8a4bSErik Hugne  * Returns the publication item if successful, otherwise NULL.
319f4ad8a4bSErik Hugne  */
3200fc4dffaSErik Hugne static bool tipc_update_nametbl(struct distr_item *i, u32 node, u32 dtype)
321f4ad8a4bSErik Hugne {
322f4ad8a4bSErik Hugne 	struct publication *publ = NULL;
323f4ad8a4bSErik Hugne 
324f4ad8a4bSErik Hugne 	if (dtype == PUBLICATION) {
325f4ad8a4bSErik Hugne 		publ = tipc_nametbl_insert_publ(ntohl(i->type), ntohl(i->lower),
326f4ad8a4bSErik Hugne 						ntohl(i->upper),
327f4ad8a4bSErik Hugne 						TIPC_CLUSTER_SCOPE, node,
328f4ad8a4bSErik Hugne 						ntohl(i->ref), ntohl(i->key));
329f4ad8a4bSErik Hugne 		if (publ) {
330a8f48af5SYing Xue 			tipc_publ_subscribe(publ, node);
3310fc4dffaSErik Hugne 			return true;
332f4ad8a4bSErik Hugne 		}
333f4ad8a4bSErik Hugne 	} else if (dtype == WITHDRAWAL) {
334f4ad8a4bSErik Hugne 		publ = tipc_nametbl_remove_publ(ntohl(i->type), ntohl(i->lower),
335f4ad8a4bSErik Hugne 						node, ntohl(i->ref),
336f4ad8a4bSErik Hugne 						ntohl(i->key));
337f4ad8a4bSErik Hugne 		if (publ) {
338a8f48af5SYing Xue 			tipc_publ_unsubscribe(publ, node);
339f4ad8a4bSErik Hugne 			kfree(publ);
3400fc4dffaSErik Hugne 			return true;
341f4ad8a4bSErik Hugne 		}
342f4ad8a4bSErik Hugne 	} else {
343f4ad8a4bSErik Hugne 		pr_warn("Unrecognized name table message received\n");
344f4ad8a4bSErik Hugne 	}
3450fc4dffaSErik Hugne 	return false;
346f4ad8a4bSErik Hugne }
347f4ad8a4bSErik Hugne 
348f4ad8a4bSErik Hugne /**
349a5325ae5SErik Hugne  * tipc_named_add_backlog - add a failed name table update to the backlog
350a5325ae5SErik Hugne  *
351a5325ae5SErik Hugne  */
352a5325ae5SErik Hugne static void tipc_named_add_backlog(struct distr_item *i, u32 type, u32 node)
353a5325ae5SErik Hugne {
354a5325ae5SErik Hugne 	struct distr_queue_item *e;
355a5325ae5SErik Hugne 	unsigned long now = get_jiffies_64();
356a5325ae5SErik Hugne 
357a5325ae5SErik Hugne 	e = kzalloc(sizeof(*e), GFP_ATOMIC);
358a5325ae5SErik Hugne 	if (!e)
359a5325ae5SErik Hugne 		return;
360a5325ae5SErik Hugne 	e->dtype = type;
361a5325ae5SErik Hugne 	e->node = node;
362a5325ae5SErik Hugne 	e->expires = now + msecs_to_jiffies(sysctl_tipc_named_timeout);
363a5325ae5SErik Hugne 	memcpy(e, i, sizeof(*i));
364a5325ae5SErik Hugne 	list_add_tail(&e->next, &tipc_dist_queue);
365a5325ae5SErik Hugne }
366a5325ae5SErik Hugne 
367a5325ae5SErik Hugne /**
368a5325ae5SErik Hugne  * tipc_named_process_backlog - try to process any pending name table updates
369a5325ae5SErik Hugne  * from the network.
370a5325ae5SErik Hugne  */
371a5325ae5SErik Hugne void tipc_named_process_backlog(void)
372a5325ae5SErik Hugne {
373a5325ae5SErik Hugne 	struct distr_queue_item *e, *tmp;
374a5325ae5SErik Hugne 	char addr[16];
375a5325ae5SErik Hugne 	unsigned long now = get_jiffies_64();
376a5325ae5SErik Hugne 
377a5325ae5SErik Hugne 	list_for_each_entry_safe(e, tmp, &tipc_dist_queue, next) {
378a5325ae5SErik Hugne 		if (time_after(e->expires, now)) {
379a5325ae5SErik Hugne 			if (!tipc_update_nametbl(&e->i, e->node, e->dtype))
380a5325ae5SErik Hugne 				continue;
381a5325ae5SErik Hugne 		} else {
382a5325ae5SErik Hugne 			tipc_addr_string_fill(addr, e->node);
383a5325ae5SErik Hugne 			pr_warn_ratelimited("Dropping name table update (%d) of {%u, %u, %u} from %s key=%u\n",
384a5325ae5SErik Hugne 					    e->dtype, ntohl(e->i.type),
385a5325ae5SErik Hugne 					    ntohl(e->i.lower),
386a5325ae5SErik Hugne 					    ntohl(e->i.upper),
387a5325ae5SErik Hugne 					    addr, ntohl(e->i.key));
388a5325ae5SErik Hugne 		}
389a5325ae5SErik Hugne 		list_del(&e->next);
390a5325ae5SErik Hugne 		kfree(e);
391a5325ae5SErik Hugne 	}
392a5325ae5SErik Hugne }
393a5325ae5SErik Hugne 
394a5325ae5SErik Hugne /**
395247f0f3cSYing Xue  * tipc_named_rcv - process name table update message sent by another node
396b97bf3fdSPer Liden  */
397247f0f3cSYing Xue void tipc_named_rcv(struct sk_buff *buf)
398b97bf3fdSPer Liden {
399b97bf3fdSPer Liden 	struct tipc_msg *msg = buf_msg(buf);
400b97bf3fdSPer Liden 	struct distr_item *item = (struct distr_item *)msg_data(msg);
401b97bf3fdSPer Liden 	u32 count = msg_data_sz(msg) / ITEM_SIZE;
402a5325ae5SErik Hugne 	u32 node = msg_orignode(msg);
403b97bf3fdSPer Liden 
4044323add6SPer Liden 	write_lock_bh(&tipc_nametbl_lock);
405b97bf3fdSPer Liden 	while (count--) {
406a5325ae5SErik Hugne 		if (!tipc_update_nametbl(item, node, msg_type(msg)))
407a5325ae5SErik Hugne 			tipc_named_add_backlog(item, msg_type(msg), node);
408b97bf3fdSPer Liden 		item++;
409b97bf3fdSPer Liden 	}
410a5325ae5SErik Hugne 	tipc_named_process_backlog();
4114323add6SPer Liden 	write_unlock_bh(&tipc_nametbl_lock);
4125f6d9123SAllan Stephens 	kfree_skb(buf);
413b97bf3fdSPer Liden }
414b97bf3fdSPer Liden 
415b97bf3fdSPer Liden /**
4161110b8d3SAllan Stephens  * tipc_named_reinit - re-initialize local publications
417b97bf3fdSPer Liden  *
418945af1c3SAllan Stephens  * This routine is called whenever TIPC networking is enabled.
4191110b8d3SAllan Stephens  * All name table entries published by this node are updated to reflect
4201110b8d3SAllan Stephens  * the node's new network address.
421b97bf3fdSPer Liden  */
4224323add6SPer Liden void tipc_named_reinit(void)
423b97bf3fdSPer Liden {
424b97bf3fdSPer Liden 	struct publication *publ;
425a909804fSAllan Stephens 	int scope;
426b97bf3fdSPer Liden 
4274323add6SPer Liden 	write_lock_bh(&tipc_nametbl_lock);
428945af1c3SAllan Stephens 
4291110b8d3SAllan Stephens 	for (scope = TIPC_ZONE_SCOPE; scope <= TIPC_NODE_SCOPE; scope++)
430a909804fSAllan Stephens 		list_for_each_entry(publ, &publ_lists[scope]->list, local_list)
431b97bf3fdSPer Liden 			publ->node = tipc_own_addr;
432945af1c3SAllan Stephens 
4334323add6SPer Liden 	write_unlock_bh(&tipc_nametbl_lock);
434b97bf3fdSPer Liden }
435