blob: 0d61f582640701d5795947aad97638af6d6dbfb1 [file] [log] [blame]
Per Lidenb97bf3f2006-01-02 19:04:38 +01001/*
2 * net/tipc/name_table.c: TIPC name table code
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +09003 *
Richard Alpe15931232014-11-20 10:29:20 +01004 * Copyright (c) 2000-2006, 2014, Ericsson AB
Ying Xue993bfe52014-12-02 15:00:24 +08005 * Copyright (c) 2004-2008, 2010-2014, Wind River Systems
Per Lidenb97bf3f2006-01-02 19:04:38 +01006 * All rights reserved.
7 *
Per Liden9ea1fd32006-01-11 13:30:43 +01008 * Redistribution and use in source and binary forms, with or without
Per Lidenb97bf3f2006-01-02 19:04:38 +01009 * modification, are permitted provided that the following conditions are met:
10 *
Per Liden9ea1fd32006-01-11 13:30:43 +010011 * 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 Lidenb97bf3f2006-01-02 19:04:38 +010019 *
Per Liden9ea1fd32006-01-11 13:30:43 +010020 * 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 Lidenb97bf3f2006-01-02 19:04:38 +010034 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#include "core.h"
38#include "config.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010039#include "name_table.h"
40#include "name_distr.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010041#include "subscr.h"
Per Lidenb97bf3f2006-01-02 19:04:38 +010042
Ying Xuef046e7d2012-08-16 12:09:11 +000043#define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */
Per Lidenb97bf3f2006-01-02 19:04:38 +010044
Richard Alpe15931232014-11-20 10:29:20 +010045static const struct nla_policy
46tipc_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 Lidenb97bf3f2006-01-02 19:04:38 +010051/**
Allan Stephensb52124a2011-05-30 09:44:38 -040052 * struct name_info - name sequence publication info
Allan Stephens968edbe2008-07-14 22:45:33 -070053 * @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 Lidenb97bf3f2006-01-02 19:04:38 +010063 */
Allan Stephensb52124a2011-05-30 09:44:38 -040064struct name_info {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -040065 struct list_head node_list;
66 struct list_head cluster_list;
67 struct list_head zone_list;
Allan Stephens968edbe2008-07-14 22:45:33 -070068 u32 node_list_size;
69 u32 cluster_list_size;
70 u32 zone_list_size;
Per Lidenb97bf3f2006-01-02 19:04:38 +010071};
72
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +090073/**
Allan Stephensb52124a2011-05-30 09:44:38 -040074 * 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 Stephensb52124a2011-05-30 09:44:38 -040079struct sub_seq {
80 u32 lower;
81 u32 upper;
82 struct name_info *info;
83};
84
85/**
Per Lidenb97bf3f2006-01-02 19:04:38 +010086 * 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 Stephensf1310722006-06-25 23:51:37 -070091 * @first_free: array index of first unused sub-sequence entry
Per Lidenb97bf3f2006-01-02 19:04:38 +010092 * @ns_list: links to adjacent name sequences in hash chain
93 * @subscriptions: list of subscriptions for this 'type'
Allan Stephens307fdf52008-06-04 17:38:22 -070094 * @lock: spinlock controlling access to publication lists of all sub-sequences
Per Lidenb97bf3f2006-01-02 19:04:38 +010095 */
Per Lidenb97bf3f2006-01-02 19:04:38 +010096struct name_seq {
97 u32 type;
98 struct sub_seq *sseqs;
99 u32 alloc;
100 u32 first_free;
101 struct hlist_node ns_list;
102 struct list_head subscriptions;
103 spinlock_t lock;
104};
105
Ying Xue993bfe52014-12-02 15:00:24 +0800106struct name_table *tipc_nametbl;
Ingo Molnar34af9462006-06-27 02:53:55 -0700107DEFINE_RWLOCK(tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100108
Sam Ravnborg05790c62006-03-20 22:37:04 -0800109static int hash(int x)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100110{
Ying Xuef046e7d2012-08-16 12:09:11 +0000111 return x & (TIPC_NAMETBL_SIZE - 1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100112}
113
114/**
115 * publ_create - create a publication structure
116 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900117static struct publication *publ_create(u32 type, u32 lower, u32 upper,
118 u32 scope, u32 node, u32 port_ref,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100119 u32 key)
120{
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700121 struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100122 if (publ == NULL) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400123 pr_warn("Publication creation failure, no memory\n");
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800124 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100125 }
126
Per Lidenb97bf3f2006-01-02 19:04:38 +0100127 publ->type = type;
128 publ->lower = lower;
129 publ->upper = upper;
130 publ->scope = scope;
131 publ->node = node;
132 publ->ref = port_ref;
133 publ->key = key;
134 INIT_LIST_HEAD(&publ->local_list);
135 INIT_LIST_HEAD(&publ->pport_list);
Ying Xuea8f48af2014-11-26 11:41:45 +0800136 INIT_LIST_HEAD(&publ->nodesub_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100137 return publ;
138}
139
140/**
Per Liden4323add2006-01-18 00:38:21 +0100141 * tipc_subseq_alloc - allocate a specified number of sub-sequence structures
Per Lidenb97bf3f2006-01-02 19:04:38 +0100142 */
Adrian Bunk988f0882006-03-20 22:37:52 -0800143static struct sub_seq *tipc_subseq_alloc(u32 cnt)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100144{
wangweidong0cee6bb2013-12-12 09:36:39 +0800145 return kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100146}
147
148/**
Per Liden4323add2006-01-18 00:38:21 +0100149 * tipc_nameseq_create - create a name sequence structure for the specified 'type'
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900150 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100151 * Allocates a single sub-sequence structure and sets it to all 0's.
152 */
Adrian Bunk988f0882006-03-20 22:37:52 -0800153static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100154{
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700155 struct name_seq *nseq = kzalloc(sizeof(*nseq), GFP_ATOMIC);
Per Liden4323add2006-01-18 00:38:21 +0100156 struct sub_seq *sseq = tipc_subseq_alloc(1);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100157
158 if (!nseq || !sseq) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400159 pr_warn("Name sequence creation failed, no memory\n");
Per Lidenb97bf3f2006-01-02 19:04:38 +0100160 kfree(nseq);
161 kfree(sseq);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800162 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100163 }
164
Ingo Molnar34af9462006-06-27 02:53:55 -0700165 spin_lock_init(&nseq->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100166 nseq->type = type;
167 nseq->sseqs = sseq;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100168 nseq->alloc = 1;
169 INIT_HLIST_NODE(&nseq->ns_list);
170 INIT_LIST_HEAD(&nseq->subscriptions);
171 hlist_add_head(&nseq->ns_list, seq_head);
172 return nseq;
173}
174
Ben Hutchings2c530402012-07-10 10:55:09 +0000175/**
Per Lidenb97bf3f2006-01-02 19:04:38 +0100176 * nameseq_find_subseq - find sub-sequence (if any) matching a name instance
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900177 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100178 * Very time-critical, so binary searches through sub-sequence array.
179 */
Sam Ravnborg05790c62006-03-20 22:37:04 -0800180static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq,
181 u32 instance)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100182{
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 Ravnborg1fc54d82006-03-20 22:36:47 -0800197 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100198}
199
200/**
201 * nameseq_locate_subseq - determine position of name instance in sub-sequence
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900202 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100203 * 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 Lidenb97bf3f2006-01-02 19:04:38 +0100209static 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 Gortmaker617d3c72012-04-30 15:29:02 -0400229 * tipc_nameseq_insert_publ
Per Lidenb97bf3f2006-01-02 19:04:38 +0100230 */
Adrian Bunk988f0882006-03-20 22:37:52 -0800231static 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 Lidenb97bf3f2006-01-02 19:04:38 +0100234{
Paul Gortmakerfead3902011-12-29 20:43:44 -0500235 struct tipc_subscription *s;
236 struct tipc_subscription *st;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100237 struct publication *publ;
238 struct sub_seq *sseq;
Allan Stephensb52124a2011-05-30 09:44:38 -0400239 struct name_info *info;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100240 int created_subseq = 0;
241
Per Lidenb97bf3f2006-01-02 19:04:38 +0100242 sseq = nameseq_find_subseq(nseq, lower);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100243 if (sseq) {
244
245 /* Lower end overlaps existing entry => need an exact match */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100246 if ((sseq->lower != lower) || (sseq->upper != upper)) {
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800247 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100248 }
Allan Stephensb52124a2011-05-30 09:44:38 -0400249
250 info = sseq->info;
Allan Stephensf80c24d2011-11-03 11:12:01 -0400251
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 Lidenb97bf3f2006-01-02 19:04:38 +0100258 } else {
259 u32 inspos;
260 struct sub_seq *freesseq;
261
262 /* Find where lower end should be inserted */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100263 inspos = nameseq_locate_subseq(nseq, lower);
264
265 /* Fail if upper end overlaps into an existing entry */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100266 if ((inspos < nseq->first_free) &&
267 (upper >= nseq->sseqs[inspos].lower)) {
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800268 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100269 }
270
271 /* Ensure there is space for new sub-sequence */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100272 if (nseq->first_free == nseq->alloc) {
Allan Stephens9ab230f2006-06-25 23:37:24 -0700273 struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2);
274
275 if (!sseqs) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400276 pr_warn("Cannot publish {%u,%u,%u}, no memory\n",
277 type, lower, upper);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800278 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100279 }
Allan Stephens9ab230f2006-06-25 23:37:24 -0700280 memcpy(sseqs, nseq->sseqs,
281 nseq->alloc * sizeof(struct sub_seq));
282 kfree(nseq->sseqs);
283 nseq->sseqs = sseqs;
284 nseq->alloc *= 2;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100285 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100286
Allan Stephensb52124a2011-05-30 09:44:38 -0400287 info = kzalloc(sizeof(*info), GFP_ATOMIC);
288 if (!info) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400289 pr_warn("Cannot publish {%u,%u,%u}, no memory\n",
290 type, lower, upper);
Allan Stephensb52124a2011-05-30 09:44:38 -0400291 return NULL;
292 }
293
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400294 INIT_LIST_HEAD(&info->node_list);
295 INIT_LIST_HEAD(&info->cluster_list);
296 INIT_LIST_HEAD(&info->zone_list);
297
Per Lidenb97bf3f2006-01-02 19:04:38 +0100298 /* Insert new sub-sequence */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100299 sseq = &nseq->sseqs[inspos];
300 freesseq = &nseq->sseqs[nseq->first_free];
Allan Stephens0e659672010-12-31 18:59:32 +0000301 memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof(*sseq));
302 memset(sseq, 0, sizeof(*sseq));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100303 nseq->first_free++;
304 sseq->lower = lower;
305 sseq->upper = upper;
Allan Stephensb52124a2011-05-30 09:44:38 -0400306 sseq->info = info;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100307 created_subseq = 1;
308 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100309
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400310 /* Insert a publication */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100311 publ = publ_create(type, lower, upper, scope, node, port, key);
312 if (!publ)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800313 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100314
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400315 list_add(&publ->zone_list, &info->zone_list);
Allan Stephensb52124a2011-05-30 09:44:38 -0400316 info->zone_list_size++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100317
Allan Stephensd4f5c122012-04-17 18:16:34 -0400318 if (in_own_cluster(node)) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400319 list_add(&publ->cluster_list, &info->cluster_list);
Allan Stephensb52124a2011-05-30 09:44:38 -0400320 info->cluster_list_size++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100321 }
322
Allan Stephensd4f5c122012-04-17 18:16:34 -0400323 if (in_own_node(node)) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400324 list_add(&publ->node_list, &info->node_list);
Allan Stephensb52124a2011-05-30 09:44:38 -0400325 info->node_list_size++;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100326 }
327
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400328 /* Any subscriptions waiting for notification? */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100329 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
Per Liden4323add2006-01-18 00:38:21 +0100330 tipc_subscr_report_overlap(s,
331 publ->lower,
332 publ->upper,
333 TIPC_PUBLISHED,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900334 publ->ref,
Per Liden4323add2006-01-18 00:38:21 +0100335 publ->node,
336 created_subseq);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100337 }
338 return publ;
339}
340
341/**
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400342 * tipc_nameseq_remove_publ
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900343 *
Allan Stephensf1310722006-06-25 23:51:37 -0700344 * 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 Lidenb97bf3f2006-01-02 19:04:38 +0100351 */
Adrian Bunk988f0882006-03-20 22:37:52 -0800352static struct publication *tipc_nameseq_remove_publ(struct name_seq *nseq, u32 inst,
353 u32 node, u32 ref, u32 key)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100354{
355 struct publication *publ;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100356 struct sub_seq *sseq = nameseq_find_subseq(nseq, inst);
Allan Stephensb52124a2011-05-30 09:44:38 -0400357 struct name_info *info;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100358 struct sub_seq *free;
Paul Gortmakerfead3902011-12-29 20:43:44 -0500359 struct tipc_subscription *s, *st;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100360 int removed_subseq = 0;
361
Allan Stephensf1310722006-06-25 23:51:37 -0700362 if (!sseq)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800363 return NULL;
Allan Stephensf1310722006-06-25 23:51:37 -0700364
Allan Stephensb52124a2011-05-30 09:44:38 -0400365 info = sseq->info;
366
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400367 /* Locate publication, if it exists */
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400368 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
375found:
Allan Stephensf1310722006-06-25 23:51:37 -0700376 /* Remove publication from zone scope list */
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400377 list_del(&publ->zone_list);
Allan Stephensb52124a2011-05-30 09:44:38 -0400378 info->zone_list_size--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100379
Allan Stephensf1310722006-06-25 23:51:37 -0700380 /* Remove publication from cluster scope list, if present */
Allan Stephensd4f5c122012-04-17 18:16:34 -0400381 if (in_own_cluster(node)) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400382 list_del(&publ->cluster_list);
Allan Stephensb52124a2011-05-30 09:44:38 -0400383 info->cluster_list_size--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100384 }
Allan Stephensf1310722006-06-25 23:51:37 -0700385
386 /* Remove publication from node scope list, if present */
Allan Stephensd4f5c122012-04-17 18:16:34 -0400387 if (in_own_node(node)) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400388 list_del(&publ->node_list);
Allan Stephensb52124a2011-05-30 09:44:38 -0400389 info->node_list_size--;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100390 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100391
Allan Stephensf1310722006-06-25 23:51:37 -0700392 /* Contract subseq list if no more publications for that subseq */
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400393 if (list_empty(&info->zone_list)) {
Allan Stephensb52124a2011-05-30 09:44:38 -0400394 kfree(info);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100395 free = &nseq->sseqs[nseq->first_free--];
Allan Stephens0e659672010-12-31 18:59:32 +0000396 memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100397 removed_subseq = 1;
398 }
399
Allan Stephensf1310722006-06-25 23:51:37 -0700400 /* Notify any waiting subscriptions */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100401 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
Per Liden4323add2006-01-18 00:38:21 +0100402 tipc_subscr_report_overlap(s,
403 publ->lower,
404 publ->upper,
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900405 TIPC_WITHDRAWN,
406 publ->ref,
Per Liden4323add2006-01-18 00:38:21 +0100407 publ->node,
408 removed_subseq);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100409 }
Allan Stephensf1310722006-06-25 23:51:37 -0700410
Per Lidenb97bf3f2006-01-02 19:04:38 +0100411 return publ;
412}
413
414/**
Ben Hutchings2c530402012-07-10 10:55:09 +0000415 * tipc_nameseq_subscribe - attach a subscription, and issue
Per Lidenb97bf3f2006-01-02 19:04:38 +0100416 * the prescribed number of events if there is any sub-
417 * sequence overlapping with the requested sequence
418 */
Paul Gortmakerfead3902011-12-29 20:43:44 -0500419static void tipc_nameseq_subscribe(struct name_seq *nseq,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400420 struct tipc_subscription *s)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100421{
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 Stephensf6f0a4d2011-05-30 10:48:48 -0400430 if (tipc_subscr_overlap(s, sseq->lower, sseq->upper)) {
431 struct publication *crs;
432 struct name_info *info = sseq->info;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100433 int must_report = 1;
434
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400435 list_for_each_entry(crs, &info->zone_list, zone_list) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900436 tipc_subscr_report_overlap(s,
437 sseq->lower,
Per Liden4323add2006-01-18 00:38:21 +0100438 sseq->upper,
439 TIPC_PUBLISHED,
440 crs->ref,
441 crs->node,
442 must_report);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100443 must_report = 0;
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400444 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100445 }
446 sseq++;
447 }
448}
449
450static struct name_seq *nametbl_find_seq(u32 type)
451{
452 struct hlist_head *seq_head;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100453 struct name_seq *ns;
454
Ying Xue993bfe52014-12-02 15:00:24 +0800455 seq_head = &tipc_nametbl->seq_hlist[hash(type)];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800456 hlist_for_each_entry(ns, seq_head, ns_list) {
Allan Stephensb29f1422010-12-31 18:59:25 +0000457 if (ns->type == type)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100458 return ns;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100459 }
460
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800461 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100462};
463
Per Liden4323add2006-01-18 00:38:21 +0100464struct publication *tipc_nametbl_insert_publ(u32 type, u32 lower, u32 upper,
465 u32 scope, u32 node, u32 port, u32 key)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100466{
Ying Xuefb9962f2014-12-02 15:00:26 +0800467 struct publication *publ;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100468 struct name_seq *seq = nametbl_find_seq(type);
Ying Xue993bfe52014-12-02 15:00:24 +0800469 int index = hash(type);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100470
Allan Stephens8f177892012-04-26 17:57:17 -0400471 if ((scope < TIPC_ZONE_SCOPE) || (scope > TIPC_NODE_SCOPE) ||
472 (lower > upper)) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400473 pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n",
474 type, lower, upper, scope);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800475 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100476 }
477
Allan Stephensb29f1422010-12-31 18:59:25 +0000478 if (!seq)
Ying Xue993bfe52014-12-02 15:00:24 +0800479 seq = tipc_nameseq_create(type,
480 &tipc_nametbl->seq_hlist[index]);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100481 if (!seq)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800482 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100483
Ying Xuefb9962f2014-12-02 15:00:26 +0800484 spin_lock_bh(&seq->lock);
485 publ = tipc_nameseq_insert_publ(seq, type, lower, upper,
Per Liden4323add2006-01-18 00:38:21 +0100486 scope, node, port, key);
Ying Xuefb9962f2014-12-02 15:00:26 +0800487 spin_unlock_bh(&seq->lock);
488 return publ;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100489}
490
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900491struct publication *tipc_nametbl_remove_publ(u32 type, u32 lower,
Per Liden4323add2006-01-18 00:38:21 +0100492 u32 node, u32 ref, u32 key)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100493{
494 struct publication *publ;
495 struct name_seq *seq = nametbl_find_seq(type);
496
497 if (!seq)
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800498 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100499
Ying Xuefb9962f2014-12-02 15:00:26 +0800500 spin_lock_bh(&seq->lock);
Per Liden4323add2006-01-18 00:38:21 +0100501 publ = tipc_nameseq_remove_publ(seq, lower, node, ref, key);
Ying Xuefb9962f2014-12-02 15:00:26 +0800502 if (!seq->first_free && list_empty(&seq->subscriptions)) {
503 hlist_del_init(&seq->ns_list);
504 spin_unlock_bh(&seq->lock);
505 kfree(seq->sseqs);
506 kfree(seq);
507 return publ;
508 }
509 spin_unlock_bh(&seq->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100510 return publ;
511}
512
Ben Hutchings2c530402012-07-10 10:55:09 +0000513/**
Allan Stephensbc9f8142011-11-07 17:00:54 -0500514 * tipc_nametbl_translate - perform name translation
Per Lidenb97bf3f2006-01-02 19:04:38 +0100515 *
Allan Stephensbc9f8142011-11-07 17:00:54 -0500516 * 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 Lidenb97bf3f2006-01-02 19:04:38 +0100525 */
Per Liden4323add2006-01-18 00:38:21 +0100526u32 tipc_nametbl_translate(u32 type, u32 instance, u32 *destnode)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100527{
528 struct sub_seq *sseq;
Allan Stephensb52124a2011-05-30 09:44:38 -0400529 struct name_info *info;
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400530 struct publication *publ;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100531 struct name_seq *seq;
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400532 u32 ref = 0;
Allan Stephensbc9f8142011-11-07 17:00:54 -0500533 u32 node = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100534
Allan Stephensc68ca7b2010-05-11 14:30:12 +0000535 if (!tipc_in_scope(*destnode, tipc_own_addr))
Per Lidenb97bf3f2006-01-02 19:04:38 +0100536 return 0;
537
Per Liden4323add2006-01-18 00:38:21 +0100538 read_lock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100539 seq = nametbl_find_seq(type);
540 if (unlikely(!seq))
541 goto not_found;
Ying Xuefb9962f2014-12-02 15:00:26 +0800542 spin_lock_bh(&seq->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100543 sseq = nameseq_find_subseq(seq, instance);
544 if (unlikely(!sseq))
Ying Xuefb9962f2014-12-02 15:00:26 +0800545 goto no_match;
Allan Stephensb52124a2011-05-30 09:44:38 -0400546 info = sseq->info;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100547
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400548 /* Closest-First Algorithm */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100549 if (likely(!*destnode)) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400550 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 Stephens8af46382011-05-30 11:27:50 -0400562 } else {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400563 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 Stephens8af46382011-05-30 11:27:50 -0400568 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100569 }
570
Paul Gortmaker617d3c72012-04-30 15:29:02 -0400571 /* Round-Robin Algorithm */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100572 else if (*destnode == tipc_own_addr) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400573 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 Stephens336ebf52012-04-17 18:02:01 -0400578 } else if (in_own_cluster_exact(*destnode)) {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400579 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 Lidenb97bf3f2006-01-02 19:04:38 +0100584 } else {
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400585 publ = list_first_entry(&info->zone_list, struct publication,
586 zone_list);
587 list_move_tail(&publ->zone_list, &info->zone_list);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100588 }
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400589
590 ref = publ->ref;
Allan Stephensbc9f8142011-11-07 17:00:54 -0500591 node = publ->node;
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400592no_match:
Per Lidenb97bf3f2006-01-02 19:04:38 +0100593 spin_unlock_bh(&seq->lock);
594not_found:
Per Liden4323add2006-01-18 00:38:21 +0100595 read_unlock_bh(&tipc_nametbl_lock);
Allan Stephensbc9f8142011-11-07 17:00:54 -0500596 *destnode = node;
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400597 return ref;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100598}
599
600/**
Per Liden4323add2006-01-18 00:38:21 +0100601 * tipc_nametbl_mc_translate - find multicast destinations
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900602 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100603 * 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 Hideakic4307282007-02-09 23:25:21 +0900609 *
Per Lidenb97bf3f2006-01-02 19:04:38 +0100610 * Returns non-zero if any off-node ports overlap
611 */
Per Liden4323add2006-01-18 00:38:21 +0100612int tipc_nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit,
Paul Gortmaker45843102011-12-29 20:33:30 -0500613 struct tipc_port_list *dports)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100614{
615 struct name_seq *seq;
616 struct sub_seq *sseq;
617 struct sub_seq *sseq_stop;
Allan Stephensb52124a2011-05-30 09:44:38 -0400618 struct name_info *info;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100619 int res = 0;
620
Per Liden4323add2006-01-18 00:38:21 +0100621 read_lock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100622 seq = nametbl_find_seq(type);
623 if (!seq)
624 goto exit;
625
626 spin_lock_bh(&seq->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100627 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 Stephens968edbe2008-07-14 22:45:33 -0700634
Allan Stephensb52124a2011-05-30 09:44:38 -0400635 info = sseq->info;
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400636 list_for_each_entry(publ, &info->node_list, node_list) {
637 if (publ->scope <= limit)
638 tipc_port_list_add(dports, publ->ref);
Allan Stephens968edbe2008-07-14 22:45:33 -0700639 }
640
Allan Stephensb52124a2011-05-30 09:44:38 -0400641 if (info->cluster_list_size != info->node_list_size)
Allan Stephens968edbe2008-07-14 22:45:33 -0700642 res = 1;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100643 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100644 spin_unlock_bh(&seq->lock);
645exit:
Per Liden4323add2006-01-18 00:38:21 +0100646 read_unlock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100647 return res;
648}
649
Allan Stephensc422f1b2011-11-02 15:49:40 -0400650/*
Per Liden4323add2006-01-18 00:38:21 +0100651 * tipc_nametbl_publish - add name publication to network name tables
Per Lidenb97bf3f2006-01-02 19:04:38 +0100652 */
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900653struct publication *tipc_nametbl_publish(u32 type, u32 lower, u32 upper,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400654 u32 scope, u32 port_ref, u32 key)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100655{
656 struct publication *publ;
Ying Xueeab8c0452014-04-28 18:00:10 +0800657 struct sk_buff *buf = NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100658
Ying Xue993bfe52014-12-02 15:00:24 +0800659 if (tipc_nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400660 pr_warn("Publication failed, local publication limit reached (%u)\n",
Ying Xuee6a04b12012-08-16 12:09:14 +0000661 TIPC_MAX_PUBLICATIONS);
Sam Ravnborg1fc54d82006-03-20 22:36:47 -0800662 return NULL;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100663 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100664
Per Liden4323add2006-01-18 00:38:21 +0100665 write_lock_bh(&tipc_nametbl_lock);
Per Liden4323add2006-01-18 00:38:21 +0100666 publ = tipc_nametbl_insert_publ(type, lower, upper, scope,
Per Lidenb97bf3f2006-01-02 19:04:38 +0100667 tipc_own_addr, port_ref, key);
Allan Stephensfd6eced2011-11-09 14:22:52 -0500668 if (likely(publ)) {
Ying Xue993bfe52014-12-02 15:00:24 +0800669 tipc_nametbl->local_publ_count++;
Ying Xueeab8c0452014-04-28 18:00:10 +0800670 buf = tipc_named_publish(publ);
Erik Hugnea5325ae2014-08-28 09:08:47 +0200671 /* Any pending external events? */
672 tipc_named_process_backlog();
Allan Stephensfd6eced2011-11-09 14:22:52 -0500673 }
Per Liden4323add2006-01-18 00:38:21 +0100674 write_unlock_bh(&tipc_nametbl_lock);
Ying Xueeab8c0452014-04-28 18:00:10 +0800675
676 if (buf)
677 named_cluster_distribute(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100678 return publ;
679}
680
681/**
Per Liden4323add2006-01-18 00:38:21 +0100682 * tipc_nametbl_withdraw - withdraw name publication from network name tables
Per Lidenb97bf3f2006-01-02 19:04:38 +0100683 */
Per Liden4323add2006-01-18 00:38:21 +0100684int tipc_nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100685{
686 struct publication *publ;
Ying Xueeab8c0452014-04-28 18:00:10 +0800687 struct sk_buff *buf;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100688
Per Liden4323add2006-01-18 00:38:21 +0100689 write_lock_bh(&tipc_nametbl_lock);
690 publ = tipc_nametbl_remove_publ(type, lower, tipc_own_addr, ref, key);
Allan Stephensf1310722006-06-25 23:51:37 -0700691 if (likely(publ)) {
Ying Xue993bfe52014-12-02 15:00:24 +0800692 tipc_nametbl->local_publ_count--;
Ying Xueeab8c0452014-04-28 18:00:10 +0800693 buf = tipc_named_withdraw(publ);
Erik Hugnea5325ae2014-08-28 09:08:47 +0200694 /* Any pending external events? */
695 tipc_named_process_backlog();
Per Liden4323add2006-01-18 00:38:21 +0100696 write_unlock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100697 list_del_init(&publ->pport_list);
698 kfree(publ);
Ying Xueeab8c0452014-04-28 18:00:10 +0800699
700 if (buf)
701 named_cluster_distribute(buf);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100702 return 1;
703 }
Per Liden4323add2006-01-18 00:38:21 +0100704 write_unlock_bh(&tipc_nametbl_lock);
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400705 pr_err("Unable to remove local publication\n"
706 "(type=%u, lower=%u, ref=%u, key=%u)\n",
707 type, lower, ref, key);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100708 return 0;
709}
710
711/**
Per Liden4323add2006-01-18 00:38:21 +0100712 * tipc_nametbl_subscribe - add a subscription object to the name table
Per Lidenb97bf3f2006-01-02 19:04:38 +0100713 */
Paul Gortmakerfead3902011-12-29 20:43:44 -0500714void tipc_nametbl_subscribe(struct tipc_subscription *s)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100715{
716 u32 type = s->seq.type;
Ying Xue993bfe52014-12-02 15:00:24 +0800717 int index = hash(type);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100718 struct name_seq *seq;
719
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900720 write_lock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100721 seq = nametbl_find_seq(type);
Allan Stephensa0168922010-12-31 18:59:35 +0000722 if (!seq)
Ying Xue993bfe52014-12-02 15:00:24 +0800723 seq = tipc_nameseq_create(type,
724 &tipc_nametbl->seq_hlist[index]);
Allan Stephens0e659672010-12-31 18:59:32 +0000725 if (seq) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900726 spin_lock_bh(&seq->lock);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900727 tipc_nameseq_subscribe(seq, s);
728 spin_unlock_bh(&seq->lock);
729 } else {
Erik Hugne2cf8aa12012-06-29 00:16:37 -0400730 pr_warn("Failed to create subscription for {%u,%u,%u}\n",
731 s->seq.type, s->seq.lower, s->seq.upper);
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900732 }
733 write_unlock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100734}
735
736/**
Per Liden4323add2006-01-18 00:38:21 +0100737 * tipc_nametbl_unsubscribe - remove a subscription object from name table
Per Lidenb97bf3f2006-01-02 19:04:38 +0100738 */
Paul Gortmakerfead3902011-12-29 20:43:44 -0500739void tipc_nametbl_unsubscribe(struct tipc_subscription *s)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100740{
741 struct name_seq *seq;
742
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900743 write_lock_bh(&tipc_nametbl_lock);
744 seq = nametbl_find_seq(s->seq.type);
Allan Stephens0e659672010-12-31 18:59:32 +0000745 if (seq != NULL) {
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900746 spin_lock_bh(&seq->lock);
747 list_del_init(&s->nameseq_list);
Ying Xuefb9962f2014-12-02 15:00:26 +0800748 if (!seq->first_free && list_empty(&seq->subscriptions)) {
749 hlist_del_init(&seq->ns_list);
750 spin_unlock_bh(&seq->lock);
751 kfree(seq->sseqs);
752 kfree(seq);
753 } else {
754 spin_unlock_bh(&seq->lock);
755 }
YOSHIFUJI Hideakic4307282007-02-09 23:25:21 +0900756 }
757 write_unlock_bh(&tipc_nametbl_lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100758}
759
760
761/**
Ben Hutchings2c530402012-07-10 10:55:09 +0000762 * subseq_list - print specified sub-sequence contents into the given buffer
Per Lidenb97bf3f2006-01-02 19:04:38 +0100763 */
Erik Hugnedc1aed32012-06-29 00:50:23 -0400764static int subseq_list(struct sub_seq *sseq, char *buf, int len, u32 depth,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400765 u32 index)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100766{
767 char portIdStr[27];
Allan Stephensc2de5812010-08-17 11:00:14 +0000768 const char *scope_str[] = {"", " zone", " cluster", " node"};
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400769 struct publication *publ;
770 struct name_info *info;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400771 int ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100772
Erik Hugnedc1aed32012-06-29 00:50:23 -0400773 ret = tipc_snprintf(buf, len, "%-10u %-10u ", sseq->lower, sseq->upper);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100774
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400775 if (depth == 2) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400776 ret += tipc_snprintf(buf - ret, len + ret, "\n");
777 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100778 }
779
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400780 info = sseq->info;
781
782 list_for_each_entry(publ, &info->zone_list, zone_list) {
Allan Stephens0e659672010-12-31 18:59:32 +0000783 sprintf(portIdStr, "<%u.%u.%u:%u>",
Per Lidenb97bf3f2006-01-02 19:04:38 +0100784 tipc_zone(publ->node), tipc_cluster(publ->node),
785 tipc_node(publ->node), publ->ref);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400786 ret += tipc_snprintf(buf + ret, len - ret, "%-26s ", portIdStr);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100787 if (depth > 3) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400788 ret += tipc_snprintf(buf + ret, len - ret, "%-10u %s",
789 publ->key, scope_str[publ->scope]);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100790 }
Allan Stephensf6f0a4d2011-05-30 10:48:48 -0400791 if (!list_is_last(&publ->zone_list, &info->zone_list))
Erik Hugnedc1aed32012-06-29 00:50:23 -0400792 ret += tipc_snprintf(buf + ret, len - ret,
793 "\n%33s", " ");
Peter Senna Tschudinadccff32012-09-18 07:10:45 +0000794 }
Per Lidenb97bf3f2006-01-02 19:04:38 +0100795
Erik Hugnedc1aed32012-06-29 00:50:23 -0400796 ret += tipc_snprintf(buf + ret, len - ret, "\n");
797 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100798}
799
800/**
Ben Hutchings2c530402012-07-10 10:55:09 +0000801 * nameseq_list - print specified name sequence contents into the given buffer
Per Lidenb97bf3f2006-01-02 19:04:38 +0100802 */
Erik Hugnedc1aed32012-06-29 00:50:23 -0400803static int nameseq_list(struct name_seq *seq, char *buf, int len, u32 depth,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400804 u32 type, u32 lowbound, u32 upbound, u32 index)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100805{
806 struct sub_seq *sseq;
807 char typearea[11];
Erik Hugnedc1aed32012-06-29 00:50:23 -0400808 int ret = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100809
Allan Stephens0f15d362008-06-04 17:37:59 -0700810 if (seq->first_free == 0)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400811 return 0;
Allan Stephens0f15d362008-06-04 17:37:59 -0700812
Per Lidenb97bf3f2006-01-02 19:04:38 +0100813 sprintf(typearea, "%-10u", seq->type);
814
815 if (depth == 1) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400816 ret += tipc_snprintf(buf, len, "%s\n", typearea);
817 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100818 }
819
820 for (sseq = seq->sseqs; sseq != &seq->sseqs[seq->first_free]; sseq++) {
821 if ((lowbound <= sseq->upper) && (upbound >= sseq->lower)) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400822 ret += tipc_snprintf(buf + ret, len - ret, "%s ",
823 typearea);
Allan Stephens307fdf52008-06-04 17:38:22 -0700824 spin_lock_bh(&seq->lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400825 ret += subseq_list(sseq, buf + ret, len - ret,
826 depth, index);
Allan Stephens307fdf52008-06-04 17:38:22 -0700827 spin_unlock_bh(&seq->lock);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100828 sprintf(typearea, "%10s", " ");
829 }
830 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400831 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100832}
833
834/**
835 * nametbl_header - print name table header into the given buffer
836 */
Erik Hugnedc1aed32012-06-29 00:50:23 -0400837static int nametbl_header(char *buf, int len, u32 depth)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100838{
Allan Stephensc2de5812010-08-17 11:00:14 +0000839 const char *header[] = {
840 "Type ",
841 "Lower Upper ",
842 "Port Identity ",
843 "Publication Scope"
844 };
Per Lidenb97bf3f2006-01-02 19:04:38 +0100845
Allan Stephensc2de5812010-08-17 11:00:14 +0000846 int i;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400847 int ret = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100848
Allan Stephensc2de5812010-08-17 11:00:14 +0000849 if (depth > 4)
850 depth = 4;
851 for (i = 0; i < depth; i++)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400852 ret += tipc_snprintf(buf + ret, len - ret, header[i]);
853 ret += tipc_snprintf(buf + ret, len - ret, "\n");
854 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100855}
856
857/**
858 * nametbl_list - print specified name table contents into the given buffer
859 */
Erik Hugnedc1aed32012-06-29 00:50:23 -0400860static int nametbl_list(char *buf, int len, u32 depth_info,
Paul Gortmakerae8509c2013-06-17 10:54:47 -0400861 u32 type, u32 lowbound, u32 upbound)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100862{
863 struct hlist_head *seq_head;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100864 struct name_seq *seq;
865 int all_types;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400866 int ret = 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100867 u32 depth;
868 u32 i;
869
870 all_types = (depth_info & TIPC_NTQ_ALLTYPES);
871 depth = (depth_info & ~TIPC_NTQ_ALLTYPES);
872
873 if (depth == 0)
Erik Hugnedc1aed32012-06-29 00:50:23 -0400874 return 0;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100875
876 if (all_types) {
877 /* display all entries in name table to specified depth */
Erik Hugnedc1aed32012-06-29 00:50:23 -0400878 ret += nametbl_header(buf, len, depth);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100879 lowbound = 0;
880 upbound = ~0;
Ying Xuef046e7d2012-08-16 12:09:11 +0000881 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
Ying Xue993bfe52014-12-02 15:00:24 +0800882 seq_head = &tipc_nametbl->seq_hlist[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800883 hlist_for_each_entry(seq, seq_head, ns_list) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400884 ret += nameseq_list(seq, buf + ret, len - ret,
885 depth, seq->type,
886 lowbound, upbound, i);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100887 }
888 }
889 } else {
890 /* display only the sequence that matches the specified type */
891 if (upbound < lowbound) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400892 ret += tipc_snprintf(buf + ret, len - ret,
893 "invalid name sequence specified\n");
894 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100895 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400896 ret += nametbl_header(buf + ret, len - ret, depth);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100897 i = hash(type);
Ying Xue993bfe52014-12-02 15:00:24 +0800898 seq_head = &tipc_nametbl->seq_hlist[i];
Sasha Levinb67bfe02013-02-27 17:06:00 -0800899 hlist_for_each_entry(seq, seq_head, ns_list) {
Per Lidenb97bf3f2006-01-02 19:04:38 +0100900 if (seq->type == type) {
Erik Hugnedc1aed32012-06-29 00:50:23 -0400901 ret += nameseq_list(seq, buf + ret, len - ret,
902 depth, type,
903 lowbound, upbound, i);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100904 break;
905 }
906 }
907 }
Erik Hugnedc1aed32012-06-29 00:50:23 -0400908 return ret;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100909}
910
Per Liden4323add2006-01-18 00:38:21 +0100911struct sk_buff *tipc_nametbl_get(const void *req_tlv_area, int req_tlv_space)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100912{
913 struct sk_buff *buf;
914 struct tipc_name_table_query *argv;
915 struct tlv_desc *rep_tlv;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400916 char *pb;
917 int pb_len;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100918 int str_len;
919
920 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NAME_TBL_QUERY))
Per Liden4323add2006-01-18 00:38:21 +0100921 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100922
Erik Hugnedc1aed32012-06-29 00:50:23 -0400923 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
Per Lidenb97bf3f2006-01-02 19:04:38 +0100924 if (!buf)
925 return NULL;
926
927 rep_tlv = (struct tlv_desc *)buf->data;
Erik Hugnedc1aed32012-06-29 00:50:23 -0400928 pb = TLV_DATA(rep_tlv);
929 pb_len = ULTRA_STRING_MAX_LEN;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100930 argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area);
Per Liden4323add2006-01-18 00:38:21 +0100931 read_lock_bh(&tipc_nametbl_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400932 str_len = nametbl_list(pb, pb_len, ntohl(argv->depth),
933 ntohl(argv->type),
934 ntohl(argv->lowbound), ntohl(argv->upbound));
Per Liden4323add2006-01-18 00:38:21 +0100935 read_unlock_bh(&tipc_nametbl_lock);
Erik Hugnedc1aed32012-06-29 00:50:23 -0400936 str_len += 1; /* for "\0" */
Per Lidenb97bf3f2006-01-02 19:04:38 +0100937 skb_put(buf, TLV_SPACE(str_len));
938 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
939
940 return buf;
941}
942
Per Liden4323add2006-01-18 00:38:21 +0100943int tipc_nametbl_init(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100944{
Ying Xue993bfe52014-12-02 15:00:24 +0800945 int i;
946
947 tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC);
948 if (!tipc_nametbl)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100949 return -ENOMEM;
950
Ying Xue993bfe52014-12-02 15:00:24 +0800951 for (i = 0; i < TIPC_NAMETBL_SIZE; i++)
952 INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]);
953
954 INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_ZONE_SCOPE]);
955 INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_CLUSTER_SCOPE]);
956 INIT_LIST_HEAD(&tipc_nametbl->publ_list[TIPC_NODE_SCOPE]);
Per Lidenb97bf3f2006-01-02 19:04:38 +0100957 return 0;
958}
959
Erik Hugne1bb8dce2014-03-06 14:40:20 +0100960/**
961 * tipc_purge_publications - remove all publications for a given type
962 *
963 * tipc_nametbl_lock must be held when calling this function
964 */
965static void tipc_purge_publications(struct name_seq *seq)
966{
967 struct publication *publ, *safe;
968 struct sub_seq *sseq;
969 struct name_info *info;
970
Ying Xuefb9962f2014-12-02 15:00:26 +0800971 spin_lock_bh(&seq->lock);
Erik Hugne1bb8dce2014-03-06 14:40:20 +0100972 sseq = seq->sseqs;
973 info = sseq->info;
974 list_for_each_entry_safe(publ, safe, &info->zone_list, zone_list) {
975 tipc_nametbl_remove_publ(publ->type, publ->lower, publ->node,
976 publ->ref, publ->key);
Ying Xue1621b942014-04-29 11:12:18 +0800977 kfree(publ);
Erik Hugne1bb8dce2014-03-06 14:40:20 +0100978 }
Ying Xue38622f42014-12-02 15:00:25 +0800979 hlist_del_init(&seq->ns_list);
Ying Xuefb9962f2014-12-02 15:00:26 +0800980 spin_lock_bh(&seq->lock);
981
Ying Xue38622f42014-12-02 15:00:25 +0800982 kfree(seq->sseqs);
983 kfree(seq);
Erik Hugne1bb8dce2014-03-06 14:40:20 +0100984}
985
Per Liden4323add2006-01-18 00:38:21 +0100986void tipc_nametbl_stop(void)
Per Lidenb97bf3f2006-01-02 19:04:38 +0100987{
Per Lidenb97bf3f2006-01-02 19:04:38 +0100988 u32 i;
Erik Hugne1bb8dce2014-03-06 14:40:20 +0100989 struct name_seq *seq;
990 struct hlist_head *seq_head;
991 struct hlist_node *safe;
Per Lidenb97bf3f2006-01-02 19:04:38 +0100992
Erik Hugne1bb8dce2014-03-06 14:40:20 +0100993 /* Verify name table is empty and purge any lingering
994 * publications, then release the name table
995 */
Per Liden4323add2006-01-18 00:38:21 +0100996 write_lock_bh(&tipc_nametbl_lock);
Ying Xuef046e7d2012-08-16 12:09:11 +0000997 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
Ying Xue993bfe52014-12-02 15:00:24 +0800998 if (hlist_empty(&tipc_nametbl->seq_hlist[i]))
Paul Gortmakerf705ab92012-07-11 17:35:01 -0400999 continue;
Ying Xue993bfe52014-12-02 15:00:24 +08001000 seq_head = &tipc_nametbl->seq_hlist[i];
Erik Hugne1bb8dce2014-03-06 14:40:20 +01001001 hlist_for_each_entry_safe(seq, safe, seq_head, ns_list) {
1002 tipc_purge_publications(seq);
1003 }
Per Lidenb97bf3f2006-01-02 19:04:38 +01001004 }
Per Liden4323add2006-01-18 00:38:21 +01001005 write_unlock_bh(&tipc_nametbl_lock);
Ying Xue993bfe52014-12-02 15:00:24 +08001006
1007 kfree(tipc_nametbl);
1008
Per Lidenb97bf3f2006-01-02 19:04:38 +01001009}
Richard Alpe15931232014-11-20 10:29:20 +01001010
Richard Alped8182802014-11-24 11:10:29 +01001011static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg,
1012 struct name_seq *seq,
1013 struct sub_seq *sseq, u32 *last_publ)
Richard Alpe15931232014-11-20 10:29:20 +01001014{
1015 void *hdr;
1016 struct nlattr *attrs;
1017 struct nlattr *publ;
1018 struct publication *p;
1019
1020 if (*last_publ) {
1021 list_for_each_entry(p, &sseq->info->zone_list, zone_list)
1022 if (p->key == *last_publ)
1023 break;
1024 if (p->key != *last_publ)
1025 return -EPIPE;
1026 } else {
1027 p = list_first_entry(&sseq->info->zone_list, struct publication,
1028 zone_list);
1029 }
1030
1031 list_for_each_entry_from(p, &sseq->info->zone_list, zone_list) {
1032 *last_publ = p->key;
1033
1034 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq,
1035 &tipc_genl_v2_family, NLM_F_MULTI,
1036 TIPC_NL_NAME_TABLE_GET);
1037 if (!hdr)
1038 return -EMSGSIZE;
1039
1040 attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE);
1041 if (!attrs)
1042 goto msg_full;
1043
1044 publ = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL);
1045 if (!publ)
1046 goto attr_msg_full;
1047
1048 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, seq->type))
1049 goto publ_msg_full;
1050 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sseq->lower))
1051 goto publ_msg_full;
1052 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sseq->upper))
1053 goto publ_msg_full;
1054 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope))
1055 goto publ_msg_full;
1056 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node))
1057 goto publ_msg_full;
1058 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->ref))
1059 goto publ_msg_full;
1060 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key))
1061 goto publ_msg_full;
1062
1063 nla_nest_end(msg->skb, publ);
1064 nla_nest_end(msg->skb, attrs);
1065 genlmsg_end(msg->skb, hdr);
1066 }
1067 *last_publ = 0;
1068
1069 return 0;
1070
1071publ_msg_full:
1072 nla_nest_cancel(msg->skb, publ);
1073attr_msg_full:
1074 nla_nest_cancel(msg->skb, attrs);
1075msg_full:
1076 genlmsg_cancel(msg->skb, hdr);
1077
1078 return -EMSGSIZE;
1079}
1080
Richard Alped8182802014-11-24 11:10:29 +01001081static int __tipc_nl_subseq_list(struct tipc_nl_msg *msg, struct name_seq *seq,
1082 u32 *last_lower, u32 *last_publ)
Richard Alpe15931232014-11-20 10:29:20 +01001083{
1084 struct sub_seq *sseq;
1085 struct sub_seq *sseq_start;
1086 int err;
1087
1088 if (*last_lower) {
1089 sseq_start = nameseq_find_subseq(seq, *last_lower);
1090 if (!sseq_start)
1091 return -EPIPE;
1092 } else {
1093 sseq_start = seq->sseqs;
1094 }
1095
1096 for (sseq = sseq_start; sseq != &seq->sseqs[seq->first_free]; sseq++) {
1097 err = __tipc_nl_add_nametable_publ(msg, seq, sseq, last_publ);
1098 if (err) {
1099 *last_lower = sseq->lower;
1100 return err;
1101 }
1102 }
1103 *last_lower = 0;
1104
1105 return 0;
1106}
1107
Richard Alped8182802014-11-24 11:10:29 +01001108static int __tipc_nl_seq_list(struct tipc_nl_msg *msg, u32 *last_type,
1109 u32 *last_lower, u32 *last_publ)
Richard Alpe15931232014-11-20 10:29:20 +01001110{
1111 struct hlist_head *seq_head;
1112 struct name_seq *seq;
1113 int err;
1114 int i;
1115
1116 if (*last_type)
1117 i = hash(*last_type);
1118 else
1119 i = 0;
1120
1121 for (; i < TIPC_NAMETBL_SIZE; i++) {
Ying Xue993bfe52014-12-02 15:00:24 +08001122 seq_head = &tipc_nametbl->seq_hlist[i];
Richard Alpe15931232014-11-20 10:29:20 +01001123
1124 if (*last_type) {
1125 seq = nametbl_find_seq(*last_type);
1126 if (!seq)
1127 return -EPIPE;
1128 } else {
1129 seq = hlist_entry_safe((seq_head)->first,
1130 struct name_seq, ns_list);
1131 if (!seq)
1132 continue;
1133 }
1134
1135 hlist_for_each_entry_from(seq, ns_list) {
1136 spin_lock_bh(&seq->lock);
Richard Alpe15931232014-11-20 10:29:20 +01001137 err = __tipc_nl_subseq_list(msg, seq, last_lower,
1138 last_publ);
1139
1140 if (err) {
1141 *last_type = seq->type;
1142 spin_unlock_bh(&seq->lock);
1143 return err;
1144 }
1145 spin_unlock_bh(&seq->lock);
1146 }
1147 *last_type = 0;
1148 }
1149 return 0;
1150}
1151
1152int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)
1153{
1154 int err;
1155 int done = cb->args[3];
1156 u32 last_type = cb->args[0];
1157 u32 last_lower = cb->args[1];
1158 u32 last_publ = cb->args[2];
1159 struct tipc_nl_msg msg;
1160
1161 if (done)
1162 return 0;
1163
1164 msg.skb = skb;
1165 msg.portid = NETLINK_CB(cb->skb).portid;
1166 msg.seq = cb->nlh->nlmsg_seq;
1167
1168 read_lock_bh(&tipc_nametbl_lock);
1169
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 }
1182
1183 read_unlock_bh(&tipc_nametbl_lock);
1184
1185 cb->args[0] = last_type;
1186 cb->args[1] = last_lower;
1187 cb->args[2] = last_publ;
1188 cb->args[3] = done;
1189
1190 return skb->len;
1191}