xref: /titanic_51/usr/src/uts/common/inet/ilb.h (revision cbdcbd056f15c9c9fd82d5543b3a502677c4d391)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 #ifndef _INET_ILB_H
27 #define	_INET_ILB_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /*
34  * This file contains the private interface to IP to configure ILB in
35  * the system.  Note that this is not a supported interface, and is
36  * subject to be changed without notice.  User level apps should instead
37  * use the libilb library to interface with ILB.
38  */
39 
40 /* ioctl cmds to IP to configure ILB */
41 typedef enum {
42 	ILB_CREATE_RULE,
43 	ILB_DESTROY_RULE,
44 	ILB_ENABLE_RULE,
45 	ILB_DISABLE_RULE,
46 	ILB_NUM_RULES,
47 	ILB_NUM_SERVERS,
48 	ILB_RULE_NAMES,
49 	ILB_LIST_RULE,
50 	ILB_LIST_SERVERS,
51 	ILB_ADD_SERVERS,
52 	ILB_DEL_SERVERS,
53 	ILB_ENABLE_SERVERS,
54 	ILB_DISABLE_SERVERS,
55 	ILB_LIST_NAT_TABLE,
56 	ILB_LIST_STICKY_TABLE
57 } ilb_cmd_t;
58 
59 /* Supported load balancing algorithm type */
60 typedef enum {
61 	ILB_ALG_IMPL_ROUNDROBIN = 1,
62 	ILB_ALG_IMPL_HASH_IP,
63 	ILB_ALG_IMPL_HASH_IP_SPORT,
64 	ILB_ALG_IMPL_HASH_IP_VIP
65 } ilb_algo_impl_t;
66 
67 /* Supported load balancing method */
68 typedef enum {
69 	ILB_TOPO_IMPL_DSR = 1,
70 	ILB_TOPO_IMPL_NAT,
71 	ILB_TOPO_IMPL_HALF_NAT
72 } ilb_topo_impl_t;
73 
74 /* Max ILB rule name length */
75 #define	ILB_RULE_NAMESZ	20
76 
77 /* Max kstat server name length */
78 #define	ILB_SERVER_NAMESZ 20
79 
80 /* Rule destroy/enable/disable command struct */
81 typedef struct {
82 	ilb_cmd_t	cmd;
83 	char		name[ILB_RULE_NAMESZ];
84 	uint32_t	flags;
85 } ilb_name_cmd_t;
86 
87 /* Flags for rule creation command */
88 /* these are echoed in lib/libilb/common/libilb.h - please keep in sync */
89 #define	ILB_RULE_ENABLED	0x1
90 #define	ILB_RULE_STICKY		0x2
91 #define	ILB_RULE_ALLRULES	0x4
92 #define	ILB_RULE_BUSY		0x8
93 
94 /* Rule creation/retrieval command struct */
95 typedef struct {
96 	ilb_cmd_t	cmd;
97 	char		name[ILB_RULE_NAMESZ];
98 	uint32_t	ip_ver;
99 	in6_addr_t	vip;
100 	char		vip_itf[LIFNAMSIZ];
101 	uint32_t	proto;
102 	in_port_t	min_port;	/* In network byte order */
103 	in_port_t	max_port;
104 	ilb_algo_impl_t	algo;
105 	ilb_topo_impl_t	topo;
106 	char		servers_itf[LIFNAMSIZ];
107 	in6_addr_t	nat_src_start;
108 	in6_addr_t	nat_src_end;
109 	uint32_t	flags;
110 	in6_addr_t	sticky_mask;
111 	uint32_t	conn_drain_timeout;	/* Time value is in seconds */
112 	uint32_t	nat_expiry;
113 	uint32_t	sticky_expiry;
114 } ilb_rule_cmd_t;
115 
116 /* Get number of servers command struct */
117 typedef struct {
118 	ilb_cmd_t	cmd;
119 	char		name[ILB_RULE_NAMESZ];
120 	uint32_t	num;
121 } ilb_num_servers_cmd_t;
122 
123 /* Get number of rules command struct */
124 typedef struct {
125 	ilb_cmd_t	cmd;
126 	uint32_t	num;
127 } ilb_num_rules_cmd_t;
128 
129 /* Get all rule names command struct */
130 typedef struct {
131 	ilb_cmd_t	cmd;
132 	uint32_t	num_names;
133 	/* buf size is (num_names * ILB_RULE_NAMESZ) */
134 	char		buf[ILB_RULE_NAMESZ];
135 } ilb_rule_names_cmd_t;
136 
137 /* Flags for ilb_server_info_t */
138 #define	ILB_SERVER_ENABLED	0x1
139 
140 /* Struct to represent a backend server for add/list command */
141 typedef struct {
142 	char		name[ILB_SERVER_NAMESZ];
143 	in6_addr_t	addr;
144 	in_port_t	min_port;	/* In network byte order */
145 	in_port_t	max_port;
146 	uint32_t	flags;
147 	int		err;	/* In return, non zero value indicates error */
148 } ilb_server_info_t;
149 
150 /* Add/list servers command struct */
151 typedef struct {
152 	ilb_cmd_t		cmd;
153 	char			name[ILB_RULE_NAMESZ];
154 	uint32_t		num_servers;
155 	ilb_server_info_t	servers[1];
156 } ilb_servers_info_cmd_t;
157 
158 /*
159  * Struct to represent a backend server for delete/enable/disable
160  * command
161  */
162 typedef struct {
163 	in6_addr_t	addr;
164 	int		err;	/* In return, non zero value indicates error */
165 } ilb_server_arg_t;
166 
167 /* Delete/enable/disable a server command struct */
168 typedef struct {
169 	ilb_cmd_t		cmd;
170 	char			name[ILB_RULE_NAMESZ];
171 	uint32_t		num_servers;
172 	ilb_server_arg_t	servers[1];
173 } ilb_servers_cmd_t;
174 
175 /*
176  * Flags for listing NAT/persistence table entries
177  *
178  * ILB_LIST_BEGIN: start from the beginning of the table
179  * ILB_LIST_CONT: start from the last reply
180  * ILB_LIST_END: on return, this flag indicates the end of the table
181  */
182 #define	ILB_LIST_BEGIN	0x1
183 #define	ILB_LIST_CONT	0x2
184 #define	ILB_LIST_END	0x4
185 
186 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
187 #pragma pack(4)
188 #endif
189 
190 typedef struct {
191 	uint32_t	proto;
192 
193 	in6_addr_t	in_local;
194 	in6_addr_t	in_global;
195 	in6_addr_t	out_local;
196 	in6_addr_t	out_global;
197 
198 	in_port_t	in_local_port;
199 	in_port_t	in_global_port;
200 	in_port_t	out_local_port;
201 	in_port_t	out_global_port;
202 
203 	int64_t		create_time;
204 	int64_t		last_access_time;
205 	uint64_t	pkt_cnt;
206 } ilb_nat_entry_t;
207 
208 /* List NAT table entries command struct */
209 typedef struct {
210 	ilb_cmd_t	cmd;
211 	uint32_t	flags;
212 	uint32_t	num_nat;
213 	ilb_nat_entry_t	entries[1];
214 } ilb_list_nat_cmd_t;
215 
216 typedef struct {
217 	char		rule_name[ILB_RULE_NAMESZ];
218 	in6_addr_t	req_addr;
219 	in6_addr_t	srv_addr;
220 	int64_t		expiry_time;
221 } ilb_sticky_entry_t;
222 
223 /* List sticky table entries command struct */
224 typedef struct {
225 	ilb_cmd_t		cmd;
226 	uint32_t		flags;
227 	uint32_t		num_sticky;
228 	ilb_sticky_entry_t	entries[1];
229 } ilb_list_sticky_cmd_t;
230 
231 #if _LONG_LONG_ALIGNMENT == 8 && _LONG_LONG_ALIGNMENT_32 == 4
232 #pragma pack()
233 #endif
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif /* _INET_ILB_H */
240