2 * net/tipc/name_table.c: TIPC name table code
4 * Copyright (c) 2000-2006, Ericsson AB
5 * Copyright (c) 2004-2005, 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.
40 #include "name_table.h"
41 #include "name_distr.h"
43 #include "node_subscr.h"
49 static int tipc_nametbl_size
= 1024; /* must be a power of 2 */
52 * struct sub_seq - container for all published instances of a name sequence
53 * @lower: name sequence lower bound
54 * @upper: name sequence upper bound
55 * @node_list: circular list of matching publications with >= node scope
56 * @cluster_list: circular list of matching publications with >= cluster scope
57 * @zone_list: circular list of matching publications with >= zone scope
63 struct publication
*node_list
;
64 struct publication
*cluster_list
;
65 struct publication
*zone_list
;
69 * struct name_seq - container for all published instances of a name type
70 * @type: 32 bit 'type' value for name sequence
71 * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type';
72 * sub-sequences are sorted in ascending order
73 * @alloc: number of sub-sequences currently in array
74 * @first_free: array index of first unused sub-sequence entry
75 * @ns_list: links to adjacent name sequences in hash chain
76 * @subscriptions: list of subscriptions for this 'type'
77 * @lock: spinlock controlling access to publication lists of all sub-sequences
82 struct sub_seq
*sseqs
;
85 struct hlist_node ns_list
;
86 struct list_head subscriptions
;
91 * struct name_table - table containing all existing port name publications
92 * @types: pointer to fixed-sized array of name sequence lists,
93 * accessed via hashing on 'type'; name sequence lists are *not* sorted
94 * @local_publ_count: number of publications issued by this node
98 struct hlist_head
*types
;
102 static struct name_table table
= { NULL
} ;
103 static atomic_t rsv_publ_ok
= ATOMIC_INIT(0);
104 DEFINE_RWLOCK(tipc_nametbl_lock
);
107 static int hash(int x
)
109 return(x
& (tipc_nametbl_size
- 1));
113 * publ_create - create a publication structure
116 static struct publication
*publ_create(u32 type
, u32 lower
, u32 upper
,
117 u32 scope
, u32 node
, u32 port_ref
,
120 struct publication
*publ
= kzalloc(sizeof(*publ
), GFP_ATOMIC
);
122 warn("Publication creation failure, no memory\n");
131 publ
->ref
= port_ref
;
133 INIT_LIST_HEAD(&publ
->local_list
);
134 INIT_LIST_HEAD(&publ
->pport_list
);
135 INIT_LIST_HEAD(&publ
->subscr
.nodesub_list
);
140 * tipc_subseq_alloc - allocate a specified number of sub-sequence structures
143 static struct sub_seq
*tipc_subseq_alloc(u32 cnt
)
145 struct sub_seq
*sseq
= kcalloc(cnt
, sizeof(struct sub_seq
), GFP_ATOMIC
);
150 * tipc_nameseq_create - create a name sequence structure for the specified 'type'
152 * Allocates a single sub-sequence structure and sets it to all 0's.
155 static struct name_seq
*tipc_nameseq_create(u32 type
, struct hlist_head
*seq_head
)
157 struct name_seq
*nseq
= kzalloc(sizeof(*nseq
), GFP_ATOMIC
);
158 struct sub_seq
*sseq
= tipc_subseq_alloc(1);
160 if (!nseq
|| !sseq
) {
161 warn("Name sequence creation failed, no memory\n");
167 spin_lock_init(&nseq
->lock
);
170 dbg("tipc_nameseq_create(): nseq = %p, type %u, ssseqs %p, ff: %u\n",
171 nseq
, type
, nseq
->sseqs
, nseq
->first_free
);
173 INIT_HLIST_NODE(&nseq
->ns_list
);
174 INIT_LIST_HEAD(&nseq
->subscriptions
);
175 hlist_add_head(&nseq
->ns_list
, seq_head
);
180 * nameseq_find_subseq - find sub-sequence (if any) matching a name instance
182 * Very time-critical, so binary searches through sub-sequence array.
185 static struct sub_seq
*nameseq_find_subseq(struct name_seq
*nseq
,
188 struct sub_seq
*sseqs
= nseq
->sseqs
;
190 int high
= nseq
->first_free
- 1;
193 while (low
<= high
) {
194 mid
= (low
+ high
) / 2;
195 if (instance
< sseqs
[mid
].lower
)
197 else if (instance
> sseqs
[mid
].upper
)
206 * nameseq_locate_subseq - determine position of name instance in sub-sequence
208 * Returns index in sub-sequence array of the entry that contains the specified
209 * instance value; if no entry contains that value, returns the position
210 * where a new entry for it would be inserted in the array.
212 * Note: Similar to binary search code for locating a sub-sequence.
215 static u32
nameseq_locate_subseq(struct name_seq
*nseq
, u32 instance
)
217 struct sub_seq
*sseqs
= nseq
->sseqs
;
219 int high
= nseq
->first_free
- 1;
222 while (low
<= high
) {
223 mid
= (low
+ high
) / 2;
224 if (instance
< sseqs
[mid
].lower
)
226 else if (instance
> sseqs
[mid
].upper
)
235 * tipc_nameseq_insert_publ -
238 static struct publication
*tipc_nameseq_insert_publ(struct name_seq
*nseq
,
239 u32 type
, u32 lower
, u32 upper
,
240 u32 scope
, u32 node
, u32 port
, u32 key
)
242 struct subscription
*s
;
243 struct subscription
*st
;
244 struct publication
*publ
;
245 struct sub_seq
*sseq
;
246 int created_subseq
= 0;
248 sseq
= nameseq_find_subseq(nseq
, lower
);
249 dbg("nameseq_ins: for seq %p, {%u,%u}, found sseq %p\n",
250 nseq
, type
, lower
, sseq
);
253 /* Lower end overlaps existing entry => need an exact match */
255 if ((sseq
->lower
!= lower
) || (sseq
->upper
!= upper
)) {
256 warn("Cannot publish {%u,%u,%u}, overlap error\n",
262 struct sub_seq
*freesseq
;
264 /* Find where lower end should be inserted */
266 inspos
= nameseq_locate_subseq(nseq
, lower
);
268 /* Fail if upper end overlaps into an existing entry */
270 if ((inspos
< nseq
->first_free
) &&
271 (upper
>= nseq
->sseqs
[inspos
].lower
)) {
272 warn("Cannot publish {%u,%u,%u}, overlap error\n",
277 /* Ensure there is space for new sub-sequence */
279 if (nseq
->first_free
== nseq
->alloc
) {
280 struct sub_seq
*sseqs
= tipc_subseq_alloc(nseq
->alloc
* 2);
283 warn("Cannot publish {%u,%u,%u}, no memory\n",
287 dbg("Allocated %u more sseqs\n", nseq
->alloc
);
288 memcpy(sseqs
, nseq
->sseqs
,
289 nseq
->alloc
* sizeof(struct sub_seq
));
294 dbg("Have %u sseqs for type %u\n", nseq
->alloc
, type
);
296 /* Insert new sub-sequence */
298 dbg("ins in pos %u, ff = %u\n", inspos
, nseq
->first_free
);
299 sseq
= &nseq
->sseqs
[inspos
];
300 freesseq
= &nseq
->sseqs
[nseq
->first_free
];
301 memmove(sseq
+ 1, sseq
, (freesseq
- sseq
) * sizeof (*sseq
));
302 memset(sseq
, 0, sizeof (*sseq
));
308 dbg("inserting {%u,%u,%u} from <0x%x:%u> into sseq %p(%u,%u) of seq %p\n",
309 type
, lower
, upper
, node
, port
, sseq
,
310 sseq
->lower
, sseq
->upper
, nseq
);
312 /* Insert a publication: */
314 publ
= publ_create(type
, lower
, upper
, scope
, node
, port
, key
);
317 dbg("inserting publ %p, node=0x%x publ->node=0x%x, subscr->node=%p\n",
318 publ
, node
, publ
->node
, publ
->subscr
.node
);
320 if (!sseq
->zone_list
)
321 sseq
->zone_list
= publ
->zone_list_next
= publ
;
323 publ
->zone_list_next
= sseq
->zone_list
->zone_list_next
;
324 sseq
->zone_list
->zone_list_next
= publ
;
327 if (in_own_cluster(node
)) {
328 if (!sseq
->cluster_list
)
329 sseq
->cluster_list
= publ
->cluster_list_next
= publ
;
331 publ
->cluster_list_next
=
332 sseq
->cluster_list
->cluster_list_next
;
333 sseq
->cluster_list
->cluster_list_next
= publ
;
337 if (node
== tipc_own_addr
) {
338 if (!sseq
->node_list
)
339 sseq
->node_list
= publ
->node_list_next
= publ
;
341 publ
->node_list_next
= sseq
->node_list
->node_list_next
;
342 sseq
->node_list
->node_list_next
= publ
;
347 * Any subscriptions waiting for notification?
349 list_for_each_entry_safe(s
, st
, &nseq
->subscriptions
, nameseq_list
) {
350 dbg("calling report_overlap()\n");
351 tipc_subscr_report_overlap(s
,
363 * tipc_nameseq_remove_publ -
365 * NOTE: There may be cases where TIPC is asked to remove a publication
366 * that is not in the name table. For example, if another node issues a
367 * publication for a name sequence that overlaps an existing name sequence
368 * the publication will not be recorded, which means the publication won't
369 * be found when the name sequence is later withdrawn by that node.
370 * A failed withdraw request simply returns a failure indication and lets the
371 * caller issue any error or warning messages associated with such a problem.
374 static struct publication
*tipc_nameseq_remove_publ(struct name_seq
*nseq
, u32 inst
,
375 u32 node
, u32 ref
, u32 key
)
377 struct publication
*publ
;
378 struct publication
*curr
;
379 struct publication
*prev
;
380 struct sub_seq
*sseq
= nameseq_find_subseq(nseq
, inst
);
381 struct sub_seq
*free
;
382 struct subscription
*s
, *st
;
383 int removed_subseq
= 0;
388 dbg("tipc_nameseq_remove_publ: seq: %p, sseq %p, {%u,%u}, key %u\n",
389 nseq
, sseq
, nseq
->type
, inst
, key
);
391 /* Remove publication from zone scope list */
393 prev
= sseq
->zone_list
;
394 publ
= sseq
->zone_list
->zone_list_next
;
395 while ((publ
->key
!= key
) || (publ
->ref
!= ref
) ||
396 (publ
->node
&& (publ
->node
!= node
))) {
398 publ
= publ
->zone_list_next
;
399 if (prev
== sseq
->zone_list
) {
401 /* Prevent endless loop if publication not found */
406 if (publ
!= sseq
->zone_list
)
407 prev
->zone_list_next
= publ
->zone_list_next
;
408 else if (publ
->zone_list_next
!= publ
) {
409 prev
->zone_list_next
= publ
->zone_list_next
;
410 sseq
->zone_list
= publ
->zone_list_next
;
412 sseq
->zone_list
= NULL
;
415 /* Remove publication from cluster scope list, if present */
417 if (in_own_cluster(node
)) {
418 prev
= sseq
->cluster_list
;
419 curr
= sseq
->cluster_list
->cluster_list_next
;
420 while (curr
!= publ
) {
422 curr
= curr
->cluster_list_next
;
423 if (prev
== sseq
->cluster_list
) {
425 /* Prevent endless loop for malformed list */
427 err("Unable to de-list cluster publication\n"
428 "{%u%u}, node=0x%x, ref=%u, key=%u)\n",
429 publ
->type
, publ
->lower
, publ
->node
,
430 publ
->ref
, publ
->key
);
434 if (publ
!= sseq
->cluster_list
)
435 prev
->cluster_list_next
= publ
->cluster_list_next
;
436 else if (publ
->cluster_list_next
!= publ
) {
437 prev
->cluster_list_next
= publ
->cluster_list_next
;
438 sseq
->cluster_list
= publ
->cluster_list_next
;
440 sseq
->cluster_list
= NULL
;
445 /* Remove publication from node scope list, if present */
447 if (node
== tipc_own_addr
) {
448 prev
= sseq
->node_list
;
449 curr
= sseq
->node_list
->node_list_next
;
450 while (curr
!= publ
) {
452 curr
= curr
->node_list_next
;
453 if (prev
== sseq
->node_list
) {
455 /* Prevent endless loop for malformed list */
457 err("Unable to de-list node publication\n"
458 "{%u%u}, node=0x%x, ref=%u, key=%u)\n",
459 publ
->type
, publ
->lower
, publ
->node
,
460 publ
->ref
, publ
->key
);
464 if (publ
!= sseq
->node_list
)
465 prev
->node_list_next
= publ
->node_list_next
;
466 else if (publ
->node_list_next
!= publ
) {
467 prev
->node_list_next
= publ
->node_list_next
;
468 sseq
->node_list
= publ
->node_list_next
;
470 sseq
->node_list
= NULL
;
475 /* Contract subseq list if no more publications for that subseq */
477 if (!sseq
->zone_list
) {
478 free
= &nseq
->sseqs
[nseq
->first_free
--];
479 memmove(sseq
, sseq
+ 1, (free
- (sseq
+ 1)) * sizeof (*sseq
));
483 /* Notify any waiting subscriptions */
485 list_for_each_entry_safe(s
, st
, &nseq
->subscriptions
, nameseq_list
) {
486 tipc_subscr_report_overlap(s
,
499 * tipc_nameseq_subscribe: attach a subscription, and issue
500 * the prescribed number of events if there is any sub-
501 * sequence overlapping with the requested sequence
504 static void tipc_nameseq_subscribe(struct name_seq
*nseq
, struct subscription
*s
)
506 struct sub_seq
*sseq
= nseq
->sseqs
;
508 list_add(&s
->nameseq_list
, &nseq
->subscriptions
);
513 while (sseq
!= &nseq
->sseqs
[nseq
->first_free
]) {
514 struct publication
*zl
= sseq
->zone_list
;
515 if (zl
&& tipc_subscr_overlap(s
,sseq
->lower
,sseq
->upper
)) {
516 struct publication
*crs
= zl
;
520 tipc_subscr_report_overlap(s
,
528 crs
= crs
->zone_list_next
;
535 static struct name_seq
*nametbl_find_seq(u32 type
)
537 struct hlist_head
*seq_head
;
538 struct hlist_node
*seq_node
;
541 dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n",
542 type
, ntohl(type
), type
, table
.types
, hash(type
));
544 seq_head
= &table
.types
[hash(type
)];
545 hlist_for_each_entry(ns
, seq_node
, seq_head
, ns_list
) {
546 if (ns
->type
== type
) {
547 dbg("found %p\n", ns
);
555 struct publication
*tipc_nametbl_insert_publ(u32 type
, u32 lower
, u32 upper
,
556 u32 scope
, u32 node
, u32 port
, u32 key
)
558 struct name_seq
*seq
= nametbl_find_seq(type
);
560 dbg("tipc_nametbl_insert_publ: {%u,%u,%u} found %p\n", type
, lower
, upper
, seq
);
562 warn("Failed to publish illegal {%u,%u,%u}\n",
567 dbg("Publishing {%u,%u,%u} from 0x%x\n", type
, lower
, upper
, node
);
569 seq
= tipc_nameseq_create(type
, &table
.types
[hash(type
)]);
570 dbg("tipc_nametbl_insert_publ: created %p\n", seq
);
575 return tipc_nameseq_insert_publ(seq
, type
, lower
, upper
,
576 scope
, node
, port
, key
);
579 struct publication
*tipc_nametbl_remove_publ(u32 type
, u32 lower
,
580 u32 node
, u32 ref
, u32 key
)
582 struct publication
*publ
;
583 struct name_seq
*seq
= nametbl_find_seq(type
);
588 dbg("Withdrawing {%u,%u} from 0x%x\n", type
, lower
, node
);
589 publ
= tipc_nameseq_remove_publ(seq
, lower
, node
, ref
, key
);
591 if (!seq
->first_free
&& list_empty(&seq
->subscriptions
)) {
592 hlist_del_init(&seq
->ns_list
);
600 * tipc_nametbl_translate(): Translate tipc_name -> tipc_portid.
601 * Very time-critical.
603 * Note: on entry 'destnode' is the search domain used during translation;
604 * on exit it passes back the node address of the matching port (if any)
607 u32
tipc_nametbl_translate(u32 type
, u32 instance
, u32
*destnode
)
609 struct sub_seq
*sseq
;
610 struct publication
*publ
= NULL
;
611 struct name_seq
*seq
;
614 if (!in_scope(*destnode
, tipc_own_addr
))
617 read_lock_bh(&tipc_nametbl_lock
);
618 seq
= nametbl_find_seq(type
);
621 sseq
= nameseq_find_subseq(seq
, instance
);
624 spin_lock_bh(&seq
->lock
);
626 /* Closest-First Algorithm: */
627 if (likely(!*destnode
)) {
628 publ
= sseq
->node_list
;
630 sseq
->node_list
= publ
->node_list_next
;
633 *destnode
= publ
->node
;
634 spin_unlock_bh(&seq
->lock
);
635 read_unlock_bh(&tipc_nametbl_lock
);
638 publ
= sseq
->cluster_list
;
640 sseq
->cluster_list
= publ
->cluster_list_next
;
643 publ
= sseq
->zone_list
;
645 sseq
->zone_list
= publ
->zone_list_next
;
650 /* Round-Robin Algorithm: */
651 else if (*destnode
== tipc_own_addr
) {
652 publ
= sseq
->node_list
;
654 sseq
->node_list
= publ
->node_list_next
;
657 } else if (in_own_cluster(*destnode
)) {
658 publ
= sseq
->cluster_list
;
660 sseq
->cluster_list
= publ
->cluster_list_next
;
664 publ
= sseq
->zone_list
;
666 sseq
->zone_list
= publ
->zone_list_next
;
670 spin_unlock_bh(&seq
->lock
);
673 read_unlock_bh(&tipc_nametbl_lock
);
678 * tipc_nametbl_mc_translate - find multicast destinations
680 * Creates list of all local ports that overlap the given multicast address;
681 * also determines if any off-node ports overlap.
683 * Note: Publications with a scope narrower than 'limit' are ignored.
684 * (i.e. local node-scope publications mustn't receive messages arriving
685 * from another node, even if the multcast link brought it here)
687 * Returns non-zero if any off-node ports overlap
690 int tipc_nametbl_mc_translate(u32 type
, u32 lower
, u32 upper
, u32 limit
,
691 struct port_list
*dports
)
693 struct name_seq
*seq
;
694 struct sub_seq
*sseq
;
695 struct sub_seq
*sseq_stop
;
698 read_lock_bh(&tipc_nametbl_lock
);
699 seq
= nametbl_find_seq(type
);
703 spin_lock_bh(&seq
->lock
);
705 sseq
= seq
->sseqs
+ nameseq_locate_subseq(seq
, lower
);
706 sseq_stop
= seq
->sseqs
+ seq
->first_free
;
707 for (; sseq
!= sseq_stop
; sseq
++) {
708 struct publication
*publ
;
710 if (sseq
->lower
> upper
)
712 publ
= sseq
->cluster_list
;
715 if (publ
->scope
> limit
)
716 /* ignore out-of-scope publication */ ;
717 else if (publ
->node
== tipc_own_addr
)
718 tipc_port_list_add(dports
, publ
->ref
);
721 publ
= publ
->cluster_list_next
;
722 } while (publ
!= sseq
->cluster_list
);
725 spin_unlock_bh(&seq
->lock
);
727 read_unlock_bh(&tipc_nametbl_lock
);
732 * tipc_nametbl_publish_rsv - publish port name using a reserved name type
735 int tipc_nametbl_publish_rsv(u32 ref
, unsigned int scope
,
736 struct tipc_name_seq
const *seq
)
740 atomic_inc(&rsv_publ_ok
);
741 res
= tipc_publish(ref
, scope
, seq
);
742 atomic_dec(&rsv_publ_ok
);
747 * tipc_nametbl_publish - add name publication to network name tables
750 struct publication
*tipc_nametbl_publish(u32 type
, u32 lower
, u32 upper
,
751 u32 scope
, u32 port_ref
, u32 key
)
753 struct publication
*publ
;
755 if (table
.local_publ_count
>= tipc_max_publications
) {
756 warn("Publication failed, local publication limit reached (%u)\n",
757 tipc_max_publications
);
760 if ((type
< TIPC_RESERVED_TYPES
) && !atomic_read(&rsv_publ_ok
)) {
761 warn("Publication failed, reserved name {%u,%u,%u}\n",
766 write_lock_bh(&tipc_nametbl_lock
);
767 table
.local_publ_count
++;
768 publ
= tipc_nametbl_insert_publ(type
, lower
, upper
, scope
,
769 tipc_own_addr
, port_ref
, key
);
770 if (publ
&& (scope
!= TIPC_NODE_SCOPE
)) {
771 tipc_named_publish(publ
);
773 write_unlock_bh(&tipc_nametbl_lock
);
778 * tipc_nametbl_withdraw - withdraw name publication from network name tables
781 int tipc_nametbl_withdraw(u32 type
, u32 lower
, u32 ref
, u32 key
)
783 struct publication
*publ
;
785 dbg("tipc_nametbl_withdraw: {%u,%u}, key=%u\n", type
, lower
, key
);
786 write_lock_bh(&tipc_nametbl_lock
);
787 publ
= tipc_nametbl_remove_publ(type
, lower
, tipc_own_addr
, ref
, key
);
789 table
.local_publ_count
--;
790 if (publ
->scope
!= TIPC_NODE_SCOPE
)
791 tipc_named_withdraw(publ
);
792 write_unlock_bh(&tipc_nametbl_lock
);
793 list_del_init(&publ
->pport_list
);
797 write_unlock_bh(&tipc_nametbl_lock
);
798 err("Unable to remove local publication\n"
799 "(type=%u, lower=%u, ref=%u, key=%u)\n",
800 type
, lower
, ref
, key
);
805 * tipc_nametbl_subscribe - add a subscription object to the name table
808 void tipc_nametbl_subscribe(struct subscription
*s
)
810 u32 type
= s
->seq
.type
;
811 struct name_seq
*seq
;
813 write_lock_bh(&tipc_nametbl_lock
);
814 seq
= nametbl_find_seq(type
);
816 seq
= tipc_nameseq_create(type
, &table
.types
[hash(type
)]);
819 spin_lock_bh(&seq
->lock
);
820 dbg("tipc_nametbl_subscribe:found %p for {%u,%u,%u}\n",
821 seq
, type
, s
->seq
.lower
, s
->seq
.upper
);
822 tipc_nameseq_subscribe(seq
, s
);
823 spin_unlock_bh(&seq
->lock
);
825 warn("Failed to create subscription for {%u,%u,%u}\n",
826 s
->seq
.type
, s
->seq
.lower
, s
->seq
.upper
);
828 write_unlock_bh(&tipc_nametbl_lock
);
832 * tipc_nametbl_unsubscribe - remove a subscription object from name table
835 void tipc_nametbl_unsubscribe(struct subscription
*s
)
837 struct name_seq
*seq
;
839 write_lock_bh(&tipc_nametbl_lock
);
840 seq
= nametbl_find_seq(s
->seq
.type
);
842 spin_lock_bh(&seq
->lock
);
843 list_del_init(&s
->nameseq_list
);
844 spin_unlock_bh(&seq
->lock
);
845 if ((seq
->first_free
== 0) && list_empty(&seq
->subscriptions
)) {
846 hlist_del_init(&seq
->ns_list
);
851 write_unlock_bh(&tipc_nametbl_lock
);
856 * subseq_list: print specified sub-sequence contents into the given buffer
859 static void subseq_list(struct sub_seq
*sseq
, struct print_buf
*buf
, u32 depth
,
864 struct publication
*publ
= sseq
->zone_list
;
866 tipc_printf(buf
, "%-10u %-10u ", sseq
->lower
, sseq
->upper
);
868 if (depth
== 2 || !publ
) {
869 tipc_printf(buf
, "\n");
874 sprintf (portIdStr
, "<%u.%u.%u:%u>",
875 tipc_zone(publ
->node
), tipc_cluster(publ
->node
),
876 tipc_node(publ
->node
), publ
->ref
);
877 tipc_printf(buf
, "%-26s ", portIdStr
);
879 if (publ
->node
!= tipc_own_addr
)
881 else if (publ
->scope
== TIPC_NODE_SCOPE
)
883 else if (publ
->scope
== TIPC_CLUSTER_SCOPE
)
884 scopeStr
= "cluster";
887 tipc_printf(buf
, "%-10u %s", publ
->key
, scopeStr
);
890 publ
= publ
->zone_list_next
;
891 if (publ
== sseq
->zone_list
)
894 tipc_printf(buf
, "\n%33s", " ");
897 tipc_printf(buf
, "\n");
901 * nameseq_list: print specified name sequence contents into the given buffer
904 static void nameseq_list(struct name_seq
*seq
, struct print_buf
*buf
, u32 depth
,
905 u32 type
, u32 lowbound
, u32 upbound
, u32 index
)
907 struct sub_seq
*sseq
;
910 if (seq
->first_free
== 0)
913 sprintf(typearea
, "%-10u", seq
->type
);
916 tipc_printf(buf
, "%s\n", typearea
);
920 for (sseq
= seq
->sseqs
; sseq
!= &seq
->sseqs
[seq
->first_free
]; sseq
++) {
921 if ((lowbound
<= sseq
->upper
) && (upbound
>= sseq
->lower
)) {
922 tipc_printf(buf
, "%s ", typearea
);
923 spin_lock_bh(&seq
->lock
);
924 subseq_list(sseq
, buf
, depth
, index
);
925 spin_unlock_bh(&seq
->lock
);
926 sprintf(typearea
, "%10s", " ");
932 * nametbl_header - print name table header into the given buffer
935 static void nametbl_header(struct print_buf
*buf
, u32 depth
)
937 tipc_printf(buf
, "Type ");
940 tipc_printf(buf
, "Lower Upper ");
942 tipc_printf(buf
, "Port Identity ");
944 tipc_printf(buf
, "Publication");
946 tipc_printf(buf
, "\n-----------");
949 tipc_printf(buf
, "--------------------- ");
951 tipc_printf(buf
, "-------------------------- ");
953 tipc_printf(buf
, "------------------");
955 tipc_printf(buf
, "\n");
959 * nametbl_list - print specified name table contents into the given buffer
962 static void nametbl_list(struct print_buf
*buf
, u32 depth_info
,
963 u32 type
, u32 lowbound
, u32 upbound
)
965 struct hlist_head
*seq_head
;
966 struct hlist_node
*seq_node
;
967 struct name_seq
*seq
;
972 all_types
= (depth_info
& TIPC_NTQ_ALLTYPES
);
973 depth
= (depth_info
& ~TIPC_NTQ_ALLTYPES
);
979 /* display all entries in name table to specified depth */
980 nametbl_header(buf
, depth
);
983 for (i
= 0; i
< tipc_nametbl_size
; i
++) {
984 seq_head
= &table
.types
[i
];
985 hlist_for_each_entry(seq
, seq_node
, seq_head
, ns_list
) {
986 nameseq_list(seq
, buf
, depth
, seq
->type
,
987 lowbound
, upbound
, i
);
991 /* display only the sequence that matches the specified type */
992 if (upbound
< lowbound
) {
993 tipc_printf(buf
, "invalid name sequence specified\n");
996 nametbl_header(buf
, depth
);
998 seq_head
= &table
.types
[i
];
999 hlist_for_each_entry(seq
, seq_node
, seq_head
, ns_list
) {
1000 if (seq
->type
== type
) {
1001 nameseq_list(seq
, buf
, depth
, type
,
1002 lowbound
, upbound
, i
);
1010 void tipc_nametbl_print(struct print_buf
*buf
, const char *str
)
1012 tipc_printf(buf
, str
);
1013 read_lock_bh(&tipc_nametbl_lock
);
1014 nametbl_list(buf
, 0, 0, 0, 0);
1015 read_unlock_bh(&tipc_nametbl_lock
);
1019 #define MAX_NAME_TBL_QUERY 32768
1021 struct sk_buff
*tipc_nametbl_get(const void *req_tlv_area
, int req_tlv_space
)
1023 struct sk_buff
*buf
;
1024 struct tipc_name_table_query
*argv
;
1025 struct tlv_desc
*rep_tlv
;
1029 if (!TLV_CHECK(req_tlv_area
, req_tlv_space
, TIPC_TLV_NAME_TBL_QUERY
))
1030 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR
);
1032 buf
= tipc_cfg_reply_alloc(TLV_SPACE(MAX_NAME_TBL_QUERY
));
1036 rep_tlv
= (struct tlv_desc
*)buf
->data
;
1037 tipc_printbuf_init(&b
, TLV_DATA(rep_tlv
), MAX_NAME_TBL_QUERY
);
1038 argv
= (struct tipc_name_table_query
*)TLV_DATA(req_tlv_area
);
1039 read_lock_bh(&tipc_nametbl_lock
);
1040 nametbl_list(&b
, ntohl(argv
->depth
), ntohl(argv
->type
),
1041 ntohl(argv
->lowbound
), ntohl(argv
->upbound
));
1042 read_unlock_bh(&tipc_nametbl_lock
);
1043 str_len
= tipc_printbuf_validate(&b
);
1045 skb_put(buf
, TLV_SPACE(str_len
));
1046 TLV_SET(rep_tlv
, TIPC_TLV_ULTRA_STRING
, NULL
, str_len
);
1052 void tipc_nametbl_dump(void)
1054 nametbl_list(TIPC_CONS
, 0, 0, 0, 0);
1058 int tipc_nametbl_init(void)
1060 table
.types
= kcalloc(tipc_nametbl_size
, sizeof(struct hlist_head
),
1065 table
.local_publ_count
= 0;
1069 void tipc_nametbl_stop(void)
1076 /* Verify name table is empty, then release it */
1078 write_lock_bh(&tipc_nametbl_lock
);
1079 for (i
= 0; i
< tipc_nametbl_size
; i
++) {
1080 if (!hlist_empty(&table
.types
[i
]))
1081 err("tipc_nametbl_stop(): hash chain %u is non-null\n", i
);
1085 write_unlock_bh(&tipc_nametbl_lock
);