xref: /openbmc/linux/net/tipc/name_table.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1b97bf3fdSPer Liden /*
2b97bf3fdSPer Liden  * net/tipc/name_table.h: Include file for TIPC name table code
3b97bf3fdSPer Liden  *
4935439ccSJon Maloy  * Copyright (c) 2000-2006, 2014-2018, Ericsson AB
5f6f0a4d2SAllan Stephens  * Copyright (c) 2004-2005, 2010-2011, Wind River Systems
6998d3907SJon Maloy  * Copyright (c) 2020-2021, Red Hat Inc
7b97bf3fdSPer Liden  * All rights reserved.
8b97bf3fdSPer Liden  *
9b97bf3fdSPer Liden  * Redistribution and use in source and binary forms, with or without
10b97bf3fdSPer Liden  * modification, are permitted provided that the following conditions are met:
11b97bf3fdSPer Liden  *
129ea1fd3cSPer Liden  * 1. Redistributions of source code must retain the above copyright
139ea1fd3cSPer Liden  *    notice, this list of conditions and the following disclaimer.
149ea1fd3cSPer Liden  * 2. Redistributions in binary form must reproduce the above copyright
159ea1fd3cSPer Liden  *    notice, this list of conditions and the following disclaimer in the
169ea1fd3cSPer Liden  *    documentation and/or other materials provided with the distribution.
179ea1fd3cSPer Liden  * 3. Neither the names of the copyright holders nor the names of its
189ea1fd3cSPer Liden  *    contributors may be used to endorse or promote products derived from
199ea1fd3cSPer Liden  *    this software without specific prior written permission.
209ea1fd3cSPer Liden  *
219ea1fd3cSPer Liden  * Alternatively, this software may be distributed under the terms of the
229ea1fd3cSPer Liden  * GNU General Public License ("GPL") version 2 as published by the Free
239ea1fd3cSPer Liden  * Software Foundation.
24b97bf3fdSPer Liden  *
25b97bf3fdSPer Liden  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26b97bf3fdSPer Liden  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27b97bf3fdSPer Liden  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28b97bf3fdSPer Liden  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29b97bf3fdSPer Liden  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30b97bf3fdSPer Liden  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31b97bf3fdSPer Liden  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32b97bf3fdSPer Liden  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33b97bf3fdSPer Liden  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34b97bf3fdSPer Liden  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35b97bf3fdSPer Liden  * POSSIBILITY OF SUCH DAMAGE.
36b97bf3fdSPer Liden  */
37b97bf3fdSPer Liden 
38b97bf3fdSPer Liden #ifndef _TIPC_NAME_TABLE_H
39b97bf3fdSPer Liden #define _TIPC_NAME_TABLE_H
40b97bf3fdSPer Liden 
41fead3909SPaul Gortmaker struct tipc_subscription;
423c724acdSJon Paul Maloy struct tipc_plist;
432ae0b8afSJon Paul Maloy struct tipc_nlist;
4475da2163SJon Maloy struct tipc_group;
4550a3499aSJon Maloy struct tipc_uaddr;
46b97bf3fdSPer Liden 
47b97bf3fdSPer Liden /*
48b97bf3fdSPer Liden  * TIPC name types reserved for internal TIPC use (both current and planned)
49b97bf3fdSPer Liden  */
50b97bf3fdSPer Liden #define TIPC_ZM_SRV		3	/* zone master service name type */
51993bfe5dSYing Xue #define TIPC_PUBL_SCOPE_NUM	(TIPC_NODE_SCOPE + 1)
52993bfe5dSYing Xue #define TIPC_NAMETBL_SIZE	1024	/* must be a power of 2 */
53b97bf3fdSPer Liden 
54*5ef21325SJon Maloy #define TIPC_ANY_SCOPE 10      /* Both node and cluster scope will match */
55*5ef21325SJon Maloy 
56b97bf3fdSPer Liden /**
57998d3907SJon Maloy  * struct publication - info about a published service address or range
58998d3907SJon Maloy  * @sr: service range represented by this publication
59998d3907SJon Maloy  * @sk: address of socket bound to this publication
60e50e73e1SJon Maloy  * @scope: scope of publication, TIPC_NODE_SCOPE or TIPC_CLUSTER_SCOPE
61e50e73e1SJon Maloy  * @key: publication key, unique across the cluster
6241b416f1STuong Lien  * @id: publication id
63e50e73e1SJon Maloy  * @binding_node: all publications from the same node which bound this one
64ff10527eSRandy Dunlap  * - Remote publications: in node->publ_list;
65e50e73e1SJon Maloy  * Used by node/name distr to withdraw publications when node is lost
66e50e73e1SJon Maloy  * - Local/node scope publications: in name_table->node_scope list
67e50e73e1SJon Maloy  * - Local/cluster scope publications: in name_table->cluster_scope list
68e50e73e1SJon Maloy  * @binding_sock: all publications from the same socket which bound this one
69e50e73e1SJon Maloy  *   Used by socket to withdraw publications when socket is unbound/released
70e50e73e1SJon Maloy  * @local_publ: list of identical publications made from this node
71e50e73e1SJon Maloy  *   Used by closest_first and multicast receive lookup algorithms
72e50e73e1SJon Maloy  * @all_publ: all publications identical to this one, whatever node and scope
73e50e73e1SJon Maloy  *   Used by round-robin lookup algorithm
7441b416f1STuong Lien  * @list: to form a list of publications in temporal order
7597ede29eSYing Xue  * @rcu: RCU callback head used for deferred freeing
76b97bf3fdSPer Liden  */
77b97bf3fdSPer Liden struct publication {
78998d3907SJon Maloy 	struct tipc_service_range sr;
79998d3907SJon Maloy 	struct tipc_socket_addr sk;
80a45ffa68SJon Maloy 	u16 scope;
81b97bf3fdSPer Liden 	u32 key;
8241b416f1STuong Lien 	u32 id;
83935439ccSJon Maloy 	struct list_head binding_node;
84e50e73e1SJon Maloy 	struct list_head binding_sock;
85e50e73e1SJon Maloy 	struct list_head local_publ;
86e50e73e1SJon Maloy 	struct list_head all_publ;
8741b416f1STuong Lien 	struct list_head list;
8897ede29eSYing Xue 	struct rcu_head rcu;
89b97bf3fdSPer Liden };
90b97bf3fdSPer Liden 
91993bfe5dSYing Xue /**
92993bfe5dSYing Xue  * struct name_table - table containing all existing port name publications
93ff10527eSRandy Dunlap  * @services: name sequence hash lists
9464a52b26SJon Maloy  * @node_scope: all local publications with node scope
95e50e73e1SJon Maloy  *               - used by name_distr during re-init of name table
9664a52b26SJon Maloy  * @cluster_scope: all local publications with cluster scope
97e50e73e1SJon Maloy  *               - used by name_distr to send bulk updates to new nodes
98e50e73e1SJon Maloy  *               - used by name_distr during re-init of name table
99ff10527eSRandy Dunlap  * @cluster_scope_lock: lock for accessing @cluster_scope
100993bfe5dSYing Xue  * @local_publ_count: number of publications issued by this node
101ff10527eSRandy Dunlap  * @rc_dests: destination node counter
102ff10527eSRandy Dunlap  * @snd_nxt: next sequence number to be used
103993bfe5dSYing Xue  */
104993bfe5dSYing Xue struct name_table {
105218527feSJon Maloy 	struct hlist_head services[TIPC_NAMETBL_SIZE];
10664a52b26SJon Maloy 	struct list_head node_scope;
10764a52b26SJon Maloy 	struct list_head cluster_scope;
108988f3f16SJon Maloy 	rwlock_t cluster_scope_lock;
109993bfe5dSYing Xue 	u32 local_publ_count;
110cad2929dSHoang Huu Le 	u32 rc_dests;
111cad2929dSHoang Huu Le 	u32 snd_nxt;
112993bfe5dSYing Xue };
113b97bf3fdSPer Liden 
1141593123aSRichard Alpe int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
115908148bcSJon Maloy bool tipc_nametbl_lookup_anycast(struct net *net, struct tipc_uaddr *ua,
116908148bcSJon Maloy 				 struct tipc_socket_addr *sk);
11745ceea2dSJon Maloy void tipc_nametbl_lookup_mcast_sockets(struct net *net, struct tipc_uaddr *ua,
118*5ef21325SJon Maloy 				       struct list_head *dports);
119833f8670SJon Maloy void tipc_nametbl_lookup_mcast_nodes(struct net *net, struct tipc_uaddr *ua,
120833f8670SJon Maloy 				     struct tipc_nlist *nodes);
121006ed14eSJon Maloy bool tipc_nametbl_lookup_group(struct net *net, struct tipc_uaddr *ua,
122006ed14eSJon Maloy 			       struct list_head *dsts, int *dstcnt,
123006ed14eSJon Maloy 			       u32 exclude, bool mcast);
12475da2163SJon Maloy void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp,
1256e44867bSJon Maloy 			      struct tipc_uaddr *ua);
12650a3499aSJon Maloy struct publication *tipc_nametbl_publish(struct net *net, struct tipc_uaddr *ua,
12750a3499aSJon Maloy 					 struct tipc_socket_addr *sk, u32 key);
1282c98da07SJon Maloy void tipc_nametbl_withdraw(struct net *net, struct tipc_uaddr *ua,
1292c98da07SJon Maloy 			   struct tipc_socket_addr *sk, u32 key);
130a45ffa68SJon Maloy struct publication *tipc_nametbl_insert_publ(struct net *net,
131a45ffa68SJon Maloy 					     struct tipc_uaddr *ua,
132a45ffa68SJon Maloy 					     struct tipc_socket_addr *sk,
133a45ffa68SJon Maloy 					     u32 key);
1342c98da07SJon Maloy struct publication *tipc_nametbl_remove_publ(struct net *net,
1352c98da07SJon Maloy 					     struct tipc_uaddr *ua,
1362c98da07SJon Maloy 					     struct tipc_socket_addr *sk,
1372c98da07SJon Maloy 					     u32 key);
138c3317f4dSJon Maloy bool tipc_nametbl_subscribe(struct tipc_subscription *s);
139fead3909SPaul Gortmaker void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
1404ac1c8d0SYing Xue int tipc_nametbl_init(struct net *net);
1414ac1c8d0SYing Xue void tipc_nametbl_stop(struct net *net);
142b97bf3fdSPer Liden 
143a80ae530SJon Maloy struct tipc_dest {
1442ae0b8afSJon Paul Maloy 	struct list_head list;
145a80ae530SJon Maloy 	u32 port;
146a80ae530SJon Maloy 	u32 node;
147a80ae530SJon Maloy };
1482ae0b8afSJon Paul Maloy 
149a80ae530SJon Maloy struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port);
150a80ae530SJon Maloy bool tipc_dest_push(struct list_head *l, u32 node, u32 port);
151a80ae530SJon Maloy bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port);
152a80ae530SJon Maloy bool tipc_dest_del(struct list_head *l, u32 node, u32 port);
153a80ae530SJon Maloy void tipc_dest_list_purge(struct list_head *l);
1543c724acdSJon Paul Maloy 
155b97bf3fdSPer Liden #endif
156