2 * net/tipc/name_table.c: TIPC name table code
4 * Copyright (c) 2000-2006, 2014-2018, Ericsson AB
5 * Copyright (c) 2004-2008, 2010-2014, 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"
49 * struct service_range - container for all bindings of a service range
50 * @lower: service range lower bound
51 * @upper: service range upper bound
52 * @tree_node: member of service range RB tree
53 * @local_publ: list of identical publications made from this node
54 * Used by closest_first lookup and multicast lookup algorithm
55 * @all_publ: all publications identical to this one, whatever node and scope
56 * Used by round-robin lookup algorithm
58 struct service_range {
61 struct rb_node tree_node;
62 struct list_head local_publ;
63 struct list_head all_publ;
67 * struct tipc_service - container for all published instances of a service type
68 * @type: 32 bit 'type' value for service
69 * @ranges: rb tree containing all service ranges for this service
70 * @service_list: links to adjacent name ranges in hash chain
71 * @subscriptions: list of subscriptions for this service type
72 * @lock: spinlock controlling access to pertaining service ranges/publications
73 * @rcu: RCU callback head used for deferred freeing
77 struct rb_root ranges;
78 struct hlist_node service_list;
79 struct list_head subscriptions;
80 spinlock_t lock; /* Covers service range list */
84 static int hash(int x)
86 return x & (TIPC_NAMETBL_SIZE - 1);
90 * tipc_publ_create - create a publication structure
92 static struct publication *tipc_publ_create(u32 type, u32 lower, u32 upper,
93 u32 scope, u32 node, u32 port,
96 struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC);
108 INIT_LIST_HEAD(&publ->binding_sock);
109 INIT_LIST_HEAD(&publ->binding_node);
110 INIT_LIST_HEAD(&publ->local_publ);
111 INIT_LIST_HEAD(&publ->all_publ);
116 * tipc_service_create - create a service structure for the specified 'type'
118 * Allocates a single range structure and sets it to all 0's.
120 static struct tipc_service *tipc_service_create(u32 type, struct hlist_head *hd)
122 struct tipc_service *service = kzalloc(sizeof(*service), GFP_ATOMIC);
125 pr_warn("Service creation failed, no memory\n");
129 spin_lock_init(&service->lock);
130 service->type = type;
131 service->ranges = RB_ROOT;
132 INIT_HLIST_NODE(&service->service_list);
133 INIT_LIST_HEAD(&service->subscriptions);
134 hlist_add_head_rcu(&service->service_list, hd);
139 * tipc_service_find_range - find service range matching a service instance
141 * Very time-critical, so binary search through range rb tree
143 static struct service_range *tipc_service_find_range(struct tipc_service *sc,
146 struct rb_node *n = sc->ranges.rb_node;
147 struct service_range *sr;
150 sr = container_of(n, struct service_range, tree_node);
151 if (sr->lower > instance)
153 else if (sr->upper < instance)
161 static struct service_range *tipc_service_create_range(struct tipc_service *sc,
162 u32 lower, u32 upper)
164 struct rb_node **n, *parent = NULL;
165 struct service_range *sr, *tmp;
167 n = &sc->ranges.rb_node;
169 tmp = container_of(*n, struct service_range, tree_node);
171 tmp = container_of(parent, struct service_range, tree_node);
172 if (lower < tmp->lower)
174 else if (lower > tmp->lower)
176 else if (upper < tmp->upper)
178 else if (upper > tmp->upper)
183 sr = kzalloc(sizeof(*sr), GFP_ATOMIC);
188 INIT_LIST_HEAD(&sr->local_publ);
189 INIT_LIST_HEAD(&sr->all_publ);
190 rb_link_node(&sr->tree_node, parent, n);
191 rb_insert_color(&sr->tree_node, &sc->ranges);
195 static struct publication *tipc_service_insert_publ(struct net *net,
196 struct tipc_service *sc,
198 u32 upper, u32 scope,
202 struct tipc_subscription *sub, *tmp;
203 struct service_range *sr;
204 struct publication *p;
207 sr = tipc_service_create_range(sc, lower, upper);
211 first = list_empty(&sr->all_publ);
213 /* Return if the publication already exists */
214 list_for_each_entry(p, &sr->all_publ, all_publ) {
215 if (p->key == key && (!p->node || p->node == node))
219 /* Create and insert publication */
220 p = tipc_publ_create(type, lower, upper, scope, node, port, key);
223 if (in_own_node(net, node))
224 list_add(&p->local_publ, &sr->local_publ);
225 list_add(&p->all_publ, &sr->all_publ);
227 /* Any subscriptions waiting for notification? */
228 list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
229 tipc_sub_report_overlap(sub, p->lower, p->upper, TIPC_PUBLISHED,
230 p->port, p->node, p->scope, first);
234 pr_warn("Failed to bind to %u,%u,%u, no memory\n", type, lower, upper);
239 * tipc_service_remove_publ - remove a publication from a service
241 static struct publication *tipc_service_remove_publ(struct net *net,
242 struct tipc_service *sc,
243 u32 lower, u32 upper,
246 struct tipc_subscription *sub, *tmp;
247 struct service_range *sr;
248 struct publication *p;
253 sr = tipc_service_find_range(sc, lower);
257 /* Find exact matching service range */
258 for (n = &sr->tree_node; n; n = rb_next(n)) {
259 sr = container_of(n, struct service_range, tree_node);
260 if (sr->upper == upper)
263 if (!n || sr->lower != lower || sr->upper != upper)
266 /* Find publication, if it exists */
267 list_for_each_entry(p, &sr->all_publ, all_publ) {
268 if (p->key != key || (node && node != p->node))
276 list_del(&p->all_publ);
277 list_del(&p->local_publ);
279 /* Remove service range item if this was its last publication */
280 if (list_empty(&sr->all_publ)) {
282 rb_erase(&sr->tree_node, &sc->ranges);
286 /* Notify any waiting subscriptions */
287 list_for_each_entry_safe(sub, tmp, &sc->subscriptions, service_list) {
288 tipc_sub_report_overlap(sub, p->lower, p->upper, TIPC_WITHDRAWN,
289 p->port, p->node, p->scope, last);
295 * tipc_service_subscribe - attach a subscription, and optionally
296 * issue the prescribed number of events if there is any service
297 * range overlapping with the requested range
299 static void tipc_service_subscribe(struct tipc_service *service,
300 struct tipc_subscription *sub)
302 struct tipc_subscr *sb = &sub->evt.s;
303 struct service_range *sr;
304 struct tipc_name_seq ns;
305 struct publication *p;
309 ns.type = tipc_sub_read(sb, seq.type);
310 ns.lower = tipc_sub_read(sb, seq.lower);
311 ns.upper = tipc_sub_read(sb, seq.upper);
314 list_add(&sub->service_list, &service->subscriptions);
316 if (tipc_sub_read(sb, filter) & TIPC_SUB_NO_STATUS)
319 for (n = rb_first(&service->ranges); n; n = rb_next(n)) {
320 sr = container_of(n, struct service_range, tree_node);
321 if (sr->lower > ns.upper)
323 if (!tipc_sub_check_overlap(&ns, sr->lower, sr->upper))
327 list_for_each_entry(p, &sr->all_publ, all_publ) {
328 tipc_sub_report_overlap(sub, sr->lower, sr->upper,
329 TIPC_PUBLISHED, p->port,
330 p->node, p->scope, first);
336 static struct tipc_service *tipc_service_find(struct net *net, u32 type)
338 struct name_table *nt = tipc_name_table(net);
339 struct hlist_head *service_head;
340 struct tipc_service *service;
342 service_head = &nt->services[hash(type)];
343 hlist_for_each_entry_rcu(service, service_head, service_list) {
344 if (service->type == type)
350 struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
351 u32 lower, u32 upper,
355 struct name_table *nt = tipc_name_table(net);
356 struct tipc_service *sc;
357 struct publication *p;
359 if (scope > TIPC_NODE_SCOPE || lower > upper) {
360 pr_debug("Failed to bind illegal {%u,%u,%u} with scope %u\n",
361 type, lower, upper, scope);
364 sc = tipc_service_find(net, type);
366 sc = tipc_service_create(type, &nt->services[hash(type)]);
370 spin_lock_bh(&sc->lock);
371 p = tipc_service_insert_publ(net, sc, type, lower, upper,
372 scope, node, port, key);
373 spin_unlock_bh(&sc->lock);
377 struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
378 u32 lower, u32 upper,
381 struct tipc_service *sc = tipc_service_find(net, type);
382 struct publication *p = NULL;
387 spin_lock_bh(&sc->lock);
388 p = tipc_service_remove_publ(net, sc, lower, upper, node, key);
390 /* Delete service item if this no more publications and subscriptions */
391 if (RB_EMPTY_ROOT(&sc->ranges) && list_empty(&sc->subscriptions)) {
392 hlist_del_init_rcu(&sc->service_list);
395 spin_unlock_bh(&sc->lock);
400 * tipc_nametbl_translate - perform service instance to socket translation
402 * On entry, 'dnode' is the search domain used during translation.
405 * - if translation is deferred to another node, leave 'dnode' unchanged and
407 * - if translation is attempted and succeeds, set 'dnode' to the publishing
408 * node and return the published (non-zero) port number
409 * - if translation is attempted and fails, set 'dnode' to 0 and return 0
411 * Note that for legacy users (node configured with Z.C.N address format) the
412 * 'closest-first' lookup algorithm must be maintained, i.e., if dnode is 0
413 * we must look in the local binding list first
415 u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *dnode)
417 struct tipc_net *tn = tipc_net(net);
418 bool legacy = tn->legacy_addr_format;
419 u32 self = tipc_own_addr(net);
420 struct service_range *sr;
421 struct tipc_service *sc;
422 struct list_head *list;
423 struct publication *p;
427 if (!tipc_in_scope(legacy, *dnode, self))
431 sc = tipc_service_find(net, type);
435 spin_lock_bh(&sc->lock);
436 sr = tipc_service_find_range(sc, instance);
440 /* Select lookup algorithm: local, closest-first or round-robin */
441 if (*dnode == self) {
442 list = &sr->local_publ;
443 if (list_empty(list))
445 p = list_first_entry(list, struct publication, local_publ);
446 list_move_tail(&p->local_publ, &sr->local_publ);
447 } else if (legacy && !*dnode && !list_empty(&sr->local_publ)) {
448 list = &sr->local_publ;
449 p = list_first_entry(list, struct publication, local_publ);
450 list_move_tail(&p->local_publ, &sr->local_publ);
452 list = &sr->all_publ;
453 p = list_first_entry(list, struct publication, all_publ);
454 list_move_tail(&p->all_publ, &sr->all_publ);
459 spin_unlock_bh(&sc->lock);
466 bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 scope,
467 struct list_head *dsts, int *dstcnt, u32 exclude,
470 u32 self = tipc_own_addr(net);
471 struct service_range *sr;
472 struct tipc_service *sc;
473 struct publication *p;
477 sc = tipc_service_find(net, type);
481 spin_lock_bh(&sc->lock);
483 sr = tipc_service_find_range(sc, instance);
487 list_for_each_entry(p, &sr->all_publ, all_publ) {
488 if (p->scope != scope)
490 if (p->port == exclude && p->node == self)
492 tipc_dest_push(dsts, p->node, p->port);
496 list_move_tail(&p->all_publ, &sr->all_publ);
500 spin_unlock_bh(&sc->lock);
503 return !list_empty(dsts);
506 void tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper,
507 u32 scope, bool exact, struct list_head *dports)
509 struct service_range *sr;
510 struct tipc_service *sc;
511 struct publication *p;
515 sc = tipc_service_find(net, type);
519 spin_lock_bh(&sc->lock);
521 for (n = rb_first(&sc->ranges); n; n = rb_next(n)) {
522 sr = container_of(n, struct service_range, tree_node);
523 if (sr->upper < lower)
525 if (sr->lower > upper)
527 list_for_each_entry(p, &sr->local_publ, local_publ) {
528 if (p->scope == scope || (!exact && p->scope < scope))
529 tipc_dest_push(dports, 0, p->port);
532 spin_unlock_bh(&sc->lock);
537 /* tipc_nametbl_lookup_dst_nodes - find broadcast destination nodes
538 * - Creates list of nodes that overlap the given multicast address
539 * - Determines if any node local destinations overlap
541 void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower,
542 u32 upper, struct tipc_nlist *nodes)
544 struct service_range *sr;
545 struct tipc_service *sc;
546 struct publication *p;
550 sc = tipc_service_find(net, type);
554 spin_lock_bh(&sc->lock);
556 for (n = rb_first(&sc->ranges); n; n = rb_next(n)) {
557 sr = container_of(n, struct service_range, tree_node);
558 if (sr->upper < lower)
560 if (sr->lower > upper)
562 list_for_each_entry(p, &sr->all_publ, all_publ) {
563 tipc_nlist_add(nodes, p->node);
566 spin_unlock_bh(&sc->lock);
571 /* tipc_nametbl_build_group - build list of communication group members
573 void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp,
576 struct service_range *sr;
577 struct tipc_service *sc;
578 struct publication *p;
582 sc = tipc_service_find(net, type);
586 spin_lock_bh(&sc->lock);
587 for (n = rb_first(&sc->ranges); n; n = rb_next(n)) {
588 sr = container_of(n, struct service_range, tree_node);
589 list_for_each_entry(p, &sr->all_publ, all_publ) {
590 if (p->scope != scope)
592 tipc_group_add_member(grp, p->node, p->port, p->lower);
595 spin_unlock_bh(&sc->lock);
600 /* tipc_nametbl_publish - add service binding to name table
602 struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
603 u32 upper, u32 scope, u32 port,
606 struct name_table *nt = tipc_name_table(net);
607 struct tipc_net *tn = tipc_net(net);
608 struct publication *p = NULL;
609 struct sk_buff *skb = NULL;
611 spin_lock_bh(&tn->nametbl_lock);
613 if (nt->local_publ_count >= TIPC_MAX_PUBL) {
614 pr_warn("Bind failed, max limit %u reached\n", TIPC_MAX_PUBL);
618 p = tipc_nametbl_insert_publ(net, type, lower, upper, scope,
619 tipc_own_addr(net), port, key);
621 nt->local_publ_count++;
622 skb = tipc_named_publish(net, p);
625 spin_unlock_bh(&tn->nametbl_lock);
628 tipc_node_broadcast(net, skb);
633 * tipc_nametbl_withdraw - withdraw a service binding
635 int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower,
638 struct name_table *nt = tipc_name_table(net);
639 struct tipc_net *tn = tipc_net(net);
640 u32 self = tipc_own_addr(net);
641 struct sk_buff *skb = NULL;
642 struct publication *p;
644 spin_lock_bh(&tn->nametbl_lock);
646 p = tipc_nametbl_remove_publ(net, type, lower, upper, self, key);
648 nt->local_publ_count--;
649 skb = tipc_named_withdraw(net, p);
650 list_del_init(&p->binding_sock);
653 pr_err("Failed to remove local publication {%u,%u,%u}/%u\n",
654 type, lower, upper, key);
656 spin_unlock_bh(&tn->nametbl_lock);
659 tipc_node_broadcast(net, skb);
666 * tipc_nametbl_subscribe - add a subscription object to the name table
668 void tipc_nametbl_subscribe(struct tipc_subscription *sub)
670 struct name_table *nt = tipc_name_table(sub->net);
671 struct tipc_net *tn = tipc_net(sub->net);
672 struct tipc_subscr *s = &sub->evt.s;
673 u32 type = tipc_sub_read(s, seq.type);
674 struct tipc_service *sc;
676 spin_lock_bh(&tn->nametbl_lock);
677 sc = tipc_service_find(sub->net, type);
679 sc = tipc_service_create(type, &nt->services[hash(type)]);
681 spin_lock_bh(&sc->lock);
682 tipc_service_subscribe(sc, sub);
683 spin_unlock_bh(&sc->lock);
685 pr_warn("Failed to subscribe for {%u,%u,%u}\n", type,
686 tipc_sub_read(s, seq.lower),
687 tipc_sub_read(s, seq.upper));
689 spin_unlock_bh(&tn->nametbl_lock);
693 * tipc_nametbl_unsubscribe - remove a subscription object from name table
695 void tipc_nametbl_unsubscribe(struct tipc_subscription *sub)
697 struct tipc_net *tn = tipc_net(sub->net);
698 struct tipc_subscr *s = &sub->evt.s;
699 u32 type = tipc_sub_read(s, seq.type);
700 struct tipc_service *sc;
702 spin_lock_bh(&tn->nametbl_lock);
703 sc = tipc_service_find(sub->net, type);
707 spin_lock_bh(&sc->lock);
708 list_del_init(&sub->service_list);
711 /* Delete service item if no more publications and subscriptions */
712 if (RB_EMPTY_ROOT(&sc->ranges) && list_empty(&sc->subscriptions)) {
713 hlist_del_init_rcu(&sc->service_list);
716 spin_unlock_bh(&sc->lock);
718 spin_unlock_bh(&tn->nametbl_lock);
721 int tipc_nametbl_init(struct net *net)
723 struct tipc_net *tn = tipc_net(net);
724 struct name_table *nt;
727 nt = kzalloc(sizeof(*nt), GFP_ATOMIC);
731 for (i = 0; i < TIPC_NAMETBL_SIZE; i++)
732 INIT_HLIST_HEAD(&nt->services[i]);
734 INIT_LIST_HEAD(&nt->node_scope);
735 INIT_LIST_HEAD(&nt->cluster_scope);
737 spin_lock_init(&tn->nametbl_lock);
742 * tipc_service_delete - purge all publications for a service and delete it
744 static void tipc_service_delete(struct net *net, struct tipc_service *sc)
746 struct service_range *sr, *tmpr;
747 struct publication *p, *tmpb;
749 spin_lock_bh(&sc->lock);
750 rbtree_postorder_for_each_entry_safe(sr, tmpr, &sc->ranges, tree_node) {
751 list_for_each_entry_safe(p, tmpb,
752 &sr->all_publ, all_publ) {
753 tipc_service_remove_publ(net, sc, p->lower, p->upper,
758 hlist_del_init_rcu(&sc->service_list);
759 spin_unlock_bh(&sc->lock);
763 void tipc_nametbl_stop(struct net *net)
765 struct name_table *nt = tipc_name_table(net);
766 struct tipc_net *tn = tipc_net(net);
767 struct hlist_head *service_head;
768 struct tipc_service *service;
771 /* Verify name table is empty and purge any lingering
772 * publications, then release the name table
774 spin_lock_bh(&tn->nametbl_lock);
775 for (i = 0; i < TIPC_NAMETBL_SIZE; i++) {
776 if (hlist_empty(&nt->services[i]))
778 service_head = &nt->services[i];
779 hlist_for_each_entry_rcu(service, service_head, service_list) {
780 tipc_service_delete(net, service);
783 spin_unlock_bh(&tn->nametbl_lock);
789 static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg,
790 struct tipc_service *service,
791 struct service_range *sr,
794 struct publication *p;
795 struct nlattr *attrs;
800 list_for_each_entry(p, &sr->all_publ, all_publ)
801 if (p->key == *last_key)
803 if (p->key != *last_key)
806 p = list_first_entry(&sr->all_publ,
811 list_for_each_entry_from(p, &sr->all_publ, all_publ) {
814 hdr = genlmsg_put(msg->skb, msg->portid, msg->seq,
815 &tipc_genl_family, NLM_F_MULTI,
816 TIPC_NL_NAME_TABLE_GET);
820 attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE);
824 b = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL);
828 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, service->type))
830 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sr->lower))
832 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sr->upper))
834 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope))
836 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node))
838 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->port))
840 if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key))
843 nla_nest_end(msg->skb, b);
844 nla_nest_end(msg->skb, attrs);
845 genlmsg_end(msg->skb, hdr);
852 nla_nest_cancel(msg->skb, b);
854 nla_nest_cancel(msg->skb, attrs);
856 genlmsg_cancel(msg->skb, hdr);
861 static int __tipc_nl_service_range_list(struct tipc_nl_msg *msg,
862 struct tipc_service *sc,
863 u32 *last_lower, u32 *last_key)
865 struct service_range *sr;
869 for (n = rb_first(&sc->ranges); n; n = rb_next(n)) {
870 sr = container_of(n, struct service_range, tree_node);
871 if (sr->lower < *last_lower)
873 err = __tipc_nl_add_nametable_publ(msg, sc, sr, last_key);
875 *last_lower = sr->lower;
883 static int tipc_nl_service_list(struct net *net, struct tipc_nl_msg *msg,
884 u32 *last_type, u32 *last_lower, u32 *last_key)
886 struct tipc_net *tn = tipc_net(net);
887 struct tipc_service *service = NULL;
888 struct hlist_head *head;
893 i = hash(*last_type);
897 for (; i < TIPC_NAMETBL_SIZE; i++) {
898 head = &tn->nametbl->services[i];
901 service = tipc_service_find(net, *last_type);
905 hlist_for_each_entry_rcu(service, head, service_list)
911 hlist_for_each_entry_from_rcu(service, service_list) {
912 spin_lock_bh(&service->lock);
913 err = __tipc_nl_service_range_list(msg, service,
918 *last_type = service->type;
919 spin_unlock_bh(&service->lock);
922 spin_unlock_bh(&service->lock);
929 int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb)
931 struct net *net = sock_net(skb->sk);
932 u32 last_type = cb->args[0];
933 u32 last_lower = cb->args[1];
934 u32 last_key = cb->args[2];
935 int done = cb->args[3];
936 struct tipc_nl_msg msg;
943 msg.portid = NETLINK_CB(cb->skb).portid;
944 msg.seq = cb->nlh->nlmsg_seq;
947 err = tipc_nl_service_list(net, &msg, &last_type,
948 &last_lower, &last_key);
951 } else if (err != -EMSGSIZE) {
952 /* We never set seq or call nl_dump_check_consistent() this
953 * means that setting prev_seq here will cause the consistence
954 * check to fail in the netlink callback handler. Resulting in
955 * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if
962 cb->args[0] = last_type;
963 cb->args[1] = last_lower;
964 cb->args[2] = last_key;
970 struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port)
972 u64 value = (u64)node << 32 | port;
973 struct tipc_dest *dst;
975 list_for_each_entry(dst, l, list) {
976 if (dst->value != value)
983 bool tipc_dest_push(struct list_head *l, u32 node, u32 port)
985 u64 value = (u64)node << 32 | port;
986 struct tipc_dest *dst;
988 if (tipc_dest_find(l, node, port))
991 dst = kmalloc(sizeof(*dst), GFP_ATOMIC);
995 list_add(&dst->list, l);
999 bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port)
1001 struct tipc_dest *dst;
1005 dst = list_first_entry(l, typeof(*dst), list);
1010 list_del(&dst->list);
1015 bool tipc_dest_del(struct list_head *l, u32 node, u32 port)
1017 struct tipc_dest *dst;
1019 dst = tipc_dest_find(l, node, port);
1022 list_del(&dst->list);
1027 void tipc_dest_list_purge(struct list_head *l)
1029 struct tipc_dest *dst, *tmp;
1031 list_for_each_entry_safe(dst, tmp, l, list) {
1032 list_del(&dst->list);
1037 int tipc_dest_list_len(struct list_head *l)
1039 struct tipc_dest *dst;
1042 list_for_each_entry(dst, l, list) {