2 * net/tipc/name_table.c: TIPC name table code
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2004-2008, Wind River Systems
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
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.
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.
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
34 * POSSIBILITY OF SUCH DAMAGE.
39 #include "name_table.h"
40 #include "name_distr.h"
44 static int tipc_nametbl_size
= 1024; /* must be a power of 2 */
47 * struct sub_seq - container for all published instances of a name sequence
48 * @lower: name sequence lower bound
49 * @upper: name sequence upper bound
50 * @node_list: circular list of publications made by own node
51 * @cluster_list: circular list of publications made by own cluster
52 * @zone_list: circular list of publications made by own zone
53 * @node_list_size: number of entries in "node_list"
54 * @cluster_list_size: number of entries in "cluster_list"
55 * @zone_list_size: number of entries in "zone_list"
57 * Note: The zone list always contains at least one entry, since all
58 * publications of the associated name sequence belong to it.
59 * (The cluster and node lists may be empty.)
65 struct publication
*node_list
;
66 struct publication
*cluster_list
;
67 struct publication
*zone_list
;
69 u32 cluster_list_size
;
74 * struct name_seq - container for all published instances of a name type
75 * @type: 32 bit 'type' value for name sequence
76 * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type';
77 * sub-sequences are sorted in ascending order
78 * @alloc: number of sub-sequences currently in array
79 * @first_free: array index of first unused sub-sequence entry
80 * @ns_list: links to adjacent name sequences in hash chain
81 * @subscriptions: list of subscriptions for this 'type'
82 * @lock: spinlock controlling access to publication lists of all sub-sequences
87 struct sub_seq
*sseqs
;
90 struct hlist_node ns_list
;
91 struct list_head subscriptions
;
96 * struct name_table - table containing all existing port name publications
97 * @types: pointer to fixed-sized array of name sequence lists,
98 * accessed via hashing on 'type'; name sequence lists are *not* sorted
99 * @local_publ_count: number of publications issued by this node
103 struct hlist_head
*types
;
104 u32 local_publ_count
;
107 static struct name_table table
;
108 static atomic_t rsv_publ_ok
= ATOMIC_INIT(0);
109 DEFINE_RWLOCK(tipc_nametbl_lock
);
112 static int hash(int x
)
114 return x
& (tipc_nametbl_size
- 1);
118 * publ_create - create a publication structure
121 static struct publication
*publ_create(u32 type
, u32 lower
, u32 upper
,
122 u32 scope
, u32 node
, u32 port_ref
,
125 struct publication
*publ
= kzalloc(sizeof(*publ
), GFP_ATOMIC
);
127 warn("Publication creation failure, no memory\n");
136 publ
->ref
= port_ref
;
138 INIT_LIST_HEAD(&publ
->local_list
);
139 INIT_LIST_HEAD(&publ
->pport_list
);
140 INIT_LIST_HEAD(&publ
->subscr
.nodesub_list
);
145 * tipc_subseq_alloc - allocate a specified number of sub-sequence structures
148 static struct sub_seq
*tipc_subseq_alloc(u32 cnt
)
150 struct sub_seq
*sseq
= kcalloc(cnt
, sizeof(struct sub_seq
), GFP_ATOMIC
);
155 * tipc_nameseq_create - create a name sequence structure for the specified 'type'
157 * Allocates a single sub-sequence structure and sets it to all 0's.
160 static struct name_seq
*tipc_nameseq_create(u32 type
, struct hlist_head
*seq_head
)
162 struct name_seq
*nseq
= kzalloc(sizeof(*nseq
), GFP_ATOMIC
);
163 struct sub_seq
*sseq
= tipc_subseq_alloc(1);
165 if (!nseq
|| !sseq
) {
166 warn("Name sequence creation failed, no memory\n");
172 spin_lock_init(&nseq
->lock
);
176 INIT_HLIST_NODE(&nseq
->ns_list
);
177 INIT_LIST_HEAD(&nseq
->subscriptions
);
178 hlist_add_head(&nseq
->ns_list
, seq_head
);
183 * nameseq_find_subseq - find sub-sequence (if any) matching a name instance
185 * Very time-critical, so binary searches through sub-sequence array.
188 static struct sub_seq
*nameseq_find_subseq(struct name_seq
*nseq
,
191 struct sub_seq
*sseqs
= nseq
->sseqs
;
193 int high
= nseq
->first_free
- 1;
196 while (low
<= high
) {
197 mid
= (low
+ high
) / 2;
198 if (instance
< sseqs
[mid
].lower
)
200 else if (instance
> sseqs
[mid
].upper
)
209 * nameseq_locate_subseq - determine position of name instance in sub-sequence
211 * Returns index in sub-sequence array of the entry that contains the specified
212 * instance value; if no entry contains that value, returns the position
213 * where a new entry for it would be inserted in the array.
215 * Note: Similar to binary search code for locating a sub-sequence.
218 static u32
nameseq_locate_subseq(struct name_seq
*nseq
, u32 instance
)
220 struct sub_seq
*sseqs
= nseq
->sseqs
;
222 int high
= nseq
->first_free
- 1;
225 while (low
<= high
) {
226 mid
= (low
+ high
) / 2;
227 if (instance
< sseqs
[mid
].lower
)
229 else if (instance
> sseqs
[mid
].upper
)
238 * tipc_nameseq_insert_publ -
241 static struct publication
*tipc_nameseq_insert_publ(struct name_seq
*nseq
,
242 u32 type
, u32 lower
, u32 upper
,
243 u32 scope
, u32 node
, u32 port
, u32 key
)
245 struct subscription
*s
;
246 struct subscription
*st
;
247 struct publication
*publ
;
248 struct sub_seq
*sseq
;
249 int created_subseq
= 0;
251 sseq
= nameseq_find_subseq(nseq
, lower
);
254 /* Lower end overlaps existing entry => need an exact match */
256 if ((sseq
->lower
!= lower
) || (sseq
->upper
!= upper
)) {
257 warn("Cannot publish {%u,%u,%u}, overlap error\n",
263 struct sub_seq
*freesseq
;
265 /* Find where lower end should be inserted */
267 inspos
= nameseq_locate_subseq(nseq
, lower
);
269 /* Fail if upper end overlaps into an existing entry */
271 if ((inspos
< nseq
->first_free
) &&
272 (upper
>= nseq
->sseqs
[inspos
].lower
)) {
273 warn("Cannot publish {%u,%u,%u}, overlap error\n",
278 /* Ensure there is space for new sub-sequence */
280 if (nseq
->first_free
== nseq
->alloc
) {
281 struct sub_seq
*sseqs
= tipc_subseq_alloc(nseq
->alloc
* 2);
284 warn("Cannot publish {%u,%u,%u}, no memory\n",
288 memcpy(sseqs
, nseq
->sseqs
,
289 nseq
->alloc
* sizeof(struct sub_seq
));
295 /* Insert new sub-sequence */
297 sseq
= &nseq
->sseqs
[inspos
];
298 freesseq
= &nseq
->sseqs
[nseq
->first_free
];
299 memmove(sseq
+ 1, sseq
, (freesseq
- sseq
) * sizeof(*sseq
));
300 memset(sseq
, 0, sizeof(*sseq
));
307 /* Insert a publication: */
309 publ
= publ_create(type
, lower
, upper
, scope
, node
, port
, key
);
313 sseq
->zone_list_size
++;
314 if (!sseq
->zone_list
)
315 sseq
->zone_list
= publ
->zone_list_next
= publ
;
317 publ
->zone_list_next
= sseq
->zone_list
->zone_list_next
;
318 sseq
->zone_list
->zone_list_next
= publ
;
321 if (in_own_cluster(node
)) {
322 sseq
->cluster_list_size
++;
323 if (!sseq
->cluster_list
)
324 sseq
->cluster_list
= publ
->cluster_list_next
= publ
;
326 publ
->cluster_list_next
=
327 sseq
->cluster_list
->cluster_list_next
;
328 sseq
->cluster_list
->cluster_list_next
= publ
;
332 if (node
== tipc_own_addr
) {
333 sseq
->node_list_size
++;
334 if (!sseq
->node_list
)
335 sseq
->node_list
= publ
->node_list_next
= publ
;
337 publ
->node_list_next
= sseq
->node_list
->node_list_next
;
338 sseq
->node_list
->node_list_next
= publ
;
343 * Any subscriptions waiting for notification?
345 list_for_each_entry_safe(s
, st
, &nseq
->subscriptions
, nameseq_list
) {
346 tipc_subscr_report_overlap(s
,
358 * tipc_nameseq_remove_publ -
360 * NOTE: There may be cases where TIPC is asked to remove a publication
361 * that is not in the name table. For example, if another node issues a
362 * publication for a name sequence that overlaps an existing name sequence
363 * the publication will not be recorded, which means the publication won't
364 * be found when the name sequence is later withdrawn by that node.
365 * A failed withdraw request simply returns a failure indication and lets the
366 * caller issue any error or warning messages associated with such a problem.
369 static struct publication
*tipc_nameseq_remove_publ(struct name_seq
*nseq
, u32 inst
,
370 u32 node
, u32 ref
, u32 key
)
372 struct publication
*publ
;
373 struct publication
*curr
;
374 struct publication
*prev
;
375 struct sub_seq
*sseq
= nameseq_find_subseq(nseq
, inst
);
376 struct sub_seq
*free
;
377 struct subscription
*s
, *st
;
378 int removed_subseq
= 0;
383 /* Remove publication from zone scope list */
385 prev
= sseq
->zone_list
;
386 publ
= sseq
->zone_list
->zone_list_next
;
387 while ((publ
->key
!= key
) || (publ
->ref
!= ref
) ||
388 (publ
->node
&& (publ
->node
!= node
))) {
390 publ
= publ
->zone_list_next
;
391 if (prev
== sseq
->zone_list
) {
393 /* Prevent endless loop if publication not found */
398 if (publ
!= sseq
->zone_list
)
399 prev
->zone_list_next
= publ
->zone_list_next
;
400 else if (publ
->zone_list_next
!= publ
) {
401 prev
->zone_list_next
= publ
->zone_list_next
;
402 sseq
->zone_list
= publ
->zone_list_next
;
404 sseq
->zone_list
= NULL
;
406 sseq
->zone_list_size
--;
408 /* Remove publication from cluster scope list, if present */
410 if (in_own_cluster(node
)) {
411 prev
= sseq
->cluster_list
;
412 curr
= sseq
->cluster_list
->cluster_list_next
;
413 while (curr
!= publ
) {
415 curr
= curr
->cluster_list_next
;
416 if (prev
== sseq
->cluster_list
) {
418 /* Prevent endless loop for malformed list */
420 err("Unable to de-list cluster publication\n"
421 "{%u%u}, node=0x%x, ref=%u, key=%u)\n",
422 publ
->type
, publ
->lower
, publ
->node
,
423 publ
->ref
, publ
->key
);
427 if (publ
!= sseq
->cluster_list
)
428 prev
->cluster_list_next
= publ
->cluster_list_next
;
429 else if (publ
->cluster_list_next
!= publ
) {
430 prev
->cluster_list_next
= publ
->cluster_list_next
;
431 sseq
->cluster_list
= publ
->cluster_list_next
;
433 sseq
->cluster_list
= NULL
;
435 sseq
->cluster_list_size
--;
439 /* Remove publication from node scope list, if present */
441 if (node
== tipc_own_addr
) {
442 prev
= sseq
->node_list
;
443 curr
= sseq
->node_list
->node_list_next
;
444 while (curr
!= publ
) {
446 curr
= curr
->node_list_next
;
447 if (prev
== sseq
->node_list
) {
449 /* Prevent endless loop for malformed list */
451 err("Unable to de-list node publication\n"
452 "{%u%u}, node=0x%x, ref=%u, key=%u)\n",
453 publ
->type
, publ
->lower
, publ
->node
,
454 publ
->ref
, publ
->key
);
458 if (publ
!= sseq
->node_list
)
459 prev
->node_list_next
= publ
->node_list_next
;
460 else if (publ
->node_list_next
!= publ
) {
461 prev
->node_list_next
= publ
->node_list_next
;
462 sseq
->node_list
= publ
->node_list_next
;
464 sseq
->node_list
= NULL
;
466 sseq
->node_list_size
--;
470 /* Contract subseq list if no more publications for that subseq */
472 if (!sseq
->zone_list
) {
473 free
= &nseq
->sseqs
[nseq
->first_free
--];
474 memmove(sseq
, sseq
+ 1, (free
- (sseq
+ 1)) * sizeof(*sseq
));
478 /* Notify any waiting subscriptions */
480 list_for_each_entry_safe(s
, st
, &nseq
->subscriptions
, nameseq_list
) {
481 tipc_subscr_report_overlap(s
,
494 * tipc_nameseq_subscribe: attach a subscription, and issue
495 * the prescribed number of events if there is any sub-
496 * sequence overlapping with the requested sequence
499 static void tipc_nameseq_subscribe(struct name_seq
*nseq
, struct subscription
*s
)
501 struct sub_seq
*sseq
= nseq
->sseqs
;
503 list_add(&s
->nameseq_list
, &nseq
->subscriptions
);
508 while (sseq
!= &nseq
->sseqs
[nseq
->first_free
]) {
509 struct publication
*zl
= sseq
->zone_list
;
510 if (zl
&& tipc_subscr_overlap(s
, sseq
->lower
, sseq
->upper
)) {
511 struct publication
*crs
= zl
;
515 tipc_subscr_report_overlap(s
,
523 crs
= crs
->zone_list_next
;
530 static struct name_seq
*nametbl_find_seq(u32 type
)
532 struct hlist_head
*seq_head
;
533 struct hlist_node
*seq_node
;
536 seq_head
= &table
.types
[hash(type
)];
537 hlist_for_each_entry(ns
, seq_node
, seq_head
, ns_list
) {
538 if (ns
->type
== type
)
545 struct publication
*tipc_nametbl_insert_publ(u32 type
, u32 lower
, u32 upper
,
546 u32 scope
, u32 node
, u32 port
, u32 key
)
548 struct name_seq
*seq
= nametbl_find_seq(type
);
551 warn("Failed to publish illegal {%u,%u,%u}\n",
557 seq
= tipc_nameseq_create(type
, &table
.types
[hash(type
)]);
561 return tipc_nameseq_insert_publ(seq
, type
, lower
, upper
,
562 scope
, node
, port
, key
);
565 struct publication
*tipc_nametbl_remove_publ(u32 type
, u32 lower
,
566 u32 node
, u32 ref
, u32 key
)
568 struct publication
*publ
;
569 struct name_seq
*seq
= nametbl_find_seq(type
);
574 publ
= tipc_nameseq_remove_publ(seq
, lower
, node
, ref
, key
);
576 if (!seq
->first_free
&& list_empty(&seq
->subscriptions
)) {
577 hlist_del_init(&seq
->ns_list
);
585 * tipc_nametbl_translate - translate name to port id
587 * Note: on entry 'destnode' is the search domain used during translation;
588 * on exit it passes back the node address of the matching port (if any)
591 u32
tipc_nametbl_translate(u32 type
, u32 instance
, u32
*destnode
)
593 struct sub_seq
*sseq
;
594 struct publication
*publ
= NULL
;
595 struct name_seq
*seq
;
598 if (!tipc_in_scope(*destnode
, tipc_own_addr
))
601 read_lock_bh(&tipc_nametbl_lock
);
602 seq
= nametbl_find_seq(type
);
605 sseq
= nameseq_find_subseq(seq
, instance
);
608 spin_lock_bh(&seq
->lock
);
610 /* Closest-First Algorithm: */
611 if (likely(!*destnode
)) {
612 publ
= sseq
->node_list
;
614 sseq
->node_list
= publ
->node_list_next
;
617 *destnode
= publ
->node
;
618 spin_unlock_bh(&seq
->lock
);
619 read_unlock_bh(&tipc_nametbl_lock
);
622 publ
= sseq
->cluster_list
;
624 sseq
->cluster_list
= publ
->cluster_list_next
;
627 publ
= sseq
->zone_list
;
629 sseq
->zone_list
= publ
->zone_list_next
;
634 /* Round-Robin Algorithm: */
635 else if (*destnode
== tipc_own_addr
) {
636 publ
= sseq
->node_list
;
638 sseq
->node_list
= publ
->node_list_next
;
641 } else if (in_own_cluster(*destnode
)) {
642 publ
= sseq
->cluster_list
;
644 sseq
->cluster_list
= publ
->cluster_list_next
;
648 publ
= sseq
->zone_list
;
650 sseq
->zone_list
= publ
->zone_list_next
;
654 spin_unlock_bh(&seq
->lock
);
656 read_unlock_bh(&tipc_nametbl_lock
);
661 * tipc_nametbl_mc_translate - find multicast destinations
663 * Creates list of all local ports that overlap the given multicast address;
664 * also determines if any off-node ports overlap.
666 * Note: Publications with a scope narrower than 'limit' are ignored.
667 * (i.e. local node-scope publications mustn't receive messages arriving
668 * from another node, even if the multcast link brought it here)
670 * Returns non-zero if any off-node ports overlap
673 int tipc_nametbl_mc_translate(u32 type
, u32 lower
, u32 upper
, u32 limit
,
674 struct port_list
*dports
)
676 struct name_seq
*seq
;
677 struct sub_seq
*sseq
;
678 struct sub_seq
*sseq_stop
;
681 read_lock_bh(&tipc_nametbl_lock
);
682 seq
= nametbl_find_seq(type
);
686 spin_lock_bh(&seq
->lock
);
688 sseq
= seq
->sseqs
+ nameseq_locate_subseq(seq
, lower
);
689 sseq_stop
= seq
->sseqs
+ seq
->first_free
;
690 for (; sseq
!= sseq_stop
; sseq
++) {
691 struct publication
*publ
;
693 if (sseq
->lower
> upper
)
696 publ
= sseq
->node_list
;
699 if (publ
->scope
<= limit
)
700 tipc_port_list_add(dports
, publ
->ref
);
701 publ
= publ
->node_list_next
;
702 } while (publ
!= sseq
->node_list
);
705 if (sseq
->cluster_list_size
!= sseq
->node_list_size
)
709 spin_unlock_bh(&seq
->lock
);
711 read_unlock_bh(&tipc_nametbl_lock
);
716 * tipc_nametbl_publish_rsv - publish port name using a reserved name type
719 int tipc_nametbl_publish_rsv(u32 ref
, unsigned int scope
,
720 struct tipc_name_seq
const *seq
)
724 atomic_inc(&rsv_publ_ok
);
725 res
= tipc_publish(ref
, scope
, seq
);
726 atomic_dec(&rsv_publ_ok
);
731 * tipc_nametbl_publish - add name publication to network name tables
734 struct publication
*tipc_nametbl_publish(u32 type
, u32 lower
, u32 upper
,
735 u32 scope
, u32 port_ref
, u32 key
)
737 struct publication
*publ
;
739 if (table
.local_publ_count
>= tipc_max_publications
) {
740 warn("Publication failed, local publication limit reached (%u)\n",
741 tipc_max_publications
);
744 if ((type
< TIPC_RESERVED_TYPES
) && !atomic_read(&rsv_publ_ok
)) {
745 warn("Publication failed, reserved name {%u,%u,%u}\n",
750 write_lock_bh(&tipc_nametbl_lock
);
751 table
.local_publ_count
++;
752 publ
= tipc_nametbl_insert_publ(type
, lower
, upper
, scope
,
753 tipc_own_addr
, port_ref
, key
);
754 if (publ
&& (scope
!= TIPC_NODE_SCOPE
))
755 tipc_named_publish(publ
);
756 write_unlock_bh(&tipc_nametbl_lock
);
761 * tipc_nametbl_withdraw - withdraw name publication from network name tables
764 int tipc_nametbl_withdraw(u32 type
, u32 lower
, u32 ref
, u32 key
)
766 struct publication
*publ
;
768 write_lock_bh(&tipc_nametbl_lock
);
769 publ
= tipc_nametbl_remove_publ(type
, lower
, tipc_own_addr
, ref
, key
);
771 table
.local_publ_count
--;
772 if (publ
->scope
!= TIPC_NODE_SCOPE
)
773 tipc_named_withdraw(publ
);
774 write_unlock_bh(&tipc_nametbl_lock
);
775 list_del_init(&publ
->pport_list
);
779 write_unlock_bh(&tipc_nametbl_lock
);
780 err("Unable to remove local publication\n"
781 "(type=%u, lower=%u, ref=%u, key=%u)\n",
782 type
, lower
, ref
, key
);
787 * tipc_nametbl_subscribe - add a subscription object to the name table
790 void tipc_nametbl_subscribe(struct subscription
*s
)
792 u32 type
= s
->seq
.type
;
793 struct name_seq
*seq
;
795 write_lock_bh(&tipc_nametbl_lock
);
796 seq
= nametbl_find_seq(type
);
798 seq
= tipc_nameseq_create(type
, &table
.types
[hash(type
)]);
800 spin_lock_bh(&seq
->lock
);
801 tipc_nameseq_subscribe(seq
, s
);
802 spin_unlock_bh(&seq
->lock
);
804 warn("Failed to create subscription for {%u,%u,%u}\n",
805 s
->seq
.type
, s
->seq
.lower
, s
->seq
.upper
);
807 write_unlock_bh(&tipc_nametbl_lock
);
811 * tipc_nametbl_unsubscribe - remove a subscription object from name table
814 void tipc_nametbl_unsubscribe(struct subscription
*s
)
816 struct name_seq
*seq
;
818 write_lock_bh(&tipc_nametbl_lock
);
819 seq
= nametbl_find_seq(s
->seq
.type
);
821 spin_lock_bh(&seq
->lock
);
822 list_del_init(&s
->nameseq_list
);
823 spin_unlock_bh(&seq
->lock
);
824 if ((seq
->first_free
== 0) && list_empty(&seq
->subscriptions
)) {
825 hlist_del_init(&seq
->ns_list
);
830 write_unlock_bh(&tipc_nametbl_lock
);
835 * subseq_list: print specified sub-sequence contents into the given buffer
838 static void subseq_list(struct sub_seq
*sseq
, struct print_buf
*buf
, u32 depth
,
842 const char *scope_str
[] = {"", " zone", " cluster", " node"};
843 struct publication
*publ
= sseq
->zone_list
;
845 tipc_printf(buf
, "%-10u %-10u ", sseq
->lower
, sseq
->upper
);
847 if (depth
== 2 || !publ
) {
848 tipc_printf(buf
, "\n");
853 sprintf(portIdStr
, "<%u.%u.%u:%u>",
854 tipc_zone(publ
->node
), tipc_cluster(publ
->node
),
855 tipc_node(publ
->node
), publ
->ref
);
856 tipc_printf(buf
, "%-26s ", portIdStr
);
858 tipc_printf(buf
, "%-10u %s", publ
->key
,
859 scope_str
[publ
->scope
]);
862 publ
= publ
->zone_list_next
;
863 if (publ
== sseq
->zone_list
)
866 tipc_printf(buf
, "\n%33s", " ");
869 tipc_printf(buf
, "\n");
873 * nameseq_list: print specified name sequence contents into the given buffer
876 static void nameseq_list(struct name_seq
*seq
, struct print_buf
*buf
, u32 depth
,
877 u32 type
, u32 lowbound
, u32 upbound
, u32 index
)
879 struct sub_seq
*sseq
;
882 if (seq
->first_free
== 0)
885 sprintf(typearea
, "%-10u", seq
->type
);
888 tipc_printf(buf
, "%s\n", typearea
);
892 for (sseq
= seq
->sseqs
; sseq
!= &seq
->sseqs
[seq
->first_free
]; sseq
++) {
893 if ((lowbound
<= sseq
->upper
) && (upbound
>= sseq
->lower
)) {
894 tipc_printf(buf
, "%s ", typearea
);
895 spin_lock_bh(&seq
->lock
);
896 subseq_list(sseq
, buf
, depth
, index
);
897 spin_unlock_bh(&seq
->lock
);
898 sprintf(typearea
, "%10s", " ");
904 * nametbl_header - print name table header into the given buffer
907 static void nametbl_header(struct print_buf
*buf
, u32 depth
)
909 const char *header
[] = {
920 for (i
= 0; i
< depth
; i
++)
921 tipc_printf(buf
, header
[i
]);
922 tipc_printf(buf
, "\n");
926 * nametbl_list - print specified name table contents into the given buffer
929 static void nametbl_list(struct print_buf
*buf
, u32 depth_info
,
930 u32 type
, u32 lowbound
, u32 upbound
)
932 struct hlist_head
*seq_head
;
933 struct hlist_node
*seq_node
;
934 struct name_seq
*seq
;
939 all_types
= (depth_info
& TIPC_NTQ_ALLTYPES
);
940 depth
= (depth_info
& ~TIPC_NTQ_ALLTYPES
);
946 /* display all entries in name table to specified depth */
947 nametbl_header(buf
, depth
);
950 for (i
= 0; i
< tipc_nametbl_size
; i
++) {
951 seq_head
= &table
.types
[i
];
952 hlist_for_each_entry(seq
, seq_node
, seq_head
, ns_list
) {
953 nameseq_list(seq
, buf
, depth
, seq
->type
,
954 lowbound
, upbound
, i
);
958 /* display only the sequence that matches the specified type */
959 if (upbound
< lowbound
) {
960 tipc_printf(buf
, "invalid name sequence specified\n");
963 nametbl_header(buf
, depth
);
965 seq_head
= &table
.types
[i
];
966 hlist_for_each_entry(seq
, seq_node
, seq_head
, ns_list
) {
967 if (seq
->type
== type
) {
968 nameseq_list(seq
, buf
, depth
, type
,
969 lowbound
, upbound
, i
);
976 #define MAX_NAME_TBL_QUERY 32768
978 struct sk_buff
*tipc_nametbl_get(const void *req_tlv_area
, int req_tlv_space
)
981 struct tipc_name_table_query
*argv
;
982 struct tlv_desc
*rep_tlv
;
986 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_NAME_TBL_QUERY
))
987 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
989 buf
= tipc_cfg_reply_alloc(TLV_SPACE(MAX_NAME_TBL_QUERY
));
993 rep_tlv
= (struct tlv_desc
*)buf
->data
;
994 tipc_printbuf_init(&b
, TLV_DATA(rep_tlv
), MAX_NAME_TBL_QUERY
);
995 argv
= (struct tipc_name_table_query
*)TLV_DATA(req_tlv_area
);
996 read_lock_bh(&tipc_nametbl_lock
);
997 nametbl_list(&b
, ntohl(argv
->depth
), ntohl(argv
->type
),
998 ntohl(argv
->lowbound
), ntohl(argv
->upbound
));
999 read_unlock_bh(&tipc_nametbl_lock
);
1000 str_len
= tipc_printbuf_validate(&b
);
1002 skb_put(buf
, TLV_SPACE(str_len
));
1003 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
1008 int tipc_nametbl_init(void)
1010 table
.types
= kcalloc(tipc_nametbl_size
, sizeof(struct hlist_head
),
1015 table
.local_publ_count
= 0;
1019 void tipc_nametbl_stop(void)
1026 /* Verify name table is empty, then release it */
1028 write_lock_bh(&tipc_nametbl_lock
);
1029 for (i
= 0; i
< tipc_nametbl_size
; i
++) {
1030 if (!hlist_empty(&table
.types
[i
]))
1031 err("tipc_nametbl_stop(): hash chain %u is non-null\n", i
);
1035 write_unlock_bh(&tipc_nametbl_lock
);