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 | * |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 4 | * Copyright (c) 2000-2006, 2014, 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 | |
| 37 | #include "core.h" |
| 38 | #include "config.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 39 | #include "name_table.h" |
| 40 | #include "name_distr.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 41 | #include "subscr.h" |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 42 | |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 43 | #define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 44 | |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 45 | static const struct nla_policy |
| 46 | tipc_nl_name_table_policy[TIPC_NLA_NAME_TABLE_MAX + 1] = { |
| 47 | [TIPC_NLA_NAME_TABLE_UNSPEC] = { .type = NLA_UNSPEC }, |
| 48 | [TIPC_NLA_NAME_TABLE_PUBL] = { .type = NLA_NESTED } |
| 49 | }; |
| 50 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 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 | |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 108 | struct name_table *tipc_nametbl; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 109 | DEFINE_SPINLOCK(tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 110 | |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 111 | static int hash(int x) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 112 | { |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 113 | return x & (TIPC_NAMETBL_SIZE - 1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /** |
| 117 | * publ_create - create a publication structure |
| 118 | */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 119 | static struct publication *publ_create(u32 type, u32 lower, u32 upper, |
| 120 | u32 scope, u32 node, u32 port_ref, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 121 | u32 key) |
| 122 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 123 | struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 124 | if (publ == NULL) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 125 | pr_warn("Publication creation failure, no memory\n"); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 126 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 129 | publ->type = type; |
| 130 | publ->lower = lower; |
| 131 | publ->upper = upper; |
| 132 | publ->scope = scope; |
| 133 | publ->node = node; |
| 134 | publ->ref = port_ref; |
| 135 | publ->key = key; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 136 | INIT_LIST_HEAD(&publ->pport_list); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 137 | return publ; |
| 138 | } |
| 139 | |
| 140 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 141 | * tipc_subseq_alloc - allocate a specified number of sub-sequence structures |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 142 | */ |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 143 | static struct sub_seq *tipc_subseq_alloc(u32 cnt) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 144 | { |
wangweidong | 0cee6bb | 2013-12-12 09:36:39 +0800 | [diff] [blame] | 145 | return kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 149 | * tipc_nameseq_create - create a name sequence structure for the specified 'type' |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 150 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 151 | * Allocates a single sub-sequence structure and sets it to all 0's. |
| 152 | */ |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 153 | 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] | 154 | { |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 155 | struct name_seq *nseq = kzalloc(sizeof(*nseq), GFP_ATOMIC); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 156 | struct sub_seq *sseq = tipc_subseq_alloc(1); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 157 | |
| 158 | if (!nseq || !sseq) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 159 | pr_warn("Name sequence creation failed, no memory\n"); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 160 | kfree(nseq); |
| 161 | kfree(sseq); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 162 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Ingo Molnar | 34af946 | 2006-06-27 02:53:55 -0700 | [diff] [blame] | 165 | spin_lock_init(&nseq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 166 | nseq->type = type; |
| 167 | nseq->sseqs = sseq; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 168 | nseq->alloc = 1; |
| 169 | INIT_HLIST_NODE(&nseq->ns_list); |
| 170 | INIT_LIST_HEAD(&nseq->subscriptions); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 171 | hlist_add_head_rcu(&nseq->ns_list, seq_head); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 172 | return nseq; |
| 173 | } |
| 174 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 175 | /** |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 176 | * nameseq_find_subseq - find sub-sequence (if any) matching a name instance |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 177 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 178 | * Very time-critical, so binary searches through sub-sequence array. |
| 179 | */ |
Sam Ravnborg | 05790c6 | 2006-03-20 22:37:04 -0800 | [diff] [blame] | 180 | static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq, |
| 181 | u32 instance) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 182 | { |
| 183 | struct sub_seq *sseqs = nseq->sseqs; |
| 184 | int low = 0; |
| 185 | int high = nseq->first_free - 1; |
| 186 | int mid; |
| 187 | |
| 188 | while (low <= high) { |
| 189 | mid = (low + high) / 2; |
| 190 | if (instance < sseqs[mid].lower) |
| 191 | high = mid - 1; |
| 192 | else if (instance > sseqs[mid].upper) |
| 193 | low = mid + 1; |
| 194 | else |
| 195 | return &sseqs[mid]; |
| 196 | } |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 197 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | /** |
| 201 | * nameseq_locate_subseq - determine position of name instance in sub-sequence |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 202 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 203 | * Returns index in sub-sequence array of the entry that contains the specified |
| 204 | * instance value; if no entry contains that value, returns the position |
| 205 | * where a new entry for it would be inserted in the array. |
| 206 | * |
| 207 | * Note: Similar to binary search code for locating a sub-sequence. |
| 208 | */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 209 | static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance) |
| 210 | { |
| 211 | struct sub_seq *sseqs = nseq->sseqs; |
| 212 | int low = 0; |
| 213 | int high = nseq->first_free - 1; |
| 214 | int mid; |
| 215 | |
| 216 | while (low <= high) { |
| 217 | mid = (low + high) / 2; |
| 218 | if (instance < sseqs[mid].lower) |
| 219 | high = mid - 1; |
| 220 | else if (instance > sseqs[mid].upper) |
| 221 | low = mid + 1; |
| 222 | else |
| 223 | return mid; |
| 224 | } |
| 225 | return low; |
| 226 | } |
| 227 | |
| 228 | /** |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 229 | * tipc_nameseq_insert_publ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 230 | */ |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 231 | static struct publication *tipc_nameseq_insert_publ(struct name_seq *nseq, |
| 232 | u32 type, u32 lower, u32 upper, |
| 233 | u32 scope, u32 node, u32 port, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 234 | { |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 235 | struct tipc_subscription *s; |
| 236 | struct tipc_subscription *st; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 237 | struct publication *publ; |
| 238 | struct sub_seq *sseq; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 239 | struct name_info *info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 240 | int created_subseq = 0; |
| 241 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 242 | sseq = nameseq_find_subseq(nseq, lower); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 243 | if (sseq) { |
| 244 | |
| 245 | /* Lower end overlaps existing entry => need an exact match */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 246 | if ((sseq->lower != lower) || (sseq->upper != upper)) { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 247 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 248 | } |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 249 | |
| 250 | info = sseq->info; |
Allan Stephens | f80c24d | 2011-11-03 11:12:01 -0400 | [diff] [blame] | 251 | |
| 252 | /* Check if an identical publication already exists */ |
| 253 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
| 254 | if ((publ->ref == port) && (publ->key == key) && |
| 255 | (!publ->node || (publ->node == node))) |
| 256 | return NULL; |
| 257 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 258 | } else { |
| 259 | u32 inspos; |
| 260 | struct sub_seq *freesseq; |
| 261 | |
| 262 | /* Find where lower end should be inserted */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 263 | inspos = nameseq_locate_subseq(nseq, lower); |
| 264 | |
| 265 | /* Fail if upper end overlaps into an existing entry */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 266 | if ((inspos < nseq->first_free) && |
| 267 | (upper >= nseq->sseqs[inspos].lower)) { |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 268 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | /* Ensure there is space for new sub-sequence */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 272 | if (nseq->first_free == nseq->alloc) { |
Allan Stephens | 9ab230f | 2006-06-25 23:37:24 -0700 | [diff] [blame] | 273 | struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2); |
| 274 | |
| 275 | if (!sseqs) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 276 | pr_warn("Cannot publish {%u,%u,%u}, no memory\n", |
| 277 | type, lower, upper); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 278 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 279 | } |
Allan Stephens | 9ab230f | 2006-06-25 23:37:24 -0700 | [diff] [blame] | 280 | memcpy(sseqs, nseq->sseqs, |
| 281 | nseq->alloc * sizeof(struct sub_seq)); |
| 282 | kfree(nseq->sseqs); |
| 283 | nseq->sseqs = sseqs; |
| 284 | nseq->alloc *= 2; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 285 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 286 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 287 | info = kzalloc(sizeof(*info), GFP_ATOMIC); |
| 288 | if (!info) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 289 | pr_warn("Cannot publish {%u,%u,%u}, no memory\n", |
| 290 | type, lower, upper); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 291 | return NULL; |
| 292 | } |
| 293 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 294 | INIT_LIST_HEAD(&info->node_list); |
| 295 | INIT_LIST_HEAD(&info->cluster_list); |
| 296 | INIT_LIST_HEAD(&info->zone_list); |
| 297 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 298 | /* Insert new sub-sequence */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 299 | sseq = &nseq->sseqs[inspos]; |
| 300 | freesseq = &nseq->sseqs[nseq->first_free]; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 301 | memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof(*sseq)); |
| 302 | memset(sseq, 0, sizeof(*sseq)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 303 | nseq->first_free++; |
| 304 | sseq->lower = lower; |
| 305 | sseq->upper = upper; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 306 | sseq->info = info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 307 | created_subseq = 1; |
| 308 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 309 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 310 | /* Insert a publication */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 311 | publ = publ_create(type, lower, upper, scope, node, port, key); |
| 312 | if (!publ) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 313 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 314 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 315 | list_add(&publ->zone_list, &info->zone_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 316 | info->zone_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 317 | |
Allan Stephens | d4f5c12 | 2012-04-17 18:16:34 -0400 | [diff] [blame] | 318 | if (in_own_cluster(node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 319 | list_add(&publ->cluster_list, &info->cluster_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 320 | info->cluster_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 321 | } |
| 322 | |
Allan Stephens | d4f5c12 | 2012-04-17 18:16:34 -0400 | [diff] [blame] | 323 | if (in_own_node(node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 324 | list_add(&publ->node_list, &info->node_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 325 | info->node_list_size++; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 326 | } |
| 327 | |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 328 | /* Any subscriptions waiting for notification? */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 329 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 330 | tipc_subscr_report_overlap(s, |
| 331 | publ->lower, |
| 332 | publ->upper, |
| 333 | TIPC_PUBLISHED, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 334 | publ->ref, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 335 | publ->node, |
| 336 | created_subseq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 337 | } |
| 338 | return publ; |
| 339 | } |
| 340 | |
| 341 | /** |
Paul Gortmaker | 617d3c7 | 2012-04-30 15:29:02 -0400 | [diff] [blame] | 342 | * tipc_nameseq_remove_publ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 343 | * |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 344 | * NOTE: There may be cases where TIPC is asked to remove a publication |
| 345 | * that is not in the name table. For example, if another node issues a |
| 346 | * publication for a name sequence that overlaps an existing name sequence |
| 347 | * the publication will not be recorded, which means the publication won't |
| 348 | * be found when the name sequence is later withdrawn by that node. |
| 349 | * A failed withdraw request simply returns a failure indication and lets the |
| 350 | * caller issue any error or warning messages associated with such a problem. |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 351 | */ |
Adrian Bunk | 988f088 | 2006-03-20 22:37:52 -0800 | [diff] [blame] | 352 | static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst, |
| 353 | u32 node, u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 354 | { |
| 355 | struct publication *publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 356 | struct sub_seq *sseq = nameseq_find_subseq(nseq, inst); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 357 | struct name_info *info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 358 | struct sub_seq *free; |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 359 | struct tipc_subscription *s, *st; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 360 | int removed_subseq = 0; |
| 361 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 362 | if (!sseq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 363 | return NULL; |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 364 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 365 | info = sseq->info; |
| 366 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 367 | /* Locate publication, if it exists */ |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 368 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
| 369 | if ((publ->key == key) && (publ->ref == ref) && |
| 370 | (!publ->node || (publ->node == node))) |
| 371 | goto found; |
| 372 | } |
| 373 | return NULL; |
| 374 | |
| 375 | found: |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 376 | /* Remove publication from zone scope list */ |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 377 | list_del(&publ->zone_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 378 | info->zone_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 379 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 380 | /* Remove publication from cluster scope list, if present */ |
Allan Stephens | d4f5c12 | 2012-04-17 18:16:34 -0400 | [diff] [blame] | 381 | if (in_own_cluster(node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 382 | list_del(&publ->cluster_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 383 | info->cluster_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 384 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 385 | |
| 386 | /* Remove publication from node scope list, if present */ |
Allan Stephens | d4f5c12 | 2012-04-17 18:16:34 -0400 | [diff] [blame] | 387 | if (in_own_node(node)) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 388 | list_del(&publ->node_list); |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 389 | info->node_list_size--; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 390 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 391 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 392 | /* Contract subseq list if no more publications for that subseq */ |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 393 | if (list_empty(&info->zone_list)) { |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 394 | kfree(info); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 395 | free = &nseq->sseqs[nseq->first_free--]; |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 396 | memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 397 | removed_subseq = 1; |
| 398 | } |
| 399 | |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 400 | /* Notify any waiting subscriptions */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 401 | list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 402 | tipc_subscr_report_overlap(s, |
| 403 | publ->lower, |
| 404 | publ->upper, |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 405 | TIPC_WITHDRAWN, |
| 406 | publ->ref, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 407 | publ->node, |
| 408 | removed_subseq); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 409 | } |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 410 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 411 | return publ; |
| 412 | } |
| 413 | |
| 414 | /** |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 415 | * tipc_nameseq_subscribe - attach a subscription, and issue |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 416 | * the prescribed number of events if there is any sub- |
| 417 | * sequence overlapping with the requested sequence |
| 418 | */ |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 419 | static void tipc_nameseq_subscribe(struct name_seq *nseq, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 420 | struct tipc_subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 421 | { |
| 422 | struct sub_seq *sseq = nseq->sseqs; |
| 423 | |
| 424 | list_add(&s->nameseq_list, &nseq->subscriptions); |
| 425 | |
| 426 | if (!sseq) |
| 427 | return; |
| 428 | |
| 429 | while (sseq != &nseq->sseqs[nseq->first_free]) { |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 430 | if (tipc_subscr_overlap(s, sseq->lower, sseq->upper)) { |
| 431 | struct publication *crs; |
| 432 | struct name_info *info = sseq->info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 433 | int must_report = 1; |
| 434 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 435 | list_for_each_entry(crs, &info->zone_list, zone_list) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 436 | tipc_subscr_report_overlap(s, |
| 437 | sseq->lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 438 | sseq->upper, |
| 439 | TIPC_PUBLISHED, |
| 440 | crs->ref, |
| 441 | crs->node, |
| 442 | must_report); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 443 | must_report = 0; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 444 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 445 | } |
| 446 | sseq++; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | static struct name_seq *nametbl_find_seq(u32 type) |
| 451 | { |
| 452 | struct hlist_head *seq_head; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 453 | struct name_seq *ns; |
| 454 | |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 455 | seq_head = &tipc_nametbl->seq_hlist[hash(type)]; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 456 | hlist_for_each_entry_rcu(ns, seq_head, ns_list) { |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 457 | if (ns->type == type) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 458 | return ns; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 461 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 462 | }; |
| 463 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 464 | struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper, |
| 465 | u32 scope, u32 node, u32 port, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 466 | { |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 467 | struct publication *publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 468 | struct name_seq *seq = nametbl_find_seq(type); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 469 | int index = hash(type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 470 | |
Allan Stephens | 8f17789 | 2012-04-26 17:57:17 -0400 | [diff] [blame] | 471 | if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) || |
| 472 | (lower > upper)) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 473 | pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n", |
| 474 | type, lower, upper, scope); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 475 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Allan Stephens | b29f142 | 2010-12-31 18:59:25 +0000 | [diff] [blame] | 478 | if (!seq) |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 479 | seq = tipc_nameseq_create(type, |
| 480 | &tipc_nametbl->seq_hlist[index]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 481 | if (!seq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 482 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 483 | |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 484 | spin_lock_bh(&seq->lock); |
| 485 | publ = tipc_nameseq_insert_publ(seq, type, lower, upper, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 486 | scope, node, port, key); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 487 | spin_unlock_bh(&seq->lock); |
| 488 | return publ; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 489 | } |
| 490 | |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 491 | struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower, |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 492 | u32 node, u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 493 | { |
| 494 | struct publication *publ; |
| 495 | struct name_seq *seq = nametbl_find_seq(type); |
| 496 | |
| 497 | if (!seq) |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 498 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 499 | |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 500 | spin_lock_bh(&seq->lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 501 | publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 502 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 503 | hlist_del_init_rcu(&seq->ns_list); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 504 | kfree(seq->sseqs); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 505 | spin_unlock_bh(&seq->lock); |
| 506 | kfree_rcu(seq, rcu); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 507 | return publ; |
| 508 | } |
| 509 | spin_unlock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 510 | return publ; |
| 511 | } |
| 512 | |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 513 | /** |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 514 | * tipc_nametbl_translate - perform name translation |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 515 | * |
Allan Stephens | bc9f814 | 2011-11-07 17:00:54 -0500 | [diff] [blame] | 516 | * On entry, 'destnode' is the search domain used during translation. |
| 517 | * |
| 518 | * On exit: |
| 519 | * - if name translation is deferred to another node/cluster/zone, |
| 520 | * leaves 'destnode' unchanged (will be non-zero) and returns 0 |
| 521 | * - if name translation is attempted and succeeds, sets 'destnode' |
| 522 | * to publishing node and returns port reference (will be non-zero) |
| 523 | * - if name translation is attempted and fails, sets 'destnode' to 0 |
| 524 | * and returns 0 |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 525 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 526 | u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 527 | { |
| 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 | |
Allan Stephens | c68ca7b | 2010-05-11 14:30:12 +0000 | [diff] [blame] | 535 | if (!tipc_in_scope(*destnode, tipc_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(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 539 | seq = nametbl_find_seq(type); |
| 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 */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 572 | else if (*destnode == tipc_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); |
Allan Stephens | 336ebf5 | 2012-04-17 18:02:01 -0400 | [diff] [blame] | 578 | } else if (in_own_cluster_exact(*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 | |
| 600 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 601 | * tipc_nametbl_mc_translate - find multicast destinations |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 602 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 603 | * Creates list of all local ports that overlap the given multicast address; |
| 604 | * also determines if any off-node ports overlap. |
| 605 | * |
| 606 | * Note: Publications with a scope narrower than 'limit' are ignored. |
| 607 | * (i.e. local node-scope publications mustn't receive messages arriving |
| 608 | * from another node, even if the multcast link brought it here) |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 609 | * |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 610 | * Returns non-zero if any off-node ports overlap |
| 611 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 612 | int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit, |
Paul Gortmaker | 4584310 | 2011-12-29 20:33:30 -0500 | [diff] [blame] | 613 | struct tipc_port_list *dports) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 614 | { |
| 615 | struct name_seq *seq; |
| 616 | struct sub_seq *sseq; |
| 617 | struct sub_seq *sseq_stop; |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 618 | struct name_info *info; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 619 | int res = 0; |
| 620 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 621 | rcu_read_lock(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 622 | seq = nametbl_find_seq(type); |
| 623 | if (!seq) |
| 624 | goto exit; |
| 625 | |
| 626 | spin_lock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 627 | sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); |
| 628 | sseq_stop = seq->sseqs + seq->first_free; |
| 629 | for (; sseq != sseq_stop; sseq++) { |
| 630 | struct publication *publ; |
| 631 | |
| 632 | if (sseq->lower > upper) |
| 633 | break; |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 634 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 635 | info = sseq->info; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 636 | list_for_each_entry(publ, &info->node_list, node_list) { |
| 637 | if (publ->scope <= limit) |
| 638 | tipc_port_list_add(dports, publ->ref); |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 639 | } |
| 640 | |
Allan Stephens | b52124a | 2011-05-30 09:44:38 -0400 | [diff] [blame] | 641 | if (info->cluster_list_size != info->node_list_size) |
Allan Stephens | 968edbe | 2008-07-14 22:45:33 -0700 | [diff] [blame] | 642 | res = 1; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 643 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 644 | spin_unlock_bh(&seq->lock); |
| 645 | exit: |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 646 | rcu_read_unlock(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 647 | return res; |
| 648 | } |
| 649 | |
Allan Stephens | c422f1b | 2011-11-02 15:49:40 -0400 | [diff] [blame] | 650 | /* |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 651 | * tipc_nametbl_publish - add name publication to network name tables |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 652 | */ |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 653 | struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 654 | u32 scope, u32 port_ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 655 | { |
| 656 | struct publication *publ; |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 657 | struct sk_buff *buf = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 658 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 659 | spin_lock_bh(&tipc_nametbl_lock); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 660 | if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 661 | pr_warn("Publication failed, local publication limit reached (%u)\n", |
Ying Xue | e6a04b1 | 2012-08-16 12:09:14 +0000 | [diff] [blame] | 662 | TIPC_MAX_PUBLICATIONS); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 663 | spin_unlock_bh(&tipc_nametbl_lock); |
Sam Ravnborg | 1fc54d8 | 2006-03-20 22:36:47 -0800 | [diff] [blame] | 664 | return NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 665 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 666 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 667 | publ = tipc_nametbl_insert_publ(type, lower, upper, scope, |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 668 | tipc_own_addr, port_ref, key); |
Allan Stephens | fd6eced | 2011-11-09 14:22:52 -0500 | [diff] [blame] | 669 | if (likely(publ)) { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 670 | tipc_nametbl->local_publ_count++; |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 671 | buf = tipc_named_publish(publ); |
Erik Hugne | a5325ae | 2014-08-28 09:08:47 +0200 | [diff] [blame] | 672 | /* Any pending external events? */ |
| 673 | tipc_named_process_backlog(); |
Allan Stephens | fd6eced | 2011-11-09 14:22:52 -0500 | [diff] [blame] | 674 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 675 | spin_unlock_bh(&tipc_nametbl_lock); |
Ying Xue | eab8c045 | 2014-04-28 18:00:10 +0800 | [diff] [blame] | 676 | |
| 677 | if (buf) |
| 678 | named_cluster_distribute(buf); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 679 | return publ; |
| 680 | } |
| 681 | |
| 682 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 683 | * tipc_nametbl_withdraw - withdraw name publication from network name tables |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 684 | */ |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 685 | int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 686 | { |
| 687 | struct publication *publ; |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 688 | struct sk_buff *skb = NULL; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 689 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 690 | spin_lock_bh(&tipc_nametbl_lock); |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 691 | publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key); |
Allan Stephens | f131072 | 2006-06-25 23:51:37 -0700 | [diff] [blame] | 692 | if (likely(publ)) { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 693 | tipc_nametbl->local_publ_count--; |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 694 | skb = tipc_named_withdraw(publ); |
Erik Hugne | a5325ae | 2014-08-28 09:08:47 +0200 | [diff] [blame] | 695 | /* Any pending external events? */ |
| 696 | tipc_named_process_backlog(); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 697 | list_del_init(&publ->pport_list); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 698 | kfree_rcu(publ, rcu); |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 699 | } else { |
| 700 | pr_err("Unable to remove local publication\n" |
| 701 | "(type=%u, lower=%u, ref=%u, key=%u)\n", |
| 702 | type, lower, ref, key); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 703 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 704 | spin_unlock_bh(&tipc_nametbl_lock); |
Ying Xue | 5492390 | 2014-12-02 15:00:28 +0800 | [diff] [blame] | 705 | |
| 706 | if (skb) { |
| 707 | named_cluster_distribute(skb); |
| 708 | return 1; |
| 709 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 714 | * tipc_nametbl_subscribe - add a subscription object to the name table |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 715 | */ |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 716 | void tipc_nametbl_subscribe(struct tipc_subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 717 | { |
| 718 | u32 type = s->seq.type; |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 719 | int index = hash(type); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 720 | struct name_seq *seq; |
| 721 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 722 | spin_lock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 723 | seq = nametbl_find_seq(type); |
Allan Stephens | a016892 | 2010-12-31 18:59:35 +0000 | [diff] [blame] | 724 | if (!seq) |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 725 | seq = tipc_nameseq_create(type, |
| 726 | &tipc_nametbl->seq_hlist[index]); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 727 | if (seq) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 728 | spin_lock_bh(&seq->lock); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 729 | tipc_nameseq_subscribe(seq, s); |
| 730 | spin_unlock_bh(&seq->lock); |
| 731 | } else { |
Erik Hugne | 2cf8aa1 | 2012-06-29 00:16:37 -0400 | [diff] [blame] | 732 | pr_warn("Failed to create subscription for {%u,%u,%u}\n", |
| 733 | s->seq.type, s->seq.lower, s->seq.upper); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 734 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 735 | spin_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /** |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 739 | * tipc_nametbl_unsubscribe - remove a subscription object from name table |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 740 | */ |
Paul Gortmaker | fead390 | 2011-12-29 20:43:44 -0500 | [diff] [blame] | 741 | void tipc_nametbl_unsubscribe(struct tipc_subscription *s) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 742 | { |
| 743 | struct name_seq *seq; |
| 744 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 745 | spin_lock_bh(&tipc_nametbl_lock); |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 746 | seq = nametbl_find_seq(s->seq.type); |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 747 | if (seq != NULL) { |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 748 | spin_lock_bh(&seq->lock); |
| 749 | list_del_init(&s->nameseq_list); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 750 | if (!seq->first_free && list_empty(&seq->subscriptions)) { |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 751 | hlist_del_init_rcu(&seq->ns_list); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 752 | kfree(seq->sseqs); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 753 | spin_unlock_bh(&seq->lock); |
| 754 | kfree_rcu(seq, rcu); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 755 | } else { |
| 756 | spin_unlock_bh(&seq->lock); |
| 757 | } |
YOSHIFUJI Hideaki | c430728 | 2007-02-09 23:25:21 +0900 | [diff] [blame] | 758 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 759 | spin_unlock_bh(&tipc_nametbl_lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 762 | /** |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 763 | * subseq_list - print specified sub-sequence contents into the given buffer |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 764 | */ |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 765 | static int subseq_list(struct sub_seq *sseq, char *buf, int len, u32 depth, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 766 | u32 index) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 767 | { |
| 768 | char portIdStr[27]; |
Allan Stephens | c2de581 | 2010-08-17 11:00:14 +0000 | [diff] [blame] | 769 | const char *scope_str[] = {"", " zone", " cluster", " node"}; |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 770 | struct publication *publ; |
| 771 | struct name_info *info; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 772 | int ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 773 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 774 | ret = tipc_snprintf(buf, len, "%-10u %-10u ", sseq->lower, sseq->upper); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 775 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 776 | if (depth == 2) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 777 | ret += tipc_snprintf(buf - ret, len + ret, "\n"); |
| 778 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 781 | info = sseq->info; |
| 782 | |
| 783 | list_for_each_entry(publ, &info->zone_list, zone_list) { |
Allan Stephens | 0e65967 | 2010-12-31 18:59:32 +0000 | [diff] [blame] | 784 | sprintf(portIdStr, "<%u.%u.%u:%u>", |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 785 | tipc_zone(publ->node), tipc_cluster(publ->node), |
| 786 | tipc_node(publ->node), publ->ref); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 787 | ret += tipc_snprintf(buf + ret, len - ret, "%-26s ", portIdStr); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 788 | if (depth > 3) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 789 | ret += tipc_snprintf(buf + ret, len - ret, "%-10u %s", |
| 790 | publ->key, scope_str[publ->scope]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 791 | } |
Allan Stephens | f6f0a4d | 2011-05-30 10:48:48 -0400 | [diff] [blame] | 792 | if (!list_is_last(&publ->zone_list, &info->zone_list)) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 793 | ret += tipc_snprintf(buf + ret, len - ret, |
| 794 | "\n%33s", " "); |
Peter Senna Tschudin | adccff3 | 2012-09-18 07:10:45 +0000 | [diff] [blame] | 795 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 796 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 797 | ret += tipc_snprintf(buf + ret, len - ret, "\n"); |
| 798 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | /** |
Ben Hutchings | 2c53040 | 2012-07-10 10:55:09 +0000 | [diff] [blame] | 802 | * nameseq_list - print specified name sequence contents into the given buffer |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 803 | */ |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 804 | static int nameseq_list(struct name_seq *seq, char *buf, int len, u32 depth, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 805 | u32 type, u32 lowbound, u32 upbound, u32 index) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 806 | { |
| 807 | struct sub_seq *sseq; |
| 808 | char typearea[11]; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 809 | int ret = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 810 | |
Allan Stephens | 0f15d36 | 2008-06-04 17:37:59 -0700 | [diff] [blame] | 811 | if (seq->first_free == 0) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 812 | return 0; |
Allan Stephens | 0f15d36 | 2008-06-04 17:37:59 -0700 | [diff] [blame] | 813 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 814 | sprintf(typearea, "%-10u", seq->type); |
| 815 | |
| 816 | if (depth == 1) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 817 | ret += tipc_snprintf(buf, len, "%s\n", typearea); |
| 818 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | for (sseq = seq->sseqs; sseq != &seq->sseqs[seq->first_free]; sseq++) { |
| 822 | if ((lowbound <= sseq->upper) && (upbound >= sseq->lower)) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 823 | ret += tipc_snprintf(buf + ret, len - ret, "%s ", |
| 824 | typearea); |
Allan Stephens | 307fdf5 | 2008-06-04 17:38:22 -0700 | [diff] [blame] | 825 | spin_lock_bh(&seq->lock); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 826 | ret += subseq_list(sseq, buf + ret, len - ret, |
| 827 | depth, index); |
Allan Stephens | 307fdf5 | 2008-06-04 17:38:22 -0700 | [diff] [blame] | 828 | spin_unlock_bh(&seq->lock); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 829 | sprintf(typearea, "%10s", " "); |
| 830 | } |
| 831 | } |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 832 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | /** |
| 836 | * nametbl_header - print name table header into the given buffer |
| 837 | */ |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 838 | static int nametbl_header(char *buf, int len, u32 depth) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 839 | { |
Allan Stephens | c2de581 | 2010-08-17 11:00:14 +0000 | [diff] [blame] | 840 | const char *header[] = { |
| 841 | "Type ", |
| 842 | "Lower Upper ", |
| 843 | "Port Identity ", |
| 844 | "Publication Scope" |
| 845 | }; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 846 | |
Allan Stephens | c2de581 | 2010-08-17 11:00:14 +0000 | [diff] [blame] | 847 | int i; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 848 | int ret = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 849 | |
Allan Stephens | c2de581 | 2010-08-17 11:00:14 +0000 | [diff] [blame] | 850 | if (depth > 4) |
| 851 | depth = 4; |
| 852 | for (i = 0; i < depth; i++) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 853 | ret += tipc_snprintf(buf + ret, len - ret, header[i]); |
| 854 | ret += tipc_snprintf(buf + ret, len - ret, "\n"); |
| 855 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /** |
| 859 | * nametbl_list - print specified name table contents into the given buffer |
| 860 | */ |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 861 | static int nametbl_list(char *buf, int len, u32 depth_info, |
Paul Gortmaker | ae8509c | 2013-06-17 10:54:47 -0400 | [diff] [blame] | 862 | u32 type, u32 lowbound, u32 upbound) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 863 | { |
| 864 | struct hlist_head *seq_head; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 865 | struct name_seq *seq; |
| 866 | int all_types; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 867 | int ret = 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 868 | u32 depth; |
| 869 | u32 i; |
| 870 | |
| 871 | all_types = (depth_info & TIPC_NTQ_ALLTYPES); |
| 872 | depth = (depth_info & ~TIPC_NTQ_ALLTYPES); |
| 873 | |
| 874 | if (depth == 0) |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 875 | return 0; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 876 | |
| 877 | if (all_types) { |
| 878 | /* display all entries in name table to specified depth */ |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 879 | ret += nametbl_header(buf, len, depth); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 880 | lowbound = 0; |
| 881 | upbound = ~0; |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 882 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 883 | seq_head = &tipc_nametbl->seq_hlist[i]; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 884 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 885 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 886 | depth, seq->type, |
| 887 | lowbound, upbound, i); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 888 | } |
| 889 | } |
| 890 | } else { |
| 891 | /* display only the sequence that matches the specified type */ |
| 892 | if (upbound < lowbound) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 893 | ret += tipc_snprintf(buf + ret, len - ret, |
| 894 | "invalid name sequence specified\n"); |
| 895 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 896 | } |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 897 | ret += nametbl_header(buf + ret, len - ret, depth); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 898 | i = hash(type); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 899 | seq_head = &tipc_nametbl->seq_hlist[i]; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 900 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 901 | if (seq->type == type) { |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 902 | ret += nameseq_list(seq, buf + ret, len - ret, |
| 903 | depth, type, |
| 904 | lowbound, upbound, i); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 905 | break; |
| 906 | } |
| 907 | } |
| 908 | } |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 909 | return ret; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 910 | } |
| 911 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 912 | struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 913 | { |
| 914 | struct sk_buff *buf; |
| 915 | struct tipc_name_table_query *argv; |
| 916 | struct tlv_desc *rep_tlv; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 917 | char *pb; |
| 918 | int pb_len; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 919 | int str_len; |
| 920 | |
| 921 | if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NAME_TBL_QUERY)) |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 922 | return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 923 | |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 924 | buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN)); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 925 | if (!buf) |
| 926 | return NULL; |
| 927 | |
| 928 | rep_tlv = (struct tlv_desc *)buf->data; |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 929 | pb = TLV_DATA(rep_tlv); |
| 930 | pb_len = ULTRA_STRING_MAX_LEN; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 931 | argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 932 | rcu_read_lock(); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 933 | str_len = nametbl_list(pb, pb_len, ntohl(argv->depth), |
| 934 | ntohl(argv->type), |
| 935 | ntohl(argv->lowbound), ntohl(argv->upbound)); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 936 | rcu_read_unlock(); |
Erik Hugne | dc1aed3 | 2012-06-29 00:50:23 -0400 | [diff] [blame] | 937 | str_len += 1; /* for "\0" */ |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 938 | skb_put(buf, TLV_SPACE(str_len)); |
| 939 | TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); |
| 940 | |
| 941 | return buf; |
| 942 | } |
| 943 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 944 | int tipc_nametbl_init(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 945 | { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 946 | int i; |
| 947 | |
| 948 | tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC); |
| 949 | if (!tipc_nametbl) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 950 | return -ENOMEM; |
| 951 | |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 952 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) |
| 953 | INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]); |
| 954 | |
| 955 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]); |
| 956 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]); |
| 957 | INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]); |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 958 | return 0; |
| 959 | } |
| 960 | |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 961 | /** |
| 962 | * tipc_purge_publications - remove all publications for a given type |
| 963 | * |
| 964 | * tipc_nametbl_lock must be held when calling this function |
| 965 | */ |
| 966 | static void tipc_purge_publications(struct name_seq *seq) |
| 967 | { |
| 968 | struct publication *publ, *safe; |
| 969 | struct sub_seq *sseq; |
| 970 | struct name_info *info; |
| 971 | |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 972 | spin_lock_bh(&seq->lock); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 973 | sseq = seq->sseqs; |
| 974 | info = sseq->info; |
| 975 | list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) { |
| 976 | tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node, |
| 977 | publ->ref, publ->key); |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 978 | kfree_rcu(publ, rcu); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 979 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 980 | hlist_del_init_rcu(&seq->ns_list); |
| 981 | kfree(seq->sseqs); |
Ying Xue | fb9962f | 2014-12-02 15:00:26 +0800 | [diff] [blame] | 982 | spin_lock_bh(&seq->lock); |
| 983 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 984 | kfree_rcu(seq, rcu); |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 985 | } |
| 986 | |
Per Liden | 4323add | 2006-01-18 00:38:21 +0100 | [diff] [blame] | 987 | void tipc_nametbl_stop(void) |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 988 | { |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 989 | u32 i; |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 990 | struct name_seq *seq; |
| 991 | struct hlist_head *seq_head; |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 992 | |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 993 | /* Verify name table is empty and purge any lingering |
| 994 | * publications, then release the name table |
| 995 | */ |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 996 | spin_lock_bh(&tipc_nametbl_lock); |
Ying Xue | f046e7d | 2012-08-16 12:09:11 +0000 | [diff] [blame] | 997 | for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 998 | if (hlist_empty(&tipc_nametbl->seq_hlist[i])) |
Paul Gortmaker | f705ab9 | 2012-07-11 17:35:01 -0400 | [diff] [blame] | 999 | continue; |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 1000 | seq_head = &tipc_nametbl->seq_hlist[i]; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1001 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) { |
Erik Hugne | 1bb8dce | 2014-03-06 14:40:20 +0100 | [diff] [blame] | 1002 | tipc_purge_publications(seq); |
| 1003 | } |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1004 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1005 | spin_unlock_bh(&tipc_nametbl_lock); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 1006 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1007 | synchronize_net(); |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 1008 | kfree(tipc_nametbl); |
| 1009 | |
Per Liden | b97bf3f | 2006-01-02 19:04:38 +0100 | [diff] [blame] | 1010 | } |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1011 | |
Richard Alpe | d818280 | 2014-11-24 11:10:29 +0100 | [diff] [blame] | 1012 | static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg, |
| 1013 | struct name_seq *seq, |
| 1014 | struct sub_seq *sseq, u32 *last_publ) |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1015 | { |
| 1016 | void *hdr; |
| 1017 | struct nlattr *attrs; |
| 1018 | struct nlattr *publ; |
| 1019 | struct publication *p; |
| 1020 | |
| 1021 | if (*last_publ) { |
| 1022 | list_for_each_entry(p, &sseq->info->zone_list, zone_list) |
| 1023 | if (p->key == *last_publ) |
| 1024 | break; |
| 1025 | if (p->key != *last_publ) |
| 1026 | return -EPIPE; |
| 1027 | } else { |
| 1028 | p = list_first_entry(&sseq->info->zone_list, struct publication, |
| 1029 | zone_list); |
| 1030 | } |
| 1031 | |
| 1032 | list_for_each_entry_from(p, &sseq->info->zone_list, zone_list) { |
| 1033 | *last_publ = p->key; |
| 1034 | |
| 1035 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, |
| 1036 | &tipc_genl_v2_family, NLM_F_MULTI, |
| 1037 | TIPC_NL_NAME_TABLE_GET); |
| 1038 | if (!hdr) |
| 1039 | return -EMSGSIZE; |
| 1040 | |
| 1041 | attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE); |
| 1042 | if (!attrs) |
| 1043 | goto msg_full; |
| 1044 | |
| 1045 | publ = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL); |
| 1046 | if (!publ) |
| 1047 | goto attr_msg_full; |
| 1048 | |
| 1049 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, seq->type)) |
| 1050 | goto publ_msg_full; |
| 1051 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sseq->lower)) |
| 1052 | goto publ_msg_full; |
| 1053 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sseq->upper)) |
| 1054 | goto publ_msg_full; |
| 1055 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope)) |
| 1056 | goto publ_msg_full; |
| 1057 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node)) |
| 1058 | goto publ_msg_full; |
| 1059 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->ref)) |
| 1060 | goto publ_msg_full; |
| 1061 | if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key)) |
| 1062 | goto publ_msg_full; |
| 1063 | |
| 1064 | nla_nest_end(msg->skb, publ); |
| 1065 | nla_nest_end(msg->skb, attrs); |
| 1066 | genlmsg_end(msg->skb, hdr); |
| 1067 | } |
| 1068 | *last_publ = 0; |
| 1069 | |
| 1070 | return 0; |
| 1071 | |
| 1072 | publ_msg_full: |
| 1073 | nla_nest_cancel(msg->skb, publ); |
| 1074 | attr_msg_full: |
| 1075 | nla_nest_cancel(msg->skb, attrs); |
| 1076 | msg_full: |
| 1077 | genlmsg_cancel(msg->skb, hdr); |
| 1078 | |
| 1079 | return -EMSGSIZE; |
| 1080 | } |
| 1081 | |
Richard Alpe | d818280 | 2014-11-24 11:10:29 +0100 | [diff] [blame] | 1082 | static int __tipc_nl_subseq_list(struct tipc_nl_msg *msg, struct name_seq *seq, |
| 1083 | u32 *last_lower, u32 *last_publ) |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1084 | { |
| 1085 | struct sub_seq *sseq; |
| 1086 | struct sub_seq *sseq_start; |
| 1087 | int err; |
| 1088 | |
| 1089 | if (*last_lower) { |
| 1090 | sseq_start = nameseq_find_subseq(seq, *last_lower); |
| 1091 | if (!sseq_start) |
| 1092 | return -EPIPE; |
| 1093 | } else { |
| 1094 | sseq_start = seq->sseqs; |
| 1095 | } |
| 1096 | |
| 1097 | for (sseq = sseq_start; sseq != &seq->sseqs[seq->first_free]; sseq++) { |
| 1098 | err = __tipc_nl_add_nametable_publ(msg, seq, sseq, last_publ); |
| 1099 | if (err) { |
| 1100 | *last_lower = sseq->lower; |
| 1101 | return err; |
| 1102 | } |
| 1103 | } |
| 1104 | *last_lower = 0; |
| 1105 | |
| 1106 | return 0; |
| 1107 | } |
| 1108 | |
Richard Alpe | d818280 | 2014-11-24 11:10:29 +0100 | [diff] [blame] | 1109 | static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type, |
| 1110 | u32 *last_lower, u32 *last_publ) |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1111 | { |
| 1112 | struct hlist_head *seq_head; |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1113 | struct name_seq *seq = NULL; |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1114 | int err; |
| 1115 | int i; |
| 1116 | |
| 1117 | if (*last_type) |
| 1118 | i = hash(*last_type); |
| 1119 | else |
| 1120 | i = 0; |
| 1121 | |
| 1122 | for (; i < TIPC_NAMETBL_SIZE; i++) { |
Ying Xue | 993bfe5 | 2014-12-02 15:00:24 +0800 | [diff] [blame] | 1123 | seq_head = &tipc_nametbl->seq_hlist[i]; |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1124 | |
| 1125 | if (*last_type) { |
| 1126 | seq = nametbl_find_seq(*last_type); |
| 1127 | if (!seq) |
| 1128 | return -EPIPE; |
| 1129 | } else { |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1130 | hlist_for_each_entry_rcu(seq, seq_head, ns_list) |
| 1131 | break; |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1132 | if (!seq) |
| 1133 | continue; |
| 1134 | } |
| 1135 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1136 | hlist_for_each_entry_from_rcu(seq, ns_list) { |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1137 | spin_lock_bh(&seq->lock); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1138 | err = __tipc_nl_subseq_list(msg, seq, last_lower, |
| 1139 | last_publ); |
| 1140 | |
| 1141 | if (err) { |
| 1142 | *last_type = seq->type; |
| 1143 | spin_unlock_bh(&seq->lock); |
| 1144 | return err; |
| 1145 | } |
| 1146 | spin_unlock_bh(&seq->lock); |
| 1147 | } |
| 1148 | *last_type = 0; |
| 1149 | } |
| 1150 | return 0; |
| 1151 | } |
| 1152 | |
| 1153 | int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) |
| 1154 | { |
| 1155 | int err; |
| 1156 | int done = cb->args[3]; |
| 1157 | u32 last_type = cb->args[0]; |
| 1158 | u32 last_lower = cb->args[1]; |
| 1159 | u32 last_publ = cb->args[2]; |
| 1160 | struct tipc_nl_msg msg; |
| 1161 | |
| 1162 | if (done) |
| 1163 | return 0; |
| 1164 | |
| 1165 | msg.skb = skb; |
| 1166 | msg.portid = NETLINK_CB(cb->skb).portid; |
| 1167 | msg.seq = cb->nlh->nlmsg_seq; |
| 1168 | |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1169 | rcu_read_lock(); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1170 | err = __tipc_nl_seq_list(&msg, &last_type, &last_lower, &last_publ); |
| 1171 | if (!err) { |
| 1172 | done = 1; |
| 1173 | } else if (err != -EMSGSIZE) { |
| 1174 | /* We never set seq or call nl_dump_check_consistent() this |
| 1175 | * means that setting prev_seq here will cause the consistence |
| 1176 | * check to fail in the netlink callback handler. Resulting in |
| 1177 | * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if |
| 1178 | * we got an error. |
| 1179 | */ |
| 1180 | cb->prev_seq = 1; |
| 1181 | } |
Ying Xue | 97ede29 | 2014-12-02 15:00:30 +0800 | [diff] [blame^] | 1182 | rcu_read_unlock(); |
Richard Alpe | 1593123 | 2014-11-20 10:29:20 +0100 | [diff] [blame] | 1183 | |
| 1184 | cb->args[0] = last_type; |
| 1185 | cb->args[1] = last_lower; |
| 1186 | cb->args[2] = last_publ; |
| 1187 | cb->args[3] = done; |
| 1188 | |
| 1189 | return skb->len; |
| 1190 | } |