Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/name_distr.c: TIPC name distribution code |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 4 | * Copyright (c) 2000-2006, 2014-2019, Ericsson AB |
Allan Stephens | 431697e | 2011-02-23 13:51:15 -0500 | [diff] [blame] | 5 | * Copyright (c) 2005, 2010-2011, Wind River Systems |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 6 | * Copyright (c) 2020-2021, Red Hat Inc |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 7 | * All rights reserved. |
| 8 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 9 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 10 | * modification, are permitted provided that the following conditions are met: |
| 11 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 12 | * 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 20 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 21 | * 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 35 | * POSSIBILITY OF SUCH DAMAGE. |
| 36 | */ |
| 37 | |
| 38 | #include "core.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | #include "link.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 40 | #include "name_distr.h" |
| 41 | |
Erik Hugne | a5325ae | 2014-08-28 09:08:47 +0200 | [diff] [blame] | 42 | int sysctl_tipc_named_timeout __read_mostly = 2000; |
| 43 | |
Erik Hugne | a5325ae | 2014-08-28 09:08:47 +0200 | [diff] [blame] | 44 | struct 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 52 | /** |
| 53 | * publ_to_item - add publication info to a publication message |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 54 | * @p: publication info |
| 55 | * @i: location of item in the message |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 56 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 57 | static void publ_to_item(struct distr_item *i, struct publication *p) |
| 58 | { |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 59 | 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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 63 | i->key = htonl(p->key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /** |
| 67 | * named_prepare_buf - allocate & initialize a publication message |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 68 | * @net: the associated network namespace |
| 69 | * @type: message type |
| 70 | * @size: payload size |
| 71 | * @dest: destination node |
Parthasarathy Bhuvaragan | d2f394d | 2016-09-01 16:22:16 +0200 | [diff] [blame] | 72 | * |
| 73 | * The buffer returned is of size INT_H_SIZE + payload size |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 74 | */ |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 75 | static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size, |
| 76 | u32 dest) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 77 | { |
Parthasarathy Bhuvaragan | 57d5f64 | 2017-01-13 15:46:25 +0100 | [diff] [blame] | 78 | struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC); |
Jon Maloy | 23fd3ea | 2018-03-22 20:42:49 +0100 | [diff] [blame] | 79 | u32 self = tipc_own_addr(net); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 80 | struct tipc_msg *msg; |
| 81 | |
| 82 | if (buf != NULL) { |
| 83 | msg = buf_msg(buf); |
Jon Maloy | 23fd3ea | 2018-03-22 20:42:49 +0100 | [diff] [blame] | 84 | tipc_msg_init(self, msg, NAME_DISTRIBUTOR, |
| 85 | type, INT_H_SIZE, dest); |
Allan Stephens | 741d9eb | 2011-05-31 15:03:18 -0400 | [diff] [blame] | 86 | msg_set_size(msg, INT_H_SIZE + size); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 87 | } |
| 88 | return buf; |
| 89 | } |
| 90 | |
| 91 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 92 | * tipc_named_publish - tell other nodes about a new publication by this node |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 93 | * @net: the associated network namespace |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 94 | * @p: the new publication |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 95 | */ |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 96 | struct sk_buff *tipc_named_publish(struct net *net, struct publication *p) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 97 | { |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 98 | struct name_table *nt = tipc_name_table(net); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 99 | struct distr_item *item; |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 100 | struct sk_buff *skb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 101 | |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 102 | if (p->scope == TIPC_NODE_SCOPE) { |
| 103 | list_add_tail_rcu(&p->binding_node, &nt->node_scope); |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 104 | return NULL; |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 105 | } |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 106 | write_lock_bh(&nt->cluster_scope_lock); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 107 | list_add_tail(&p->binding_node, &nt->cluster_scope); |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 108 | write_unlock_bh(&nt->cluster_scope_lock); |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 109 | skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0); |
| 110 | if (!skb) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 111 | pr_warn("Publication distribution failure\n"); |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 112 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 113 | } |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 114 | msg_set_named_seqno(buf_msg(skb), nt->snd_nxt++); |
| 115 | msg_set_non_legacy(buf_msg(skb)); |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 116 | item = (struct distr_item *)msg_data(buf_msg(skb)); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 117 | publ_to_item(item, p); |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 118 | return skb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 122 | * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 123 | * @net: the associated network namespace |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 124 | * @p: the withdrawn publication |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 125 | */ |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 126 | struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *p) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 127 | { |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 128 | struct name_table *nt = tipc_name_table(net); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 129 | struct distr_item *item; |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 130 | struct sk_buff *skb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 131 | |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 132 | write_lock_bh(&nt->cluster_scope_lock); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 133 | list_del(&p->binding_node); |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 134 | write_unlock_bh(&nt->cluster_scope_lock); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 135 | if (p->scope == TIPC_NODE_SCOPE) |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 136 | return NULL; |
Allan Stephens | 1110b8d | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 137 | |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 138 | skb = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0); |
| 139 | if (!skb) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 140 | pr_warn("Withdrawal distribution failure\n"); |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 141 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 142 | } |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 143 | 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 Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 146 | publ_to_item(item, p); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 147 | return skb; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Jon Paul Maloy | dbdf6d2 | 2014-07-16 20:40:58 -0400 | [diff] [blame] | 150 | /** |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 151 | * named_distribute - prepare name info for bulk distribution to another node |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 152 | * @net: the associated network namespace |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 153 | * @list: list of messages (buffers) to be returned from this function |
Jon Paul Maloy | dbdf6d2 | 2014-07-16 20:40:58 -0400 | [diff] [blame] | 154 | * @dnode: node to be updated |
| 155 | * @pls: linked list of publication items to be packed into buffer chain |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 156 | * @seqno: sequence number for this message |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 157 | */ |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 158 | static void named_distribute(struct net *net, struct sk_buff_head *list, |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 159 | u32 dnode, struct list_head *pls, u16 seqno) |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 160 | { |
| 161 | struct publication *publ; |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 162 | struct sk_buff *skb = NULL; |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 163 | struct distr_item *item = NULL; |
Hoang Le | f73b128 | 2019-10-29 07:51:21 +0700 | [diff] [blame] | 164 | u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0, false) - INT_H_SIZE) / |
Parthasarathy Bhuvaragan | d2f394d | 2016-09-01 16:22:16 +0200 | [diff] [blame] | 165 | ITEM_SIZE) * ITEM_SIZE; |
| 166 | u32 msg_rem = msg_dsz; |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 167 | struct tipc_msg *hdr; |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 168 | |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 169 | list_for_each_entry(publ, pls, binding_node) { |
Jon Paul Maloy | dbdf6d2 | 2014-07-16 20:40:58 -0400 | [diff] [blame] | 170 | /* Prepare next buffer: */ |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 171 | if (!skb) { |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 172 | skb = named_prepare_buf(net, PUBLICATION, msg_rem, |
| 173 | dnode); |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 174 | if (!skb) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 175 | pr_warn("Bulk publication failure\n"); |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 176 | return; |
| 177 | } |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 178 | 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 Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 183 | } |
Jon Paul Maloy | dbdf6d2 | 2014-07-16 20:40:58 -0400 | [diff] [blame] | 184 | |
| 185 | /* Pack publication into message: */ |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 186 | publ_to_item(item, publ); |
| 187 | item++; |
Jon Paul Maloy | dbdf6d2 | 2014-07-16 20:40:58 -0400 | [diff] [blame] | 188 | msg_rem -= ITEM_SIZE; |
| 189 | |
| 190 | /* Append full buffer to list: */ |
| 191 | if (!msg_rem) { |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 192 | __skb_queue_tail(list, skb); |
| 193 | skb = NULL; |
Ying Xue | 1b61e70 | 2014-12-02 15:00:23 +0800 | [diff] [blame] | 194 | msg_rem = msg_dsz; |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 195 | } |
| 196 | } |
Ying Xue | 1b61e70 | 2014-12-02 15:00:23 +0800 | [diff] [blame] | 197 | if (skb) { |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 198 | hdr = buf_msg(skb); |
| 199 | msg_set_size(hdr, INT_H_SIZE + (msg_dsz - msg_rem)); |
Ying Xue | 1b61e70 | 2014-12-02 15:00:23 +0800 | [diff] [blame] | 200 | skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem)); |
| 201 | __skb_queue_tail(list, skb); |
| 202 | } |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 203 | hdr = buf_msg(skb_peek_tail(list)); |
| 204 | msg_set_last_bulk(hdr); |
| 205 | msg_set_named_seqno(hdr, seqno); |
Allan Stephens | e11aa05 | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 206 | } |
| 207 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 208 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 209 | * tipc_named_node_up - tell specified node about all publications by this node |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 210 | * @net: the associated network namespace |
| 211 | * @dnode: destination node |
| 212 | * @capabilities: peer node's capabilities |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 213 | */ |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 214 | void tipc_named_node_up(struct net *net, u32 dnode, u16 capabilities) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 215 | { |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 216 | struct name_table *nt = tipc_name_table(net); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 217 | struct tipc_net *tn = tipc_net(net); |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 218 | struct sk_buff_head head; |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 219 | u16 seqno; |
Ying Xue | a6ca109 | 2014-11-26 11:41:55 +0800 | [diff] [blame] | 220 | |
Jon Maloy | e654f9f | 2019-08-15 16:42:50 +0200 | [diff] [blame] | 221 | __skb_queue_head_init(&head); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 222 | 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 Stephens | 9aa88c2 | 2011-05-31 13:38:02 -0400 | [diff] [blame] | 227 | |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 228 | read_lock_bh(&nt->cluster_scope_lock); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 229 | named_distribute(net, &head, dnode, &nt->cluster_scope, seqno); |
Jon Paul Maloy | c49a0a84 | 2015-10-22 08:51:47 -0400 | [diff] [blame] | 230 | tipc_node_xmit(net, &head, dnode, 0); |
Jon Maloy | 988f3f1 | 2018-10-19 19:55:40 +0200 | [diff] [blame] | 231 | read_unlock_bh(&nt->cluster_scope_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
Ying Xue | a8f48af | 2014-11-26 11:41:45 +0800 | [diff] [blame] | 235 | * tipc_publ_purge - remove publication associated with a failed node |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 236 | * @net: the associated network namespace |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 237 | * @p: the publication to remove |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 238 | * @addr: failed node's address |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 239 | * |
| 240 | * Invoked for each publication issued by a newly failed node. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 241 | * Removes publication structure from name table & deletes it. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 242 | */ |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 243 | static void tipc_publ_purge(struct net *net, struct publication *p, u32 addr) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 244 | { |
Jon Maloy | 37922ea | 2018-03-29 23:20:43 +0200 | [diff] [blame] | 245 | struct tipc_net *tn = tipc_net(net); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 246 | struct publication *_p; |
Jon Maloy | 2c98da0 | 2021-03-16 22:06:13 -0400 | [diff] [blame] | 247 | struct tipc_uaddr ua; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 248 | |
Jon Maloy | 2c98da0 | 2021-03-16 22:06:13 -0400 | [diff] [blame] | 249 | tipc_uaddr(&ua, TIPC_SERVICE_RANGE, p->scope, p->sr.type, |
| 250 | p->sr.lower, p->sr.upper); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 251 | spin_lock_bh(&tn->nametbl_lock); |
Jon Maloy | 2c98da0 | 2021-03-16 22:06:13 -0400 | [diff] [blame] | 252 | _p = tipc_nametbl_remove_publ(net, &ua, &p->sk, p->key); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 253 | if (_p) |
| 254 | tipc_node_unsubscribe(net, &_p->binding_node, addr); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 255 | spin_unlock_bh(&tn->nametbl_lock); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 256 | if (_p) |
| 257 | kfree_rcu(_p, rcu); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 258 | } |
| 259 | |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 260 | void tipc_publ_notify(struct net *net, struct list_head *nsub_list, |
| 261 | u32 addr, u16 capabilities) |
Ying Xue | a8f48af | 2014-11-26 11:41:45 +0800 | [diff] [blame] | 262 | { |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 263 | struct name_table *nt = tipc_name_table(net); |
| 264 | struct tipc_net *tn = tipc_net(net); |
| 265 | |
Ying Xue | a8f48af | 2014-11-26 11:41:45 +0800 | [diff] [blame] | 266 | struct publication *publ, *tmp; |
| 267 | |
Jon Maloy | 935439c | 2018-03-15 16:48:54 +0100 | [diff] [blame] | 268 | list_for_each_entry_safe(publ, tmp, nsub_list, binding_node) |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 269 | tipc_publ_purge(net, publ, addr); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 270 | spin_lock_bh(&tn->nametbl_lock); |
| 271 | if (!(capabilities & TIPC_NAMED_BCAST)) |
| 272 | nt->rc_dests--; |
| 273 | spin_unlock_bh(&tn->nametbl_lock); |
Ying Xue | a8f48af | 2014-11-26 11:41:45 +0800 | [diff] [blame] | 274 | } |
| 275 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 276 | /** |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 277 | * tipc_update_nametbl - try to process a nametable update and notify |
| 278 | * subscribers |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 279 | * @net: the associated network namespace |
| 280 | * @i: location of item in the message |
| 281 | * @node: node address |
| 282 | * @dtype: name distributor message type |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 283 | * |
| 284 | * tipc_nametbl_lock must be held. |
Randy Dunlap | 637b77f | 2020-11-29 10:32:48 -0800 | [diff] [blame] | 285 | * Return: the publication item if successful, otherwise NULL. |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 286 | */ |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 287 | static bool tipc_update_nametbl(struct net *net, struct distr_item *i, |
| 288 | u32 node, u32 dtype) |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 289 | { |
Jon Maloy | 37922ea | 2018-03-29 23:20:43 +0200 | [diff] [blame] | 290 | struct publication *p = NULL; |
Jon Maloy | a45ffa6 | 2021-03-16 22:06:12 -0400 | [diff] [blame] | 291 | struct tipc_socket_addr sk; |
| 292 | struct tipc_uaddr ua; |
Jon Maloy | 37922ea | 2018-03-29 23:20:43 +0200 | [diff] [blame] | 293 | u32 key = ntohl(i->key); |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 294 | |
Jon Maloy | a45ffa6 | 2021-03-16 22:06:12 -0400 | [diff] [blame] | 295 | 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 Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 300 | if (dtype == PUBLICATION) { |
Jon Maloy | a45ffa6 | 2021-03-16 22:06:12 -0400 | [diff] [blame] | 301 | p = tipc_nametbl_insert_publ(net, &ua, &sk, key); |
Jon Maloy | 37922ea | 2018-03-29 23:20:43 +0200 | [diff] [blame] | 302 | if (p) { |
| 303 | tipc_node_subscribe(net, &p->binding_node, node); |
Erik Hugne | 0fc4dff | 2014-09-10 14:02:50 +0200 | [diff] [blame] | 304 | return true; |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 305 | } |
| 306 | } else if (dtype == WITHDRAWAL) { |
Jon Maloy | 2c98da0 | 2021-03-16 22:06:13 -0400 | [diff] [blame] | 307 | p = tipc_nametbl_remove_publ(net, &ua, &sk, key); |
Jon Maloy | 37922ea | 2018-03-29 23:20:43 +0200 | [diff] [blame] | 308 | if (p) { |
| 309 | tipc_node_unsubscribe(net, &p->binding_node, node); |
| 310 | kfree_rcu(p, rcu); |
Erik Hugne | 0fc4dff | 2014-09-10 14:02:50 +0200 | [diff] [blame] | 311 | return true; |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 312 | } |
Jon Maloy | a45ffa6 | 2021-03-16 22:06:12 -0400 | [diff] [blame] | 313 | pr_warn_ratelimited("Failed to remove binding %u,%u from %u\n", |
| 314 | ua.sr.type, ua.sr.lower, node); |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 315 | } else { |
| 316 | pr_warn("Unrecognized name table message received\n"); |
| 317 | } |
Erik Hugne | 0fc4dff | 2014-09-10 14:02:50 +0200 | [diff] [blame] | 318 | return false; |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 319 | } |
| 320 | |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 321 | static 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 Le | 7b50ee3 | 2020-10-08 14:31:56 +0700 | [diff] [blame] | 328 | spin_lock_bh(&namedq->lock); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 329 | skb_queue_walk_safe(namedq, skb, tmp) { |
Hoang Huu Le | 7b50ee3 | 2020-10-08 14:31:56 +0700 | [diff] [blame] | 330 | if (unlikely(skb_linearize(skb))) { |
| 331 | __skb_unlink(skb, namedq); |
| 332 | kfree_skb(skb); |
| 333 | continue; |
| 334 | } |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 335 | 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 Le | 7b50ee3 | 2020-10-08 14:31:56 +0700 | [diff] [blame] | 344 | spin_unlock_bh(&namedq->lock); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 345 | return skb; |
| 346 | } |
| 347 | |
| 348 | if (*open && (*rcv_nxt == seqno)) { |
| 349 | (*rcv_nxt)++; |
| 350 | __skb_unlink(skb, namedq); |
Hoang Huu Le | 7b50ee3 | 2020-10-08 14:31:56 +0700 | [diff] [blame] | 351 | spin_unlock_bh(&namedq->lock); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 352 | 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 Le | 7b50ee3 | 2020-10-08 14:31:56 +0700 | [diff] [blame] | 361 | spin_unlock_bh(&namedq->lock); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 362 | return NULL; |
| 363 | } |
| 364 | |
Erik Hugne | f4ad8a4 | 2014-08-28 09:08:46 +0200 | [diff] [blame] | 365 | /** |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 366 | * tipc_named_rcv - process name table update messages sent by another node |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 367 | * @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 Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 371 | */ |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 372 | void tipc_named_rcv(struct net *net, struct sk_buff_head *namedq, |
| 373 | u16 *rcv_nxt, bool *open) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 374 | { |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 375 | struct tipc_net *tn = tipc_net(net); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 376 | struct distr_item *item; |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 377 | struct tipc_msg *hdr; |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 378 | struct sk_buff *skb; |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 379 | u32 count, node; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 380 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 381 | spin_lock_bh(&tn->nametbl_lock); |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 382 | 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 Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 387 | while (count--) { |
Hoang Huu Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 388 | tipc_update_nametbl(net, item, node, msg_type(hdr)); |
Jon Paul Maloy | c637c10 | 2015-02-05 08:36:41 -0500 | [diff] [blame] | 389 | item++; |
| 390 | } |
| 391 | kfree_skb(skb); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 392 | } |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 393 | spin_unlock_bh(&tn->nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /** |
Allan Stephens | 1110b8d | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 397 | * tipc_named_reinit - re-initialize local publications |
Randy Dunlap | cb67296 | 2020-11-29 10:32:45 -0800 | [diff] [blame] | 398 | * @net: the associated network namespace |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 399 | * |
Allan Stephens | 945af1c | 2011-10-14 14:42:25 -0400 | [diff] [blame] | 400 | * This routine is called whenever TIPC networking is enabled. |
Allan Stephens | 1110b8d | 2012-04-17 17:57:52 -0400 | [diff] [blame] | 401 | * All name table entries published by this node are updated to reflect |
| 402 | * the node's new network address. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 403 | */ |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 404 | void tipc_named_reinit(struct net *net) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 405 | { |
Jon Maloy | 64a52b26d5 | 2018-03-15 16:48:52 +0100 | [diff] [blame] | 406 | struct name_table *nt = tipc_name_table(net); |
| 407 | struct tipc_net *tn = tipc_net(net); |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 408 | struct publication *p; |
Jon Maloy | 23fd3ea | 2018-03-22 20:42:49 +0100 | [diff] [blame] | 409 | u32 self = tipc_own_addr(net); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 410 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 411 | spin_lock_bh(&tn->nametbl_lock); |
Allan Stephens | 945af1c | 2011-10-14 14:42:25 -0400 | [diff] [blame] | 412 | |
Jon Maloy | 998d390 | 2021-03-16 22:06:08 -0400 | [diff] [blame] | 413 | 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 Le | cad2929 | 2020-06-17 13:56:05 +0700 | [diff] [blame] | 417 | nt->rc_dests = 0; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 418 | spin_unlock_bh(&tn->nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 419 | } |