xref: /OK3568_Linux_fs/kernel/net/tipc/name_table.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * net/tipc/name_table.h: Include file for TIPC name table code
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Copyright (c) 2000-2006, 2014-2018, Ericsson AB
5*4882a593Smuzhiyun  * Copyright (c) 2004-2005, 2010-2011, Wind River Systems
6*4882a593Smuzhiyun  * All rights reserved.
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
9*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions are met:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * 1. Redistributions of source code must retain the above copyright
12*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
13*4882a593Smuzhiyun  * 2. Redistributions in binary form must reproduce the above copyright
14*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in the
15*4882a593Smuzhiyun  *    documentation and/or other materials provided with the distribution.
16*4882a593Smuzhiyun  * 3. Neither the names of the copyright holders nor the names of its
17*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived from
18*4882a593Smuzhiyun  *    this software without specific prior written permission.
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Alternatively, this software may be distributed under the terms of the
21*4882a593Smuzhiyun  * GNU General Public License ("GPL") version 2 as published by the Free
22*4882a593Smuzhiyun  * Software Foundation.
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25*4882a593Smuzhiyun  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*4882a593Smuzhiyun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27*4882a593Smuzhiyun  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28*4882a593Smuzhiyun  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29*4882a593Smuzhiyun  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30*4882a593Smuzhiyun  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31*4882a593Smuzhiyun  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32*4882a593Smuzhiyun  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33*4882a593Smuzhiyun  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34*4882a593Smuzhiyun  * POSSIBILITY OF SUCH DAMAGE.
35*4882a593Smuzhiyun  */
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #ifndef _TIPC_NAME_TABLE_H
38*4882a593Smuzhiyun #define _TIPC_NAME_TABLE_H
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun struct tipc_subscription;
41*4882a593Smuzhiyun struct tipc_plist;
42*4882a593Smuzhiyun struct tipc_nlist;
43*4882a593Smuzhiyun struct tipc_group;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /*
46*4882a593Smuzhiyun  * TIPC name types reserved for internal TIPC use (both current and planned)
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun #define TIPC_ZM_SRV		3	/* zone master service name type */
49*4882a593Smuzhiyun #define TIPC_PUBL_SCOPE_NUM	(TIPC_NODE_SCOPE + 1)
50*4882a593Smuzhiyun #define TIPC_NAMETBL_SIZE	1024	/* must be a power of 2 */
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun /**
53*4882a593Smuzhiyun  * struct publication - info about a published (name or) name sequence
54*4882a593Smuzhiyun  * @type: name sequence type
55*4882a593Smuzhiyun  * @lower: name sequence lower bound
56*4882a593Smuzhiyun  * @upper: name sequence upper bound
57*4882a593Smuzhiyun  * @scope: scope of publication, TIPC_NODE_SCOPE or TIPC_CLUSTER_SCOPE
58*4882a593Smuzhiyun  * @node: network address of publishing socket's node
59*4882a593Smuzhiyun  * @port: publishing port
60*4882a593Smuzhiyun  * @key: publication key, unique across the cluster
61*4882a593Smuzhiyun  * @id: publication id
62*4882a593Smuzhiyun  * @binding_node: all publications from the same node which bound this one
63*4882a593Smuzhiyun  * - Remote publications: in node->publ_list
64*4882a593Smuzhiyun  *   Used by node/name distr to withdraw publications when node is lost
65*4882a593Smuzhiyun  * - Local/node scope publications: in name_table->node_scope list
66*4882a593Smuzhiyun  * - Local/cluster scope publications: in name_table->cluster_scope list
67*4882a593Smuzhiyun  * @binding_sock: all publications from the same socket which bound this one
68*4882a593Smuzhiyun  *   Used by socket to withdraw publications when socket is unbound/released
69*4882a593Smuzhiyun  * @local_publ: list of identical publications made from this node
70*4882a593Smuzhiyun  *   Used by closest_first and multicast receive lookup algorithms
71*4882a593Smuzhiyun  * @all_publ: all publications identical to this one, whatever node and scope
72*4882a593Smuzhiyun  *   Used by round-robin lookup algorithm
73*4882a593Smuzhiyun  * @list: to form a list of publications in temporal order
74*4882a593Smuzhiyun  * @rcu: RCU callback head used for deferred freeing
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun struct publication {
77*4882a593Smuzhiyun 	u32 type;
78*4882a593Smuzhiyun 	u32 lower;
79*4882a593Smuzhiyun 	u32 upper;
80*4882a593Smuzhiyun 	u32 scope;
81*4882a593Smuzhiyun 	u32 node;
82*4882a593Smuzhiyun 	u32 port;
83*4882a593Smuzhiyun 	u32 key;
84*4882a593Smuzhiyun 	u32 id;
85*4882a593Smuzhiyun 	struct list_head binding_node;
86*4882a593Smuzhiyun 	struct list_head binding_sock;
87*4882a593Smuzhiyun 	struct list_head local_publ;
88*4882a593Smuzhiyun 	struct list_head all_publ;
89*4882a593Smuzhiyun 	struct list_head list;
90*4882a593Smuzhiyun 	struct rcu_head rcu;
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /**
94*4882a593Smuzhiyun  * struct name_table - table containing all existing port name publications
95*4882a593Smuzhiyun  * @seq_hlist: name sequence hash lists
96*4882a593Smuzhiyun  * @node_scope: all local publications with node scope
97*4882a593Smuzhiyun  *               - used by name_distr during re-init of name table
98*4882a593Smuzhiyun  * @cluster_scope: all local publications with cluster scope
99*4882a593Smuzhiyun  *               - used by name_distr to send bulk updates to new nodes
100*4882a593Smuzhiyun  *               - used by name_distr during re-init of name table
101*4882a593Smuzhiyun  * @local_publ_count: number of publications issued by this node
102*4882a593Smuzhiyun  */
103*4882a593Smuzhiyun struct name_table {
104*4882a593Smuzhiyun 	struct hlist_head services[TIPC_NAMETBL_SIZE];
105*4882a593Smuzhiyun 	struct list_head node_scope;
106*4882a593Smuzhiyun 	struct list_head cluster_scope;
107*4882a593Smuzhiyun 	rwlock_t cluster_scope_lock;
108*4882a593Smuzhiyun 	u32 local_publ_count;
109*4882a593Smuzhiyun 	u32 rc_dests;
110*4882a593Smuzhiyun 	u32 snd_nxt;
111*4882a593Smuzhiyun };
112*4882a593Smuzhiyun 
113*4882a593Smuzhiyun int tipc_nl_name_table_dump(struct sk_buff *skb, struct netlink_callback *cb);
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun u32 tipc_nametbl_translate(struct net *net, u32 type, u32 instance, u32 *node);
116*4882a593Smuzhiyun void tipc_nametbl_mc_lookup(struct net *net, u32 type, u32 lower, u32 upper,
117*4882a593Smuzhiyun 			    u32 scope, bool exact, struct list_head *dports);
118*4882a593Smuzhiyun void tipc_nametbl_build_group(struct net *net, struct tipc_group *grp,
119*4882a593Smuzhiyun 			      u32 type, u32 domain);
120*4882a593Smuzhiyun void tipc_nametbl_lookup_dst_nodes(struct net *net, u32 type, u32 lower,
121*4882a593Smuzhiyun 				   u32 upper, struct tipc_nlist *nodes);
122*4882a593Smuzhiyun bool tipc_nametbl_lookup(struct net *net, u32 type, u32 instance, u32 domain,
123*4882a593Smuzhiyun 			 struct list_head *dsts, int *dstcnt, u32 exclude,
124*4882a593Smuzhiyun 			 bool all);
125*4882a593Smuzhiyun struct publication *tipc_nametbl_publish(struct net *net, u32 type, u32 lower,
126*4882a593Smuzhiyun 					 u32 upper, u32 scope, u32 port,
127*4882a593Smuzhiyun 					 u32 key);
128*4882a593Smuzhiyun int tipc_nametbl_withdraw(struct net *net, u32 type, u32 lower, u32 upper,
129*4882a593Smuzhiyun 			  u32 key);
130*4882a593Smuzhiyun struct publication *tipc_nametbl_insert_publ(struct net *net, u32 type,
131*4882a593Smuzhiyun 					     u32 lower, u32 upper, u32 scope,
132*4882a593Smuzhiyun 					     u32 node, u32 ref, u32 key);
133*4882a593Smuzhiyun struct publication *tipc_nametbl_remove_publ(struct net *net, u32 type,
134*4882a593Smuzhiyun 					     u32 lower, u32 upper,
135*4882a593Smuzhiyun 					     u32 node, u32 key);
136*4882a593Smuzhiyun bool tipc_nametbl_subscribe(struct tipc_subscription *s);
137*4882a593Smuzhiyun void tipc_nametbl_unsubscribe(struct tipc_subscription *s);
138*4882a593Smuzhiyun int tipc_nametbl_init(struct net *net);
139*4882a593Smuzhiyun void tipc_nametbl_stop(struct net *net);
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun struct tipc_dest {
142*4882a593Smuzhiyun 	struct list_head list;
143*4882a593Smuzhiyun 	u32 port;
144*4882a593Smuzhiyun 	u32 node;
145*4882a593Smuzhiyun };
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun struct tipc_dest *tipc_dest_find(struct list_head *l, u32 node, u32 port);
148*4882a593Smuzhiyun bool tipc_dest_push(struct list_head *l, u32 node, u32 port);
149*4882a593Smuzhiyun bool tipc_dest_pop(struct list_head *l, u32 *node, u32 *port);
150*4882a593Smuzhiyun bool tipc_dest_del(struct list_head *l, u32 node, u32 port);
151*4882a593Smuzhiyun void tipc_dest_list_purge(struct list_head *l);
152*4882a593Smuzhiyun int tipc_dest_list_len(struct list_head *l);
153*4882a593Smuzhiyun 
154*4882a593Smuzhiyun #endif
155