2 * net/tipc/name_table.c: TIPC name table code
4 * Copyright (c) 2003-2005, Ericsson Research Canada
5 * Copyright (c) 2004-2005, Wind River Systems
6 * Copyright (c) 2005-2006, Ericsson AB
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 * Neither the names of the copyright holders nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
37 #include "name_table.h"
38 #include "name_distr.h"
40 #include "node_subscr.h"
46 int tipc_nametbl_size = 1024; /* must be a power of 2 */
49 * struct sub_seq - container for all published instances of a name sequence
50 * @lower: name sequence lower bound
51 * @upper: name sequence upper bound
52 * @node_list: circular list of matching publications with >= node scope
53 * @cluster_list: circular list of matching publications with >= cluster scope
54 * @zone_list: circular list of matching publications with >= zone scope
60 struct publication *node_list;
61 struct publication *cluster_list;
62 struct publication *zone_list;
66 * struct name_seq - container for all published instances of a name type
67 * @type: 32 bit 'type' value for name sequence
68 * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type';
69 * sub-sequences are sorted in ascending order
70 * @alloc: number of sub-sequences currently in array
71 * @first_free: upper bound of highest sub-sequence + 1
72 * @ns_list: links to adjacent name sequences in hash chain
73 * @subscriptions: list of subscriptions for this 'type'
74 * @lock: spinlock controlling access to name sequence structure
79 struct sub_seq *sseqs;
82 struct hlist_node ns_list;
83 struct list_head subscriptions;
88 * struct name_table - table containing all existing port name publications
89 * @types: pointer to fixed-sized array of name sequence lists,
90 * accessed via hashing on 'type'; name sequence lists are *not* sorted
91 * @local_publ_count: number of publications issued by this node
95 struct hlist_head *types;
99 struct name_table table = { NULL } ;
100 static atomic_t rsv_publ_ok = ATOMIC_INIT(0);
101 rwlock_t nametbl_lock = RW_LOCK_UNLOCKED;
104 static inline int hash(int x)
106 return(x & (tipc_nametbl_size - 1));
110 * publ_create - create a publication structure
113 static struct publication *publ_create(u32 type, u32 lower, u32 upper,
114 u32 scope, u32 node, u32 port_ref,
117 struct publication *publ =
118 (struct publication *)kmalloc(sizeof(*publ), GFP_ATOMIC);
120 warn("Memory squeeze; failed to create publication\n");
124 memset(publ, 0, sizeof(*publ));
130 publ->ref = port_ref;
132 INIT_LIST_HEAD(&publ->local_list);
133 INIT_LIST_HEAD(&publ->pport_list);
134 INIT_LIST_HEAD(&publ->subscr.nodesub_list);
139 * subseq_alloc - allocate a specified number of sub-sequence structures
142 struct sub_seq *subseq_alloc(u32 cnt)
144 u32 sz = cnt * sizeof(struct sub_seq);
145 struct sub_seq *sseq = (struct sub_seq *)kmalloc(sz, GFP_ATOMIC);
153 * nameseq_create - create a name sequence structure for the specified 'type'
155 * Allocates a single sub-sequence structure and sets it to all 0's.
158 struct name_seq *nameseq_create(u32 type, struct hlist_head *seq_head)
160 struct name_seq *nseq =
161 (struct name_seq *)kmalloc(sizeof(*nseq), GFP_ATOMIC);
162 struct sub_seq *sseq = subseq_alloc(1);
164 if (!nseq || !sseq) {
165 warn("Memory squeeze; failed to create name sequence\n");
171 memset(nseq, 0, sizeof(*nseq));
172 nseq->lock = SPIN_LOCK_UNLOCKED;
175 dbg("nameseq_create() nseq = %x type %u, ssseqs %x, ff: %u\n",
176 nseq, type, nseq->sseqs, nseq->first_free);
178 INIT_HLIST_NODE(&nseq->ns_list);
179 INIT_LIST_HEAD(&nseq->subscriptions);
180 hlist_add_head(&nseq->ns_list, seq_head);
185 * nameseq_find_subseq - find sub-sequence (if any) matching a name instance
187 * Very time-critical, so binary searches through sub-sequence array.
190 static inline struct sub_seq *nameseq_find_subseq(struct name_seq *nseq,
193 struct sub_seq *sseqs = nseq->sseqs;
195 int high = nseq->first_free - 1;
198 while (low <= high) {
199 mid = (low + high) / 2;
200 if (instance < sseqs[mid].lower)
202 else if (instance > sseqs[mid].upper)
211 * nameseq_locate_subseq - determine position of name instance in sub-sequence
213 * Returns index in sub-sequence array of the entry that contains the specified
214 * instance value; if no entry contains that value, returns the position
215 * where a new entry for it would be inserted in the array.
217 * Note: Similar to binary search code for locating a sub-sequence.
220 static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance)
222 struct sub_seq *sseqs = nseq->sseqs;
224 int high = nseq->first_free - 1;
227 while (low <= high) {
228 mid = (low + high) / 2;
229 if (instance < sseqs[mid].lower)
231 else if (instance > sseqs[mid].upper)
240 * nameseq_insert_publ -
243 struct publication *nameseq_insert_publ(struct name_seq *nseq,
244 u32 type, u32 lower, u32 upper,
245 u32 scope, u32 node, u32 port, u32 key)
247 struct subscription *s;
248 struct subscription *st;
249 struct publication *publ;
250 struct sub_seq *sseq;
251 int created_subseq = 0;
253 assert(nseq->first_free <= nseq->alloc);
254 sseq = nameseq_find_subseq(nseq, lower);
255 dbg("nameseq_ins: for seq %x,<%u,%u>, found sseq %x\n",
256 nseq, type, lower, sseq);
259 /* Lower end overlaps existing entry => need an exact match */
261 if ((sseq->lower != lower) || (sseq->upper != upper)) {
262 warn("Overlapping publ <%u,%u,%u>\n", type, lower, upper);
267 struct sub_seq *freesseq;
269 /* Find where lower end should be inserted */
271 inspos = nameseq_locate_subseq(nseq, lower);
273 /* Fail if upper end overlaps into an existing entry */
275 if ((inspos < nseq->first_free) &&
276 (upper >= nseq->sseqs[inspos].lower)) {
277 warn("Overlapping publ <%u,%u,%u>\n", type, lower, upper);
281 /* Ensure there is space for new sub-sequence */
283 if (nseq->first_free == nseq->alloc) {
284 struct sub_seq *sseqs = nseq->sseqs;
285 nseq->sseqs = subseq_alloc(nseq->alloc * 2);
286 if (nseq->sseqs != NULL) {
287 memcpy(nseq->sseqs, sseqs,
288 nseq->alloc * sizeof (struct sub_seq));
290 dbg("Allocated %u sseqs\n", nseq->alloc);
293 warn("Memory squeeze; failed to create sub-sequence\n");
297 dbg("Have %u sseqs for type %u\n", nseq->alloc, type);
299 /* Insert new sub-sequence */
301 dbg("ins in pos %u, ff = %u\n", inspos, nseq->first_free);
302 sseq = &nseq->sseqs[inspos];
303 freesseq = &nseq->sseqs[nseq->first_free];
304 memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof (*sseq));
305 memset(sseq, 0, sizeof (*sseq));
311 dbg("inserting (%u %u %u) from %x:%u into sseq %x(%u,%u) of seq %x\n",
312 type, lower, upper, node, port, sseq,
313 sseq->lower, sseq->upper, nseq);
315 /* Insert a publication: */
317 publ = publ_create(type, lower, upper, scope, node, port, key);
320 dbg("inserting publ %x, node=%x publ->node=%x, subscr->node=%x\n",
321 publ, node, publ->node, publ->subscr.node);
323 if (!sseq->zone_list)
324 sseq->zone_list = publ->zone_list_next = publ;
326 publ->zone_list_next = sseq->zone_list->zone_list_next;
327 sseq->zone_list->zone_list_next = publ;
330 if (in_own_cluster(node)) {
331 if (!sseq->cluster_list)
332 sseq->cluster_list = publ->cluster_list_next = publ;
334 publ->cluster_list_next =
335 sseq->cluster_list->cluster_list_next;
336 sseq->cluster_list->cluster_list_next = publ;
340 if (node == tipc_own_addr) {
341 if (!sseq->node_list)
342 sseq->node_list = publ->node_list_next = publ;
344 publ->node_list_next = sseq->node_list->node_list_next;
345 sseq->node_list->node_list_next = publ;
350 * Any subscriptions waiting for notification?
352 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
353 dbg("calling report_overlap()\n");
354 subscr_report_overlap(s,
366 * nameseq_remove_publ -
369 struct publication *nameseq_remove_publ(struct name_seq *nseq, u32 inst,
370 u32 node, u32 ref, u32 key)
372 struct publication *publ;
373 struct publication *prev;
374 struct sub_seq *sseq = nameseq_find_subseq(nseq, inst);
375 struct sub_seq *free;
376 struct subscription *s, *st;
377 int removed_subseq = 0;
384 warn("Withdraw unknown <%u,%u>?\n", nseq->type, inst);
386 dbg("Dumping subseqs %x for %x, alloc = %u,ff=%u\n",
387 nseq->sseqs, nseq, nseq->alloc,
389 for (i = 0; i < nseq->first_free; i++) {
390 dbg("Subseq %u(%x): lower = %u,upper = %u\n",
391 i, &nseq->sseqs[i], nseq->sseqs[i].lower,
392 nseq->sseqs[i].upper);
396 dbg("nameseq_remove: seq: %x, sseq %x, <%u,%u> key %u\n",
397 nseq, sseq, nseq->type, inst, key);
399 prev = sseq->zone_list;
400 publ = sseq->zone_list->zone_list_next;
401 while ((publ->key != key) || (publ->ref != ref) ||
402 (publ->node && (publ->node != node))) {
404 publ = publ->zone_list_next;
405 assert(prev != sseq->zone_list);
407 if (publ != sseq->zone_list)
408 prev->zone_list_next = publ->zone_list_next;
409 else if (publ->zone_list_next != publ) {
410 prev->zone_list_next = publ->zone_list_next;
411 sseq->zone_list = publ->zone_list_next;
416 if (in_own_cluster(node)) {
417 prev = sseq->cluster_list;
418 publ = sseq->cluster_list->cluster_list_next;
419 while ((publ->key != key) || (publ->ref != ref) ||
420 (publ->node && (publ->node != node))) {
422 publ = publ->cluster_list_next;
423 assert(prev != sseq->cluster_list);
425 if (publ != sseq->cluster_list)
426 prev->cluster_list_next = publ->cluster_list_next;
427 else if (publ->cluster_list_next != publ) {
428 prev->cluster_list_next = publ->cluster_list_next;
429 sseq->cluster_list = publ->cluster_list_next;
431 sseq->cluster_list = 0;
435 if (node == tipc_own_addr) {
436 prev = sseq->node_list;
437 publ = sseq->node_list->node_list_next;
438 while ((publ->key != key) || (publ->ref != ref) ||
439 (publ->node && (publ->node != node))) {
441 publ = publ->node_list_next;
442 assert(prev != sseq->node_list);
444 if (publ != sseq->node_list)
445 prev->node_list_next = publ->node_list_next;
446 else if (publ->node_list_next != publ) {
447 prev->node_list_next = publ->node_list_next;
448 sseq->node_list = publ->node_list_next;
453 assert(!publ->node || (publ->node == node));
454 assert(publ->ref == ref);
455 assert(publ->key == key);
458 * Contract subseq list if no more publications:
460 if (!sseq->node_list && !sseq->cluster_list && !sseq->zone_list) {
461 free = &nseq->sseqs[nseq->first_free--];
462 memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof (*sseq));
467 * Any subscriptions waiting ?
469 list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) {
470 subscr_report_overlap(s,
482 * nameseq_subscribe: attach a subscription, and issue
483 * the prescribed number of events if there is any sub-
484 * sequence overlapping with the requested sequence
487 void nameseq_subscribe(struct name_seq *nseq, struct subscription *s)
489 struct sub_seq *sseq = nseq->sseqs;
491 list_add(&s->nameseq_list, &nseq->subscriptions);
496 while (sseq != &nseq->sseqs[nseq->first_free]) {
497 struct publication *zl = sseq->zone_list;
498 if (zl && subscr_overlap(s,sseq->lower,sseq->upper)) {
499 struct publication *crs = zl;
503 subscr_report_overlap(s,
511 crs = crs->zone_list_next;
518 static struct name_seq *nametbl_find_seq(u32 type)
520 struct hlist_head *seq_head;
521 struct hlist_node *seq_node;
524 dbg("find_seq %u,(%u,0x%x) table = %p, hash[type] = %u\n",
525 type, ntohl(type), type, table.types, hash(type));
527 seq_head = &table.types[hash(type)];
528 hlist_for_each_entry(ns, seq_node, seq_head, ns_list) {
529 if (ns->type == type) {
530 dbg("found %x\n", ns);
538 struct publication *nametbl_insert_publ(u32 type, u32 lower, u32 upper,
539 u32 scope, u32 node, u32 port, u32 key)
541 struct name_seq *seq = nametbl_find_seq(type);
543 dbg("ins_publ: <%u,%x,%x> found %x\n", type, lower, upper, seq);
545 warn("Failed to publish illegal <%u,%u,%u>\n",
550 dbg("Publishing <%u,%u,%u> from %x\n", type, lower, upper, node);
552 seq = nameseq_create(type, &table.types[hash(type)]);
553 dbg("nametbl_insert_publ: created %x\n", seq);
558 assert(seq->type == type);
559 return nameseq_insert_publ(seq, type, lower, upper,
560 scope, node, port, key);
563 struct publication *nametbl_remove_publ(u32 type, u32 lower,
564 u32 node, u32 ref, u32 key)
566 struct publication *publ;
567 struct name_seq *seq = nametbl_find_seq(type);
572 dbg("Withdrawing <%u,%u> from %x\n", type, lower, node);
573 publ = nameseq_remove_publ(seq, lower, node, ref, key);
575 if (!seq->first_free && list_empty(&seq->subscriptions)) {
576 hlist_del_init(&seq->ns_list);
584 * nametbl_translate(): Translate tipc_name -> tipc_portid.
585 * Very time-critical.
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 nametbl_translate(u32 type, u32 instance, u32 *destnode)
593 struct sub_seq *sseq;
594 struct publication *publ = 0;
595 struct name_seq *seq;
598 if (!in_scope(*destnode, tipc_own_addr))
601 read_lock_bh(&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(&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);
657 read_unlock_bh(&nametbl_lock);
662 * nametbl_mc_translate - find multicast destinations
664 * Creates list of all local ports that overlap the given multicast address;
665 * also determines if any off-node ports overlap.
667 * Note: Publications with a scope narrower than 'limit' are ignored.
668 * (i.e. local node-scope publications mustn't receive messages arriving
669 * from another node, even if the multcast link brought it here)
671 * Returns non-zero if any off-node ports overlap
674 int nametbl_mc_translate(u32 type, u32 lower, u32 upper, u32 limit,
675 struct port_list *dports)
677 struct name_seq *seq;
678 struct sub_seq *sseq;
679 struct sub_seq *sseq_stop;
682 read_lock_bh(&nametbl_lock);
683 seq = nametbl_find_seq(type);
687 spin_lock_bh(&seq->lock);
689 sseq = seq->sseqs + nameseq_locate_subseq(seq, lower);
690 sseq_stop = seq->sseqs + seq->first_free;
691 for (; sseq != sseq_stop; sseq++) {
692 struct publication *publ;
694 if (sseq->lower > upper)
696 publ = sseq->cluster_list;
697 if (publ && (publ->scope <= limit))
699 if (publ->node == tipc_own_addr)
700 port_list_add(dports, publ->ref);
703 publ = publ->cluster_list_next;
704 } while (publ != sseq->cluster_list);
707 spin_unlock_bh(&seq->lock);
709 read_unlock_bh(&nametbl_lock);
714 * nametbl_publish_rsv - publish port name using a reserved name type
717 int nametbl_publish_rsv(u32 ref, unsigned int scope,
718 struct tipc_name_seq const *seq)
722 atomic_inc(&rsv_publ_ok);
723 res = tipc_publish(ref, scope, seq);
724 atomic_dec(&rsv_publ_ok);
729 * nametbl_publish - add name publication to network name tables
732 struct publication *nametbl_publish(u32 type, u32 lower, u32 upper,
733 u32 scope, u32 port_ref, u32 key)
735 struct publication *publ;
737 if (table.local_publ_count >= tipc_max_publications) {
738 warn("Failed publish: max %u local publication\n",
739 tipc_max_publications);
742 if ((type < TIPC_RESERVED_TYPES) && !atomic_read(&rsv_publ_ok)) {
743 warn("Failed to publish reserved name <%u,%u,%u>\n",
748 write_lock_bh(&nametbl_lock);
749 table.local_publ_count++;
750 publ = nametbl_insert_publ(type, lower, upper, scope,
751 tipc_own_addr, port_ref, key);
752 if (publ && (scope != TIPC_NODE_SCOPE)) {
755 write_unlock_bh(&nametbl_lock);
760 * nametbl_withdraw - withdraw name publication from network name tables
763 int nametbl_withdraw(u32 type, u32 lower, u32 ref, u32 key)
765 struct publication *publ;
767 dbg("nametbl_withdraw:<%d,%d,%d>\n", type, lower, key);
768 write_lock_bh(&nametbl_lock);
769 publ = nametbl_remove_publ(type, lower, tipc_own_addr, ref, key);
771 table.local_publ_count--;
772 if (publ->scope != TIPC_NODE_SCOPE)
773 named_withdraw(publ);
774 write_unlock_bh(&nametbl_lock);
775 list_del_init(&publ->pport_list);
779 write_unlock_bh(&nametbl_lock);
784 * nametbl_subscribe - add a subscription object to the name table
788 nametbl_subscribe(struct subscription *s)
790 u32 type = s->seq.type;
791 struct name_seq *seq;
793 write_lock_bh(&nametbl_lock);
794 seq = nametbl_find_seq(type);
796 seq = nameseq_create(type, &table.types[hash(type)]);
799 spin_lock_bh(&seq->lock);
800 dbg("nametbl_subscribe:found %x for <%u,%u,%u>\n",
801 seq, type, s->seq.lower, s->seq.upper);
802 assert(seq->type == type);
803 nameseq_subscribe(seq, s);
804 spin_unlock_bh(&seq->lock);
806 write_unlock_bh(&nametbl_lock);
810 * nametbl_unsubscribe - remove a subscription object from name table
814 nametbl_unsubscribe(struct subscription *s)
816 struct name_seq *seq;
818 write_lock_bh(&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(&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,
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 if (publ->node != tipc_own_addr)
860 else if (publ->scope == TIPC_NODE_SCOPE)
862 else if (publ->scope == TIPC_CLUSTER_SCOPE)
863 scopeStr = "cluster";
866 tipc_printf(buf, "%-10u %s", publ->key, scopeStr);
869 publ = publ->zone_list_next;
870 if (publ == sseq->zone_list)
873 tipc_printf(buf, "\n%33s", " ");
876 tipc_printf(buf, "\n");
880 * nameseq_list: print specified name sequence contents into the given buffer
883 static void nameseq_list(struct name_seq *seq, struct print_buf *buf, u32 depth,
884 u32 type, u32 lowbound, u32 upbound, u32 index)
886 struct sub_seq *sseq;
889 sprintf(typearea, "%-10u", seq->type);
892 tipc_printf(buf, "%s\n", typearea);
896 for (sseq = seq->sseqs; sseq != &seq->sseqs[seq->first_free]; sseq++) {
897 if ((lowbound <= sseq->upper) && (upbound >= sseq->lower)) {
898 tipc_printf(buf, "%s ", typearea);
899 subseq_list(sseq, buf, depth, index);
900 sprintf(typearea, "%10s", " ");
906 * nametbl_header - print name table header into the given buffer
909 static void nametbl_header(struct print_buf *buf, u32 depth)
911 tipc_printf(buf, "Type ");
914 tipc_printf(buf, "Lower Upper ");
916 tipc_printf(buf, "Port Identity ");
918 tipc_printf(buf, "Publication");
920 tipc_printf(buf, "\n-----------");
923 tipc_printf(buf, "--------------------- ");
925 tipc_printf(buf, "-------------------------- ");
927 tipc_printf(buf, "------------------");
929 tipc_printf(buf, "\n");
933 * nametbl_list - print specified name table contents into the given buffer
936 static void nametbl_list(struct print_buf *buf, u32 depth_info,
937 u32 type, u32 lowbound, u32 upbound)
939 struct hlist_head *seq_head;
940 struct hlist_node *seq_node;
941 struct name_seq *seq;
946 all_types = (depth_info & TIPC_NTQ_ALLTYPES);
947 depth = (depth_info & ~TIPC_NTQ_ALLTYPES);
953 /* display all entries in name table to specified depth */
954 nametbl_header(buf, depth);
957 for (i = 0; i < tipc_nametbl_size; i++) {
958 seq_head = &table.types[i];
959 hlist_for_each_entry(seq, seq_node, seq_head, ns_list) {
960 nameseq_list(seq, buf, depth, seq->type,
961 lowbound, upbound, i);
965 /* display only the sequence that matches the specified type */
966 if (upbound < lowbound) {
967 tipc_printf(buf, "invalid name sequence specified\n");
970 nametbl_header(buf, depth);
972 seq_head = &table.types[i];
973 hlist_for_each_entry(seq, seq_node, seq_head, ns_list) {
974 if (seq->type == type) {
975 nameseq_list(seq, buf, depth, type,
976 lowbound, upbound, i);
983 void nametbl_print(struct print_buf *buf, const char *str)
985 tipc_printf(buf, str);
986 read_lock_bh(&nametbl_lock);
987 nametbl_list(buf, 0, 0, 0, 0);
988 read_unlock_bh(&nametbl_lock);
991 #define MAX_NAME_TBL_QUERY 32768
993 struct sk_buff *nametbl_get(const void *req_tlv_area, int req_tlv_space)
996 struct tipc_name_table_query *argv;
997 struct tlv_desc *rep_tlv;
1001 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NAME_TBL_QUERY))
1002 return cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
1004 buf = cfg_reply_alloc(TLV_SPACE(MAX_NAME_TBL_QUERY));
1008 rep_tlv = (struct tlv_desc *)buf->data;
1009 printbuf_init(&b, TLV_DATA(rep_tlv), MAX_NAME_TBL_QUERY);
1010 argv = (struct tipc_name_table_query *)TLV_DATA(req_tlv_area);
1011 read_lock_bh(&nametbl_lock);
1012 nametbl_list(&b, ntohl(argv->depth), ntohl(argv->type),
1013 ntohl(argv->lowbound), ntohl(argv->upbound));
1014 read_unlock_bh(&nametbl_lock);
1015 str_len = printbuf_validate(&b);
1017 skb_put(buf, TLV_SPACE(str_len));
1018 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
1023 void nametbl_dump(void)
1025 nametbl_list(CONS, 0, 0, 0, 0);
1028 int nametbl_init(void)
1030 int array_size = sizeof(struct hlist_head) * tipc_nametbl_size;
1032 table.types = (struct hlist_head *)kmalloc(array_size, GFP_ATOMIC);
1036 write_lock_bh(&nametbl_lock);
1037 memset(table.types, 0, array_size);
1038 table.local_publ_count = 0;
1039 write_unlock_bh(&nametbl_lock);
1043 void nametbl_stop(void)
1045 struct hlist_head *seq_head;
1046 struct hlist_node *seq_node;
1047 struct hlist_node *tmp;
1048 struct name_seq *seq;
1054 write_lock_bh(&nametbl_lock);
1055 for (i = 0; i < tipc_nametbl_size; i++) {
1056 seq_head = &table.types[i];
1057 hlist_for_each_entry_safe(seq, seq_node, tmp, seq_head, ns_list) {
1058 struct sub_seq *sseq = seq->sseqs;
1060 for (; sseq != &seq->sseqs[seq->first_free]; sseq++) {
1061 struct publication *publ = sseq->zone_list;
1064 struct publication *next =
1065 publ->zone_list_next;
1069 while (publ != sseq->zone_list);
1075 write_unlock_bh(&nametbl_lock);