The terminology used for functions, struct and variables in the address binding table is still reflecting the specific, non-Linux environment where they were originally created.
We now change this to a more intuitive and consistent terminology, in accordance with how TIPC is described in the current documentation. Despite the size of this commit, the set of changes is in reality quite limited, and entail no functional changes. name -> service (in some cases to binding) publication -> binding sequence -> range Signed-off-by: Jon Maloy <[email protected]> --- net/tipc/Makefile | 2 +- net/tipc/bcast.c | 2 +- net/tipc/binding_distr.c | 391 +++++++++++++++ net/tipc/binding_distr.h | 78 +++ net/tipc/binding_table.c | 1151 ++++++++++++++++++++++++++++++++++++++++++++ net/tipc/binding_table.h | 149 ++++++ net/tipc/core.c | 8 +- net/tipc/core.h | 12 +- net/tipc/group.c | 2 +- net/tipc/link.c | 2 +- net/tipc/msg.c | 4 +- net/tipc/name_distr.c | 393 --------------- net/tipc/name_distr.h | 78 --- net/tipc/name_table.c | 1153 --------------------------------------------- net/tipc/name_table.h | 152 ------ net/tipc/net.c | 10 +- net/tipc/netlink.c | 4 +- net/tipc/netlink_compat.c | 4 +- net/tipc/node.c | 13 +- net/tipc/socket.c | 61 ++- net/tipc/subscr.c | 6 +- net/tipc/subscr.h | 2 +- net/tipc/sysctl.c | 6 +- 23 files changed, 1837 insertions(+), 1846 deletions(-) create mode 100644 net/tipc/binding_distr.c create mode 100644 net/tipc/binding_distr.h create mode 100644 net/tipc/binding_table.c create mode 100644 net/tipc/binding_table.h delete mode 100644 net/tipc/name_distr.c delete mode 100644 net/tipc/name_distr.h delete mode 100644 net/tipc/name_table.c delete mode 100644 net/tipc/name_table.h diff --git a/net/tipc/Makefile b/net/tipc/Makefile index aca168f..65875ed 100644 --- a/net/tipc/Makefile +++ b/net/tipc/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_TIPC) := tipc.o tipc-y += addr.o bcast.o bearer.o \ core.o link.o discover.o msg.o \ - name_distr.o subscr.o monitor.o name_table.o net.o \ + binding_distr.o subscr.o monitor.o binding_table.o net.o \ netlink.o netlink_compat.o node.o socket.o eth_media.o \ topsrv.o socket.o group.o diff --git a/net/tipc/bcast.c b/net/tipc/bcast.c index f371117..6b62487 100644 --- a/net/tipc/bcast.c +++ b/net/tipc/bcast.c @@ -40,7 +40,7 @@ #include "msg.h" #include "bcast.h" #include "link.h" -#include "name_table.h" +#include "binding_table.h" #define BCLINK_WIN_DEFAULT 50 /* bcast link window size (default) */ #define BCLINK_WIN_MIN 32 /* bcast minimum link window size */ diff --git a/net/tipc/binding_distr.c b/net/tipc/binding_distr.c new file mode 100644 index 0000000..207ff87 --- /dev/null +++ b/net/tipc/binding_distr.c @@ -0,0 +1,391 @@ +/* + * net/tipc/name_distr.c: TIPC name distribution code + * + * Copyright (c) 2000-2006, 2018, Ericsson AB + * Copyright (c) 2005, 2010-2011, Wind River Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "core.h" +#include "link.h" +#include "binding_distr.h" + +int sysctl_tipc_bindist_timeout __read_mostly = 2000; + +struct distr_queue_item { + struct distr_item i; + u32 dtype; + u32 node; + unsigned long expires; + struct list_head next; +}; + +/** + * binding_to_item - add publication info to a publication message + */ +static void binding_to_item(struct distr_item *i, struct tipc_binding *p) +{ + i->type = htonl(p->type); + i->lower = htonl(p->lower); + i->upper = htonl(p->upper); + i->port = htonl(p->port); + i->key = htonl(p->key); +} + +/** + * bindist_prepare_buf - allocate & initialize a publication message + * + * The buffer returned is of size INT_H_SIZE + payload size + */ +static struct sk_buff *bindist_prepare_buf(struct net *net, u32 type, + u32 size, u32 dest) +{ + struct sk_buff *skb = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC); + u32 self = tipc_own_addr(net); + struct tipc_msg *hdr; + + if (skb) { + hdr = buf_msg(skb); + tipc_msg_init(self, hdr, NAME_DISTRIBUTOR, + type, INT_H_SIZE, dest); + msg_set_size(hdr, INT_H_SIZE + size); + } + return skb; +} + +/** + * tipc_bindist_publish - tell other nodes about a new binding on this node + */ +struct sk_buff *tipc_bindist_publish(struct net *net, struct tipc_binding *b) +{ + struct tipc_binding_table *bt = tipc_binding_table(net); + struct distr_item *item; + struct sk_buff *skb; + + if (b->scope == TIPC_NODE_SCOPE) { + list_add_tail_rcu(&b->binding_node, &bt->node_scope); + return NULL; + } + list_add_tail_rcu(&b->binding_node, &bt->cluster_scope); + skb = bindist_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0); + if (!skb) { + pr_warn("Publication distribution failure\n"); + return NULL; + } + + item = (struct distr_item *)msg_data(buf_msg(skb)); + binding_to_item(item, b); + return skb; +} + +/** + * tipc_bindist_withdraw - tell other nodes about a removed binding by this node + */ +struct sk_buff *tipc_bindist_withdraw(struct net *net, struct tipc_binding *b) +{ + struct sk_buff *skb; + struct distr_item *item; + + list_del(&b->binding_node); + + if (b->scope == TIPC_NODE_SCOPE) + return NULL; + + skb = bindist_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0); + if (!skb) { + pr_warn("Withdrawal distribution failure\n"); + return NULL; + } + + item = (struct distr_item *)msg_data(buf_msg(skb)); + binding_to_item(item, b); + return skb; +} + +/** + * bindist_distribute - prepare name info for bulk distribution to another node + * @list: list of messages (buffers) to be returned from this function + * @dnode: node to be updated + * @pls: linked list of publication items to be packed into buffer chain + */ +static void bindist_distribute(struct net *net, struct sk_buff_head *list, + u32 dnode, struct list_head *pls) +{ + struct tipc_binding *b; + struct sk_buff *skb = NULL; + struct distr_item *item = NULL; + u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0) - INT_H_SIZE) / + ITEM_SIZE) * ITEM_SIZE; + u32 msg_rem = msg_dsz; + + list_for_each_entry(b, pls, binding_node) { + /* Prepare next buffer: */ + if (!skb) { + skb = bindist_prepare_buf(net, PUBLICATION, msg_rem, + dnode); + if (!skb) { + pr_warn("Bulk publication failure\n"); + return; + } + msg_set_bc_ack_invalid(buf_msg(skb), true); + item = (struct distr_item *)msg_data(buf_msg(skb)); + } + + /* Pack binding into message: */ + binding_to_item(item, b); + item++; + msg_rem -= ITEM_SIZE; + + /* Append full buffer to list: */ + if (!msg_rem) { + __skb_queue_tail(list, skb); + skb = NULL; + msg_rem = msg_dsz; + } + } + if (skb) { + msg_set_size(buf_msg(skb), INT_H_SIZE + (msg_dsz - msg_rem)); + skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem)); + __skb_queue_tail(list, skb); + } +} + +/** + * tipc_bindist_node_up - tell specified node about all bindings on this node + */ +void tipc_bindist_node_up(struct net *net, u32 dnode) +{ + struct tipc_binding_table *bt = tipc_binding_table(net); + struct sk_buff_head head; + + __skb_queue_head_init(&head); + rcu_read_lock(); + bindist_distribute(net, &head, dnode, &bt->cluster_scope); + rcu_read_unlock(); + tipc_node_xmit(net, &head, dnode, 0); +} + +/** + * tipc_publ_purge - remove publication associated with a failed node + * + * Invoked for each publication issued by a newly failed node. + * Removes publication structure from name table & deletes it. + */ +static void tipc_purge_binding(struct net *net, struct tipc_binding *b, + u32 addr) +{ + struct tipc_net *tn = net_generic(net, tipc_net_id); + struct tipc_binding *p; + + spin_lock_bh(&tn->bindingtbl_lock); + p = tipc_bindtbl_remove_binding(net, b->type, b->lower, + b->node, b->port, b->key); + if (p) + tipc_node_unsubscribe(net, &p->binding_node, addr); + spin_unlock_bh(&tn->bindingtbl_lock); + + if (p != b) { + pr_err("Unable to remove publication from failed node\n" + " (type=%u, lower=%u, node=0x%x, port=%u, key=%u)\n", + b->type, b->lower, b->node, b->port, + b->key); + } + + kfree_rcu(p, rcu); +} + +/** + * tipc_dist_queue_purge - remove deferred updates from a node that went down + */ +static void tipc_dist_queue_purge(struct net *net, u32 addr) +{ + struct tipc_net *tn = net_generic(net, tipc_net_id); + struct distr_queue_item *e, *tmp; + + spin_lock_bh(&tn->bindingtbl_lock); + list_for_each_entry_safe(e, tmp, &tn->dist_queue, next) { + if (e->node != addr) + continue; + list_del(&e->next); + kfree(e); + } + spin_unlock_bh(&tn->bindingtbl_lock); +} + +void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr) +{ + struct tipc_binding *b, *tmp; + + list_for_each_entry_safe(b, tmp, nsub_list, binding_node) + tipc_purge_binding(net, b, addr); + tipc_dist_queue_purge(net, addr); +} + +/** + * tipc_update_nametbl - try to process a nametable update and notify + * subscribers + * + * tipc_bindtbl_lock must be held. + * Returns the publication item if successful, otherwise NULL. + */ +static bool tipc_update_nametbl(struct net *net, struct distr_item *i, + u32 node, u32 dtype) +{ + struct tipc_binding *b = NULL; + + if (dtype == PUBLICATION) { + b = tipc_bindtbl_insert_binding(net, ntohl(i->type), + ntohl(i->lower), + ntohl(i->upper), + TIPC_CLUSTER_SCOPE, node, + ntohl(i->port), ntohl(i->key)); + if (b) { + tipc_node_subscribe(net, &b->binding_node, node); + return true; + } + } else if (dtype == WITHDRAWAL) { + b = tipc_bindtbl_remove_binding(net, ntohl(i->type), + ntohl(i->lower), + node, ntohl(i->port), + ntohl(i->key)); + if (b) { + tipc_node_unsubscribe(net, &b->binding_node, node); + kfree_rcu(b, rcu); + return true; + } + } else { + pr_warn("Unrecognized name table message received\n"); + } + return false; +} + +/** + * tipc_bindist_add_backlog - add a failed name table update to the backlog + * + */ +static void tipc_bindist_add_backlog(struct net *net, struct distr_item *i, + u32 type, u32 node) +{ + struct distr_queue_item *e; + struct tipc_net *tn = net_generic(net, tipc_net_id); + unsigned long now = get_jiffies_64(); + + e = kzalloc(sizeof(*e), GFP_ATOMIC); + if (!e) + return; + e->dtype = type; + e->node = node; + e->expires = now + msecs_to_jiffies(sysctl_tipc_bindist_timeout); + memcpy(e, i, sizeof(*i)); + list_add_tail(&e->next, &tn->dist_queue); +} + +/** + * tipc_bindist_process_backlog - try to process any pending name table updates + * from the network. + */ +void tipc_bindist_process_backlog(struct net *net) +{ + struct distr_queue_item *e, *tmp; + struct tipc_net *tn = net_generic(net, tipc_net_id); + unsigned long now = get_jiffies_64(); + + list_for_each_entry_safe(e, tmp, &tn->dist_queue, next) { + if (time_after(e->expires, now)) { + if (!tipc_update_nametbl(net, &e->i, e->node, e->dtype)) + continue; + } else { + pr_warn_ratelimited("Dropping name table update (%d) of {%u, %u, %u} from %x key=%u\n", + e->dtype, ntohl(e->i.type), + ntohl(e->i.lower), + ntohl(e->i.upper), + e->node, ntohl(e->i.key)); + } + list_del(&e->next); + kfree(e); + } +} + +/** + * tipc_bindist_rcv - process name table update messages sent by another node + */ +void tipc_bindist_rcv(struct net *net, struct sk_buff_head *inputq) +{ + struct tipc_net *tn = net_generic(net, tipc_net_id); + struct tipc_msg *hdr; + struct distr_item *item; + uint count; + u32 node; + struct sk_buff *skb; + int mtyp; + + spin_lock_bh(&tn->bindingtbl_lock); + for (skb = skb_dequeue(inputq); skb; skb = skb_dequeue(inputq)) { + skb_linearize(skb); + hdr = buf_msg(skb); + mtyp = msg_type(hdr); + item = (struct distr_item *)msg_data(hdr); + count = msg_data_sz(hdr) / ITEM_SIZE; + node = msg_orignode(hdr); + while (count--) { + if (!tipc_update_nametbl(net, item, node, mtyp)) + tipc_bindist_add_backlog(net, item, mtyp, node); + item++; + } + kfree_skb(skb); + tipc_bindist_process_backlog(net); + } + spin_unlock_bh(&tn->bindingtbl_lock); +} + +/** + * tipc_bindist_reinit - re-initialize local publications + * + * This routine is called whenever TIPC networking is enabled. + * All name table entries bished by this node are updated to reflect + * the node's new network address. + */ +void tipc_bindist_reinit(struct net *net) +{ + struct tipc_binding_table *bt = tipc_binding_table(net); + struct tipc_net *tn = tipc_net(net); + struct tipc_binding *b; + u32 self = tipc_own_addr(net); + + spin_lock_bh(&tn->bindingtbl_lock); + + list_for_each_entry_rcu(b, &bt->node_scope, binding_node) + b->node = self; + list_for_each_entry_rcu(b, &bt->cluster_scope, binding_node) + b->node = self; + + spin_unlock_bh(&tn->bindingtbl_lock); +} diff --git a/net/tipc/binding_distr.h b/net/tipc/binding_distr.h new file mode 100644 index 0000000..6dac797 --- /dev/null +++ b/net/tipc/binding_distr.h @@ -0,0 +1,78 @@ +/* + * net/tipc/name_distr.h: Include file for TIPC name distribution code + * + * Copyright (c) 2000-2006, Ericsson AB + * Copyright (c) 2005, Wind River Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIPC_NAME_DISTR_H +#define _TIPC_NAME_DISTR_H + +#include "binding_table.h" + +#define ITEM_SIZE sizeof(struct distr_item) + +/** + * struct distr_item - publication info distributed to other nodes + * @type: name sequence type + * @lower: name sequence lower bound + * @upper: name sequence upper bound + * @ref: publishing port reference + * @key: publication key + * + * ===> All fields are stored in network byte order. <=== + * + * First 3 fields identify (name or) name sequence being published. + * Reference field uniquely identifies port that published name sequence. + * Key field uniquely identifies publication, in the event a port has + * multiple publications of the same name sequence. + * + * Note: There is no field that identifies the publishing node because it is + * the same for all items contained within a publication message. + */ +struct distr_item { + __be32 type; + __be32 lower; + __be32 upper; + __be32 port; + __be32 key; +}; + +struct sk_buff *tipc_bindist_publish(struct net *net, struct tipc_binding *b); +struct sk_buff *tipc_bindist_withdraw(struct net *net, struct tipc_binding *b); +void tipc_bindist_node_up(struct net *net, u32 dnode); +void tipc_bindist_rcv(struct net *net, struct sk_buff_head *msg_queue); +void tipc_bindist_reinit(struct net *net); +void tipc_bindist_process_backlog(struct net *net); +void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr); + +#endif diff --git a/net/tipc/binding_table.c b/net/tipc/binding_table.c new file mode 100644 index 0000000..7bb9ffc --- /dev/null +++ b/net/tipc/binding_table.c @@ -0,0 +1,1151 @@ +/* + * net/tipc/binding_table.c: TIPC binding table code + * + * Copyright (c) 2000-2006, 2014-2018, Ericsson AB + * Copyright (c) 2004-2008, 2010-2014, Wind River Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <net/sock.h> +#include "core.h" +#include "netlink.h" +#include "binding_table.h" +#include "binding_distr.h" +#include "subscr.h" +#include "bcast.h" +#include "addr.h" +#include "node.h" +#include "group.h" +#include <net/genetlink.h> + +/** + * struct name_info - name range publication info + * @node_list: list of bindings on own node of this <type,lower,upper> + * @all_bindings: list of all bindings of this <type,lower,upper> + */ +struct name_info { + struct list_head local_bindings; + struct list_head all_bindings; +}; + +/** + * struct service_range - container for all bindings of a service + * @lower: name range lower bound + * @upper: name range upper bound + * @info: pointer to name range publication info + */ +struct service_range { + u32 lower; + u32 upper; + struct name_info *info; +}; + +/** + * struct tipc_service - container for all published instances of a name type + * @type: 32 bit 'type' value for service + * @sr: pointer to dynamically-sized array of ranges of this 'type'; + * ranges are sorted in ascending order + * @alloc: number of ranges currently in array + * @first_free: array index of first unused range entry + * @service_list: links to adjacent name ranges in hash chain + * @subscriptions: list of subscriptions for this service type + * @lock: spinlock controlling access to publication lists of all ranges + * @rcu: RCU callback head used for deferred freeing + */ +struct tipc_service { + u32 type; + struct service_range *ranges; + u32 alloc; + u32 first_free; + struct hlist_node service_list; + struct list_head subscriptions; + spinlock_t lock; /* Covers service range list */ + struct rcu_head rcu; +}; + +static int hash(int x) +{ + return x & (TIPC_BINDING_TABLE_SIZE - 1); +} + +/** + * tipc_create_binding - create a binding structure + */ +static struct tipc_binding *tipc_create_binding(u32 type, u32 lower, u32 upper, + u32 scope, u32 node, u32 port, + u32 key) +{ + struct tipc_binding *b = kzalloc(sizeof(*b), GFP_ATOMIC); + + if (!b) + return NULL; + + b->type = type; + b->lower = lower; + b->upper = upper; + b->scope = scope; + b->node = node; + b->port = port; + b->key = key; + INIT_LIST_HEAD(&b->binding_sock); + return b; +} + +/** + * tipc_srvrange_alloc - allocate a specified number of service range structures + */ +static struct service_range *tipc_srvrange_alloc(u32 cnt) +{ + return kcalloc(cnt, sizeof(struct service_range), GFP_ATOMIC); +} + +/** + * tipc_service_create - create a service structure for the specified 'type' + * + * Allocates a single range structure and sets it to all 0's. + */ +static struct tipc_service *tipc_service_create(u32 type, + struct hlist_head *service_head) +{ + struct tipc_service *service = kzalloc(sizeof(*service), GFP_ATOMIC); + struct service_range *sr = tipc_srvrange_alloc(1); + + if (!service || !sr) { + pr_warn("Name range creation failed, no memory\n"); + kfree(service); + kfree(sr); + return NULL; + } + + spin_lock_init(&service->lock); + service->type = type; + service->ranges = sr; + service->alloc = 1; + INIT_HLIST_NODE(&service->service_list); + INIT_LIST_HEAD(&service->subscriptions); + hlist_add_head_rcu(&service->service_list, service_head); + return service; +} + +/** + * tipc_service_find_range - find service range matching a service instance + * + * Very time-critical, so binary searches through range array. + */ +static struct service_range *tipc_service_find_range(struct tipc_service *sc, + u32 instance) +{ + struct service_range *ranges = sc->ranges; + int low = 0; + int high = sc->first_free - 1; + int mid; + + while (low <= high) { + mid = (low + high) / 2; + if (instance < ranges[mid].lower) + high = mid - 1; + else if (instance > ranges[mid].upper) + low = mid + 1; + else + return &ranges[mid]; + } + return NULL; +} + +/** + * tipc_service_locate_range - determine position of name instance in range + * + * Returns index in range array of the entry that contains the specified + * instance value; if no entry contains that value, returns the position + * where a new entry for it would be inserted in the array. + * + * Note: Similar to binary search code for locating a range. + */ +static u32 tipc_service_locate_range(struct tipc_service *service, u32 instance) +{ + struct service_range *ranges = service->ranges; + int low = 0; + int high = service->first_free - 1; + int mid; + + while (low <= high) { + mid = (low + high) / 2; + if (instance < ranges[mid].lower) + high = mid - 1; + else if (instance > ranges[mid].upper) + low = mid + 1; + else + return mid; + } + return low; +} + +/** + * tipc_service_insert_binding + */ +static struct tipc_binding *tipc_service_insert_binding(struct net *net, + struct tipc_service *sc, + u32 type, u32 lower, + u32 upper, u32 scope, + u32 node, u32 port, + u32 key) +{ + struct tipc_subscription *s; + struct tipc_subscription *st; + struct tipc_binding *b; + struct service_range *sr; + struct name_info *info; + int created_range = 0; + + sr = tipc_service_find_range(sc, lower); + if (sr) { + /* Lower end overlaps existing entry => need an exact match */ + if (sr->lower != lower || sr->upper != upper) + return NULL; + + info = sr->info; + + /* Check if an identical binding already exists */ + list_for_each_entry(b, &info->all_bindings, all_bindings) { + if (b->port == port && b->key == key && + (!b->node || b->node == node)) + return NULL; + } + } else { + u32 inspos; + struct service_range *freesr; + + /* Find where lower end should be inserted */ + inspos = tipc_service_locate_range(sc, lower); + + /* Fail if upper end overlaps into an existing entry */ + if (inspos < sc->first_free && + upper >= sc->ranges[inspos].lower) + return NULL; + + /* Ensure there is space for new range */ + if (sc->first_free == sc->alloc) { + struct service_range *ranges = + tipc_srvrange_alloc(sc->alloc * 2); + + if (!ranges) { + pr_warn("Cannot publish {%u,%u,%u}, no memory\n", + type, lower, upper); + return NULL; + } + memcpy(ranges, sc->ranges, + sc->alloc * sizeof(*sr)); + kfree(sc->ranges); + sc->ranges = ranges; + sc->alloc *= 2; + } + + info = kzalloc(sizeof(*info), GFP_ATOMIC); + if (!info) + return NULL; + + INIT_LIST_HEAD(&info->local_bindings); + INIT_LIST_HEAD(&info->all_bindings); + + /* Insert new range */ + sr = &sc->ranges[inspos]; + freesr = &sc->ranges[sc->first_free]; + memmove(sr + 1, sr, (freesr - sr) * sizeof(*sr)); + memset(sr, 0, sizeof(*sr)); + sc->first_free++; + sr->lower = lower; + sr->upper = upper; + sr->info = info; + created_range = 1; + } + + /* Insert a binding */ + b = tipc_create_binding(type, lower, upper, scope, node, port, key); + if (!b) + return NULL; + + list_add(&b->all_bindings, &info->all_bindings); + + if (in_own_node(net, node)) + list_add(&b->local_bindings, &info->local_bindings); + + /* Any subscriptions waiting for notification? */ + list_for_each_entry_safe(s, st, &sc->subscriptions, service_list) { + tipc_sub_report_overlap(s, b->lower, b->upper, + TIPC_PUBLISHED, b->port, + b->node, b->scope, + created_range); + } + return b; +} + +/** + * tipc_service_remove_binding + * + * NOTE: There may be cases where TIPC is asked to remove a binding + * that is not in the name table. For example, if another node issues a + * binding for a name range that overlaps an existing name range + * the binding will not be recorded, which means the binding won't + * be found when the name range is later withdrawn by that node. + * A failed withdraw request simply returns a failure indication and lets the + * caller issue any error or warning messages associated with such a problem. + */ +static struct tipc_binding *tipc_service_remove_binding(struct net *net, + struct tipc_service *sc, + u32 inst, u32 node, + u32 port, u32 key) +{ + struct service_range *sr = tipc_service_find_range(sc, inst); + struct name_info *info; + struct service_range *free; + struct tipc_subscription *s, *st; + struct tipc_binding *b; + int removed_range = 0; + + if (!sr) + return NULL; + + info = sr->info; + + /* Locate binding, if it exists */ + list_for_each_entry(b, &info->all_bindings, all_bindings) { + if (b->key == key && b->port == port && + (!b->node || b->node == node)) + goto found; + } + return NULL; +found: + list_del(&b->all_bindings); + if (in_own_node(net, node)) + list_del(&b->local_bindings); + + /* Contract range list if no more bindings for that range */ + if (list_empty(&info->all_bindings)) { + kfree(info); + free = &sc->ranges[sc->first_free--]; + memmove(sr, sr + 1, (free - (sr + 1)) * sizeof(*sr)); + removed_range = 1; + } + /* Notify any waiting subscriptions */ + list_for_each_entry_safe(s, st, &sc->subscriptions, service_list) { + tipc_sub_report_overlap(s, b->lower, b->upper, + TIPC_WITHDRAWN, b->port, + b->node, b->scope, + removed_range); + } + return b; +} + +/** + * tipc_service_subscribe - attach a subscription, and optionally + * issue the prescribed number of events if there is any sub- + * range overlapping with the requested range + */ +static void tipc_service_subscribe(struct tipc_service *service, + struct tipc_subscription *sub) +{ + struct service_range *sr = service->ranges; + struct tipc_name_seq ns; + struct tipc_subscr *s = &sub->evt.s; + bool no_status; + + ns.type = tipc_sub_read(s, seq.type); + ns.lower = tipc_sub_read(s, seq.lower); + ns.upper = tipc_sub_read(s, seq.upper); + no_status = tipc_sub_read(s, filter) & TIPC_SUB_NO_STATUS; + + tipc_sub_get(sub); + list_add(&sub->service_list, &service->subscriptions); + + if (no_status || !sr) + return; + + while (sr != &service->ranges[service->first_free]) { + if (tipc_sub_check_overlap(&ns, sr->lower, sr->upper)) { + struct tipc_binding *crs; + struct name_info *info = sr->info; + int must_report = 1; + + list_for_each_entry(crs, &info->all_bindings, + all_bindings) { + tipc_sub_report_overlap(sub, sr->lower, + sr->upper, + TIPC_PUBLISHED, + crs->port, + crs->node, + crs->scope, + must_report); + must_report = 0; + } + } + sr++; + } +} + +static struct tipc_service *tipc_bindtbl_find_service(struct net *net, u32 type) +{ + struct tipc_net *tn = tipc_net(net); + struct hlist_head *service_head; + struct tipc_service *service; + + service_head = &tn->bindingtbl->services[hash(type)]; + hlist_for_each_entry_rcu(service, service_head, service_list) { + if (service->type == type) + return service; + } + return NULL; +}; + +struct tipc_binding *tipc_bindtbl_insert_binding(struct net *net, u32 type, + u32 lower, u32 upper, + u32 scope, u32 node, + u32 port, u32 key) +{ + struct tipc_net *tn = tipc_net(net); + struct tipc_binding *b; + struct tipc_service *service = tipc_bindtbl_find_service(net, type); + int index = hash(type); + + if (scope > TIPC_NODE_SCOPE || lower > upper) { + pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n", + type, lower, upper, scope); + return NULL; + } + if (!service) + service = tipc_service_create(type, + &tn->bindingtbl->services[index]); + if (!service) + return NULL; + + spin_lock_bh(&service->lock); + b = tipc_service_insert_binding(net, service, type, lower, upper, + scope, node, port, key); + spin_unlock_bh(&service->lock); + return b; +} + +struct tipc_binding *tipc_bindtbl_remove_binding(struct net *net, u32 type, + u32 lower, u32 node, u32 port, + u32 key) +{ + struct tipc_binding *b; + struct tipc_service *service = tipc_bindtbl_find_service(net, type); + + if (!service) + return NULL; + + spin_lock_bh(&service->lock); + b = tipc_service_remove_binding(net, service, lower, node, port, key); + if (!service->first_free && list_empty(&service->subscriptions)) { + hlist_del_init_rcu(&service->service_list); + kfree(service->ranges); + spin_unlock_bh(&service->lock); + kfree_rcu(service, rcu); + return b; + } + spin_unlock_bh(&service->lock); + return b; +} + +/** + * tipc_bindtbl_translate - perform name translation + * + * On entry, 'destnode' is the search domain used during translation. + * + * On exit: + * - if name translation is deferred to another node/cluster/zone, + * leaves 'destnode' unchanged (will be non-zero) and returns 0 + * - if name translation is attempted and succeeds, sets 'destnode' + * to publishing node and returns port reference (will be non-zero) + * - if name translation is attempted and fails, sets 'destnode' to 0 + * and returns 0 + */ +u32 tipc_bindtbl_translate(struct net *net, u32 type, u32 instance, + u32 *destnode) +{ + struct tipc_net *tn = tipc_net(net); + bool legacy = tn->legacy_addr_format; + u32 self = tipc_own_addr(net); + struct service_range *sr; + struct name_info *info; + struct tipc_binding *b; + struct tipc_service *service; + u32 port = 0; + u32 node = 0; + + if (!tipc_in_scope(legacy, *destnode, self)) + return 0; + + rcu_read_lock(); + service = tipc_bindtbl_find_service(net, type); + if (unlikely(!service)) + goto not_found; + spin_lock_bh(&service->lock); + sr = tipc_service_find_range(service, instance); + if (unlikely(!sr)) + goto no_match; + info = sr->info; + + /* Closest-First Algorithm */ + if (legacy && !*destnode) { + if (!list_empty(&info->local_bindings)) { + b = list_first_entry(&info->local_bindings, + struct tipc_binding, + local_bindings); + list_move_tail(&b->local_bindings, + &info->local_bindings); + } else { + b = list_first_entry(&info->all_bindings, + struct tipc_binding, + all_bindings); + list_move_tail(&b->all_bindings, + &info->all_bindings); + } + } + + /* Round-Robin Algorithm */ + else if (*destnode == tipc_own_addr(net)) { + if (list_empty(&info->local_bindings)) + goto no_match; + b = list_first_entry(&info->local_bindings, struct tipc_binding, + local_bindings); + list_move_tail(&b->local_bindings, &info->local_bindings); + } else { + b = list_first_entry(&info->all_bindings, struct tipc_binding, + all_bindings); + list_move_tail(&b->all_bindings, &info->all_bindings); + } + + port = b->port; + node = b->node; +no_match: + spin_unlock_bh(&service->lock); +not_found: + rcu_read_unlock(); + *destnode = node; + return port; +} + +bool tipc_bindtbl_lookup(struct net *net, u32 type, u32 instance, u32 scope, + struct list_head *dsts, int *dstcnt, u32 exclude, + bool all) +{ + u32 self = tipc_own_addr(net); + struct tipc_binding *b; + struct name_info *info; + struct tipc_service *service; + struct service_range *sr; + + *dstcnt = 0; + rcu_read_lock(); + service = tipc_bindtbl_find_service(net, type); + if (unlikely(!service)) + goto exit; + spin_lock_bh(&service->lock); + sr = tipc_service_find_range(service, instance); + if (likely(sr)) { + info = sr->info; + list_for_each_entry(b, &info->all_bindings, all_bindings) { + if (b->scope != scope) + continue; + if (b->port == exclude && b->node == self) + continue; + tipc_dest_push(dsts, b->node, b->port); + (*dstcnt)++; + if (all) + continue; + list_move_tail(&b->all_bindings, &info->all_bindings); + break; + } + } + spin_unlock_bh(&service->lock); +exit: + rcu_read_unlock(); + return !list_empty(dsts); +} + +void tipc_bindtbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper, + u32 scope, bool exact, struct list_head *dports) +{ + struct service_range *sr_stop; + struct name_info *info; + struct tipc_binding *p; + struct tipc_service *service; + struct service_range *sr; + + rcu_read_lock(); + service = tipc_bindtbl_find_service(net, type); + if (!service) + goto exit; + + spin_lock_bh(&service->lock); + sr = service->ranges + tipc_service_locate_range(service, lower); + sr_stop = service->ranges + service->first_free; + for (; sr != sr_stop; sr++) { + if (sr->lower > upper) + break; + info = sr->info; + list_for_each_entry(p, &info->local_bindings, local_bindings) { + if (p->scope == scope || (!exact && p->scope < scope)) + tipc_dest_push(dports, 0, p->port); + } + } + spin_unlock_bh(&service->lock); +exit: + rcu_read_unlock(); +} + +/* tipc_bindtbl_lookup_dst_nodes - find broadcast destination nodes + * - Creates list of nodes that overlap the given multicast address + * - Determines if any node local ports overlap + */ +void tipc_bindtbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower, + u32 upper, struct tipc_nlist *nodes) +{ + struct service_range *sr, *stop; + struct tipc_binding *b; + struct name_info *info; + struct tipc_service *service; + + rcu_read_lock(); + service = tipc_bindtbl_find_service(net, type); + if (!service) + goto exit; + + spin_lock_bh(&service->lock); + sr = service->ranges + tipc_service_locate_range(service, lower); + stop = service->ranges + service->first_free; + for (; sr != stop && sr->lower <= upper; sr++) { + info = sr->info; + list_for_each_entry(b, &info->all_bindings, all_bindings) { + tipc_nlist_add(nodes, b->node); + } + } + spin_unlock_bh(&service->lock); +exit: + rcu_read_unlock(); +} + +/* tipc_bindtbl_build_group - build list of communication group members + */ +void tipc_bindtbl_build_group(struct net *net, struct tipc_group *grp, + u32 type, u32 scope) +{ + struct service_range *sr, *stop; + struct name_info *info; + struct tipc_binding *b; + struct tipc_service *service; + + rcu_read_lock(); + service = tipc_bindtbl_find_service(net, type); + if (!service) + goto exit; + + spin_lock_bh(&service->lock); + sr = service->ranges; + stop = service->ranges + service->first_free; + for (; sr != stop; sr++) { + info = sr->info; + list_for_each_entry(b, &info->all_bindings, all_bindings) { + if (b->scope != scope) + continue; + tipc_group_add_member(grp, b->node, b->port, b->lower); + } + } + spin_unlock_bh(&service->lock); +exit: + rcu_read_unlock(); +} + +/* tipc_bindtbl_publish - add name binding to network name tables + */ +struct tipc_binding *tipc_bindtbl_bind(struct net *net, u32 type, u32 lower, + u32 upper, u32 scope, u32 port, + u32 key) +{ + struct tipc_binding *b; + struct sk_buff *buf = NULL; + struct tipc_net *tn = tipc_net(net); + + spin_lock_bh(&tn->bindingtbl_lock); + if (tn->bindingtbl->local_bindings_count >= TIPC_MAX_PUBLICATIONS) { + pr_warn("Binding failed, local limit reached (%u)\n", + TIPC_MAX_PUBLICATIONS); + spin_unlock_bh(&tn->bindingtbl_lock); + return NULL; + } + + b = tipc_bindtbl_insert_binding(net, type, lower, upper, scope, + tipc_own_addr(net), port, key); + if (likely(b)) { + tn->bindingtbl->local_bindings_count++; + buf = tipc_bindist_publish(net, b); + /* Any pending external events? */ + tipc_bindist_process_backlog(net); + } + spin_unlock_bh(&tn->bindingtbl_lock); + + if (buf) + tipc_node_broadcast(net, buf); + return b; +} + +/** + * tipc_bindtbl_unbind - withdraw name binding from network name tables + */ +int tipc_bindtbl_unbind(struct net *net, u32 type, u32 lower, u32 port, u32 key) +{ + struct tipc_binding *b; + struct sk_buff *skb = NULL; + struct tipc_net *tn = tipc_net(net); + + spin_lock_bh(&tn->bindingtbl_lock); + b = tipc_bindtbl_remove_binding(net, type, lower, tipc_own_addr(net), + port, key); + if (likely(b)) { + tn->bindingtbl->local_bindings_count--; + skb = tipc_bindist_withdraw(net, b); + /* Any pending external events? */ + tipc_bindist_process_backlog(net); + list_del_init(&b->binding_sock); + kfree_rcu(b, rcu); + } else { + pr_err("Unable to remove local binding\n" + "(type=%u, lower=%u, port=%u, key=%u)\n", + type, lower, port, key); + } + spin_unlock_bh(&tn->bindingtbl_lock); + + if (skb) { + tipc_node_broadcast(net, skb); + return 1; + } + return 0; +} + +/** + * tipc_bindtbl_subscribe - add a subscription object to the name table + */ +void tipc_bindtbl_subscribe(struct tipc_subscription *sub) +{ + struct tipc_net *tn = tipc_net(sub->net); + struct tipc_subscr *s = &sub->evt.s; + u32 type = tipc_sub_read(s, seq.type); + int index = hash(type); + struct tipc_service *service; + struct tipc_name_seq ns; + + spin_lock_bh(&tn->bindingtbl_lock); + service = tipc_bindtbl_find_service(sub->net, type); + if (!service) + service = tipc_service_create(type, + &tn->bindingtbl->services[index]); + + if (service) { + spin_lock_bh(&service->lock); + tipc_service_subscribe(service, sub); + spin_unlock_bh(&service->lock); + } else { + ns.type = tipc_sub_read(s, seq.type); + ns.lower = tipc_sub_read(s, seq.lower); + ns.upper = tipc_sub_read(s, seq.upper); + pr_warn("Failed to create subscription for {%u,%u,%u}\n", + ns.type, ns.lower, ns.upper); + } + spin_unlock_bh(&tn->bindingtbl_lock); +} + +/** + * tipc_bindtbl_unsubscribe - remove a subscription object from name table + */ +void tipc_bindtbl_unsubscribe(struct tipc_subscription *sub) +{ + struct tipc_subscr *s = &sub->evt.s; + struct tipc_net *tn = tipc_net(sub->net); + struct tipc_service *service; + u32 type = tipc_sub_read(s, seq.type); + + spin_lock_bh(&tn->bindingtbl_lock); + service = tipc_bindtbl_find_service(sub->net, type); + if (service) { + spin_lock_bh(&service->lock); + list_del_init(&sub->service_list); + tipc_sub_put(sub); + if (!service->first_free && + list_empty(&service->subscriptions)) { + hlist_del_init_rcu(&service->service_list); + kfree(service->ranges); + spin_unlock_bh(&service->lock); + kfree_rcu(service, rcu); + } else { + spin_unlock_bh(&service->lock); + } + } + spin_unlock_bh(&tn->bindingtbl_lock); +} + +int tipc_bindtbl_init(struct net *net) +{ + struct tipc_net *tn = tipc_net(net); + struct tipc_binding_table *bt; + int i; + + bt = kzalloc(sizeof(*bt), GFP_ATOMIC); + if (!bt) + return -ENOMEM; + + for (i = 0; i < TIPC_BINDING_TABLE_SIZE; i++) + INIT_HLIST_HEAD(&bt->services[i]); + + INIT_LIST_HEAD(&bt->node_scope); + INIT_LIST_HEAD(&bt->cluster_scope); + tn->bindingtbl = bt; + spin_lock_init(&tn->bindingtbl_lock); + return 0; +} + +/** + * tipc_purge_bindings - remove all bindings for a given type + * + * tipc_bindtbl_lock must be held when calling this function + */ +static void tipc_purge_bindings(struct net *net, struct tipc_service *service) +{ + struct tipc_binding *b, *safe; + struct service_range *sr; + struct name_info *info; + + spin_lock_bh(&service->lock); + sr = service->ranges; + info = sr->info; + list_for_each_entry_safe(b, safe, &info->all_bindings, all_bindings) { + tipc_service_remove_binding(net, service, b->lower, b->node, + b->port, b->key); + kfree_rcu(b, rcu); + } + hlist_del_init_rcu(&service->service_list); + kfree(service->ranges); + spin_unlock_bh(&service->lock); + + kfree_rcu(service, rcu); +} + +void tipc_bindtbl_stop(struct net *net) +{ + u32 i; + struct tipc_service *service; + struct hlist_head *service_head; + struct tipc_net *tn = tipc_net(net); + struct tipc_binding_table *bt = tn->bindingtbl; + + /* Verify name table is empty and purge any lingering + * bindings, then release the name table + */ + spin_lock_bh(&tn->bindingtbl_lock); + for (i = 0; i < TIPC_BINDING_TABLE_SIZE; i++) { + if (hlist_empty(&bt->services[i])) + continue; + service_head = &bt->services[i]; + hlist_for_each_entry_rcu(service, service_head, service_list) { + tipc_purge_bindings(net, service); + } + } + spin_unlock_bh(&tn->bindingtbl_lock); + + synchronize_net(); + kfree(bt); +} + +static int __tipc_nl_add_nametable_binding(struct tipc_nl_msg *msg, + struct tipc_service *service, + struct service_range *sr, + u32 *last_binding) +{ + void *hdr; + struct nlattr *attrs; + struct nlattr *b; + struct tipc_binding *p; + + if (*last_binding) { + list_for_each_entry(p, &sr->info->all_bindings, all_bindings) + if (p->key == *last_binding) + break; + if (p->key != *last_binding) + return -EPIPE; + } else { + p = list_first_entry(&sr->info->all_bindings, + struct tipc_binding, + all_bindings); + } + + list_for_each_entry_from(p, &sr->info->all_bindings, all_bindings) { + *last_binding = p->key; + + hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, + &tipc_genl_family, NLM_F_MULTI, + TIPC_NL_NAME_TABLE_GET); + if (!hdr) + return -EMSGSIZE; + + attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE); + if (!attrs) + goto msg_full; + + b = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL); + if (!b) + goto attr_msg_full; + + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, service->type)) + goto publ_msg_full; + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sr->lower)) + goto publ_msg_full; + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sr->upper)) + goto publ_msg_full; + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope)) + goto publ_msg_full; + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node)) + goto publ_msg_full; + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->port)) + goto publ_msg_full; + if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key)) + goto publ_msg_full; + + nla_nest_end(msg->skb, b); + nla_nest_end(msg->skb, attrs); + genlmsg_end(msg->skb, hdr); + } + *last_binding = 0; + + return 0; + +publ_msg_full: + nla_nest_cancel(msg->skb, b); +attr_msg_full: + nla_nest_cancel(msg->skb, attrs); +msg_full: + genlmsg_cancel(msg->skb, hdr); + + return -EMSGSIZE; +} + +static int __tipc_nl_srvrange_list(struct tipc_nl_msg *msg, + struct tipc_service *service, + u32 *last_lower, u32 *last_binding) +{ + struct service_range *sr; + struct service_range *sr_start; + int err; + + if (*last_lower) { + sr_start = tipc_service_find_range(service, *last_lower); + if (!sr_start) + return -EPIPE; + } else { + sr_start = service->ranges; + } + + for (sr = sr_start; sr != &service->ranges[service->first_free]; sr++) { + err = __tipc_nl_add_nametable_binding(msg, service, sr, + last_binding); + if (err) { + *last_lower = sr->lower; + return err; + } + } + *last_lower = 0; + + return 0; +} + +static int tipc_nl_service_list(struct net *net, struct tipc_nl_msg *msg, + u32 *last_type, u32 *last_lower, + u32 *last_binding) +{ + struct tipc_net *tn = tipc_net(net); + struct hlist_head *head; + struct tipc_service *service = NULL; + int err; + int i; + + if (*last_type) + i = hash(*last_type); + else + i = 0; + + for (; i < TIPC_BINDING_TABLE_SIZE; i++) { + head = &tn->bindingtbl->services[i]; + + if (*last_type) { + service = tipc_bindtbl_find_service(net, *last_type); + if (!service) + return -EPIPE; + } else { + hlist_for_each_entry_rcu(service, head, service_list) + break; + if (!service) + continue; + } + + hlist_for_each_entry_from_rcu(service, service_list) { + spin_lock_bh(&service->lock); + err = __tipc_nl_srvrange_list(msg, service, last_lower, + last_binding); + + if (err) { + *last_type = service->type; + spin_unlock_bh(&service->lock); + return err; + } + spin_unlock_bh(&service->lock); + } + *last_type = 0; + } + return 0; +} + +int tipc_nl_bindtbl_dump(struct sk_buff *skb, struct netlink_callback *cb) +{ + int err; + int done = cb->args[3]; + u32 last_type = cb->args[0]; + u32 last_lower = cb->args[1]; + u32 last_binding = cb->args[2]; + struct net *net = sock_net(skb->sk); + struct tipc_nl_msg msg; + + if (done) + return 0; + + msg.skb = skb; + msg.portid = NETLINK_CB(cb->skb).portid; + msg.seq = cb->nlh->nlmsg_seq; + + rcu_read_lock(); + err = tipc_nl_service_list(net, &msg, &last_type, + &last_lower, &last_binding); + if (!err) { + done = 1; + } else if (err != -EMSGSIZE) { + /* We never set seq or call nl_dump_check_consistent() this + * means that setting prev_seq here will cause the consistence + * check to fail in the netlink callback handler. Resulting in + * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if + * we got an error. + */ + cb->prev_seq = 1; + } + rcu_read_unlock(); + + cb->args[0] = last_type; + cb->args[1] = last_lower; + cb->args[2] = last_binding; + cb->args[3] = done; + + return skb->len; +} + +struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port) +{ + u64 value = (u64)node << 32 | port; + struct tipc_dest *dst; + + list_for_each_entry(dst, l, list) { + if (dst->value != value) + continue; + return dst; + } + return NULL; +} + +bool tipc_dest_push(struct list_head *l, u32 node, u32 port) +{ + u64 value = (u64)node << 32 | port; + struct tipc_dest *dst; + + if (tipc_dest_find(l, node, port)) + return false; + + dst = kmalloc(sizeof(*dst), GFP_ATOMIC); + if (unlikely(!dst)) + return false; + dst->value = value; + list_add(&dst->list, l); + return true; +} + +bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port) +{ + struct tipc_dest *dst; + + if (list_empty(l)) + return false; + dst = list_first_entry(l, typeof(*dst), list); + if (port) + *port = dst->port; + if (node) + *node = dst->node; + list_del(&dst->list); + kfree(dst); + return true; +} + +bool tipc_dest_del(struct list_head *l, u32 node, u32 port) +{ + struct tipc_dest *dst; + + dst = tipc_dest_find(l, node, port); + if (!dst) + return false; + list_del(&dst->list); + kfree(dst); + return true; +} + +void tipc_dest_list_purge(struct list_head *l) +{ + struct tipc_dest *dst, *tmp; + + list_for_each_entry_safe(dst, tmp, l, list) { + list_del(&dst->list); + kfree(dst); + } +} + +int tipc_dest_list_len(struct list_head *l) +{ + struct tipc_dest *dst; + int i = 0; + + list_for_each_entry(dst, l, list) { + i++; + } + return i; +} diff --git a/net/tipc/binding_table.h b/net/tipc/binding_table.h new file mode 100644 index 0000000..2d9f156 --- /dev/null +++ b/net/tipc/binding_table.h @@ -0,0 +1,149 @@ +/* + * net/tipc/name_table.h: Include file for TIPC name table code + * + * Copyright (c) 2000-2006, 2014-2018, Ericsson AB + * Copyright (c) 2004-2005, 2010-2011, Wind River Systems + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _TIPC_NAME_TABLE_H +#define _TIPC_NAME_TABLE_H + +struct tipc_subscription; +struct tipc_plist; +struct tipc_nlist; +struct tipc_group; + +/* TIPC name types reserved for internal TIPC use (both current and planned) + */ +#define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1) +#define TIPC_BINDING_TABLE_SIZE 1024 /* must be a power of 2 */ + +/** + * struct tipc_binding - info about a published (name or) name sequence + * @type: name sequence type + * @lower: name sequence lower bound + * @upper: name sequence upper bound + * @scope: scope of publication, TIPC_NODE_SCOPE or TIPC_CLUSTER_SCOPE + * @node: network address of publishing socket's node + * @port: publishing port + * @key: publication key, unique across the cluster + * @binding_node: all bindings from the same node which issued this one + * - Remote bindings: in node->publ_list + * Used by node/name distr to withdraw bindings when node is lost + * - Local/node scope bindings: in name_table->node_scope list + * - Local/cluster scope bindings: in name_table->cluster_scope list + * @binding_sock: all bindings from the socket socket which issued this one + * Used by socket to withdraw bindings when socket is unbound/released + * @local_bindings: list of identical bindings made from this node + * Used by closest_first lookup algorithm + * @all_bindings: all bindings identical to this one, whatever node and scope + * Used by round-robin lookup algorithm + * @rcu: RCU callback head used for deferred freeing + */ +struct tipc_binding { + u32 type; + u32 lower; + u32 upper; + u32 scope; + u32 node; + u32 port; + u32 key; + struct list_head binding_node; + struct list_head binding_sock; + struct list_head local_bindings; + struct list_head all_bindings; + struct rcu_head rcu; +}; + +/** + * struct tipc_binding_table - table containing all existing port name bindings + * @seq_hlist: name sequence hash lists + * @node_scope: all local bindings with node scope + * - used by name_distr during re-init of name table + * @cluster_scope: all local bindings with cluster scope + * - used by name_distr to send bulk updates to new nodes + * - used by name_distr during re-init of name table + * @local_bindings_count: number of bindings issued by this node + */ +struct tipc_binding_table { + struct hlist_head services[TIPC_BINDING_TABLE_SIZE]; + struct list_head node_scope; + struct list_head cluster_scope; + u32 local_bindings_count; +}; + +int tipc_nl_bindtbl_dump(struct sk_buff *skb, struct netlink_callback *cb); +u32 tipc_bindtbl_translate(struct net *net, u32 type, u32 instance, u32 *node); +void tipc_bindtbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper, + u32 scope, bool exact, struct list_head *dports); +void tipc_bindtbl_build_group(struct net *net, struct tipc_group *grp, + u32 type, u32 domain); +void tipc_bindtbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower, + u32 upper, struct tipc_nlist *nodes); +bool tipc_bindtbl_lookup(struct net *net, u32 type, u32 instance, u32 domain, + struct list_head *dsts, int *dstcnt, u32 exclude, + bool all); +struct tipc_binding *tipc_bindtbl_bind(struct net *net, u32 type, u32 lower, + u32 upper, u32 scope, u32 port_ref, + u32 key); +int tipc_bindtbl_unbind(struct net *net, u32 type, u32 lower, u32 ref, u32 key); +struct tipc_binding *tipc_bindtbl_insert_binding(struct net *net, u32 type, + u32 lower, u32 upper, + u32 scope, u32 node, u32 ref, + u32 key); +struct tipc_binding *tipc_bindtbl_remove_binding(struct net *net, u32 type, + u32 lower, u32 node, u32 ref, + u32 key); +void tipc_bindtbl_subscribe(struct tipc_subscription *s); +void tipc_bindtbl_unsubscribe(struct tipc_subscription *s); +int tipc_bindtbl_init(struct net *net); +void tipc_bindtbl_stop(struct net *net); + +struct tipc_dest { + struct list_head list; + union { + struct { + u32 port; + u32 node; + }; + u64 value; + }; +}; + +struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port); +bool tipc_dest_push(struct list_head *l, u32 node, u32 port); +bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port); +bool tipc_dest_del(struct list_head *l, u32 node, u32 port); +void tipc_dest_list_purge(struct list_head *l); +int tipc_dest_list_len(struct list_head *l); + +#endif diff --git a/net/tipc/core.c b/net/tipc/core.c index 52dfc51..c4181f5 100644 --- a/net/tipc/core.c +++ b/net/tipc/core.c @@ -37,7 +37,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include "core.h" -#include "name_table.h" +#include "binding_table.h" #include "subscr.h" #include "bearer.h" #include "net.h" @@ -70,7 +70,7 @@ static int __net_init tipc_init_net(struct net *net) if (err) goto out_sk_rht; - err = tipc_nametbl_init(net); + err = tipc_bindtbl_init(net); if (err) goto out_nametbl; @@ -88,7 +88,7 @@ static int __net_init tipc_init_net(struct net *net) out_bclink: tipc_bcast_stop(net); out_subscr: - tipc_nametbl_stop(net); + tipc_bindtbl_stop(net); out_nametbl: tipc_sk_rht_destroy(net); out_sk_rht: @@ -100,7 +100,7 @@ static void __net_exit tipc_exit_net(struct net *net) tipc_topsrv_stop(net); tipc_net_stop(net); tipc_bcast_stop(net); - tipc_nametbl_stop(net); + tipc_bindtbl_stop(net); tipc_sk_rht_destroy(net); } diff --git a/net/tipc/core.h b/net/tipc/core.h index d0f64ca..e5ff67a 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h @@ -63,7 +63,7 @@ struct tipc_node; struct tipc_bearer; struct tipc_bc_base; struct tipc_link; -struct tipc_name_table; +struct tipc_binding_table; struct tipc_topsrv; struct tipc_monitor; @@ -77,7 +77,7 @@ struct tipc_monitor; extern unsigned int tipc_net_id __read_mostly; extern int sysctl_tipc_rmem[3] __read_mostly; -extern int sysctl_tipc_named_timeout __read_mostly; +extern int sysctl_tipc_bindist_timeout __read_mostly; struct tipc_net { u8 node_id[NODE_ID_LEN]; @@ -112,8 +112,8 @@ struct tipc_net { struct rhashtable sk_rht; /* Name table */ - spinlock_t nametbl_lock; - struct name_table *nametbl; + spinlock_t bindingtbl_lock; /* Covers hash list changes */ + struct tipc_binding_table *bindingtbl; /* Name dist queue */ struct list_head dist_queue; @@ -138,9 +138,9 @@ static inline struct list_head *tipc_nodes(struct net *net) return &tipc_net(net)->node_list; } -static inline struct name_table *tipc_name_table(struct net *net) +static inline struct tipc_binding_table *tipc_binding_table(struct net *net) { - return tipc_net(net)->nametbl; + return tipc_net(net)->bindingtbl; } static inline struct tipc_topsrv *tipc_topsrv(struct net *net) diff --git a/net/tipc/group.c b/net/tipc/group.c index d7a7bef..aa9db26 100644 --- a/net/tipc/group.c +++ b/net/tipc/group.c @@ -41,7 +41,7 @@ #include "msg.h" #include "socket.h" #include "node.h" -#include "name_table.h" +#include "binding_table.h" #include "subscr.h" #define ADV_UNIT (((MAX_MSG_SIZE + MAX_H_SIZE) / FLOWCTL_BLK_SZ) + 1) diff --git a/net/tipc/link.c b/net/tipc/link.c index 1289b4b..cbb87fc 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c @@ -39,7 +39,7 @@ #include "link.h" #include "bcast.h" #include "socket.h" -#include "name_distr.h" +#include "binding_distr.h" #include "discover.h" #include "netlink.h" #include "monitor.h" diff --git a/net/tipc/msg.c b/net/tipc/msg.c index b6c45dc..fa3ed72 100644 --- a/net/tipc/msg.c +++ b/net/tipc/msg.c @@ -38,7 +38,7 @@ #include "core.h" #include "msg.h" #include "addr.h" -#include "name_table.h" +#include "binding_table.h" #define MAX_FORWARD_SIZE 1024 #define BUF_HEADROOM (LL_MAX_HEADER + 48) @@ -581,7 +581,7 @@ bool tipc_msg_lookup_dest(struct net *net, struct sk_buff *skb, int *err) if (msg_reroute_cnt(msg)) return false; dnode = tipc_scope2node(net, msg_lookup_scope(msg)); - dport = tipc_nametbl_translate(net, msg_nametype(msg), + dport = tipc_bindtbl_translate(net, msg_nametype(msg), msg_nameinst(msg), &dnode); if (!dport) return false; diff --git a/net/tipc/name_distr.c b/net/tipc/name_distr.c deleted file mode 100644 index 8240a85..0000000 --- a/net/tipc/name_distr.c +++ /dev/null @@ -1,393 +0,0 @@ -/* - * net/tipc/name_distr.c: TIPC name distribution code - * - * Copyright (c) 2000-2006, 2014, Ericsson AB - * Copyright (c) 2005, 2010-2011, Wind River Systems - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "core.h" -#include "link.h" -#include "name_distr.h" - -int sysctl_tipc_named_timeout __read_mostly = 2000; - -struct distr_queue_item { - struct distr_item i; - u32 dtype; - u32 node; - unsigned long expires; - struct list_head next; -}; - -/** - * publ_to_item - add publication info to a publication message - */ -static void publ_to_item(struct distr_item *i, struct publication *p) -{ - i->type = htonl(p->type); - i->lower = htonl(p->lower); - i->upper = htonl(p->upper); - i->port = htonl(p->port); - i->key = htonl(p->key); -} - -/** - * named_prepare_buf - allocate & initialize a publication message - * - * The buffer returned is of size INT_H_SIZE + payload size - */ -static struct sk_buff *named_prepare_buf(struct net *net, u32 type, u32 size, - u32 dest) -{ - struct sk_buff *buf = tipc_buf_acquire(INT_H_SIZE + size, GFP_ATOMIC); - u32 self = tipc_own_addr(net); - struct tipc_msg *msg; - - if (buf != NULL) { - msg = buf_msg(buf); - tipc_msg_init(self, msg, NAME_DISTRIBUTOR, - type, INT_H_SIZE, dest); - msg_set_size(msg, INT_H_SIZE + size); - } - return buf; -} - -/** - * tipc_named_publish - tell other nodes about a new publication by this node - */ -struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ) -{ - struct name_table *nt = tipc_name_table(net); - struct distr_item *item; - struct sk_buff *skb; - - if (publ->scope == TIPC_NODE_SCOPE) { - list_add_tail_rcu(&publ->binding_node, &nt->node_scope); - return NULL; - } - list_add_tail_rcu(&publ->binding_node, &nt->cluster_scope); - - skb = named_prepare_buf(net, PUBLICATION, ITEM_SIZE, 0); - if (!skb) { - pr_warn("Publication distribution failure\n"); - return NULL; - } - - item = (struct distr_item *)msg_data(buf_msg(skb)); - publ_to_item(item, publ); - return skb; -} - -/** - * tipc_named_withdraw - tell other nodes about a withdrawn publication by this node - */ -struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *publ) -{ - struct sk_buff *buf; - struct distr_item *item; - - list_del(&publ->binding_node); - - if (publ->scope == TIPC_NODE_SCOPE) - return NULL; - - buf = named_prepare_buf(net, WITHDRAWAL, ITEM_SIZE, 0); - if (!buf) { - pr_warn("Withdrawal distribution failure\n"); - return NULL; - } - - item = (struct distr_item *)msg_data(buf_msg(buf)); - publ_to_item(item, publ); - return buf; -} - -/** - * named_distribute - prepare name info for bulk distribution to another node - * @list: list of messages (buffers) to be returned from this function - * @dnode: node to be updated - * @pls: linked list of publication items to be packed into buffer chain - */ -static void named_distribute(struct net *net, struct sk_buff_head *list, - u32 dnode, struct list_head *pls) -{ - struct publication *publ; - struct sk_buff *skb = NULL; - struct distr_item *item = NULL; - u32 msg_dsz = ((tipc_node_get_mtu(net, dnode, 0) - INT_H_SIZE) / - ITEM_SIZE) * ITEM_SIZE; - u32 msg_rem = msg_dsz; - - list_for_each_entry(publ, pls, binding_node) { - /* Prepare next buffer: */ - if (!skb) { - skb = named_prepare_buf(net, PUBLICATION, msg_rem, - dnode); - if (!skb) { - pr_warn("Bulk publication failure\n"); - return; - } - msg_set_bc_ack_invalid(buf_msg(skb), true); - item = (struct distr_item *)msg_data(buf_msg(skb)); - } - - /* Pack publication into message: */ - publ_to_item(item, publ); - item++; - msg_rem -= ITEM_SIZE; - - /* Append full buffer to list: */ - if (!msg_rem) { - __skb_queue_tail(list, skb); - skb = NULL; - msg_rem = msg_dsz; - } - } - if (skb) { - msg_set_size(buf_msg(skb), INT_H_SIZE + (msg_dsz - msg_rem)); - skb_trim(skb, INT_H_SIZE + (msg_dsz - msg_rem)); - __skb_queue_tail(list, skb); - } -} - -/** - * tipc_named_node_up - tell specified node about all publications by this node - */ -void tipc_named_node_up(struct net *net, u32 dnode) -{ - struct name_table *nt = tipc_name_table(net); - struct sk_buff_head head; - - __skb_queue_head_init(&head); - - rcu_read_lock(); - named_distribute(net, &head, dnode, &nt->cluster_scope); - rcu_read_unlock(); - - tipc_node_xmit(net, &head, dnode, 0); -} - -/** - * tipc_publ_purge - remove publication associated with a failed node - * - * Invoked for each publication issued by a newly failed node. - * Removes publication structure from name table & deletes it. - */ -static void tipc_publ_purge(struct net *net, struct publication *publ, u32 addr) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct publication *p; - - spin_lock_bh(&tn->nametbl_lock); - p = tipc_nametbl_remove_publ(net, publ->type, publ->lower, - publ->node, publ->port, publ->key); - if (p) - tipc_node_unsubscribe(net, &p->binding_node, addr); - spin_unlock_bh(&tn->nametbl_lock); - - if (p != publ) { - pr_err("Unable to remove publication from failed node\n" - " (type=%u, lower=%u, node=0x%x, port=%u, key=%u)\n", - publ->type, publ->lower, publ->node, publ->port, - publ->key); - } - - kfree_rcu(p, rcu); -} - -/** - * tipc_dist_queue_purge - remove deferred updates from a node that went down - */ -static void tipc_dist_queue_purge(struct net *net, u32 addr) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct distr_queue_item *e, *tmp; - - spin_lock_bh(&tn->nametbl_lock); - list_for_each_entry_safe(e, tmp, &tn->dist_queue, next) { - if (e->node != addr) - continue; - list_del(&e->next); - kfree(e); - } - spin_unlock_bh(&tn->nametbl_lock); -} - -void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr) -{ - struct publication *publ, *tmp; - - list_for_each_entry_safe(publ, tmp, nsub_list, binding_node) - tipc_publ_purge(net, publ, addr); - tipc_dist_queue_purge(net, addr); -} - -/** - * tipc_update_nametbl - try to process a nametable update and notify - * subscribers - * - * tipc_nametbl_lock must be held. - * Returns the publication item if successful, otherwise NULL. - */ -static bool tipc_update_nametbl(struct net *net, struct distr_item *i, - u32 node, u32 dtype) -{ - struct publication *publ = NULL; - - if (dtype == PUBLICATION) { - publ = tipc_nametbl_insert_publ(net, ntohl(i->type), - ntohl(i->lower), - ntohl(i->upper), - TIPC_CLUSTER_SCOPE, node, - ntohl(i->port), ntohl(i->key)); - if (publ) { - tipc_node_subscribe(net, &publ->binding_node, node); - return true; - } - } else if (dtype == WITHDRAWAL) { - publ = tipc_nametbl_remove_publ(net, ntohl(i->type), - ntohl(i->lower), - node, ntohl(i->port), - ntohl(i->key)); - if (publ) { - tipc_node_unsubscribe(net, &publ->binding_node, node); - kfree_rcu(publ, rcu); - return true; - } - } else { - pr_warn("Unrecognized name table message received\n"); - } - return false; -} - -/** - * tipc_named_add_backlog - add a failed name table update to the backlog - * - */ -static void tipc_named_add_backlog(struct net *net, struct distr_item *i, - u32 type, u32 node) -{ - struct distr_queue_item *e; - struct tipc_net *tn = net_generic(net, tipc_net_id); - unsigned long now = get_jiffies_64(); - - e = kzalloc(sizeof(*e), GFP_ATOMIC); - if (!e) - return; - e->dtype = type; - e->node = node; - e->expires = now + msecs_to_jiffies(sysctl_tipc_named_timeout); - memcpy(e, i, sizeof(*i)); - list_add_tail(&e->next, &tn->dist_queue); -} - -/** - * tipc_named_process_backlog - try to process any pending name table updates - * from the network. - */ -void tipc_named_process_backlog(struct net *net) -{ - struct distr_queue_item *e, *tmp; - struct tipc_net *tn = net_generic(net, tipc_net_id); - unsigned long now = get_jiffies_64(); - - list_for_each_entry_safe(e, tmp, &tn->dist_queue, next) { - if (time_after(e->expires, now)) { - if (!tipc_update_nametbl(net, &e->i, e->node, e->dtype)) - continue; - } else { - pr_warn_ratelimited("Dropping name table update (%d) of {%u, %u, %u} from %x key=%u\n", - e->dtype, ntohl(e->i.type), - ntohl(e->i.lower), - ntohl(e->i.upper), - e->node, ntohl(e->i.key)); - } - list_del(&e->next); - kfree(e); - } -} - -/** - * tipc_named_rcv - process name table update messages sent by another node - */ -void tipc_named_rcv(struct net *net, struct sk_buff_head *inputq) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct tipc_msg *msg; - struct distr_item *item; - uint count; - u32 node; - struct sk_buff *skb; - int mtype; - - spin_lock_bh(&tn->nametbl_lock); - for (skb = skb_dequeue(inputq); skb; skb = skb_dequeue(inputq)) { - skb_linearize(skb); - msg = buf_msg(skb); - mtype = msg_type(msg); - item = (struct distr_item *)msg_data(msg); - count = msg_data_sz(msg) / ITEM_SIZE; - node = msg_orignode(msg); - while (count--) { - if (!tipc_update_nametbl(net, item, node, mtype)) - tipc_named_add_backlog(net, item, mtype, node); - item++; - } - kfree_skb(skb); - tipc_named_process_backlog(net); - } - spin_unlock_bh(&tn->nametbl_lock); -} - -/** - * tipc_named_reinit - re-initialize local publications - * - * This routine is called whenever TIPC networking is enabled. - * All name table entries published by this node are updated to reflect - * the node's new network address. - */ -void tipc_named_reinit(struct net *net) -{ - struct name_table *nt = tipc_name_table(net); - struct tipc_net *tn = tipc_net(net); - struct publication *publ; - u32 self = tipc_own_addr(net); - - spin_lock_bh(&tn->nametbl_lock); - - list_for_each_entry_rcu(publ, &nt->node_scope, binding_node) - publ->node = self; - list_for_each_entry_rcu(publ, &nt->cluster_scope, binding_node) - publ->node = self; - - spin_unlock_bh(&tn->nametbl_lock); -} diff --git a/net/tipc/name_distr.h b/net/tipc/name_distr.h deleted file mode 100644 index 4753e62..0000000 --- a/net/tipc/name_distr.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * net/tipc/name_distr.h: Include file for TIPC name distribution code - * - * Copyright (c) 2000-2006, Ericsson AB - * Copyright (c) 2005, Wind River Systems - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _TIPC_NAME_DISTR_H -#define _TIPC_NAME_DISTR_H - -#include "name_table.h" - -#define ITEM_SIZE sizeof(struct distr_item) - -/** - * struct distr_item - publication info distributed to other nodes - * @type: name sequence type - * @lower: name sequence lower bound - * @upper: name sequence upper bound - * @ref: publishing port reference - * @key: publication key - * - * ===> All fields are stored in network byte order. <=== - * - * First 3 fields identify (name or) name sequence being published. - * Reference field uniquely identifies port that published name sequence. - * Key field uniquely identifies publication, in the event a port has - * multiple publications of the same name sequence. - * - * Note: There is no field that identifies the publishing node because it is - * the same for all items contained within a publication message. - */ -struct distr_item { - __be32 type; - __be32 lower; - __be32 upper; - __be32 port; - __be32 key; -}; - -struct sk_buff *tipc_named_publish(struct net *net, struct publication *publ); -struct sk_buff *tipc_named_withdraw(struct net *net, struct publication *publ); -void tipc_named_node_up(struct net *net, u32 dnode); -void tipc_named_rcv(struct net *net, struct sk_buff_head *msg_queue); -void tipc_named_reinit(struct net *net); -void tipc_named_process_backlog(struct net *net); -void tipc_publ_notify(struct net *net, struct list_head *nsub_list, u32 addr); - -#endif diff --git a/net/tipc/name_table.c b/net/tipc/name_table.c deleted file mode 100644 index 4359605..0000000 --- a/net/tipc/name_table.c +++ /dev/null @@ -1,1153 +0,0 @@ -/* - * net/tipc/name_table.c: TIPC name table code - * - * Copyright (c) 2000-2006, 2014-2018, Ericsson AB - * Copyright (c) 2004-2008, 2010-2014, Wind River Systems - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include <net/sock.h> -#include "core.h" -#include "netlink.h" -#include "name_table.h" -#include "name_distr.h" -#include "subscr.h" -#include "bcast.h" -#include "addr.h" -#include "node.h" -#include "group.h" -#include <net/genetlink.h> - -#define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ - -/** - * struct name_info - name sequence publication info - * @node_list: list of publications on own node of this <type,lower,upper> - * @all_publ: list of all publications of this <type,lower,upper> - */ -struct name_info { - struct list_head local_publ; - struct list_head all_publ; -}; - -/** - * struct sub_seq - container for all published instances of a name sequence - * @lower: name sequence lower bound - * @upper: name sequence upper bound - * @info: pointer to name sequence publication info - */ -struct sub_seq { - u32 lower; - u32 upper; - struct name_info *info; -}; - -/** - * struct name_seq - container for all published instances of a name type - * @type: 32 bit 'type' value for name sequence - * @sseq: pointer to dynamically-sized array of sub-sequences of this 'type'; - * sub-sequences are sorted in ascending order - * @alloc: number of sub-sequences currently in array - * @first_free: array index of first unused sub-sequence entry - * @ns_list: links to adjacent name sequences in hash chain - * @subscriptions: list of subscriptions for this 'type' - * @lock: spinlock controlling access to publication lists of all sub-sequences - * @rcu: RCU callback head used for deferred freeing - */ -struct name_seq { - u32 type; - struct sub_seq *sseqs; - u32 alloc; - u32 first_free; - struct hlist_node ns_list; - struct list_head subscriptions; - spinlock_t lock; - struct rcu_head rcu; -}; - -static int hash(int x) -{ - return x & (TIPC_NAMETBL_SIZE - 1); -} - -/** - * publ_create - create a publication structure - */ -static struct publication *publ_create(u32 type, u32 lower, u32 upper, - u32 scope, u32 node, u32 port, - u32 key) -{ - struct publication *publ = kzalloc(sizeof(*publ), GFP_ATOMIC); - if (publ == NULL) { - pr_warn("Publication creation failure, no memory\n"); - return NULL; - } - - publ->type = type; - publ->lower = lower; - publ->upper = upper; - publ->scope = scope; - publ->node = node; - publ->port = port; - publ->key = key; - INIT_LIST_HEAD(&publ->binding_sock); - return publ; -} - -/** - * tipc_subseq_alloc - allocate a specified number of sub-sequence structures - */ -static struct sub_seq *tipc_subseq_alloc(u32 cnt) -{ - return kcalloc(cnt, sizeof(struct sub_seq), GFP_ATOMIC); -} - -/** - * tipc_nameseq_create - create a name sequence structure for the specified 'type' - * - * Allocates a single sub-sequence structure and sets it to all 0's. - */ -static struct name_seq *tipc_nameseq_create(u32 type, struct hlist_head *seq_head) -{ - struct name_seq *nseq = kzalloc(sizeof(*nseq), GFP_ATOMIC); - struct sub_seq *sseq = tipc_subseq_alloc(1); - - if (!nseq || !sseq) { - pr_warn("Name sequence creation failed, no memory\n"); - kfree(nseq); - kfree(sseq); - return NULL; - } - - spin_lock_init(&nseq->lock); - nseq->type = type; - nseq->sseqs = sseq; - nseq->alloc = 1; - INIT_HLIST_NODE(&nseq->ns_list); - INIT_LIST_HEAD(&nseq->subscriptions); - hlist_add_head_rcu(&nseq->ns_list, seq_head); - return nseq; -} - -/** - * nameseq_find_subseq - find sub-sequence (if any) matching a name instance - * - * Very time-critical, so binary searches through sub-sequence array. - */ -static struct sub_seq *nameseq_find_subseq(struct name_seq *nseq, - u32 instance) -{ - struct sub_seq *sseqs = nseq->sseqs; - int low = 0; - int high = nseq->first_free - 1; - int mid; - - while (low <= high) { - mid = (low + high) / 2; - if (instance < sseqs[mid].lower) - high = mid - 1; - else if (instance > sseqs[mid].upper) - low = mid + 1; - else - return &sseqs[mid]; - } - return NULL; -} - -/** - * nameseq_locate_subseq - determine position of name instance in sub-sequence - * - * Returns index in sub-sequence array of the entry that contains the specified - * instance value; if no entry contains that value, returns the position - * where a new entry for it would be inserted in the array. - * - * Note: Similar to binary search code for locating a sub-sequence. - */ -static u32 nameseq_locate_subseq(struct name_seq *nseq, u32 instance) -{ - struct sub_seq *sseqs = nseq->sseqs; - int low = 0; - int high = nseq->first_free - 1; - int mid; - - while (low <= high) { - mid = (low + high) / 2; - if (instance < sseqs[mid].lower) - high = mid - 1; - else if (instance > sseqs[mid].upper) - low = mid + 1; - else - return mid; - } - return low; -} - -/** - * tipc_nameseq_insert_publ - */ -static struct publication *tipc_nameseq_insert_publ(struct net *net, - struct name_seq *nseq, - u32 type, u32 lower, - u32 upper, u32 scope, - u32 node, u32 port, u32 key) -{ - struct tipc_subscription *s; - struct tipc_subscription *st; - struct publication *publ; - struct sub_seq *sseq; - struct name_info *info; - int created_subseq = 0; - - sseq = nameseq_find_subseq(nseq, lower); - if (sseq) { - - /* Lower end overlaps existing entry => need an exact match */ - if ((sseq->lower != lower) || (sseq->upper != upper)) { - return NULL; - } - - info = sseq->info; - - /* Check if an identical publication already exists */ - list_for_each_entry(publ, &info->all_publ, all_publ) { - if (publ->port == port && publ->key == key && - (!publ->node || publ->node == node)) - return NULL; - } - } else { - u32 inspos; - struct sub_seq *freesseq; - - /* Find where lower end should be inserted */ - inspos = nameseq_locate_subseq(nseq, lower); - - /* Fail if upper end overlaps into an existing entry */ - if ((inspos < nseq->first_free) && - (upper >= nseq->sseqs[inspos].lower)) { - return NULL; - } - - /* Ensure there is space for new sub-sequence */ - if (nseq->first_free == nseq->alloc) { - struct sub_seq *sseqs = tipc_subseq_alloc(nseq->alloc * 2); - - if (!sseqs) { - pr_warn("Cannot publish {%u,%u,%u}, no memory\n", - type, lower, upper); - return NULL; - } - memcpy(sseqs, nseq->sseqs, - nseq->alloc * sizeof(struct sub_seq)); - kfree(nseq->sseqs); - nseq->sseqs = sseqs; - nseq->alloc *= 2; - } - - info = kzalloc(sizeof(*info), GFP_ATOMIC); - if (!info) { - pr_warn("Cannot publish {%u,%u,%u}, no memory\n", - type, lower, upper); - return NULL; - } - - INIT_LIST_HEAD(&info->local_publ); - INIT_LIST_HEAD(&info->all_publ); - - /* Insert new sub-sequence */ - sseq = &nseq->sseqs[inspos]; - freesseq = &nseq->sseqs[nseq->first_free]; - memmove(sseq + 1, sseq, (freesseq - sseq) * sizeof(*sseq)); - memset(sseq, 0, sizeof(*sseq)); - nseq->first_free++; - sseq->lower = lower; - sseq->upper = upper; - sseq->info = info; - created_subseq = 1; - } - - /* Insert a publication */ - publ = publ_create(type, lower, upper, scope, node, port, key); - if (!publ) - return NULL; - - list_add(&publ->all_publ, &info->all_publ); - - if (in_own_node(net, node)) - list_add(&publ->local_publ, &info->local_publ); - - /* Any subscriptions waiting for notification? */ - list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { - tipc_sub_report_overlap(s, publ->lower, publ->upper, - TIPC_PUBLISHED, publ->port, - publ->node, publ->scope, - created_subseq); - } - return publ; -} - -/** - * tipc_nameseq_remove_publ - * - * NOTE: There may be cases where TIPC is asked to remove a publication - * that is not in the name table. For example, if another node issues a - * publication for a name sequence that overlaps an existing name sequence - * the publication will not be recorded, which means the publication won't - * be found when the name sequence is later withdrawn by that node. - * A failed withdraw request simply returns a failure indication and lets the - * caller issue any error or warning messages associated with such a problem. - */ -static struct publication *tipc_nameseq_remove_publ(struct net *net, - struct name_seq *nseq, - u32 inst, u32 node, - u32 port, u32 key) -{ - struct publication *publ; - struct sub_seq *sseq = nameseq_find_subseq(nseq, inst); - struct name_info *info; - struct sub_seq *free; - struct tipc_subscription *s, *st; - int removed_subseq = 0; - - if (!sseq) - return NULL; - - info = sseq->info; - - /* Locate publication, if it exists */ - list_for_each_entry(publ, &info->all_publ, all_publ) { - if (publ->key == key && publ->port == port && - (!publ->node || publ->node == node)) - goto found; - } - return NULL; - -found: - list_del(&publ->all_publ); - if (in_own_node(net, node)) - list_del(&publ->local_publ); - - /* Contract subseq list if no more publications for that subseq */ - if (list_empty(&info->all_publ)) { - kfree(info); - free = &nseq->sseqs[nseq->first_free--]; - memmove(sseq, sseq + 1, (free - (sseq + 1)) * sizeof(*sseq)); - removed_subseq = 1; - } - - /* Notify any waiting subscriptions */ - list_for_each_entry_safe(s, st, &nseq->subscriptions, nameseq_list) { - tipc_sub_report_overlap(s, publ->lower, publ->upper, - TIPC_WITHDRAWN, publ->port, - publ->node, publ->scope, - removed_subseq); - } - - return publ; -} - -/** - * tipc_nameseq_subscribe - attach a subscription, and optionally - * issue the prescribed number of events if there is any sub- - * sequence overlapping with the requested sequence - */ -static void tipc_nameseq_subscribe(struct name_seq *nseq, - struct tipc_subscription *sub) -{ - struct sub_seq *sseq = nseq->sseqs; - struct tipc_name_seq ns; - struct tipc_subscr *s = &sub->evt.s; - bool no_status; - - ns.type = tipc_sub_read(s, seq.type); - ns.lower = tipc_sub_read(s, seq.lower); - ns.upper = tipc_sub_read(s, seq.upper); - no_status = tipc_sub_read(s, filter) & TIPC_SUB_NO_STATUS; - - tipc_sub_get(sub); - list_add(&sub->nameseq_list, &nseq->subscriptions); - - if (no_status || !sseq) - return; - - while (sseq != &nseq->sseqs[nseq->first_free]) { - if (tipc_sub_check_overlap(&ns, sseq->lower, sseq->upper)) { - struct publication *crs; - struct name_info *info = sseq->info; - int must_report = 1; - - list_for_each_entry(crs, &info->all_publ, all_publ) { - tipc_sub_report_overlap(sub, sseq->lower, - sseq->upper, - TIPC_PUBLISHED, - crs->port, - crs->node, - crs->scope, - must_report); - must_report = 0; - } - } - sseq++; - } -} - -static struct name_seq *nametbl_find_seq(struct net *net, u32 type) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct hlist_head *seq_head; - struct name_seq *ns; - - seq_head = &tn->nametbl->seq_hlist[hash(type)]; - hlist_for_each_entry_rcu(ns, seq_head, ns_list) { - if (ns->type == type) - return ns; - } - - return NULL; -}; - -struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, - u32 lower, u32 upper, u32 scope, - u32 node, u32 port, u32 key) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct publication *publ; - struct name_seq *seq = nametbl_find_seq(net, type); - int index = hash(type); - - if (scope > TIPC_NODE_SCOPE || lower > upper) { - pr_debug("Failed to publish illegal {%u,%u,%u} with scope %u\n", - type, lower, upper, scope); - return NULL; - } - - if (!seq) - seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); - if (!seq) - return NULL; - - spin_lock_bh(&seq->lock); - publ = tipc_nameseq_insert_publ(net, seq, type, lower, upper, - scope, node, port, key); - spin_unlock_bh(&seq->lock); - return publ; -} - -struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, - u32 lower, u32 node, u32 port, - u32 key) -{ - struct publication *publ; - struct name_seq *seq = nametbl_find_seq(net, type); - - if (!seq) - return NULL; - - spin_lock_bh(&seq->lock); - publ = tipc_nameseq_remove_publ(net, seq, lower, node, port, key); - if (!seq->first_free && list_empty(&seq->subscriptions)) { - hlist_del_init_rcu(&seq->ns_list); - kfree(seq->sseqs); - spin_unlock_bh(&seq->lock); - kfree_rcu(seq, rcu); - return publ; - } - spin_unlock_bh(&seq->lock); - return publ; -} - -/** - * tipc_nametbl_translate - perform name translation - * - * On entry, 'destnode' is the search domain used during translation. - * - * On exit: - * - if name translation is deferred to another node/cluster/zone, - * leaves 'destnode' unchanged (will be non-zero) and returns 0 - * - if name translation is attempted and succeeds, sets 'destnode' - * to publishing node and returns port reference (will be non-zero) - * - if name translation is attempted and fails, sets 'destnode' to 0 - * and returns 0 - */ -u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, - u32 *destnode) -{ - struct tipc_net *tn = tipc_net(net); - bool legacy = tn->legacy_addr_format; - u32 self = tipc_own_addr(net); - struct sub_seq *sseq; - struct name_info *info; - struct publication *publ; - struct name_seq *seq; - u32 port = 0; - u32 node = 0; - - if (!tipc_in_scope(legacy, *destnode, self)) - return 0; - - rcu_read_lock(); - seq = nametbl_find_seq(net, type); - if (unlikely(!seq)) - goto not_found; - spin_lock_bh(&seq->lock); - sseq = nameseq_find_subseq(seq, instance); - if (unlikely(!sseq)) - goto no_match; - info = sseq->info; - - /* Closest-First Algorithm */ - if (legacy && !*destnode) { - if (!list_empty(&info->local_publ)) { - publ = list_first_entry(&info->local_publ, - struct publication, - local_publ); - list_move_tail(&publ->local_publ, - &info->local_publ); - } else { - publ = list_first_entry(&info->all_publ, - struct publication, - all_publ); - list_move_tail(&publ->all_publ, - &info->all_publ); - } - } - - /* Round-Robin Algorithm */ - else if (*destnode == tipc_own_addr(net)) { - if (list_empty(&info->local_publ)) - goto no_match; - publ = list_first_entry(&info->local_publ, struct publication, - local_publ); - list_move_tail(&publ->local_publ, &info->local_publ); - } else { - publ = list_first_entry(&info->all_publ, struct publication, - all_publ); - list_move_tail(&publ->all_publ, &info->all_publ); - } - - port = publ->port; - node = publ->node; -no_match: - spin_unlock_bh(&seq->lock); -not_found: - rcu_read_unlock(); - *destnode = node; - return port; -} - -bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 scope, - struct list_head *dsts, int *dstcnt, u32 exclude, - bool all) -{ - u32 self = tipc_own_addr(net); - struct publication *publ; - struct name_info *info; - struct name_seq *seq; - struct sub_seq *sseq; - - *dstcnt = 0; - rcu_read_lock(); - seq = nametbl_find_seq(net, type); - if (unlikely(!seq)) - goto exit; - spin_lock_bh(&seq->lock); - sseq = nameseq_find_subseq(seq, instance); - if (likely(sseq)) { - info = sseq->info; - list_for_each_entry(publ, &info->all_publ, all_publ) { - if (publ->scope != scope) - continue; - if (publ->port == exclude && publ->node == self) - continue; - tipc_dest_push(dsts, publ->node, publ->port); - (*dstcnt)++; - if (all) - continue; - list_move_tail(&publ->all_publ, &info->all_publ); - break; - } - } - spin_unlock_bh(&seq->lock); -exit: - rcu_read_unlock(); - return !list_empty(dsts); -} - -void tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper, - u32 scope, bool exact, struct list_head *dports) -{ - struct sub_seq *sseq_stop; - struct name_info *info; - struct publication *p; - struct name_seq *seq; - struct sub_seq *sseq; - - rcu_read_lock(); - seq = nametbl_find_seq(net, type); - if (!seq) - goto exit; - - spin_lock_bh(&seq->lock); - sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); - sseq_stop = seq->sseqs + seq->first_free; - for (; sseq != sseq_stop; sseq++) { - if (sseq->lower > upper) - break; - info = sseq->info; - list_for_each_entry(p, &info->local_publ, local_publ) { - if (p->scope == scope || (!exact && p->scope < scope)) - tipc_dest_push(dports, 0, p->port); - } - } - spin_unlock_bh(&seq->lock); -exit: - rcu_read_unlock(); -} - -/* tipc_nametbl_lookup_dst_nodes - find broadcast destination nodes - * - Creates list of nodes that overlap the given multicast address - * - Determines if any node local ports overlap - */ -void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower, - u32 upper, struct tipc_nlist *nodes) -{ - struct sub_seq *sseq, *stop; - struct publication *publ; - struct name_info *info; - struct name_seq *seq; - - rcu_read_lock(); - seq = nametbl_find_seq(net, type); - if (!seq) - goto exit; - - spin_lock_bh(&seq->lock); - sseq = seq->sseqs + nameseq_locate_subseq(seq, lower); - stop = seq->sseqs + seq->first_free; - for (; sseq != stop && sseq->lower <= upper; sseq++) { - info = sseq->info; - list_for_each_entry(publ, &info->all_publ, all_publ) { - tipc_nlist_add(nodes, publ->node); - } - } - spin_unlock_bh(&seq->lock); -exit: - rcu_read_unlock(); -} - -/* tipc_nametbl_build_group - build list of communication group members - */ -void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp, - u32 type, u32 scope) -{ - struct sub_seq *sseq, *stop; - struct name_info *info; - struct publication *p; - struct name_seq *seq; - - rcu_read_lock(); - seq = nametbl_find_seq(net, type); - if (!seq) - goto exit; - - spin_lock_bh(&seq->lock); - sseq = seq->sseqs; - stop = seq->sseqs + seq->first_free; - for (; sseq != stop; sseq++) { - info = sseq->info; - list_for_each_entry(p, &info->all_publ, all_publ) { - if (p->scope != scope) - continue; - tipc_group_add_member(grp, p->node, p->port, p->lower); - } - } - spin_unlock_bh(&seq->lock); -exit: - rcu_read_unlock(); -} - -/* - * tipc_nametbl_publish - add name publication to network name tables - */ -struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, - u32 upper, u32 scope, u32 port_ref, - u32 key) -{ - struct publication *publ; - struct sk_buff *buf = NULL; - struct tipc_net *tn = net_generic(net, tipc_net_id); - - spin_lock_bh(&tn->nametbl_lock); - if (tn->nametbl->local_publ_count >= TIPC_MAX_PUBLICATIONS) { - pr_warn("Publication failed, local publication limit reached (%u)\n", - TIPC_MAX_PUBLICATIONS); - spin_unlock_bh(&tn->nametbl_lock); - return NULL; - } - - publ = tipc_nametbl_insert_publ(net, type, lower, upper, scope, - tipc_own_addr(net), port_ref, key); - if (likely(publ)) { - tn->nametbl->local_publ_count++; - buf = tipc_named_publish(net, publ); - /* Any pending external events? */ - tipc_named_process_backlog(net); - } - spin_unlock_bh(&tn->nametbl_lock); - - if (buf) - tipc_node_broadcast(net, buf); - return publ; -} - -/** - * tipc_nametbl_withdraw - withdraw name publication from network name tables - */ -int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 port, - u32 key) -{ - struct publication *publ; - struct sk_buff *skb = NULL; - struct tipc_net *tn = net_generic(net, tipc_net_id); - - spin_lock_bh(&tn->nametbl_lock); - publ = tipc_nametbl_remove_publ(net, type, lower, tipc_own_addr(net), - port, key); - if (likely(publ)) { - tn->nametbl->local_publ_count--; - skb = tipc_named_withdraw(net, publ); - /* Any pending external events? */ - tipc_named_process_backlog(net); - list_del_init(&publ->binding_sock); - kfree_rcu(publ, rcu); - } else { - pr_err("Unable to remove local publication\n" - "(type=%u, lower=%u, port=%u, key=%u)\n", - type, lower, port, key); - } - spin_unlock_bh(&tn->nametbl_lock); - - if (skb) { - tipc_node_broadcast(net, skb); - return 1; - } - return 0; -} - -/** - * tipc_nametbl_subscribe - add a subscription object to the name table - */ -void tipc_nametbl_subscribe(struct tipc_subscription *sub) -{ - struct tipc_net *tn = tipc_net(sub->net); - struct tipc_subscr *s = &sub->evt.s; - u32 type = tipc_sub_read(s, seq.type); - int index = hash(type); - struct name_seq *seq; - struct tipc_name_seq ns; - - spin_lock_bh(&tn->nametbl_lock); - seq = nametbl_find_seq(sub->net, type); - if (!seq) - seq = tipc_nameseq_create(type, &tn->nametbl->seq_hlist[index]); - if (seq) { - spin_lock_bh(&seq->lock); - tipc_nameseq_subscribe(seq, sub); - spin_unlock_bh(&seq->lock); - } else { - ns.type = tipc_sub_read(s, seq.type); - ns.lower = tipc_sub_read(s, seq.lower); - ns.upper = tipc_sub_read(s, seq.upper); - pr_warn("Failed to create subscription for {%u,%u,%u}\n", - ns.type, ns.lower, ns.upper); - } - spin_unlock_bh(&tn->nametbl_lock); -} - -/** - * tipc_nametbl_unsubscribe - remove a subscription object from name table - */ -void tipc_nametbl_unsubscribe(struct tipc_subscription *sub) -{ - struct tipc_subscr *s = &sub->evt.s; - struct tipc_net *tn = tipc_net(sub->net); - struct name_seq *seq; - u32 type = tipc_sub_read(s, seq.type); - - spin_lock_bh(&tn->nametbl_lock); - seq = nametbl_find_seq(sub->net, type); - if (seq != NULL) { - spin_lock_bh(&seq->lock); - list_del_init(&sub->nameseq_list); - tipc_sub_put(sub); - if (!seq->first_free && list_empty(&seq->subscriptions)) { - hlist_del_init_rcu(&seq->ns_list); - kfree(seq->sseqs); - spin_unlock_bh(&seq->lock); - kfree_rcu(seq, rcu); - } else { - spin_unlock_bh(&seq->lock); - } - } - spin_unlock_bh(&tn->nametbl_lock); -} - -int tipc_nametbl_init(struct net *net) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct name_table *tipc_nametbl; - int i; - - tipc_nametbl = kzalloc(sizeof(*tipc_nametbl), GFP_ATOMIC); - if (!tipc_nametbl) - return -ENOMEM; - - for (i = 0; i < TIPC_NAMETBL_SIZE; i++) - INIT_HLIST_HEAD(&tipc_nametbl->seq_hlist[i]); - - INIT_LIST_HEAD(&tipc_nametbl->node_scope); - INIT_LIST_HEAD(&tipc_nametbl->cluster_scope); - tn->nametbl = tipc_nametbl; - spin_lock_init(&tn->nametbl_lock); - return 0; -} - -/** - * tipc_purge_publications - remove all publications for a given type - * - * tipc_nametbl_lock must be held when calling this function - */ -static void tipc_purge_publications(struct net *net, struct name_seq *seq) -{ - struct publication *publ, *safe; - struct sub_seq *sseq; - struct name_info *info; - - spin_lock_bh(&seq->lock); - sseq = seq->sseqs; - info = sseq->info; - list_for_each_entry_safe(publ, safe, &info->all_publ, all_publ) { - tipc_nameseq_remove_publ(net, seq, publ->lower, publ->node, - publ->port, publ->key); - kfree_rcu(publ, rcu); - } - hlist_del_init_rcu(&seq->ns_list); - kfree(seq->sseqs); - spin_unlock_bh(&seq->lock); - - kfree_rcu(seq, rcu); -} - -void tipc_nametbl_stop(struct net *net) -{ - u32 i; - struct name_seq *seq; - struct hlist_head *seq_head; - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct name_table *tipc_nametbl = tn->nametbl; - - /* Verify name table is empty and purge any lingering - * publications, then release the name table - */ - spin_lock_bh(&tn->nametbl_lock); - for (i = 0; i < TIPC_NAMETBL_SIZE; i++) { - if (hlist_empty(&tipc_nametbl->seq_hlist[i])) - continue; - seq_head = &tipc_nametbl->seq_hlist[i]; - hlist_for_each_entry_rcu(seq, seq_head, ns_list) { - tipc_purge_publications(net, seq); - } - } - spin_unlock_bh(&tn->nametbl_lock); - - synchronize_net(); - kfree(tipc_nametbl); - -} - -static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg, - struct name_seq *seq, - struct sub_seq *sseq, u32 *last_publ) -{ - void *hdr; - struct nlattr *attrs; - struct nlattr *publ; - struct publication *p; - - if (*last_publ) { - list_for_each_entry(p, &sseq->info->all_publ, all_publ) - if (p->key == *last_publ) - break; - if (p->key != *last_publ) - return -EPIPE; - } else { - p = list_first_entry(&sseq->info->all_publ, struct publication, - all_publ); - } - - list_for_each_entry_from(p, &sseq->info->all_publ, all_publ) { - *last_publ = p->key; - - hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, - &tipc_genl_family, NLM_F_MULTI, - TIPC_NL_NAME_TABLE_GET); - if (!hdr) - return -EMSGSIZE; - - attrs = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE); - if (!attrs) - goto msg_full; - - publ = nla_nest_start(msg->skb, TIPC_NLA_NAME_TABLE_PUBL); - if (!publ) - goto attr_msg_full; - - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_TYPE, seq->type)) - goto publ_msg_full; - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_LOWER, sseq->lower)) - goto publ_msg_full; - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_UPPER, sseq->upper)) - goto publ_msg_full; - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_SCOPE, p->scope)) - goto publ_msg_full; - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_NODE, p->node)) - goto publ_msg_full; - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_REF, p->port)) - goto publ_msg_full; - if (nla_put_u32(msg->skb, TIPC_NLA_PUBL_KEY, p->key)) - goto publ_msg_full; - - nla_nest_end(msg->skb, publ); - nla_nest_end(msg->skb, attrs); - genlmsg_end(msg->skb, hdr); - } - *last_publ = 0; - - return 0; - -publ_msg_full: - nla_nest_cancel(msg->skb, publ); -attr_msg_full: - nla_nest_cancel(msg->skb, attrs); -msg_full: - genlmsg_cancel(msg->skb, hdr); - - return -EMSGSIZE; -} - -static int __tipc_nl_subseq_list(struct tipc_nl_msg *msg, struct name_seq *seq, - u32 *last_lower, u32 *last_publ) -{ - struct sub_seq *sseq; - struct sub_seq *sseq_start; - int err; - - if (*last_lower) { - sseq_start = nameseq_find_subseq(seq, *last_lower); - if (!sseq_start) - return -EPIPE; - } else { - sseq_start = seq->sseqs; - } - - for (sseq = sseq_start; sseq != &seq->sseqs[seq->first_free]; sseq++) { - err = __tipc_nl_add_nametable_publ(msg, seq, sseq, last_publ); - if (err) { - *last_lower = sseq->lower; - return err; - } - } - *last_lower = 0; - - return 0; -} - -static int tipc_nl_seq_list(struct net *net, struct tipc_nl_msg *msg, - u32 *last_type, u32 *last_lower, u32 *last_publ) -{ - struct tipc_net *tn = net_generic(net, tipc_net_id); - struct hlist_head *seq_head; - struct name_seq *seq = NULL; - int err; - int i; - - if (*last_type) - i = hash(*last_type); - else - i = 0; - - for (; i < TIPC_NAMETBL_SIZE; i++) { - seq_head = &tn->nametbl->seq_hlist[i]; - - if (*last_type) { - seq = nametbl_find_seq(net, *last_type); - if (!seq) - return -EPIPE; - } else { - hlist_for_each_entry_rcu(seq, seq_head, ns_list) - break; - if (!seq) - continue; - } - - hlist_for_each_entry_from_rcu(seq, ns_list) { - spin_lock_bh(&seq->lock); - err = __tipc_nl_subseq_list(msg, seq, last_lower, - last_publ); - - if (err) { - *last_type = seq->type; - spin_unlock_bh(&seq->lock); - return err; - } - spin_unlock_bh(&seq->lock); - } - *last_type = 0; - } - return 0; -} - -int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb) -{ - int err; - int done = cb->args[3]; - u32 last_type = cb->args[0]; - u32 last_lower = cb->args[1]; - u32 last_publ = cb->args[2]; - struct net *net = sock_net(skb->sk); - struct tipc_nl_msg msg; - - if (done) - return 0; - - msg.skb = skb; - msg.portid = NETLINK_CB(cb->skb).portid; - msg.seq = cb->nlh->nlmsg_seq; - - rcu_read_lock(); - err = tipc_nl_seq_list(net, &msg, &last_type, &last_lower, &last_publ); - if (!err) { - done = 1; - } else if (err != -EMSGSIZE) { - /* We never set seq or call nl_dump_check_consistent() this - * means that setting prev_seq here will cause the consistence - * check to fail in the netlink callback handler. Resulting in - * the NLMSG_DONE message having the NLM_F_DUMP_INTR flag set if - * we got an error. - */ - cb->prev_seq = 1; - } - rcu_read_unlock(); - - cb->args[0] = last_type; - cb->args[1] = last_lower; - cb->args[2] = last_publ; - cb->args[3] = done; - - return skb->len; -} - -struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port) -{ - u64 value = (u64)node << 32 | port; - struct tipc_dest *dst; - - list_for_each_entry(dst, l, list) { - if (dst->value != value) - continue; - return dst; - } - return NULL; -} - -bool tipc_dest_push(struct list_head *l, u32 node, u32 port) -{ - u64 value = (u64)node << 32 | port; - struct tipc_dest *dst; - - if (tipc_dest_find(l, node, port)) - return false; - - dst = kmalloc(sizeof(*dst), GFP_ATOMIC); - if (unlikely(!dst)) - return false; - dst->value = value; - list_add(&dst->list, l); - return true; -} - -bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port) -{ - struct tipc_dest *dst; - - if (list_empty(l)) - return false; - dst = list_first_entry(l, typeof(*dst), list); - if (port) - *port = dst->port; - if (node) - *node = dst->node; - list_del(&dst->list); - kfree(dst); - return true; -} - -bool tipc_dest_del(struct list_head *l, u32 node, u32 port) -{ - struct tipc_dest *dst; - - dst = tipc_dest_find(l, node, port); - if (!dst) - return false; - list_del(&dst->list); - kfree(dst); - return true; -} - -void tipc_dest_list_purge(struct list_head *l) -{ - struct tipc_dest *dst, *tmp; - - list_for_each_entry_safe(dst, tmp, l, list) { - list_del(&dst->list); - kfree(dst); - } -} - -int tipc_dest_list_len(struct list_head *l) -{ - struct tipc_dest *dst; - int i = 0; - - list_for_each_entry(dst, l, list) { - i++; - } - return i; -} diff --git a/net/tipc/name_table.h b/net/tipc/name_table.h deleted file mode 100644 index 34a4ccb..0000000 --- a/net/tipc/name_table.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * net/tipc/name_table.h: Include file for TIPC name table code - * - * Copyright (c) 2000-2006, 2014-2018, Ericsson AB - * Copyright (c) 2004-2005, 2010-2011, Wind River Systems - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the names of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _TIPC_NAME_TABLE_H -#define _TIPC_NAME_TABLE_H - -struct tipc_subscription; -struct tipc_plist; -struct tipc_nlist; -struct tipc_group; - -/* - * TIPC name types reserved for internal TIPC use (both current and planned) - */ -#define TIPC_ZM_SRV 3 /* zone master service name type */ -#define TIPC_PUBL_SCOPE_NUM (TIPC_NODE_SCOPE + 1) -#define TIPC_NAMETBL_SIZE 1024 /* must be a power of 2 */ - -/** - * struct publication - info about a published (name or) name sequence - * @type: name sequence type - * @lower: name sequence lower bound - * @upper: name sequence upper bound - * @scope: scope of publication, TIPC_NODE_SCOPE or TIPC_CLUSTER_SCOPE - * @node: network address of publishing socket's node - * @port: publishing port - * @key: publication key, unique across the cluster - * @binding_node: all publications from the same node which bound this one - * - Remote publications: in node->publ_list - * Used by node/name distr to withdraw publications when node is lost - * - Local/node scope publications: in name_table->node_scope list - * - Local/cluster scope publications: in name_table->cluster_scope list - * @binding_sock: all publications from the same socket which bound this one - * Used by socket to withdraw publications when socket is unbound/released - * @local_publ: list of identical publications made from this node - * Used by closest_first and multicast receive lookup algorithms - * @all_publ: all publications identical to this one, whatever node and scope - * Used by round-robin lookup algorithm - * @rcu: RCU callback head used for deferred freeing - */ -struct publication { - u32 type; - u32 lower; - u32 upper; - u32 scope; - u32 node; - u32 port; - u32 key; - struct list_head binding_node; - struct list_head binding_sock; - struct list_head local_publ; - struct list_head all_publ; - struct rcu_head rcu; -}; - -/** - * struct name_table - table containing all existing port name publications - * @seq_hlist: name sequence hash lists - * @node_scope: all local publications with node scope - * - used by name_distr during re-init of name table - * @cluster_scope: all local publications with cluster scope - * - used by name_distr to send bulk updates to new nodes - * - used by name_distr during re-init of name table - * @local_publ_count: number of publications issued by this node - */ -struct name_table { - struct hlist_head seq_hlist[TIPC_NAMETBL_SIZE]; - struct list_head node_scope; - struct list_head cluster_scope; - u32 local_publ_count; -}; - -int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb); - -u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node); -void tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper, - u32 scope, bool exact, struct list_head *dports); -void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp, - u32 type, u32 domain); -void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower, - u32 upper, struct tipc_nlist *nodes); -bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain, - struct list_head *dsts, int *dstcnt, u32 exclude, - bool all); -struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower, - u32 upper, u32 scope, u32 port_ref, - u32 key); -int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 ref, - u32 key); -struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type, - u32 lower, u32 upper, u32 scope, - u32 node, u32 ref, u32 key); -struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type, - u32 lower, u32 node, u32 ref, - u32 key); -void tipc_nametbl_subscribe(struct tipc_subscription *s); -void tipc_nametbl_unsubscribe(struct tipc_subscription *s); -int tipc_nametbl_init(struct net *net); -void tipc_nametbl_stop(struct net *net); - -struct tipc_dest { - struct list_head list; - union { - struct { - u32 port; - u32 node; - }; - u64 value; - }; -}; - -struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port); -bool tipc_dest_push(struct list_head *l, u32 node, u32 port); -bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port); -bool tipc_dest_del(struct list_head *l, u32 node, u32 port); -void tipc_dest_list_purge(struct list_head *l); -int tipc_dest_list_len(struct list_head *l); - -#endif diff --git a/net/tipc/net.c b/net/tipc/net.c index 29538dc..a37c8cb 100644 --- a/net/tipc/net.c +++ b/net/tipc/net.c @@ -36,7 +36,7 @@ #include "core.h" #include "net.h" -#include "name_distr.h" +#include "binding_distr.h" #include "subscr.h" #include "socket.h" #include "node.h" @@ -123,10 +123,10 @@ void tipc_net_finalize(struct net *net, u32 addr) { tipc_set_node_addr(net, addr); smp_mb(); - tipc_named_reinit(net); + tipc_bindist_reinit(net); tipc_sk_reinit(net); - tipc_nametbl_publish(net, TIPC_CFG_SRV, addr, addr, - TIPC_CLUSTER_SCOPE, 0, addr); + tipc_bindtbl_bind(net, TIPC_CFG_SRV, addr, addr, + TIPC_CLUSTER_SCOPE, 0, addr); } void tipc_net_stop(struct net *net) @@ -136,7 +136,7 @@ void tipc_net_stop(struct net *net) if (!self) return; - tipc_nametbl_withdraw(net, TIPC_CFG_SRV, self, 0, self); + tipc_bindtbl_unbind(net, TIPC_CFG_SRV, self, 0, self); rtnl_lock(); tipc_bearer_stop(net); tipc_node_stop(net); diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index b76f13f..feaf740 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c @@ -36,7 +36,7 @@ #include "core.h" #include "socket.h" -#include "name_table.h" +#include "binding_table.h" #include "bearer.h" #include "link.h" #include "node.h" @@ -216,7 +216,7 @@ static const struct genl_ops tipc_genl_v2_ops[] = { }, { .cmd = TIPC_NL_NAME_TABLE_GET, - .dumpit = tipc_nl_name_table_dump, + .dumpit = tipc_nl_bindtbl_dump, .policy = tipc_nl_policy, }, { diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c index 4492cda..5ba51e8 100644 --- a/net/tipc/netlink_compat.c +++ b/net/tipc/netlink_compat.c @@ -34,7 +34,7 @@ #include "core.h" #include "bearer.h" #include "link.h" -#include "name_table.h" +#include "binding_table.h" #include "socket.h" #include "node.h" #include "net.h" @@ -1130,7 +1130,7 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg) msg->rep_size = ULTRA_STRING_MAX_LEN; msg->rep_type = TIPC_TLV_ULTRA_STRING; dump.header = tipc_nl_compat_name_table_dump_header; - dump.dumpit = tipc_nl_name_table_dump; + dump.dumpit = tipc_nl_bindtbl_dump; dump.format = tipc_nl_compat_name_table_dump; return tipc_nl_compat_dumpit(&dump, msg); case TIPC_CMD_SHOW_PORTS: diff --git a/net/tipc/node.c b/net/tipc/node.c index 4a95c8c..b7a2413 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c @@ -37,7 +37,7 @@ #include "core.h" #include "link.h" #include "node.h" -#include "name_distr.h" +#include "binding_distr.h" #include "socket.h" #include "bcast.h" #include "monitor.h" @@ -319,17 +319,16 @@ static void tipc_node_write_unlock(struct tipc_node *n) tipc_publ_notify(net, publ_list, addr); if (flags & TIPC_NOTIFY_NODE_UP) - tipc_named_node_up(net, addr); + tipc_bindist_node_up(net, addr); if (flags & TIPC_NOTIFY_LINK_UP) { tipc_mon_peer_up(net, addr, bearer_id); - tipc_nametbl_publish(net, TIPC_LINK_STATE, addr, addr, - TIPC_NODE_SCOPE, link_id, addr); + tipc_bindtbl_bind(net, TIPC_LINK_STATE, addr, addr, + TIPC_NODE_SCOPE, link_id, addr); } if (flags & TIPC_NOTIFY_LINK_DOWN) { tipc_mon_peer_down(net, addr, bearer_id); - tipc_nametbl_withdraw(net, TIPC_LINK_STATE, addr, - link_id, addr); + tipc_bindtbl_unbind(net, TIPC_LINK_STATE, addr, link_id, addr); } } @@ -1665,7 +1664,7 @@ void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b) tipc_node_link_down(n, bearer_id, false); if (unlikely(!skb_queue_empty(&n->bc_entry.namedq))) - tipc_named_rcv(net, &n->bc_entry.namedq); + tipc_bindist_rcv(net, &n->bc_entry.namedq); if (unlikely(!skb_queue_empty(&n->bc_entry.inputq1))) tipc_node_mcast_rcv(n); diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 275b666..a242869 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c @@ -38,10 +38,9 @@ #include <linux/sched/signal.h> #include "core.h" -#include "name_table.h" +#include "binding_table.h" #include "node.h" #include "link.h" -#include "name_distr.h" #include "socket.h" #include "bcast.h" #include "netlink.h" @@ -783,7 +782,7 @@ static int tipc_sendmcast(struct socket *sock, struct tipc_name_seq *seq, /* Lookup destination nodes */ tipc_nlist_init(&dsts, tipc_own_addr(net)); - tipc_nametbl_lookup_dst_nodes(net, seq->type, seq->lower, + tipc_bindtbl_lookup_dst_nodes(net, seq->type, seq->lower, seq->upper, &dsts); if (!dsts.local && !dsts.remote) return -EHOSTUNREACH; @@ -947,7 +946,7 @@ static int tipc_send_group_anycast(struct socket *sock, struct msghdr *m, /* Look for a non-congested destination member, if any */ while (1) { - if (!tipc_nametbl_lookup(net, type, inst, scope, &dsts, + if (!tipc_bindtbl_lookup(net, type, inst, scope, &dsts, &dstcnt, exclude, false)) return -EHOSTUNREACH; tipc_dest_pop(&dsts, &node, &port); @@ -1091,7 +1090,7 @@ static int tipc_send_group_mcast(struct socket *sock, struct msghdr *m, scope = msg_lookup_scope(hdr); exclude = tipc_group_exclude(grp); - if (!tipc_nametbl_lookup(net, type, inst, scope, &dsts, + if (!tipc_bindtbl_lookup(net, type, inst, scope, &dsts, &dstcnt, exclude, true)) return -EHOSTUNREACH; @@ -1166,7 +1165,7 @@ void tipc_sk_mcast_rcv(struct net *net, struct sk_buff_head *arrvq, } /* Create destination port list: */ - tipc_nametbl_mc_lookup(net, type, lower, upper, + tipc_bindtbl_mc_lookup(net, type, lower, upper, scope, exact, &dports); /* Clone message per destination */ @@ -1336,7 +1335,7 @@ static int __tipc_sendmsg(struct socket *sock, struct msghdr *m, size_t dlen) msg_set_nametype(hdr, type); msg_set_nameinst(hdr, inst); msg_set_lookup_scope(hdr, tipc_node2scope(dnode)); - dport = tipc_nametbl_translate(net, type, inst, &dnode); + dport = tipc_bindtbl_translate(net, type, inst, &dnode); msg_set_destnode(hdr, dnode); msg_set_destport(hdr, dport); if (unlikely(!dport && !dnode)) @@ -2589,7 +2588,7 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, { struct sock *sk = &tsk->sk; struct net *net = sock_net(sk); - struct publication *publ; + struct tipc_binding *b; u32 key; if (scope != TIPC_NODE_SCOPE) @@ -2601,12 +2600,12 @@ static int tipc_sk_publish(struct tipc_sock *tsk, uint scope, if (key == tsk->portid) return -EADDRINUSE; - publ = tipc_nametbl_publish(net, seq->type, seq->lower, seq->upper, - scope, tsk->portid, key); - if (unlikely(!publ)) + b = tipc_bindtbl_bind(net, seq->type, seq->lower, seq->upper, + scope, tsk->portid, key); + if (unlikely(!b)) return -EINVAL; - list_add(&publ->binding_sock, &tsk->publications); + list_add(&b->binding_sock, &tsk->publications); tsk->pub_count++; tsk->published = 1; return 0; @@ -2616,30 +2615,30 @@ static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope, struct tipc_name_seq const *seq) { struct net *net = sock_net(&tsk->sk); - struct publication *publ; - struct publication *safe; + struct tipc_binding *safe; + struct tipc_binding *b; + int rc = -EINVAL; if (scope != TIPC_NODE_SCOPE) scope = TIPC_CLUSTER_SCOPE; - list_for_each_entry_safe(publ, safe, &tsk->publications, binding_sock) { + list_for_each_entry_safe(b, safe, &tsk->publications, binding_sock) { if (seq) { - if (publ->scope != scope) + if (b->scope != scope) continue; - if (publ->type != seq->type) + if (b->type != seq->type) continue; - if (publ->lower != seq->lower) + if (b->lower != seq->lower) continue; - if (publ->upper != seq->upper) + if (b->upper != seq->upper) break; - tipc_nametbl_withdraw(net, publ->type, publ->lower, - publ->port, publ->key); + tipc_bindtbl_unbind(net, b->type, b->lower, + b->port, b->key); rc = 0; break; } - tipc_nametbl_withdraw(net, publ->type, publ->lower, - publ->port, publ->key); + tipc_bindtbl_unbind(net, b->type, b->lower, b->port, b->key); rc = 0; } if (list_empty(&tsk->publications)) @@ -2773,7 +2772,7 @@ static int tipc_sk_join(struct tipc_sock *tsk, struct tipc_group_req *mreq) seq.type = mreq->type; seq.lower = mreq->instance; seq.upper = seq.lower; - tipc_nametbl_build_group(net, grp, mreq->type, mreq->scope); + tipc_bindtbl_build_group(net, grp, mreq->type, mreq->scope); rc = tipc_sk_publish(tsk, mreq->scope, &seq); if (rc) { tipc_group_delete(net, grp); @@ -3328,7 +3327,7 @@ int tipc_nl_sk_dump(struct sk_buff *skb, struct netlink_callback *cb) /* Caller should hold socket lock for the passed tipc socket. */ static int __tipc_nl_add_sk_publ(struct sk_buff *skb, struct netlink_callback *cb, - struct publication *publ) + struct tipc_binding *b) { void *hdr; struct nlattr *attrs; @@ -3342,13 +3341,13 @@ static int __tipc_nl_add_sk_publ(struct sk_buff *skb, if (!attrs) goto genlmsg_cancel; - if (nla_put_u32(skb, TIPC_NLA_PUBL_KEY, publ->key)) + if (nla_put_u32(skb, TIPC_NLA_PUBL_KEY, b->key)) goto attr_msg_cancel; - if (nla_put_u32(skb, TIPC_NLA_PUBL_TYPE, publ->type)) + if (nla_put_u32(skb, TIPC_NLA_PUBL_TYPE, b->type)) goto attr_msg_cancel; - if (nla_put_u32(skb, TIPC_NLA_PUBL_LOWER, publ->lower)) + if (nla_put_u32(skb, TIPC_NLA_PUBL_LOWER, b->lower)) goto attr_msg_cancel; - if (nla_put_u32(skb, TIPC_NLA_PUBL_UPPER, publ->upper)) + if (nla_put_u32(skb, TIPC_NLA_PUBL_UPPER, b->upper)) goto attr_msg_cancel; nla_nest_end(skb, attrs); @@ -3370,7 +3369,7 @@ static int __tipc_nl_list_sk_publ(struct sk_buff *skb, struct tipc_sock *tsk, u32 *last_publ) { int err; - struct publication *p; + struct tipc_binding *p; if (*last_publ) { list_for_each_entry(p, &tsk->publications, binding_sock) { @@ -3389,7 +3388,7 @@ static int __tipc_nl_list_sk_publ(struct sk_buff *skb, return -EPIPE; } } else { - p = list_first_entry(&tsk->publications, struct publication, + p = list_first_entry(&tsk->publications, struct tipc_binding, binding_sock); } diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c index 6925a98..04b540a 100644 --- a/net/tipc/subscr.c +++ b/net/tipc/subscr.c @@ -35,7 +35,7 @@ */ #include "core.h" -#include "name_table.h" +#include "binding_table.h" #include "subscr.h" static void tipc_sub_send_event(struct tipc_subscription *sub, @@ -151,7 +151,7 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net, memcpy(&sub->evt.s, s, sizeof(*s)); spin_lock_init(&sub->lock); kref_init(&sub->kref); - tipc_nametbl_subscribe(sub); + tipc_bindtbl_subscribe(sub); timer_setup(&sub->timer, tipc_sub_timeout, 0); timeout = tipc_sub_read(&sub->evt.s, timeout); if (timeout != TIPC_WAIT_FOREVER) @@ -161,7 +161,7 @@ struct tipc_subscription *tipc_sub_subscribe(struct net *net, void tipc_sub_unsubscribe(struct tipc_subscription *sub) { - tipc_nametbl_unsubscribe(sub); + tipc_bindtbl_unsubscribe(sub); if (sub->evt.s.timeout != TIPC_WAIT_FOREVER) del_timer_sync(&sub->timer); list_del(&sub->sub_list); diff --git a/net/tipc/subscr.h b/net/tipc/subscr.h index 8b2d22b..24a720b 100644 --- a/net/tipc/subscr.h +++ b/net/tipc/subscr.h @@ -58,7 +58,7 @@ struct tipc_subscription { struct kref kref; struct net *net; struct timer_list timer; - struct list_head nameseq_list; + struct list_head service_list; struct list_head sub_list; struct tipc_event evt; int conid; diff --git a/net/tipc/sysctl.c b/net/tipc/sysctl.c index 1a779b1..ad78692 100644 --- a/net/tipc/sysctl.c +++ b/net/tipc/sysctl.c @@ -48,9 +48,9 @@ static struct ctl_table tipc_table[] = { .proc_handler = proc_dointvec, }, { - .procname = "named_timeout", - .data = &sysctl_tipc_named_timeout, - .maxlen = sizeof(sysctl_tipc_named_timeout), + .procname = "bind_dist_timeout", + .data = &sysctl_tipc_bindist_timeout, + .maxlen = sizeof(sysctl_tipc_bindist_timeout), .mode = 0644, .proc_handler = proc_dointvec, }, -- 2.1.4 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ tipc-discussion mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tipc-discussion
