162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * net/tipc/name_table.h: Include file for TIPC name table code
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 2000-2006, 2014-2018, Ericsson AB
562306a36Sopenharmony_ci * Copyright (c) 2004-2005, 2010-2011, Wind River Systems
662306a36Sopenharmony_ci * Copyright (c) 2020-2021, Red Hat Inc
762306a36Sopenharmony_ci * All rights reserved.
862306a36Sopenharmony_ci *
962306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
1062306a36Sopenharmony_ci * modification, are permitted provided that the following conditions are met:
1162306a36Sopenharmony_ci *
1262306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1362306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
1462306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
1562306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
1662306a36Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
1762306a36Sopenharmony_ci * 3. Neither the names of the copyright holders nor the names of its
1862306a36Sopenharmony_ci *    contributors may be used to endorse or promote products derived from
1962306a36Sopenharmony_ci *    this software without specific prior written permission.
2062306a36Sopenharmony_ci *
2162306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2262306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2362306a36Sopenharmony_ci * Software Foundation.
2462306a36Sopenharmony_ci *
2562306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2662306a36Sopenharmony_ci * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2762306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2862306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
2962306a36Sopenharmony_ci * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
3062306a36Sopenharmony_ci * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
3162306a36Sopenharmony_ci * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
3262306a36Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
3362306a36Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3462306a36Sopenharmony_ci * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3562306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci#ifndef _TIPC_NAME_TABLE_H
3962306a36Sopenharmony_ci#define _TIPC_NAME_TABLE_H
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_cistruct tipc_subscription;
4262306a36Sopenharmony_cistruct tipc_plist;
4362306a36Sopenharmony_cistruct tipc_nlist;
4462306a36Sopenharmony_cistruct tipc_group;
4562306a36Sopenharmony_cistruct tipc_uaddr;
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci/*
4862306a36Sopenharmony_ci * TIPC name types reserved for internal TIPC use (both current and planned)
4962306a36Sopenharmony_ci */
5062306a36Sopenharmony_ci#define TIPC_ZM_SRV		3	/* zone master service name type */
5162306a36Sopenharmony_ci#define TIPC_PUBL_SCOPE_NUM	(TIPC_NODE_SCOPE + 1)
5262306a36Sopenharmony_ci#define TIPC_NAMETBL_SIZE	1024	/* must be a power of 2 */
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ci#define TIPC_ANY_SCOPE 10      /* Both node and cluster scope will match */
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/**
5762306a36Sopenharmony_ci * struct publication - info about a published service address or range
5862306a36Sopenharmony_ci * @sr: service range represented by this publication
5962306a36Sopenharmony_ci * @sk: address of socket bound to this publication
6062306a36Sopenharmony_ci * @scope: scope of publication, TIPC_NODE_SCOPE or TIPC_CLUSTER_SCOPE
6162306a36Sopenharmony_ci * @key: publication key, unique across the cluster
6262306a36Sopenharmony_ci * @id: publication id
6362306a36Sopenharmony_ci * @binding_node: all publications from the same node which bound this one
6462306a36Sopenharmony_ci * - Remote publications: in node->publ_list;
6562306a36Sopenharmony_ci * Used by node/name distr to withdraw publications when node is lost
6662306a36Sopenharmony_ci * - Local/node scope publications: in name_table->node_scope list
6762306a36Sopenharmony_ci * - Local/cluster scope publications: in name_table->cluster_scope list
6862306a36Sopenharmony_ci * @binding_sock: all publications from the same socket which bound this one
6962306a36Sopenharmony_ci *   Used by socket to withdraw publications when socket is unbound/released
7062306a36Sopenharmony_ci * @local_publ: list of identical publications made from this node
7162306a36Sopenharmony_ci *   Used by closest_first and multicast receive lookup algorithms
7262306a36Sopenharmony_ci * @all_publ: all publications identical to this one, whatever node and scope
7362306a36Sopenharmony_ci *   Used by round-robin lookup algorithm
7462306a36Sopenharmony_ci * @list: to form a list of publications in temporal order
7562306a36Sopenharmony_ci * @rcu: RCU callback head used for deferred freeing
7662306a36Sopenharmony_ci */
7762306a36Sopenharmony_cistruct publication {
7862306a36Sopenharmony_ci	struct tipc_service_range sr;
7962306a36Sopenharmony_ci	struct tipc_socket_addr sk;
8062306a36Sopenharmony_ci	u16 scope;
8162306a36Sopenharmony_ci	u32 key;
8262306a36Sopenharmony_ci	u32 id;
8362306a36Sopenharmony_ci	struct list_head binding_node;
8462306a36Sopenharmony_ci	struct list_head binding_sock;
8562306a36Sopenharmony_ci	struct list_head local_publ;
8662306a36Sopenharmony_ci	struct list_head all_publ;
8762306a36Sopenharmony_ci	struct list_head list;
8862306a36Sopenharmony_ci	struct rcu_head rcu;
8962306a36Sopenharmony_ci};
9062306a36Sopenharmony_ci
9162306a36Sopenharmony_ci/**
9262306a36Sopenharmony_ci * struct name_table - table containing all existing port name publications
9362306a36Sopenharmony_ci * @services: name sequence hash lists
9462306a36Sopenharmony_ci * @node_scope: all local publications with node scope
9562306a36Sopenharmony_ci *               - used by name_distr during re-init of name table
9662306a36Sopenharmony_ci * @cluster_scope: all local publications with cluster scope
9762306a36Sopenharmony_ci *               - used by name_distr to send bulk updates to new nodes
9862306a36Sopenharmony_ci *               - used by name_distr during re-init of name table
9962306a36Sopenharmony_ci * @cluster_scope_lock: lock for accessing @cluster_scope
10062306a36Sopenharmony_ci * @local_publ_count: number of publications issued by this node
10162306a36Sopenharmony_ci * @rc_dests: destination node counter
10262306a36Sopenharmony_ci * @snd_nxt: next sequence number to be used
10362306a36Sopenharmony_ci */
10462306a36Sopenharmony_cistruct name_table {
10562306a36Sopenharmony_ci	struct hlist_head services[TIPC_NAMETBL_SIZE];
10662306a36Sopenharmony_ci	struct list_head node_scope;
10762306a36Sopenharmony_ci	struct list_head cluster_scope;
10862306a36Sopenharmony_ci	rwlock_t cluster_scope_lock;
10962306a36Sopenharmony_ci	u32 local_publ_count;
11062306a36Sopenharmony_ci	u32 rc_dests;
11162306a36Sopenharmony_ci	u32 snd_nxt;
11262306a36Sopenharmony_ci};
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ciint tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
11562306a36Sopenharmony_cibool tipc_nametbl_lookup_anycast(struct net *net, struct tipc_uaddr *ua,
11662306a36Sopenharmony_ci				 struct tipc_socket_addr *sk);
11762306a36Sopenharmony_civoid tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua,
11862306a36Sopenharmony_ci				       struct list_head *dports);
11962306a36Sopenharmony_civoid tipc_nametbl_lookup_mcast_nodes(struct net *net, struct tipc_uaddr *ua,
12062306a36Sopenharmony_ci				     struct tipc_nlist *nodes);
12162306a36Sopenharmony_cibool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua,
12262306a36Sopenharmony_ci			       struct list_head *dsts, int *dstcnt,
12362306a36Sopenharmony_ci			       u32 exclude, bool mcast);
12462306a36Sopenharmony_civoid tipc_nametbl_build_group(struct net *net, struct tipc_group *grp,
12562306a36Sopenharmony_ci			      struct tipc_uaddr *ua);
12662306a36Sopenharmony_cistruct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
12762306a36Sopenharmony_ci					 struct tipc_socket_addr *sk, u32 key);
12862306a36Sopenharmony_civoid tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua,
12962306a36Sopenharmony_ci			   struct tipc_socket_addr *sk, u32 key);
13062306a36Sopenharmony_cistruct publication *tipc_nametbl_insert_publ(struct net *net,
13162306a36Sopenharmony_ci					     struct tipc_uaddr *ua,
13262306a36Sopenharmony_ci					     struct tipc_socket_addr *sk,
13362306a36Sopenharmony_ci					     u32 key);
13462306a36Sopenharmony_cistruct publication *tipc_nametbl_remove_publ(struct net *net,
13562306a36Sopenharmony_ci					     struct tipc_uaddr *ua,
13662306a36Sopenharmony_ci					     struct tipc_socket_addr *sk,
13762306a36Sopenharmony_ci					     u32 key);
13862306a36Sopenharmony_cibool tipc_nametbl_subscribe(struct tipc_subscription *s);
13962306a36Sopenharmony_civoid tipc_nametbl_unsubscribe(struct tipc_subscription *s);
14062306a36Sopenharmony_ciint tipc_nametbl_init(struct net *net);
14162306a36Sopenharmony_civoid tipc_nametbl_stop(struct net *net);
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_cistruct tipc_dest {
14462306a36Sopenharmony_ci	struct list_head list;
14562306a36Sopenharmony_ci	u32 port;
14662306a36Sopenharmony_ci	u32 node;
14762306a36Sopenharmony_ci};
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_cistruct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port);
15062306a36Sopenharmony_cibool tipc_dest_push(struct list_head *l, u32 node, u32 port);
15162306a36Sopenharmony_cibool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port);
15262306a36Sopenharmony_cibool tipc_dest_del(struct list_head *l, u32 node, u32 port);
15362306a36Sopenharmony_civoid tipc_dest_list_purge(struct list_head *l);
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci#endif
156