Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1 | /* |
| 2 | * net/tipc/name_table.c: TIPC name table code |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 3 | * |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 4 | * Copyright (c) 2000-2006, 2014-2015, Ericsson AB |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 5 | * Copyright (c) 2004-2008, 2010-2014, Wind River Systems |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 6 | * All rights reserved. |
| 7 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 8 | * Redistribution and use in source and binary forms, with or without |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 9 | * modification, are permitted provided that the following conditions are met: |
| 10 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the names of the copyright holders nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 19 | * |
Per Liden | 9ea1fd3 | 2006-01-11 13:30:43 +0100 | [diff] [blame] | 20 | * Alternatively, this software may be distributed under the terms of the |
| 21 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 22 | * Software Foundation. |
| 23 | * |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 33 | * 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] | 34 | * POSSIBILITY OF SUCH DAMAGE. |
| 35 | */ |
| 36 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 37 | #include <net/sock.h> |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 38 | #include "core.h" |
Richard Alpe | 22ae7cf | 2015-02-09 09:50:18 +0100 | [diff] [blame] | 39 | #include "netlink.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 40 | #include "name_table.h" |
| 41 | #include "name_distr.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 42 | #include "subscr.h" |
Ying Xue | 1da4656 | 2015-01-09 15:27:07 +0800 | [diff] [blame] | 43 | #include "bcast.h" |
Richard Alpe | 22ae7cf | 2015-02-09 09:50:18 +0100 | [diff] [blame] | 44 | #include "addr.h" |
Jon Paul Maloy | 1d7e1c2 | 2015-11-19 14:30:42 -0500 | [diff] [blame] | 45 | #include "node.h" |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 46 | #include "group.h" |
Richard Alpe | 22ae7cf | 2015-02-09 09:50:18 +0100 | [diff] [blame] | 47 | #include <net/genetlink.h> |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 48 | |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 49 | #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 50 | |
| 51 | /** |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 52 | * struct name_info - name sequence publication info |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 53 | * @node_list: circular list of publications made by own node |
| 54 | * @cluster_list: circular list of publications made by own cluster |
| 55 | * @zone_list: circular list of publications made by own zone |
| 56 | * @node_list_size: number of entries in "node_list" |
| 57 | * @cluster_list_size: number of entries in "cluster_list" |
| 58 | * @zone_list_size: number of entries in "zone_list" |
| 59 | * |
| 60 | * Note: The zone list always contains at least one entry, since all |
| 61 | * publications of the associated name sequence belong to it. |
| 62 | * (The cluster and node lists may be empty.) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 63 | */ |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 64 | struct name_info { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 65 | struct list_head node_list; |
| 66 | struct list_head cluster_list; |
| 67 | struct list_head zone_list; |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 68 | u32 node_list_size; |
| 69 | u32 cluster_list_size; |
| 70 | u32 zone_list_size; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 73 | /** |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 74 | * struct sub_seq - container for all published instances of a name sequence |
| 75 | * @lower: name sequence lower bound |
| 76 | * @upper: name sequence upper bound |
| 77 | * @info: pointer to name sequence publication info |
| 78 | */ |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 79 | struct sub_seq { |
| 80 | u32 lower; |
| 81 | u32 upper; |
| 82 | struct name_info *info; |
| 83 | }; |
| 84 | |
| 85 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 86 | * struct name_seq - container for all published instances of a name type |
| 87 | * @type: 32 bit 'type' value for name sequence |
| 88 | * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type'; |
| 89 | * sub-sequences are sorted in ascending order |
| 90 | * @alloc: number of sub-sequences currently in array |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 91 | * @first_free: array index of first unused sub-sequence entry |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 92 | * @ns_list: links to adjacent name sequences in hash chain |
| 93 | * @subscriptions: list of subscriptions for this 'type' |
Allan Stephens | 307fdf5 | 2008-06-04 17:38:22 -0700 | [diff] [blame] | 94 | * @lock: spinlock controlling access to publication lists of all sub-sequences |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 95 | * @rcu: RCU callback head used for deferred freeing |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 96 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 97 | struct name_seq { |
| 98 | u32 type; |
| 99 | struct sub_seq *sseqs; |
| 100 | u32 alloc; |
| 101 | u32 first_free; |
| 102 | struct hlist_node ns_list; |
| 103 | struct list_head subscriptions; |
| 104 | spinlock_t lock; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 105 | struct rcu_head rcu; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 106 | }; |
| 107 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 108 | static int hash(int x) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 109 | { |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 110 | return x & (TIPC_NAMETBL_SIZE - 1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | /** |
| 114 | * publ_create - create a publication structure |
| 115 | */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 116 | static struct publication *publ_create(u32 type, u32 lower, u32 upper, |
| 117 | u32 scope, u32 node, u32 port_ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 118 | u32 key) |
| 119 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 120 | struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 121 | if (publ == NULL) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 122 | pr_warn("Publication creation failure, no memory\n"); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 123 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 124 | } |
| 125 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 126 | publ->type = type; |
| 127 | publ->lower = lower; |
| 128 | publ->upper = upper; |
| 129 | publ->scope = scope; |
| 130 | publ->node = node; |
| 131 | publ->ref = port_ref; |
| 132 | publ->key = key; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 133 | INIT_LIST_HEAD(&publ->pport_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 134 | return publ; |
| 135 | } |
| 136 | |
| 137 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 138 | * tipc_subseq_alloc - allocate a specified number of sub-sequence structures |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 139 | */ |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 140 | static struct sub_seq *tipc_subseq_alloc(u32 cnt) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 141 | { |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame] | 142 | return kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 146 | * tipc_nameseq_create - create a name sequence structure for the specified 'type' |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 147 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 148 | * Allocates a single sub-sequence structure and sets it to all 0's. |
| 149 | */ |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 150 | static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 151 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 152 | struct name_seq *nseq = kzalloc(sizeof(*nseq), GFP_ATOMIC); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 153 | struct sub_seq *sseq = tipc_subseq_alloc(1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 154 | |
| 155 | if (!nseq || !sseq) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 156 | pr_warn("Name sequence creation failed, no memory\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 157 | kfree(nseq); |
| 158 | kfree(sseq); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 159 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 162 | spin_lock_init(&nseq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 163 | nseq->type = type; |
| 164 | nseq->sseqs = sseq; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 165 | nseq->alloc = 1; |
| 166 | INIT_HLIST_NODE(&nseq->ns_list); |
| 167 | INIT_LIST_HEAD(&nseq->subscriptions); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 168 | hlist_add_head_rcu(&nseq->ns_list, seq_head); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 169 | return nseq; |
| 170 | } |
| 171 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 172 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 173 | * nameseq_find_subseq - find sub-sequence (if any) matching a name instance |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 174 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 175 | * Very time-critical, so binary searches through sub-sequence array. |
| 176 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 177 | static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq, |
| 178 | u32 instance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 179 | { |
| 180 | struct sub_seq *sseqs = nseq->sseqs; |
| 181 | int low = 0; |
| 182 | int high = nseq->first_free - 1; |
| 183 | int mid; |
| 184 | |
| 185 | while (low <= high) { |
| 186 | mid = (low + high) / 2; |
| 187 | if (instance < sseqs[mid].lower) |
| 188 | high = mid - 1; |
| 189 | else if (instance > sseqs[mid].upper) |
| 190 | low = mid + 1; |
| 191 | else |
| 192 | return &sseqs[mid]; |
| 193 | } |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 194 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
| 198 | * nameseq_locate_subseq - determine position of name instance in sub-sequence |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 199 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 200 | * Returns index in sub-sequence array of the entry that contains the specified |
| 201 | * instance value; if no entry contains that value, returns the position |
| 202 | * where a new entry for it would be inserted in the array. |
| 203 | * |
| 204 | * Note: Similar to binary search code for locating a sub-sequence. |
| 205 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 206 | static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance) |
| 207 | { |
| 208 | struct sub_seq *sseqs = nseq->sseqs; |
| 209 | int low = 0; |
| 210 | int high = nseq->first_free - 1; |
| 211 | int mid; |
| 212 | |
| 213 | while (low <= high) { |
| 214 | mid = (low + high) / 2; |
| 215 | if (instance < sseqs[mid].lower) |
| 216 | high = mid - 1; |
| 217 | else if (instance > sseqs[mid].upper) |
| 218 | low = mid + 1; |
| 219 | else |
| 220 | return mid; |
| 221 | } |
| 222 | return low; |
| 223 | } |
| 224 | |
| 225 | /** |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 226 | * tipc_nameseq_insert_publ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 227 | */ |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 228 | static struct publication *tipc_nameseq_insert_publ(struct net *net, |
| 229 | struct name_seq *nseq, |
| 230 | u32 type, u32 lower, |
| 231 | u32 upper, u32 scope, |
| 232 | u32 node, u32 port, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 233 | { |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 234 | struct tipc_subscription *s; |
| 235 | struct tipc_subscription *st; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 236 | struct publication *publ; |
| 237 | struct sub_seq *sseq; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 238 | struct name_info *info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 239 | int created_subseq = 0; |
| 240 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 241 | sseq = nameseq_find_subseq(nseq, lower); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 242 | if (sseq) { |
| 243 | |
| 244 | /* Lower end overlaps existing entry => need an exact match */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 245 | if ((sseq->lower != lower) || (sseq->upper != upper)) { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 246 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 247 | } |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 248 | |
| 249 | info = sseq->info; |
Allan Stephens | f80c24d | 2011-11-03 11:12:01 -0400 | [diff] [blame] | 250 | |
| 251 | /* Check if an identical publication already exists */ |
| 252 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
| 253 | if ((publ->ref == port) && (publ->key == key) && |
| 254 | (!publ->node || (publ->node == node))) |
| 255 | return NULL; |
| 256 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 257 | } else { |
| 258 | u32 inspos; |
| 259 | struct sub_seq *freesseq; |
| 260 | |
| 261 | /* Find where lower end should be inserted */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 262 | inspos = nameseq_locate_subseq(nseq, lower); |
| 263 | |
| 264 | /* Fail if upper end overlaps into an existing entry */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 265 | if ((inspos < nseq->first_free) && |
| 266 | (upper >= nseq->sseqs[inspos].lower)) { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 267 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /* Ensure there is space for new sub-sequence */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 271 | if (nseq->first_free == nseq->alloc) { |
Allan Stephens | 9ab230f | 2006-06-25 23:37:24 -0700 | [diff] [blame] | 272 | struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2); |
| 273 | |
| 274 | if (!sseqs) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 275 | pr_warn("Cannot publish {%u,%u,%u}, no memory\n", |
| 276 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 277 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 278 | } |
Allan Stephens | 9ab230f | 2006-06-25 23:37:24 -0700 | [diff] [blame] | 279 | memcpy(sseqs, nseq->sseqs, |
| 280 | nseq->alloc * sizeof(struct sub_seq)); |
| 281 | kfree(nseq->sseqs); |
| 282 | nseq->sseqs = sseqs; |
| 283 | nseq->alloc *= 2; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 284 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 285 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 286 | info = kzalloc(sizeof(*info), GFP_ATOMIC); |
| 287 | if (!info) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 288 | pr_warn("Cannot publish {%u,%u,%u}, no memory\n", |
| 289 | type, lower, upper); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 290 | return NULL; |
| 291 | } |
| 292 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 293 | INIT_LIST_HEAD(&info->node_list); |
| 294 | INIT_LIST_HEAD(&info->cluster_list); |
| 295 | INIT_LIST_HEAD(&info->zone_list); |
| 296 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 297 | /* Insert new sub-sequence */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | sseq = &nseq->sseqs[inspos]; |
| 299 | freesseq = &nseq->sseqs[nseq->first_free]; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 300 | memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof(*sseq)); |
| 301 | memset(sseq, 0, sizeof(*sseq)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 302 | nseq->first_free++; |
| 303 | sseq->lower = lower; |
| 304 | sseq->upper = upper; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 305 | sseq->info = info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 306 | created_subseq = 1; |
| 307 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 308 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 309 | /* Insert a publication */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 310 | publ = publ_create(type, lower, upper, scope, node, port, key); |
| 311 | if (!publ) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 312 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 313 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 314 | list_add(&publ->zone_list, &info->zone_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 315 | info->zone_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 316 | |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 317 | if (in_own_cluster(net, node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 318 | list_add(&publ->cluster_list, &info->cluster_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 319 | info->cluster_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 320 | } |
| 321 | |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 322 | if (in_own_node(net, node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 323 | list_add(&publ->node_list, &info->node_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 324 | info->node_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 325 | } |
| 326 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 327 | /* Any subscriptions waiting for notification? */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 328 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
Ying Xue | 57f1d18 | 2015-05-04 10:36:44 +0800 | [diff] [blame] | 329 | tipc_subscrp_report_overlap(s, publ->lower, publ->upper, |
| 330 | TIPC_PUBLISHED, publ->ref, |
| 331 | publ->node, created_subseq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 332 | } |
| 333 | return publ; |
| 334 | } |
| 335 | |
| 336 | /** |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 337 | * tipc_nameseq_remove_publ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 338 | * |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 339 | * NOTE: There may be cases where TIPC is asked to remove a publication |
| 340 | * that is not in the name table. For example, if another node issues a |
| 341 | * publication for a name sequence that overlaps an existing name sequence |
| 342 | * the publication will not be recorded, which means the publication won't |
| 343 | * be found when the name sequence is later withdrawn by that node. |
| 344 | * A failed withdraw request simply returns a failure indication and lets the |
| 345 | * caller issue any error or warning messages associated with such a problem. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 346 | */ |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 347 | static struct publication *tipc_nameseq_remove_publ(struct net *net, |
| 348 | struct name_seq *nseq, |
| 349 | u32 inst, u32 node, |
| 350 | u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | { |
| 352 | struct publication *publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 353 | struct sub_seq *sseq = nameseq_find_subseq(nseq, inst); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 354 | struct name_info *info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 355 | struct sub_seq *free; |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 356 | struct tipc_subscription *s, *st; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 357 | int removed_subseq = 0; |
| 358 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 359 | if (!sseq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 360 | return NULL; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 361 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 362 | info = sseq->info; |
| 363 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 364 | /* Locate publication, if it exists */ |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 365 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
| 366 | if ((publ->key == key) && (publ->ref == ref) && |
| 367 | (!publ->node || (publ->node == node))) |
| 368 | goto found; |
| 369 | } |
| 370 | return NULL; |
| 371 | |
| 372 | found: |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 373 | /* Remove publication from zone scope list */ |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 374 | list_del(&publ->zone_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 375 | info->zone_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 376 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 377 | /* Remove publication from cluster scope list, if present */ |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 378 | if (in_own_cluster(net, node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 379 | list_del(&publ->cluster_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 380 | info->cluster_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 381 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 382 | |
| 383 | /* Remove publication from node scope list, if present */ |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 384 | if (in_own_node(net, node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 385 | list_del(&publ->node_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 386 | info->node_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 387 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 388 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 389 | /* Contract subseq list if no more publications for that subseq */ |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 390 | if (list_empty(&info->zone_list)) { |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 391 | kfree(info); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 392 | free = &nseq->sseqs[nseq->first_free--]; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 393 | memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 394 | removed_subseq = 1; |
| 395 | } |
| 396 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 397 | /* Notify any waiting subscriptions */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 398 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
Ying Xue | 57f1d18 | 2015-05-04 10:36:44 +0800 | [diff] [blame] | 399 | tipc_subscrp_report_overlap(s, publ->lower, publ->upper, |
| 400 | TIPC_WITHDRAWN, publ->ref, |
| 401 | publ->node, removed_subseq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 402 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 403 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 404 | return publ; |
| 405 | } |
| 406 | |
| 407 | /** |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 408 | * tipc_nameseq_subscribe - attach a subscription, and issue |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 409 | * the prescribed number of events if there is any sub- |
| 410 | * sequence overlapping with the requested sequence |
| 411 | */ |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 412 | static void tipc_nameseq_subscribe(struct name_seq *nseq, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 413 | struct tipc_subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 414 | { |
| 415 | struct sub_seq *sseq = nseq->sseqs; |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 416 | struct tipc_name_seq ns; |
| 417 | |
| 418 | tipc_subscrp_convert_seq(&s->evt.s.seq, s->swap, &ns); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 419 | |
Ying Xue | 7efea60 | 2017-03-28 12:28:28 +0200 | [diff] [blame] | 420 | tipc_subscrp_get(s); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 421 | list_add(&s->nameseq_list, &nseq->subscriptions); |
| 422 | |
| 423 | if (!sseq) |
| 424 | return; |
| 425 | |
| 426 | while (sseq != &nseq->sseqs[nseq->first_free]) { |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 427 | if (tipc_subscrp_check_overlap(&ns, sseq->lower, sseq->upper)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 428 | struct publication *crs; |
| 429 | struct name_info *info = sseq->info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 430 | int must_report = 1; |
| 431 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 432 | list_for_each_entry(crs, &info->zone_list, zone_list) { |
Ying Xue | 57f1d18 | 2015-05-04 10:36:44 +0800 | [diff] [blame] | 433 | tipc_subscrp_report_overlap(s, sseq->lower, |
| 434 | sseq->upper, |
| 435 | TIPC_PUBLISHED, |
| 436 | crs->ref, crs->node, |
| 437 | must_report); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 438 | must_report = 0; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 439 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 440 | } |
| 441 | sseq++; |
| 442 | } |
| 443 | } |
| 444 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 445 | static struct name_seq *nametbl_find_seq(struct net *net, u32 type) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 446 | { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 447 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 448 | struct hlist_head *seq_head; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 449 | struct name_seq *ns; |
| 450 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 451 | seq_head = &tn->nametbl->seq_hlist[hash(type)]; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 452 | hlist_for_each_entry_rcu(ns, seq_head, ns_list) { |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 453 | if (ns->type == type) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 454 | return ns; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 455 | } |
| 456 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 457 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 458 | }; |
| 459 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 460 | struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, |
| 461 | u32 lower, u32 upper, u32 scope, |
| 462 | u32 node, u32 port, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 463 | { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 464 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 465 | struct publication *publ; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 466 | struct name_seq *seq = nametbl_find_seq(net, type); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 467 | int index = hash(type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 468 | |
Allan Stephens | 8f17789 | 2012-04-26 17:57:17 -0400 | [diff] [blame] | 469 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || |
| 470 | (lower > upper)) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 471 | pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n", |
| 472 | type, lower, upper, scope); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 473 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 474 | } |
| 475 | |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 476 | if (!seq) |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 477 | seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 478 | if (!seq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 479 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 480 | |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 481 | spin_lock_bh(&seq->lock); |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 482 | publ = tipc_nameseq_insert_publ(net, seq, type, lower, upper, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 483 | scope, node, port, key); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 484 | spin_unlock_bh(&seq->lock); |
| 485 | return publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 488 | struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, |
| 489 | u32 lower, u32 node, u32 ref, |
| 490 | u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 491 | { |
| 492 | struct publication *publ; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 493 | struct name_seq *seq = nametbl_find_seq(net, type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 494 | |
| 495 | if (!seq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 496 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 497 | |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 498 | spin_lock_bh(&seq->lock); |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 499 | publ = tipc_nameseq_remove_publ(net, seq, lower, node, ref, key); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 500 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 501 | hlist_del_init_rcu(&seq->ns_list); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 502 | kfree(seq->sseqs); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 503 | spin_unlock_bh(&seq->lock); |
| 504 | kfree_rcu(seq, rcu); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 505 | return publ; |
| 506 | } |
| 507 | spin_unlock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 508 | return publ; |
| 509 | } |
| 510 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 511 | /** |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 512 | * tipc_nametbl_translate - perform name translation |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 513 | * |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 514 | * On entry, 'destnode' is the search domain used during translation. |
| 515 | * |
| 516 | * On exit: |
| 517 | * - if name translation is deferred to another node/cluster/zone, |
| 518 | * leaves 'destnode' unchanged (will be non-zero) and returns 0 |
| 519 | * - if name translation is attempted and succeeds, sets 'destnode' |
| 520 | * to publishing node and returns port reference (will be non-zero) |
| 521 | * - if name translation is attempted and fails, sets 'destnode' to 0 |
| 522 | * and returns 0 |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 523 | */ |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 524 | u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, |
| 525 | u32 *destnode) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 526 | { |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 527 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 528 | struct sub_seq *sseq; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 529 | struct name_info *info; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 530 | struct publication *publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 531 | struct name_seq *seq; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 532 | u32 ref = 0; |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 533 | u32 node = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 534 | |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 535 | if (!tipc_in_scope(*destnode, tn->own_addr)) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 536 | return 0; |
| 537 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 538 | rcu_read_lock(); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 539 | seq = nametbl_find_seq(net, type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 540 | if (unlikely(!seq)) |
| 541 | goto not_found; |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 542 | spin_lock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 543 | sseq = nameseq_find_subseq(seq, instance); |
| 544 | if (unlikely(!sseq)) |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 545 | goto no_match; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 546 | info = sseq->info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 547 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 548 | /* Closest-First Algorithm */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 549 | if (likely(!*destnode)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 550 | if (!list_empty(&info->node_list)) { |
| 551 | publ = list_first_entry(&info->node_list, |
| 552 | struct publication, |
| 553 | node_list); |
| 554 | list_move_tail(&publ->node_list, |
| 555 | &info->node_list); |
| 556 | } else if (!list_empty(&info->cluster_list)) { |
| 557 | publ = list_first_entry(&info->cluster_list, |
| 558 | struct publication, |
| 559 | cluster_list); |
| 560 | list_move_tail(&publ->cluster_list, |
| 561 | &info->cluster_list); |
Allan Stephens | 8af4638 | 2011-05-30 11:27:50 -0400 | [diff] [blame] | 562 | } else { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 563 | publ = list_first_entry(&info->zone_list, |
| 564 | struct publication, |
| 565 | zone_list); |
| 566 | list_move_tail(&publ->zone_list, |
| 567 | &info->zone_list); |
Allan Stephens | 8af4638 | 2011-05-30 11:27:50 -0400 | [diff] [blame] | 568 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 571 | /* Round-Robin Algorithm */ |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 572 | else if (*destnode == tn->own_addr) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 573 | if (list_empty(&info->node_list)) |
| 574 | goto no_match; |
| 575 | publ = list_first_entry(&info->node_list, struct publication, |
| 576 | node_list); |
| 577 | list_move_tail(&publ->node_list, &info->node_list); |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 578 | } else if (in_own_cluster_exact(net, *destnode)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 579 | if (list_empty(&info->cluster_list)) |
| 580 | goto no_match; |
| 581 | publ = list_first_entry(&info->cluster_list, struct publication, |
| 582 | cluster_list); |
| 583 | list_move_tail(&publ->cluster_list, &info->cluster_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 584 | } else { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 585 | publ = list_first_entry(&info->zone_list, struct publication, |
| 586 | zone_list); |
| 587 | list_move_tail(&publ->zone_list, &info->zone_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 588 | } |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 589 | |
| 590 | ref = publ->ref; |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 591 | node = publ->node; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 592 | no_match: |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 593 | spin_unlock_bh(&seq->lock); |
| 594 | not_found: |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 595 | rcu_read_unlock(); |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 596 | *destnode = node; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 597 | return ref; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Jon Maloy | ee106d7 | 2017-10-13 11:04:28 +0200 | [diff] [blame] | 600 | bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain, |
| 601 | struct list_head *dsts, int *dstcnt, u32 exclude, |
| 602 | bool all) |
| 603 | { |
| 604 | u32 self = tipc_own_addr(net); |
| 605 | struct publication *publ; |
| 606 | struct name_info *info; |
| 607 | struct name_seq *seq; |
| 608 | struct sub_seq *sseq; |
| 609 | |
| 610 | if (!tipc_in_scope(domain, self)) |
| 611 | return false; |
| 612 | |
| 613 | *dstcnt = 0; |
| 614 | rcu_read_lock(); |
| 615 | seq = nametbl_find_seq(net, type); |
| 616 | if (unlikely(!seq)) |
| 617 | goto exit; |
| 618 | spin_lock_bh(&seq->lock); |
| 619 | sseq = nameseq_find_subseq(seq, instance); |
| 620 | if (likely(sseq)) { |
| 621 | info = sseq->info; |
| 622 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
| 623 | if (!tipc_in_scope(domain, publ->node)) |
| 624 | continue; |
| 625 | if (publ->ref == exclude && publ->node == self) |
| 626 | continue; |
| 627 | tipc_dest_push(dsts, publ->node, publ->ref); |
| 628 | (*dstcnt)++; |
| 629 | if (all) |
| 630 | continue; |
| 631 | list_move_tail(&publ->zone_list, &info->zone_list); |
| 632 | break; |
| 633 | } |
| 634 | } |
| 635 | spin_unlock_bh(&seq->lock); |
| 636 | exit: |
| 637 | rcu_read_unlock(); |
| 638 | return !list_empty(dsts); |
| 639 | } |
| 640 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 641 | int tipc_nametbl_mc_translate(struct net *net, u32 type, u32 lower, u32 upper, |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 642 | u32 limit, struct list_head *dports) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 643 | { |
| 644 | struct name_seq *seq; |
| 645 | struct sub_seq *sseq; |
| 646 | struct sub_seq *sseq_stop; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 647 | struct name_info *info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 648 | int res = 0; |
| 649 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 650 | rcu_read_lock(); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 651 | seq = nametbl_find_seq(net, type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 652 | if (!seq) |
| 653 | goto exit; |
| 654 | |
| 655 | spin_lock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 656 | sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); |
| 657 | sseq_stop = seq->sseqs + seq->first_free; |
| 658 | for (; sseq != sseq_stop; sseq++) { |
| 659 | struct publication *publ; |
| 660 | |
| 661 | if (sseq->lower > upper) |
| 662 | break; |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 663 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 664 | info = sseq->info; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 665 | list_for_each_entry(publ, &info->node_list, node_list) { |
| 666 | if (publ->scope <= limit) |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 667 | tipc_dest_push(dports, 0, publ->ref); |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 670 | if (info->cluster_list_size != info->node_list_size) |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 671 | res = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 672 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 673 | spin_unlock_bh(&seq->lock); |
| 674 | exit: |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 675 | rcu_read_unlock(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 676 | return res; |
| 677 | } |
| 678 | |
Jon Paul Maloy | 2ae0b8a | 2017-01-18 13:50:51 -0500 | [diff] [blame] | 679 | /* tipc_nametbl_lookup_dst_nodes - find broadcast destination nodes |
| 680 | * - Creates list of nodes that overlap the given multicast address |
| 681 | * - Determines if any node local ports overlap |
| 682 | */ |
| 683 | void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower, |
| 684 | u32 upper, u32 domain, |
| 685 | struct tipc_nlist *nodes) |
| 686 | { |
| 687 | struct sub_seq *sseq, *stop; |
| 688 | struct publication *publ; |
| 689 | struct name_info *info; |
| 690 | struct name_seq *seq; |
| 691 | |
| 692 | rcu_read_lock(); |
| 693 | seq = nametbl_find_seq(net, type); |
| 694 | if (!seq) |
| 695 | goto exit; |
| 696 | |
| 697 | spin_lock_bh(&seq->lock); |
| 698 | sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); |
| 699 | stop = seq->sseqs + seq->first_free; |
Jon Maloy | f65163f | 2017-10-25 16:19:52 +0200 | [diff] [blame] | 700 | for (; sseq != stop && sseq->lower <= upper; sseq++) { |
Jon Paul Maloy | 2ae0b8a | 2017-01-18 13:50:51 -0500 | [diff] [blame] | 701 | info = sseq->info; |
| 702 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
| 703 | if (tipc_in_scope(domain, publ->node)) |
| 704 | tipc_nlist_add(nodes, publ->node); |
| 705 | } |
| 706 | } |
| 707 | spin_unlock_bh(&seq->lock); |
| 708 | exit: |
| 709 | rcu_read_unlock(); |
| 710 | } |
| 711 | |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 712 | /* tipc_nametbl_build_group - build list of communication group members |
| 713 | */ |
| 714 | void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp, |
| 715 | u32 type, u32 domain) |
| 716 | { |
| 717 | struct sub_seq *sseq, *stop; |
| 718 | struct name_info *info; |
| 719 | struct publication *p; |
| 720 | struct name_seq *seq; |
| 721 | |
| 722 | rcu_read_lock(); |
| 723 | seq = nametbl_find_seq(net, type); |
| 724 | if (!seq) |
| 725 | goto exit; |
| 726 | |
| 727 | spin_lock_bh(&seq->lock); |
| 728 | sseq = seq->sseqs; |
| 729 | stop = seq->sseqs + seq->first_free; |
| 730 | for (; sseq != stop; sseq++) { |
| 731 | info = sseq->info; |
| 732 | list_for_each_entry(p, &info->zone_list, zone_list) { |
| 733 | if (!tipc_in_scope(domain, p->node)) |
| 734 | continue; |
Jon Maloy | d12d2e1 | 2018-01-08 21:03:28 +0100 | [diff] [blame^] | 735 | tipc_group_add_member(grp, p->node, p->ref, p->lower); |
Jon Maloy | 75da216 | 2017-10-13 11:04:23 +0200 | [diff] [blame] | 736 | } |
| 737 | } |
| 738 | spin_unlock_bh(&seq->lock); |
| 739 | exit: |
| 740 | rcu_read_unlock(); |
| 741 | } |
| 742 | |
Allan Stephens | c422f1b | 2011-11-02 15:49:40 -0400 | [diff] [blame] | 743 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 744 | * tipc_nametbl_publish - add name publication to network name tables |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 745 | */ |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 746 | struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, |
| 747 | u32 upper, u32 scope, u32 port_ref, |
| 748 | u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 749 | { |
| 750 | struct publication *publ; |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 751 | struct sk_buff *buf = NULL; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 752 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 753 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 754 | spin_lock_bh(&tn->nametbl_lock); |
| 755 | if (tn->nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 756 | pr_warn("Publication failed, local publication limit reached (%u)\n", |
Ying Xue | e6a04b1 | 2012-08-16 12:09:14 +0000 | [diff] [blame] | 757 | TIPC_MAX_PUBLICATIONS); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 758 | spin_unlock_bh(&tn->nametbl_lock); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 759 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 760 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 761 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 762 | publ = tipc_nametbl_insert_publ(net, type, lower, upper, scope, |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 763 | tn->own_addr, port_ref, key); |
Allan Stephens | fd6eced | 2011-11-09 14:22:52 -0500 | [diff] [blame] | 764 | if (likely(publ)) { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 765 | tn->nametbl->local_publ_count++; |
| 766 | buf = tipc_named_publish(net, publ); |
Erik Hugne | a5325ae | 2014-08-28 09:08:47 +0200 | [diff] [blame] | 767 | /* Any pending external events? */ |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 768 | tipc_named_process_backlog(net); |
Allan Stephens | fd6eced | 2011-11-09 14:22:52 -0500 | [diff] [blame] | 769 | } |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 770 | spin_unlock_bh(&tn->nametbl_lock); |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 771 | |
| 772 | if (buf) |
Jon Paul Maloy | 1d7e1c2 | 2015-11-19 14:30:42 -0500 | [diff] [blame] | 773 | tipc_node_broadcast(net, buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 774 | return publ; |
| 775 | } |
| 776 | |
| 777 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 778 | * tipc_nametbl_withdraw - withdraw name publication from network name tables |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 779 | */ |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 780 | int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref, |
| 781 | u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 782 | { |
| 783 | struct publication *publ; |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 784 | struct sk_buff *skb = NULL; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 785 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 786 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 787 | spin_lock_bh(&tn->nametbl_lock); |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 788 | publ = tipc_nametbl_remove_publ(net, type, lower, tn->own_addr, |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 789 | ref, key); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 790 | if (likely(publ)) { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 791 | tn->nametbl->local_publ_count--; |
Ying Xue | 3474753 | 2015-01-09 15:27:10 +0800 | [diff] [blame] | 792 | skb = tipc_named_withdraw(net, publ); |
Erik Hugne | a5325ae | 2014-08-28 09:08:47 +0200 | [diff] [blame] | 793 | /* Any pending external events? */ |
Ying Xue | f2f9800 | 2015-01-09 15:27:05 +0800 | [diff] [blame] | 794 | tipc_named_process_backlog(net); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 795 | list_del_init(&publ->pport_list); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 796 | kfree_rcu(publ, rcu); |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 797 | } else { |
| 798 | pr_err("Unable to remove local publication\n" |
| 799 | "(type=%u, lower=%u, ref=%u, key=%u)\n", |
| 800 | type, lower, ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 801 | } |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 802 | spin_unlock_bh(&tn->nametbl_lock); |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 803 | |
| 804 | if (skb) { |
Jon Paul Maloy | 1d7e1c2 | 2015-11-19 14:30:42 -0500 | [diff] [blame] | 805 | tipc_node_broadcast(net, skb); |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 806 | return 1; |
| 807 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 808 | return 0; |
| 809 | } |
| 810 | |
| 811 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 812 | * tipc_nametbl_subscribe - add a subscription object to the name table |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 813 | */ |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 814 | void tipc_nametbl_subscribe(struct tipc_subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 815 | { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 816 | struct tipc_net *tn = net_generic(s->net, tipc_net_id); |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 817 | u32 type = tipc_subscrp_convert_seq_type(s->evt.s.seq.type, s->swap); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 818 | int index = hash(type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 819 | struct name_seq *seq; |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 820 | struct tipc_name_seq ns; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 821 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 822 | spin_lock_bh(&tn->nametbl_lock); |
| 823 | seq = nametbl_find_seq(s->net, type); |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 824 | if (!seq) |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 825 | seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 826 | if (seq) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 827 | spin_lock_bh(&seq->lock); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 828 | tipc_nameseq_subscribe(seq, s); |
| 829 | spin_unlock_bh(&seq->lock); |
| 830 | } else { |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 831 | tipc_subscrp_convert_seq(&s->evt.s.seq, s->swap, &ns); |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 832 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 833 | ns.type, ns.lower, ns.upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 834 | } |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 835 | spin_unlock_bh(&tn->nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 836 | } |
| 837 | |
| 838 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 839 | * tipc_nametbl_unsubscribe - remove a subscription object from name table |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 840 | */ |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 841 | void tipc_nametbl_unsubscribe(struct tipc_subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 842 | { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 843 | struct tipc_net *tn = net_generic(s->net, tipc_net_id); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 844 | struct name_seq *seq; |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 845 | u32 type = tipc_subscrp_convert_seq_type(s->evt.s.seq.type, s->swap); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 846 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 847 | spin_lock_bh(&tn->nametbl_lock); |
Parthasarathy Bhuvaragan | a4273c7 | 2016-02-02 10:52:10 +0100 | [diff] [blame] | 848 | seq = nametbl_find_seq(s->net, type); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 849 | if (seq != NULL) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 850 | spin_lock_bh(&seq->lock); |
| 851 | list_del_init(&s->nameseq_list); |
Ying Xue | 7efea60 | 2017-03-28 12:28:28 +0200 | [diff] [blame] | 852 | tipc_subscrp_put(s); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 853 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 854 | hlist_del_init_rcu(&seq->ns_list); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 855 | kfree(seq->sseqs); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 856 | spin_unlock_bh(&seq->lock); |
| 857 | kfree_rcu(seq, rcu); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 858 | } else { |
| 859 | spin_unlock_bh(&seq->lock); |
| 860 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 861 | } |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 862 | spin_unlock_bh(&tn->nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 863 | } |
| 864 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 865 | int tipc_nametbl_init(struct net *net) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 866 | { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 867 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 868 | struct name_table *tipc_nametbl; |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 869 | int i; |
| 870 | |
| 871 | tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC); |
| 872 | if (!tipc_nametbl) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 873 | return -ENOMEM; |
| 874 | |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 875 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) |
| 876 | INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]); |
| 877 | |
| 878 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); |
| 879 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); |
| 880 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 881 | tn->nametbl = tipc_nametbl; |
| 882 | spin_lock_init(&tn->nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 883 | return 0; |
| 884 | } |
| 885 | |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 886 | /** |
| 887 | * tipc_purge_publications - remove all publications for a given type |
| 888 | * |
| 889 | * tipc_nametbl_lock must be held when calling this function |
| 890 | */ |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 891 | static void tipc_purge_publications(struct net *net, struct name_seq *seq) |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 892 | { |
| 893 | struct publication *publ, *safe; |
| 894 | struct sub_seq *sseq; |
| 895 | struct name_info *info; |
| 896 | |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 897 | spin_lock_bh(&seq->lock); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 898 | sseq = seq->sseqs; |
| 899 | info = sseq->info; |
| 900 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { |
Ying Xue | 8460504 | 2015-03-18 09:32:58 +0800 | [diff] [blame] | 901 | tipc_nameseq_remove_publ(net, seq, publ->lower, publ->node, |
| 902 | publ->ref, publ->key); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 903 | kfree_rcu(publ, rcu); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 904 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 905 | hlist_del_init_rcu(&seq->ns_list); |
| 906 | kfree(seq->sseqs); |
Ying Xue | 023160b | 2014-12-09 15:17:56 +0800 | [diff] [blame] | 907 | spin_unlock_bh(&seq->lock); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 908 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 909 | kfree_rcu(seq, rcu); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 912 | void tipc_nametbl_stop(struct net *net) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 913 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 914 | u32 i; |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 915 | struct name_seq *seq; |
| 916 | struct hlist_head *seq_head; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 917 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
| 918 | struct name_table *tipc_nametbl = tn->nametbl; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 919 | |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 920 | /* Verify name table is empty and purge any lingering |
| 921 | * publications, then release the name table |
| 922 | */ |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 923 | spin_lock_bh(&tn->nametbl_lock); |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 924 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 925 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) |
Paul Gortmaker | f705ab9 | 2012-07-11 17:35:01 -0400 | [diff] [blame] | 926 | continue; |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 927 | seq_head = &tipc_nametbl->seq_hlist[i]; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 928 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 929 | tipc_purge_publications(net, seq); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 930 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 931 | } |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 932 | spin_unlock_bh(&tn->nametbl_lock); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 933 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 934 | synchronize_net(); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 935 | kfree(tipc_nametbl); |
| 936 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 937 | } |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 938 | |
Richard Alpe | d818280 | 2014-11-24 11:10:29 +0100 | [diff] [blame] | 939 | static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg, |
| 940 | struct name_seq *seq, |
| 941 | struct sub_seq *sseq, u32 *last_publ) |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 942 | { |
| 943 | void *hdr; |
| 944 | struct nlattr *attrs; |
| 945 | struct nlattr *publ; |
| 946 | struct publication *p; |
| 947 | |
| 948 | if (*last_publ) { |
| 949 | list_for_each_entry(p, &sseq->info->zone_list, zone_list) |
| 950 | if (p->key == *last_publ) |
| 951 | break; |
| 952 | if (p->key != *last_publ) |
| 953 | return -EPIPE; |
| 954 | } else { |
| 955 | p = list_first_entry(&sseq->info->zone_list, struct publication, |
| 956 | zone_list); |
| 957 | } |
| 958 | |
| 959 | list_for_each_entry_from(p, &sseq->info->zone_list, zone_list) { |
| 960 | *last_publ = p->key; |
| 961 | |
| 962 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, |
Richard Alpe | bfb3e5d | 2015-02-09 09:50:03 +0100 | [diff] [blame] | 963 | &tipc_genl_family, NLM_F_MULTI, |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 964 | TIPC_NL_NAME_TABLE_GET); |
| 965 | if (!hdr) |
| 966 | return -EMSGSIZE; |
| 967 | |
| 968 | attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE); |
| 969 | if (!attrs) |
| 970 | goto msg_full; |
| 971 | |
| 972 | publ = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL); |
| 973 | if (!publ) |
| 974 | goto attr_msg_full; |
| 975 | |
| 976 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, seq->type)) |
| 977 | goto publ_msg_full; |
| 978 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sseq->lower)) |
| 979 | goto publ_msg_full; |
| 980 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sseq->upper)) |
| 981 | goto publ_msg_full; |
| 982 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope)) |
| 983 | goto publ_msg_full; |
| 984 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node)) |
| 985 | goto publ_msg_full; |
| 986 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->ref)) |
| 987 | goto publ_msg_full; |
| 988 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key)) |
| 989 | goto publ_msg_full; |
| 990 | |
| 991 | nla_nest_end(msg->skb, publ); |
| 992 | nla_nest_end(msg->skb, attrs); |
| 993 | genlmsg_end(msg->skb, hdr); |
| 994 | } |
| 995 | *last_publ = 0; |
| 996 | |
| 997 | return 0; |
| 998 | |
| 999 | publ_msg_full: |
| 1000 | nla_nest_cancel(msg->skb, publ); |
| 1001 | attr_msg_full: |
| 1002 | nla_nest_cancel(msg->skb, attrs); |
| 1003 | msg_full: |
| 1004 | genlmsg_cancel(msg->skb, hdr); |
| 1005 | |
| 1006 | return -EMSGSIZE; |
| 1007 | } |
| 1008 | |
Richard Alpe | d818280 | 2014-11-24 11:10:29 +0100 | [diff] [blame] | 1009 | static int __tipc_nl_subseq_list(struct tipc_nl_msg *msg, struct name_seq *seq, |
| 1010 | u32 *last_lower, u32 *last_publ) |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1011 | { |
| 1012 | struct sub_seq *sseq; |
| 1013 | struct sub_seq *sseq_start; |
| 1014 | int err; |
| 1015 | |
| 1016 | if (*last_lower) { |
| 1017 | sseq_start = nameseq_find_subseq(seq, *last_lower); |
| 1018 | if (!sseq_start) |
| 1019 | return -EPIPE; |
| 1020 | } else { |
| 1021 | sseq_start = seq->sseqs; |
| 1022 | } |
| 1023 | |
| 1024 | for (sseq = sseq_start; sseq != &seq->sseqs[seq->first_free]; sseq++) { |
| 1025 | err = __tipc_nl_add_nametable_publ(msg, seq, sseq, last_publ); |
| 1026 | if (err) { |
| 1027 | *last_lower = sseq->lower; |
| 1028 | return err; |
| 1029 | } |
| 1030 | } |
| 1031 | *last_lower = 0; |
| 1032 | |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 1036 | static int tipc_nl_seq_list(struct net *net, struct tipc_nl_msg *msg, |
| 1037 | u32 *last_type, u32 *last_lower, u32 *last_publ) |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1038 | { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 1039 | struct tipc_net *tn = net_generic(net, tipc_net_id); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1040 | struct hlist_head *seq_head; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 1041 | struct name_seq *seq = NULL; |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1042 | int err; |
| 1043 | int i; |
| 1044 | |
| 1045 | if (*last_type) |
| 1046 | i = hash(*last_type); |
| 1047 | else |
| 1048 | i = 0; |
| 1049 | |
| 1050 | for (; i < TIPC_NAMETBL_SIZE; i++) { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 1051 | seq_head = &tn->nametbl->seq_hlist[i]; |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1052 | |
| 1053 | if (*last_type) { |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 1054 | seq = nametbl_find_seq(net, *last_type); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1055 | if (!seq) |
| 1056 | return -EPIPE; |
| 1057 | } else { |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 1058 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) |
| 1059 | break; |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1060 | if (!seq) |
| 1061 | continue; |
| 1062 | } |
| 1063 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 1064 | hlist_for_each_entry_from_rcu(seq, ns_list) { |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1065 | spin_lock_bh(&seq->lock); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1066 | err = __tipc_nl_subseq_list(msg, seq, last_lower, |
| 1067 | last_publ); |
| 1068 | |
| 1069 | if (err) { |
| 1070 | *last_type = seq->type; |
| 1071 | spin_unlock_bh(&seq->lock); |
| 1072 | return err; |
| 1073 | } |
| 1074 | spin_unlock_bh(&seq->lock); |
| 1075 | } |
| 1076 | *last_type = 0; |
| 1077 | } |
| 1078 | return 0; |
| 1079 | } |
| 1080 | |
| 1081 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 1082 | { |
| 1083 | int err; |
| 1084 | int done = cb->args[3]; |
| 1085 | u32 last_type = cb->args[0]; |
| 1086 | u32 last_lower = cb->args[1]; |
| 1087 | u32 last_publ = cb->args[2]; |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 1088 | struct net *net = sock_net(skb->sk); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1089 | struct tipc_nl_msg msg; |
| 1090 | |
| 1091 | if (done) |
| 1092 | return 0; |
| 1093 | |
| 1094 | msg.skb = skb; |
| 1095 | msg.portid = NETLINK_CB(cb->skb).portid; |
| 1096 | msg.seq = cb->nlh->nlmsg_seq; |
| 1097 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 1098 | rcu_read_lock(); |
Ying Xue | 4ac1c8d | 2015-01-09 15:27:09 +0800 | [diff] [blame] | 1099 | err = tipc_nl_seq_list(net, &msg, &last_type, &last_lower, &last_publ); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1100 | if (!err) { |
| 1101 | done = 1; |
| 1102 | } else if (err != -EMSGSIZE) { |
| 1103 | /* We never set seq or call nl_dump_check_consistent() this |
| 1104 | * means that setting prev_seq here will cause the consistence |
| 1105 | * check to fail in the netlink callback handler. Resulting in |
| 1106 | * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if |
| 1107 | * we got an error. |
| 1108 | */ |
| 1109 | cb->prev_seq = 1; |
| 1110 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame] | 1111 | rcu_read_unlock(); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1112 | |
| 1113 | cb->args[0] = last_type; |
| 1114 | cb->args[1] = last_lower; |
| 1115 | cb->args[2] = last_publ; |
| 1116 | cb->args[3] = done; |
| 1117 | |
| 1118 | return skb->len; |
| 1119 | } |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1120 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1121 | struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port) |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1122 | { |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1123 | u64 value = (u64)node << 32 | port; |
| 1124 | struct tipc_dest *dst; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1125 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1126 | list_for_each_entry(dst, l, list) { |
| 1127 | if (dst->value != value) |
| 1128 | continue; |
| 1129 | return dst; |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1130 | } |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1131 | return NULL; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1132 | } |
| 1133 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1134 | bool tipc_dest_push(struct list_head *l, u32 node, u32 port) |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1135 | { |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1136 | u64 value = (u64)node << 32 | port; |
| 1137 | struct tipc_dest *dst; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1138 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1139 | if (tipc_dest_find(l, node, port)) |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1140 | return false; |
| 1141 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1142 | dst = kmalloc(sizeof(*dst), GFP_ATOMIC); |
| 1143 | if (unlikely(!dst)) |
| 1144 | return false; |
| 1145 | dst->value = value; |
| 1146 | list_add(&dst->list, l); |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1147 | return true; |
| 1148 | } |
| 1149 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1150 | bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port) |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1151 | { |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1152 | struct tipc_dest *dst; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1153 | |
| 1154 | if (list_empty(l)) |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1155 | return false; |
| 1156 | dst = list_first_entry(l, typeof(*dst), list); |
| 1157 | if (port) |
| 1158 | *port = dst->port; |
| 1159 | if (node) |
| 1160 | *node = dst->node; |
| 1161 | list_del(&dst->list); |
| 1162 | kfree(dst); |
| 1163 | return true; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1164 | } |
| 1165 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1166 | bool tipc_dest_del(struct list_head *l, u32 node, u32 port) |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1167 | { |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1168 | struct tipc_dest *dst; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1169 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1170 | dst = tipc_dest_find(l, node, port); |
| 1171 | if (!dst) |
| 1172 | return false; |
| 1173 | list_del(&dst->list); |
| 1174 | kfree(dst); |
| 1175 | return true; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1176 | } |
| 1177 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1178 | void tipc_dest_list_purge(struct list_head *l) |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1179 | { |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1180 | struct tipc_dest *dst, *tmp; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1181 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1182 | list_for_each_entry_safe(dst, tmp, l, list) { |
| 1183 | list_del(&dst->list); |
| 1184 | kfree(dst); |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1185 | } |
| 1186 | } |
| 1187 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1188 | int tipc_dest_list_len(struct list_head *l) |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1189 | { |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1190 | struct tipc_dest *dst; |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1191 | int i = 0; |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1192 | |
Jon Maloy | a80ae53 | 2017-10-13 11:04:22 +0200 | [diff] [blame] | 1193 | list_for_each_entry(dst, l, list) { |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1194 | i++; |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1195 | } |
Jon Paul Maloy | 4d8642d | 2017-01-03 10:55:10 -0500 | [diff] [blame] | 1196 | return i; |
Jon Paul Maloy | 3c724ac | 2015-02-05 08:36:43 -0500 | [diff] [blame] | 1197 | } |