blob: 8267b751a526a4dc30062e5e9b38da92bc97266e [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/name_distr.c: TIPC name distribution code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Jon Maloy998d3902021-03-16 22:06:08 -04004 * Copyright (c) 2000-2006, 2014-2019, Ericsson AB
Allan Stephens431697e2011-02-23 13:51:15 -05005 * Copyright (c) 2005, 2010-2011, Wind River Systems
Jon Maloy998d3902021-03-16 22:06:08 -04006 * Copyright (c) 2020-2021, Red Hat Inc
Per Lidenb97bf3f2006-01-02 19:04:38 +01007 * All rights reserved.
8 *
Per Liden9ea1fd32006-01-11 13:30:43 +01009 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +010010 * modification, are permitted provided that the following conditions are met:
11 *
Per Liden9ea1fd32006-01-11 13:30:43 +010012 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
Per Lidenb97bf3f2006-01-02 19:04:38 +010020 *
Per Liden9ea1fd32006-01-11 13:30:43 +010021 * Alternatively, this software may be distributed under the terms of the
22 * GNU General Public License ("GPL") version 2 as published by the Free
23 * Software Foundation.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Per Lidenb97bf3f2006-01-02 19:04:38 +010035 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#include "core.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010039#include "link.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010040#include "name_distr.h"
41
Erik Hugnea5325ae2014-08-28 09:08:47 +020042int sysctl_tipc_named_timeout __read_mostly = 2000;
43
Erik Hugnea5325ae2014-08-28 09:08:47 +020044struct distr_queue_item {
45 struct distr_item i;
46 u32 dtype;
47 u32 node;
48 unsigned long expires;
49 struct list_head next;
50};
51
Per Lidenb97bf3f2006-01-02 19:04:38 +010052/**
53 * publ_to_item - add publication info to a publication message
Randy Dunlapcb672962020-11-29 10:32:45 -080054 * @p: publication info
55 * @i: location of item in the message
Per Lidenb97bf3f2006-01-02 19:04:38 +010056 */
Per Lidenb97bf3f2006-01-02 19:04:38 +010057static void publ_to_item(struct distr_item *i, struct publication *p)
58{
Jon Maloy998d3902021-03-16 22:06:08 -040059 i->type = htonl(p->sr.type);
60 i->lower = htonl(p->sr.lower);
61 i->upper = htonl(p->sr.upper);
62 i->port = htonl(p->sk.ref);
Per Lidenb97bf3f2006-01-02 19:04:38 +010063 i->key = htonl(p->key);
Per Lidenb97bf3f2006-01-02 19:04:38 +010064}
65
66/**
67 * named_prepare_buf - allocate & initialize a publication message
Randy Dunlapcb672962020-11-29 10:32:45 -080068 * @net: the associated network namespace
69 * @type: message type
70 * @size: payload size
71 * @dest: destination node
Parthasarathy Bhuvaragand2f394d2016-09-01 16:22:16 +020072 *
73 * The buffer returned is of size INT_H_SIZE + payload size
Per Lidenb97bf3f2006-01-02 19:04:38 +010074 */
Ying Xue34747532015-01-09 15:27:10 +080075static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size,
76 u32 dest)
Per Lidenb97bf3f2006-01-02 19:04:38 +010077{
Parthasarathy Bhuvaragan57d5f642017-01-13 15:46:25 +010078 struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC);
Jon Maloy23fd3ea2018-03-22 20:42:49 +010079 u32 self = tipc_own_addr(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +010080 struct tipc_msg *msg;
81
82 if (buf != NULL) {
83 msg = buf_msg(buf);
Jon Maloy23fd3ea2018-03-22 20:42:49 +010084 tipc_msg_init(self, msg, NAME_DISTRIBUTOR,
85 type, INT_H_SIZE, dest);
Allan Stephens741d9eb2011-05-31 15:03:18 -040086 msg_set_size(msg, INT_H_SIZE + size);
Per Lidenb97bf3f2006-01-02 19:04:38 +010087 }
88 return buf;
89}
90
91/**
Per Liden4323add2006-01-18 00:38:21 +010092 * tipc_named_publish - tell other nodes about a new publication by this node
Randy Dunlapcb672962020-11-29 10:32:45 -080093 * @net: the associated network namespace
Jon Maloy998d3902021-03-16 22:06:08 -040094 * @p: the new publication
Per Lidenb97bf3f2006-01-02 19:04:38 +010095 */
Jon Maloy998d3902021-03-16 22:06:08 -040096struct sk_buff *tipc_named_publish(struct net *net, struct publication *p)
Per Lidenb97bf3f2006-01-02 19:04:38 +010097{
Jon Maloy64a52b26d52018-03-15 16:48:52 +010098 struct name_table *nt = tipc_name_table(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +010099 struct distr_item *item;
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100100 struct sk_buff *skb;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100101
Jon Maloy998d3902021-03-16 22:06:08 -0400102 if (p->scope == TIPC_NODE_SCOPE) {
103 list_add_tail_rcu(&p->binding_node, &nt->node_scope);
Ying Xueeab8c0452014-04-28 18:00:10 +0800104 return NULL;
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100105 }
Jon Maloy988f3f12018-10-19 19:55:40 +0200106 write_lock_bh(&nt->cluster_scope_lock);
Jon Maloy998d3902021-03-16 22:06:08 -0400107 list_add_tail(&p->binding_node, &nt->cluster_scope);
Jon Maloy988f3f12018-10-19 19:55:40 +0200108 write_unlock_bh(&nt->cluster_scope_lock);
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100109 skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0);
110 if (!skb) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400111 pr_warn("Publication distribution failure\n");
Ying Xueeab8c0452014-04-28 18:00:10 +0800112 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100113 }
Hoang Huu Lecad29292020-06-17 13:56:05 +0700114 msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
115 msg_set_non_legacy(buf_msg(skb));
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100116 item = (struct distr_item *)msg_data(buf_msg(skb));
Jon Maloy998d3902021-03-16 22:06:08 -0400117 publ_to_item(item, p);
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100118 return skb;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100119}
120
121/**
Per Liden4323add2006-01-18 00:38:21 +0100122 * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node
Randy Dunlapcb672962020-11-29 10:32:45 -0800123 * @net: the associated network namespace
Jon Maloy998d3902021-03-16 22:06:08 -0400124 * @p: the withdrawn publication
Per Lidenb97bf3f2006-01-02 19:04:38 +0100125 */
Jon Maloy998d3902021-03-16 22:06:08 -0400126struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *p)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100127{
Jon Maloy988f3f12018-10-19 19:55:40 +0200128 struct name_table *nt = tipc_name_table(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100129 struct distr_item *item;
Hoang Huu Lecad29292020-06-17 13:56:05 +0700130 struct sk_buff *skb;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100131
Jon Maloy988f3f12018-10-19 19:55:40 +0200132 write_lock_bh(&nt->cluster_scope_lock);
Jon Maloy998d3902021-03-16 22:06:08 -0400133 list_del(&p->binding_node);
Jon Maloy988f3f12018-10-19 19:55:40 +0200134 write_unlock_bh(&nt->cluster_scope_lock);
Jon Maloy998d3902021-03-16 22:06:08 -0400135 if (p->scope == TIPC_NODE_SCOPE)
Ying Xueeab8c0452014-04-28 18:00:10 +0800136 return NULL;
Allan Stephens1110b8d2012-04-17 17:57:52 -0400137
Hoang Huu Lecad29292020-06-17 13:56:05 +0700138 skb = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0);
139 if (!skb) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400140 pr_warn("Withdrawal distribution failure\n");
Ying Xueeab8c0452014-04-28 18:00:10 +0800141 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100142 }
Hoang Huu Lecad29292020-06-17 13:56:05 +0700143 msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++);
144 msg_set_non_legacy(buf_msg(skb));
145 item = (struct distr_item *)msg_data(buf_msg(skb));
Jon Maloy998d3902021-03-16 22:06:08 -0400146 publ_to_item(item, p);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700147 return skb;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100148}
149
Jon Paul Maloydbdf6d22014-07-16 20:40:58 -0400150/**
Allan Stephense11aa052012-04-17 17:57:52 -0400151 * named_distribute - prepare name info for bulk distribution to another node
Randy Dunlapcb672962020-11-29 10:32:45 -0800152 * @net: the associated network namespace
Ying Xuea6ca1092014-11-26 11:41:55 +0800153 * @list: list of messages (buffers) to be returned from this function
Jon Paul Maloydbdf6d22014-07-16 20:40:58 -0400154 * @dnode: node to be updated
155 * @pls: linked list of publication items to be packed into buffer chain
Randy Dunlapcb672962020-11-29 10:32:45 -0800156 * @seqno: sequence number for this message
Allan Stephense11aa052012-04-17 17:57:52 -0400157 */
Ying Xuef2f98002015-01-09 15:27:05 +0800158static void named_distribute(struct net *net, struct sk_buff_head *list,
Hoang Huu Lecad29292020-06-17 13:56:05 +0700159 u32 dnode, struct list_head *pls, u16 seqno)
Allan Stephense11aa052012-04-17 17:57:52 -0400160{
161 struct publication *publ;
Ying Xuea6ca1092014-11-26 11:41:55 +0800162 struct sk_buff *skb = NULL;
Allan Stephense11aa052012-04-17 17:57:52 -0400163 struct distr_item *item = NULL;
Hoang Lef73b1282019-10-29 07:51:21 +0700164 u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0, false) - INT_H_SIZE) /
Parthasarathy Bhuvaragand2f394d2016-09-01 16:22:16 +0200165 ITEM_SIZE) * ITEM_SIZE;
166 u32 msg_rem = msg_dsz;
Hoang Huu Lecad29292020-06-17 13:56:05 +0700167 struct tipc_msg *hdr;
Allan Stephense11aa052012-04-17 17:57:52 -0400168
Jon Maloy988f3f12018-10-19 19:55:40 +0200169 list_for_each_entry(publ, pls, binding_node) {
Jon Paul Maloydbdf6d22014-07-16 20:40:58 -0400170 /* Prepare next buffer: */
Ying Xuea6ca1092014-11-26 11:41:55 +0800171 if (!skb) {
Ying Xue34747532015-01-09 15:27:10 +0800172 skb = named_prepare_buf(net, PUBLICATION, msg_rem,
173 dnode);
Ying Xuea6ca1092014-11-26 11:41:55 +0800174 if (!skb) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400175 pr_warn("Bulk publication failure\n");
Allan Stephense11aa052012-04-17 17:57:52 -0400176 return;
177 }
Hoang Huu Lecad29292020-06-17 13:56:05 +0700178 hdr = buf_msg(skb);
179 msg_set_bc_ack_invalid(hdr, true);
180 msg_set_bulk(hdr);
181 msg_set_non_legacy(hdr);
182 item = (struct distr_item *)msg_data(hdr);
Allan Stephense11aa052012-04-17 17:57:52 -0400183 }
Jon Paul Maloydbdf6d22014-07-16 20:40:58 -0400184
185 /* Pack publication into message: */
Allan Stephense11aa052012-04-17 17:57:52 -0400186 publ_to_item(item, publ);
187 item++;
Jon Paul Maloydbdf6d22014-07-16 20:40:58 -0400188 msg_rem -= ITEM_SIZE;
189
190 /* Append full buffer to list: */
191 if (!msg_rem) {
Ying Xuea6ca1092014-11-26 11:41:55 +0800192 __skb_queue_tail(list, skb);
193 skb = NULL;
Ying Xue1b61e702014-12-02 15:00:23 +0800194 msg_rem = msg_dsz;
Allan Stephense11aa052012-04-17 17:57:52 -0400195 }
196 }
Ying Xue1b61e702014-12-02 15:00:23 +0800197 if (skb) {
Hoang Huu Lecad29292020-06-17 13:56:05 +0700198 hdr = buf_msg(skb);
199 msg_set_size(hdr, INT_H_SIZE + (msg_dsz - msg_rem));
Ying Xue1b61e702014-12-02 15:00:23 +0800200 skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem));
201 __skb_queue_tail(list, skb);
202 }
Hoang Huu Lecad29292020-06-17 13:56:05 +0700203 hdr = buf_msg(skb_peek_tail(list));
204 msg_set_last_bulk(hdr);
205 msg_set_named_seqno(hdr, seqno);
Allan Stephense11aa052012-04-17 17:57:52 -0400206}
207
Per Lidenb97bf3f2006-01-02 19:04:38 +0100208/**
Per Liden4323add2006-01-18 00:38:21 +0100209 * tipc_named_node_up - tell specified node about all publications by this node
Randy Dunlapcb672962020-11-29 10:32:45 -0800210 * @net: the associated network namespace
211 * @dnode: destination node
212 * @capabilities: peer node's capabilities
Per Lidenb97bf3f2006-01-02 19:04:38 +0100213 */
Hoang Huu Lecad29292020-06-17 13:56:05 +0700214void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100215{
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100216 struct name_table *nt = tipc_name_table(net);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700217 struct tipc_net *tn = tipc_net(net);
Ying Xuea6ca1092014-11-26 11:41:55 +0800218 struct sk_buff_head head;
Hoang Huu Lecad29292020-06-17 13:56:05 +0700219 u16 seqno;
Ying Xuea6ca1092014-11-26 11:41:55 +0800220
Jon Maloye654f9f2019-08-15 16:42:50 +0200221 __skb_queue_head_init(&head);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700222 spin_lock_bh(&tn->nametbl_lock);
223 if (!(capabilities & TIPC_NAMED_BCAST))
224 nt->rc_dests++;
225 seqno = nt->snd_nxt;
226 spin_unlock_bh(&tn->nametbl_lock);
Allan Stephens9aa88c22011-05-31 13:38:02 -0400227
Jon Maloy988f3f12018-10-19 19:55:40 +0200228 read_lock_bh(&nt->cluster_scope_lock);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700229 named_distribute(net, &head, dnode, &nt->cluster_scope, seqno);
Jon Paul Maloyc49a0a842015-10-22 08:51:47 -0400230 tipc_node_xmit(net, &head, dnode, 0);
Jon Maloy988f3f12018-10-19 19:55:40 +0200231 read_unlock_bh(&nt->cluster_scope_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100232}
233
234/**
Ying Xuea8f48af2014-11-26 11:41:45 +0800235 * tipc_publ_purge - remove publication associated with a failed node
Randy Dunlapcb672962020-11-29 10:32:45 -0800236 * @net: the associated network namespace
Jon Maloy998d3902021-03-16 22:06:08 -0400237 * @p: the publication to remove
Randy Dunlapcb672962020-11-29 10:32:45 -0800238 * @addr: failed node's address
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900239 *
240 * Invoked for each publication issued by a newly failed node.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100241 * Removes publication structure from name table & deletes it.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100242 */
Jon Maloy998d3902021-03-16 22:06:08 -0400243static void tipc_publ_purge(struct net *net, struct publication *p, u32 addr)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100244{
Jon Maloy37922ea2018-03-29 23:20:43 +0200245 struct tipc_net *tn = tipc_net(net);
Jon Maloy998d3902021-03-16 22:06:08 -0400246 struct publication *_p;
Jon Maloy2c98da02021-03-16 22:06:13 -0400247 struct tipc_uaddr ua;
Allan Stephensf1310722006-06-25 23:51:37 -0700248
Jon Maloy2c98da02021-03-16 22:06:13 -0400249 tipc_uaddr(&ua, TIPC_SERVICE_RANGE, p->scope, p->sr.type,
250 p->sr.lower, p->sr.upper);
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800251 spin_lock_bh(&tn->nametbl_lock);
Jon Maloy2c98da02021-03-16 22:06:13 -0400252 _p = tipc_nametbl_remove_publ(net, &ua, &p->sk, p->key);
Jon Maloy998d3902021-03-16 22:06:08 -0400253 if (_p)
254 tipc_node_unsubscribe(net, &_p->binding_node, addr);
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800255 spin_unlock_bh(&tn->nametbl_lock);
Jon Maloy998d3902021-03-16 22:06:08 -0400256 if (_p)
257 kfree_rcu(_p, rcu);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100258}
259
Hoang Huu Lecad29292020-06-17 13:56:05 +0700260void tipc_publ_notify(struct net *net, struct list_head *nsub_list,
261 u32 addr, u16 capabilities)
Ying Xuea8f48af2014-11-26 11:41:45 +0800262{
Hoang Huu Lecad29292020-06-17 13:56:05 +0700263 struct name_table *nt = tipc_name_table(net);
264 struct tipc_net *tn = tipc_net(net);
265
Ying Xuea8f48af2014-11-26 11:41:45 +0800266 struct publication *publ, *tmp;
267
Jon Maloy935439c2018-03-15 16:48:54 +0100268 list_for_each_entry_safe(publ, tmp, nsub_list, binding_node)
Ying Xuef2f98002015-01-09 15:27:05 +0800269 tipc_publ_purge(net, publ, addr);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700270 spin_lock_bh(&tn->nametbl_lock);
271 if (!(capabilities & TIPC_NAMED_BCAST))
272 nt->rc_dests--;
273 spin_unlock_bh(&tn->nametbl_lock);
Ying Xuea8f48af2014-11-26 11:41:45 +0800274}
275
Per Lidenb97bf3f2006-01-02 19:04:38 +0100276/**
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200277 * tipc_update_nametbl - try to process a nametable update and notify
278 * subscribers
Randy Dunlapcb672962020-11-29 10:32:45 -0800279 * @net: the associated network namespace
280 * @i: location of item in the message
281 * @node: node address
282 * @dtype: name distributor message type
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200283 *
284 * tipc_nametbl_lock must be held.
Randy Dunlap637b77f2020-11-29 10:32:48 -0800285 * Return: the publication item if successful, otherwise NULL.
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200286 */
Ying Xuef2f98002015-01-09 15:27:05 +0800287static bool tipc_update_nametbl(struct net *net, struct distr_item *i,
288 u32 node, u32 dtype)
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200289{
Jon Maloy37922ea2018-03-29 23:20:43 +0200290 struct publication *p = NULL;
Jon Maloya45ffa62021-03-16 22:06:12 -0400291 struct tipc_socket_addr sk;
292 struct tipc_uaddr ua;
Jon Maloy37922ea2018-03-29 23:20:43 +0200293 u32 key = ntohl(i->key);
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200294
Jon Maloya45ffa62021-03-16 22:06:12 -0400295 tipc_uaddr(&ua, TIPC_SERVICE_RANGE, TIPC_CLUSTER_SCOPE,
296 ntohl(i->type), ntohl(i->lower), ntohl(i->upper));
297 sk.ref = ntohl(i->port);
298 sk.node = node;
299
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200300 if (dtype == PUBLICATION) {
Jon Maloya45ffa62021-03-16 22:06:12 -0400301 p = tipc_nametbl_insert_publ(net, &ua, &sk, key);
Jon Maloy37922ea2018-03-29 23:20:43 +0200302 if (p) {
303 tipc_node_subscribe(net, &p->binding_node, node);
Erik Hugne0fc4dff2014-09-10 14:02:50 +0200304 return true;
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200305 }
306 } else if (dtype == WITHDRAWAL) {
Jon Maloy2c98da02021-03-16 22:06:13 -0400307 p = tipc_nametbl_remove_publ(net, &ua, &sk, key);
Jon Maloy37922ea2018-03-29 23:20:43 +0200308 if (p) {
309 tipc_node_unsubscribe(net, &p->binding_node, node);
310 kfree_rcu(p, rcu);
Erik Hugne0fc4dff2014-09-10 14:02:50 +0200311 return true;
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200312 }
Jon Maloya45ffa62021-03-16 22:06:12 -0400313 pr_warn_ratelimited("Failed to remove binding %u,%u from %u\n",
314 ua.sr.type, ua.sr.lower, node);
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200315 } else {
Jon Maloyc7223d62022-02-08 22:22:37 -0500316 pr_warn_ratelimited("Unknown name table message received\n");
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200317 }
Erik Hugne0fc4dff2014-09-10 14:02:50 +0200318 return false;
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200319}
320
Hoang Huu Lecad29292020-06-17 13:56:05 +0700321static struct sk_buff *tipc_named_dequeue(struct sk_buff_head *namedq,
322 u16 *rcv_nxt, bool *open)
323{
324 struct sk_buff *skb, *tmp;
325 struct tipc_msg *hdr;
326 u16 seqno;
327
Hoang Huu Le7b50ee32020-10-08 14:31:56 +0700328 spin_lock_bh(&namedq->lock);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700329 skb_queue_walk_safe(namedq, skb, tmp) {
Hoang Huu Le7b50ee32020-10-08 14:31:56 +0700330 if (unlikely(skb_linearize(skb))) {
331 __skb_unlink(skb, namedq);
332 kfree_skb(skb);
333 continue;
334 }
Hoang Huu Lecad29292020-06-17 13:56:05 +0700335 hdr = buf_msg(skb);
336 seqno = msg_named_seqno(hdr);
337 if (msg_is_last_bulk(hdr)) {
338 *rcv_nxt = seqno;
339 *open = true;
340 }
341
342 if (msg_is_bulk(hdr) || msg_is_legacy(hdr)) {
343 __skb_unlink(skb, namedq);
Hoang Huu Le7b50ee32020-10-08 14:31:56 +0700344 spin_unlock_bh(&namedq->lock);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700345 return skb;
346 }
347
348 if (*open && (*rcv_nxt == seqno)) {
349 (*rcv_nxt)++;
350 __skb_unlink(skb, namedq);
Hoang Huu Le7b50ee32020-10-08 14:31:56 +0700351 spin_unlock_bh(&namedq->lock);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700352 return skb;
353 }
354
355 if (less(seqno, *rcv_nxt)) {
356 __skb_unlink(skb, namedq);
357 kfree_skb(skb);
358 continue;
359 }
360 }
Hoang Huu Le7b50ee32020-10-08 14:31:56 +0700361 spin_unlock_bh(&namedq->lock);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700362 return NULL;
363}
364
Erik Hugnef4ad8a42014-08-28 09:08:46 +0200365/**
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500366 * tipc_named_rcv - process name table update messages sent by another node
Randy Dunlapcb672962020-11-29 10:32:45 -0800367 * @net: the associated network namespace
368 * @namedq: queue to receive from
369 * @rcv_nxt: store last received seqno here
370 * @open: last bulk msg was received (FIXME)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100371 */
Hoang Huu Lecad29292020-06-17 13:56:05 +0700372void tipc_named_rcv(struct net *net, struct sk_buff_head *namedq,
373 u16 *rcv_nxt, bool *open)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100374{
Hoang Huu Lecad29292020-06-17 13:56:05 +0700375 struct tipc_net *tn = tipc_net(net);
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500376 struct distr_item *item;
Hoang Huu Lecad29292020-06-17 13:56:05 +0700377 struct tipc_msg *hdr;
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500378 struct sk_buff *skb;
Hoang Huu Lecad29292020-06-17 13:56:05 +0700379 u32 count, node;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100380
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800381 spin_lock_bh(&tn->nametbl_lock);
Hoang Huu Lecad29292020-06-17 13:56:05 +0700382 while ((skb = tipc_named_dequeue(namedq, rcv_nxt, open))) {
383 hdr = buf_msg(skb);
384 node = msg_orignode(hdr);
385 item = (struct distr_item *)msg_data(hdr);
386 count = msg_data_sz(hdr) / ITEM_SIZE;
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500387 while (count--) {
Hoang Huu Lecad29292020-06-17 13:56:05 +0700388 tipc_update_nametbl(net, item, node, msg_type(hdr));
Jon Paul Maloyc637c102015-02-05 08:36:41 -0500389 item++;
390 }
391 kfree_skb(skb);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100392 }
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800393 spin_unlock_bh(&tn->nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100394}
395
396/**
Allan Stephens1110b8d2012-04-17 17:57:52 -0400397 * tipc_named_reinit - re-initialize local publications
Randy Dunlapcb672962020-11-29 10:32:45 -0800398 * @net: the associated network namespace
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900399 *
Allan Stephens945af1c2011-10-14 14:42:25 -0400400 * This routine is called whenever TIPC networking is enabled.
Allan Stephens1110b8d2012-04-17 17:57:52 -0400401 * All name table entries published by this node are updated to reflect
402 * the node's new network address.
Per Lidenb97bf3f2006-01-02 19:04:38 +0100403 */
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800404void tipc_named_reinit(struct net *net)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100405{
Jon Maloy64a52b26d52018-03-15 16:48:52 +0100406 struct name_table *nt = tipc_name_table(net);
407 struct tipc_net *tn = tipc_net(net);
Jon Maloy998d3902021-03-16 22:06:08 -0400408 struct publication *p;
Jon Maloy23fd3ea2018-03-22 20:42:49 +0100409 u32 self = tipc_own_addr(net);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100410
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800411 spin_lock_bh(&tn->nametbl_lock);
Allan Stephens945af1c2011-10-14 14:42:25 -0400412
Jon Maloy998d3902021-03-16 22:06:08 -0400413 list_for_each_entry_rcu(p, &nt->node_scope, binding_node)
414 p->sk.node = self;
415 list_for_each_entry_rcu(p, &nt->cluster_scope, binding_node)
416 p->sk.node = self;
Hoang Huu Lecad29292020-06-17 13:56:05 +0700417 nt->rc_dests = 0;
Ying Xue4ac1c8d2015-01-09 15:27:09 +0800418 spin_unlock_bh(&tn->nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100419}