1 /*
2  *      IP Virtual Server
3  *      data structure and functionality definitions
4  */
5 
6 #ifndef _IP_VS_H
7 #define _IP_VS_H
8 
9 #include <linux/types.h>	/* For __beXX types in userland */
10 
11 #define IP_VS_VERSION_CODE	0x010201
12 #define NVERSION(version)			\
13 	(version >> 16) & 0xFF,			\
14 	(version >> 8) & 0xFF,			\
15 	version & 0xFF
16 
17 /*
18  *      Virtual Service Flags
19  */
20 #define IP_VS_SVC_F_PERSISTENT	0x0001		/* persistent port */
21 #define IP_VS_SVC_F_HASHED	0x0002		/* hashed entry */
22 #define IP_VS_SVC_F_ONEPACKET	0x0004		/* one-packet scheduling */
23 
24 /*
25  *      Destination Server Flags
26  */
27 #define IP_VS_DEST_F_AVAILABLE	0x0001		/* server is available */
28 #define IP_VS_DEST_F_OVERLOAD	0x0002		/* server is overloaded */
29 
30 /*
31  *      IPVS sync daemon states
32  */
33 #define IP_VS_STATE_NONE	0x0000		/* daemon is stopped */
34 #define IP_VS_STATE_MASTER	0x0001		/* started as master */
35 #define IP_VS_STATE_BACKUP	0x0002		/* started as backup */
36 
37 /*
38  *      IPVS socket options
39  */
40 #define IP_VS_BASE_CTL		(64+1024+64)		/* base */
41 
42 #define IP_VS_SO_SET_NONE	IP_VS_BASE_CTL		/* just peek */
43 #define IP_VS_SO_SET_INSERT	(IP_VS_BASE_CTL+1)
44 #define IP_VS_SO_SET_ADD	(IP_VS_BASE_CTL+2)
45 #define IP_VS_SO_SET_EDIT	(IP_VS_BASE_CTL+3)
46 #define IP_VS_SO_SET_DEL	(IP_VS_BASE_CTL+4)
47 #define IP_VS_SO_SET_FLUSH	(IP_VS_BASE_CTL+5)
48 #define IP_VS_SO_SET_LIST	(IP_VS_BASE_CTL+6)
49 #define IP_VS_SO_SET_ADDDEST	(IP_VS_BASE_CTL+7)
50 #define IP_VS_SO_SET_DELDEST	(IP_VS_BASE_CTL+8)
51 #define IP_VS_SO_SET_EDITDEST	(IP_VS_BASE_CTL+9)
52 #define IP_VS_SO_SET_TIMEOUT	(IP_VS_BASE_CTL+10)
53 #define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
54 #define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
55 #define IP_VS_SO_SET_RESTORE    (IP_VS_BASE_CTL+13)
56 #define IP_VS_SO_SET_SAVE       (IP_VS_BASE_CTL+14)
57 #define IP_VS_SO_SET_ZERO	(IP_VS_BASE_CTL+15)
58 #define IP_VS_SO_SET_MAX	IP_VS_SO_SET_ZERO
59 
60 #define IP_VS_SO_GET_VERSION	IP_VS_BASE_CTL
61 #define IP_VS_SO_GET_INFO	(IP_VS_BASE_CTL+1)
62 #define IP_VS_SO_GET_SERVICES	(IP_VS_BASE_CTL+2)
63 #define IP_VS_SO_GET_SERVICE	(IP_VS_BASE_CTL+3)
64 #define IP_VS_SO_GET_DESTS	(IP_VS_BASE_CTL+4)
65 #define IP_VS_SO_GET_DEST	(IP_VS_BASE_CTL+5)	/* not used now */
66 #define IP_VS_SO_GET_TIMEOUT	(IP_VS_BASE_CTL+6)
67 #define IP_VS_SO_GET_DAEMON	(IP_VS_BASE_CTL+7)
68 #define IP_VS_SO_GET_MAX	IP_VS_SO_GET_DAEMON
69 
70 
71 /*
72  *      IPVS Connection Flags
73  *      Only flags 0..15 are sent to backup server
74  */
75 #define IP_VS_CONN_F_FWD_MASK	0x0007		/* mask for the fwd methods */
76 #define IP_VS_CONN_F_MASQ	0x0000		/* masquerading/NAT */
77 #define IP_VS_CONN_F_LOCALNODE	0x0001		/* local node */
78 #define IP_VS_CONN_F_TUNNEL	0x0002		/* tunneling */
79 #define IP_VS_CONN_F_DROUTE	0x0003		/* direct routing */
80 #define IP_VS_CONN_F_BYPASS	0x0004		/* cache bypass */
81 #define IP_VS_CONN_F_SYNC	0x0020		/* entry created by sync */
82 #define IP_VS_CONN_F_HASHED	0x0040		/* hashed entry */
83 #define IP_VS_CONN_F_NOOUTPUT	0x0080		/* no output packets */
84 #define IP_VS_CONN_F_INACTIVE	0x0100		/* not established */
85 #define IP_VS_CONN_F_OUT_SEQ	0x0200		/* must do output seq adjust */
86 #define IP_VS_CONN_F_IN_SEQ	0x0400		/* must do input seq adjust */
87 #define IP_VS_CONN_F_SEQ_MASK	0x0600		/* in/out sequence mask */
88 #define IP_VS_CONN_F_NO_CPORT	0x0800		/* no client port set yet */
89 #define IP_VS_CONN_F_TEMPLATE	0x1000		/* template, not connection */
90 #define IP_VS_CONN_F_ONE_PACKET	0x2000		/* forward only one packet */
91 
92 #define IP_VS_CONN_F_BACKUP_MASK (IP_VS_CONN_F_FWD_MASK | \
93 				  IP_VS_CONN_F_NOOUTPUT | \
94 				  IP_VS_CONN_F_INACTIVE | \
95 				  IP_VS_CONN_F_SEQ_MASK | \
96 				  IP_VS_CONN_F_NO_CPORT | \
97 				  IP_VS_CONN_F_TEMPLATE \
98 				 )
99 
100 /* Flags that are not sent to backup server start from bit 16 */
101 #define IP_VS_CONN_F_NFCT	(1 << 16)	/* use netfilter conntrack */
102 
103 /* Connection flags from destination that can be changed by user space */
104 #define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \
105 				IP_VS_CONN_F_ONE_PACKET | \
106 				IP_VS_CONN_F_NFCT | \
107 				0)
108 
109 #define IP_VS_SCHEDNAME_MAXLEN	16
110 #define IP_VS_PENAME_MAXLEN	16
111 #define IP_VS_IFNAME_MAXLEN	16
112 
113 #define IP_VS_PEDATA_MAXLEN     255
114 
115 /*
116  *	The struct ip_vs_service_user and struct ip_vs_dest_user are
117  *	used to set IPVS rules through setsockopt.
118  */
119 struct ip_vs_service_user {
120 	/* virtual service addresses */
121 	__u16		protocol;
122 	__be32			addr;		/* virtual ip address */
123 	__be16			port;
124 	__u32		fwmark;		/* firwall mark of service */
125 
126 	/* virtual service options */
127 	char			sched_name[IP_VS_SCHEDNAME_MAXLEN];
128 	unsigned		flags;		/* virtual service flags */
129 	unsigned		timeout;	/* persistent timeout in sec */
130 	__be32			netmask;	/* persistent netmask */
131 };
132 
133 
134 struct ip_vs_dest_user {
135 	/* destination server address */
136 	__be32			addr;
137 	__be16			port;
138 
139 	/* real server options */
140 	unsigned		conn_flags;	/* connection flags */
141 	int			weight;		/* destination weight */
142 
143 	/* thresholds for active connections */
144 	__u32		u_threshold;	/* upper threshold */
145 	__u32		l_threshold;	/* lower threshold */
146 };
147 
148 
149 /*
150  *	IPVS statistics object (for user space)
151  */
152 struct ip_vs_stats_user {
153 	__u32                   conns;          /* connections scheduled */
154 	__u32                   inpkts;         /* incoming packets */
155 	__u32                   outpkts;        /* outgoing packets */
156 	__u64                   inbytes;        /* incoming bytes */
157 	__u64                   outbytes;       /* outgoing bytes */
158 
159 	__u32			cps;		/* current connection rate */
160 	__u32			inpps;		/* current in packet rate */
161 	__u32			outpps;		/* current out packet rate */
162 	__u32			inbps;		/* current in byte rate */
163 	__u32			outbps;		/* current out byte rate */
164 };
165 
166 
167 /* The argument to IP_VS_SO_GET_INFO */
168 struct ip_vs_getinfo {
169 	/* version number */
170 	unsigned int		version;
171 
172 	/* size of connection hash table */
173 	unsigned int		size;
174 
175 	/* number of virtual services */
176 	unsigned int		num_services;
177 };
178 
179 
180 /* The argument to IP_VS_SO_GET_SERVICE */
181 struct ip_vs_service_entry {
182 	/* which service: user fills in these */
183 	__u16		protocol;
184 	__be32			addr;		/* virtual address */
185 	__be16			port;
186 	__u32		fwmark;		/* firwall mark of service */
187 
188 	/* service options */
189 	char			sched_name[IP_VS_SCHEDNAME_MAXLEN];
190 	unsigned		flags;          /* virtual service flags */
191 	unsigned		timeout;	/* persistent timeout */
192 	__be32			netmask;	/* persistent netmask */
193 
194 	/* number of real servers */
195 	unsigned int		num_dests;
196 
197 	/* statistics */
198 	struct ip_vs_stats_user stats;
199 };
200 
201 
202 struct ip_vs_dest_entry {
203 	__be32			addr;		/* destination address */
204 	__be16			port;
205 	unsigned		conn_flags;	/* connection flags */
206 	int			weight;		/* destination weight */
207 
208 	__u32		u_threshold;	/* upper threshold */
209 	__u32		l_threshold;	/* lower threshold */
210 
211 	__u32		activeconns;	/* active connections */
212 	__u32		inactconns;	/* inactive connections */
213 	__u32		persistconns;	/* persistent connections */
214 
215 	/* statistics */
216 	struct ip_vs_stats_user stats;
217 };
218 
219 
220 /* The argument to IP_VS_SO_GET_DESTS */
221 struct ip_vs_get_dests {
222 	/* which service: user fills in these */
223 	__u16		protocol;
224 	__be32			addr;		/* virtual address */
225 	__be16			port;
226 	__u32		fwmark;		/* firwall mark of service */
227 
228 	/* number of real servers */
229 	unsigned int		num_dests;
230 
231 	/* the real servers */
232 	struct ip_vs_dest_entry	entrytable[0];
233 };
234 
235 
236 /* The argument to IP_VS_SO_GET_SERVICES */
237 struct ip_vs_get_services {
238 	/* number of virtual services */
239 	unsigned int		num_services;
240 
241 	/* service table */
242 	struct ip_vs_service_entry entrytable[0];
243 };
244 
245 
246 /* The argument to IP_VS_SO_GET_TIMEOUT */
247 struct ip_vs_timeout_user {
248 	int			tcp_timeout;
249 	int			tcp_fin_timeout;
250 	int			udp_timeout;
251 };
252 
253 
254 /* The argument to IP_VS_SO_GET_DAEMON */
255 struct ip_vs_daemon_user {
256 	/* sync daemon state (master/backup) */
257 	int			state;
258 
259 	/* multicast interface name */
260 	char			mcast_ifn[IP_VS_IFNAME_MAXLEN];
261 
262 	/* SyncID we belong to */
263 	int			syncid;
264 };
265 
266 /*
267  *
268  * IPVS Generic Netlink interface definitions
269  *
270  */
271 
272 /* Generic Netlink family info */
273 
274 #define IPVS_GENL_NAME		"IPVS"
275 #define IPVS_GENL_VERSION	0x1
276 
277 struct ip_vs_flags {
278 	__be32 flags;
279 	__be32 mask;
280 };
281 
282 /* Generic Netlink command attributes */
283 enum {
284 	IPVS_CMD_UNSPEC = 0,
285 
286 	IPVS_CMD_NEW_SERVICE,		/* add service */
287 	IPVS_CMD_SET_SERVICE,		/* modify service */
288 	IPVS_CMD_DEL_SERVICE,		/* delete service */
289 	IPVS_CMD_GET_SERVICE,		/* get service info */
290 
291 	IPVS_CMD_NEW_DEST,		/* add destination */
292 	IPVS_CMD_SET_DEST,		/* modify destination */
293 	IPVS_CMD_DEL_DEST,		/* delete destination */
294 	IPVS_CMD_GET_DEST,		/* get destination info */
295 
296 	IPVS_CMD_NEW_DAEMON,		/* start sync daemon */
297 	IPVS_CMD_DEL_DAEMON,		/* stop sync daemon */
298 	IPVS_CMD_GET_DAEMON,		/* get sync daemon status */
299 
300 	IPVS_CMD_SET_CONFIG,		/* set config settings */
301 	IPVS_CMD_GET_CONFIG,		/* get config settings */
302 
303 	IPVS_CMD_SET_INFO,		/* only used in GET_INFO reply */
304 	IPVS_CMD_GET_INFO,		/* get general IPVS info */
305 
306 	IPVS_CMD_ZERO,			/* zero all counters and stats */
307 	IPVS_CMD_FLUSH,			/* flush services and dests */
308 
309 	__IPVS_CMD_MAX,
310 };
311 
312 #define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)
313 
314 /* Attributes used in the first level of commands */
315 enum {
316 	IPVS_CMD_ATTR_UNSPEC = 0,
317 	IPVS_CMD_ATTR_SERVICE,		/* nested service attribute */
318 	IPVS_CMD_ATTR_DEST,		/* nested destination attribute */
319 	IPVS_CMD_ATTR_DAEMON,		/* nested sync daemon attribute */
320 	IPVS_CMD_ATTR_TIMEOUT_TCP,	/* TCP connection timeout */
321 	IPVS_CMD_ATTR_TIMEOUT_TCP_FIN,	/* TCP FIN wait timeout */
322 	IPVS_CMD_ATTR_TIMEOUT_UDP,	/* UDP timeout */
323 	__IPVS_CMD_ATTR_MAX,
324 };
325 
326 #define IPVS_CMD_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
327 
328 /*
329  * Attributes used to describe a service
330  *
331  * Used inside nested attribute IPVS_CMD_ATTR_SERVICE
332  */
333 enum {
334 	IPVS_SVC_ATTR_UNSPEC = 0,
335 	IPVS_SVC_ATTR_AF,		/* address family */
336 	IPVS_SVC_ATTR_PROTOCOL,		/* virtual service protocol */
337 	IPVS_SVC_ATTR_ADDR,		/* virtual service address */
338 	IPVS_SVC_ATTR_PORT,		/* virtual service port */
339 	IPVS_SVC_ATTR_FWMARK,		/* firewall mark of service */
340 
341 	IPVS_SVC_ATTR_SCHED_NAME,	/* name of scheduler */
342 	IPVS_SVC_ATTR_FLAGS,		/* virtual service flags */
343 	IPVS_SVC_ATTR_TIMEOUT,		/* persistent timeout */
344 	IPVS_SVC_ATTR_NETMASK,		/* persistent netmask */
345 
346 	IPVS_SVC_ATTR_STATS,		/* nested attribute for service stats */
347 
348 	IPVS_SVC_ATTR_PE_NAME,		/* name of ct retriever */
349 
350 	__IPVS_SVC_ATTR_MAX,
351 };
352 
353 #define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
354 
355 /*
356  * Attributes used to describe a destination (real server)
357  *
358  * Used inside nested attribute IPVS_CMD_ATTR_DEST
359  */
360 enum {
361 	IPVS_DEST_ATTR_UNSPEC = 0,
362 	IPVS_DEST_ATTR_ADDR,		/* real server address */
363 	IPVS_DEST_ATTR_PORT,		/* real server port */
364 
365 	IPVS_DEST_ATTR_FWD_METHOD,	/* forwarding method */
366 	IPVS_DEST_ATTR_WEIGHT,		/* destination weight */
367 
368 	IPVS_DEST_ATTR_U_THRESH,	/* upper threshold */
369 	IPVS_DEST_ATTR_L_THRESH,	/* lower threshold */
370 
371 	IPVS_DEST_ATTR_ACTIVE_CONNS,	/* active connections */
372 	IPVS_DEST_ATTR_INACT_CONNS,	/* inactive connections */
373 	IPVS_DEST_ATTR_PERSIST_CONNS,	/* persistent connections */
374 
375 	IPVS_DEST_ATTR_STATS,		/* nested attribute for dest stats */
376 	__IPVS_DEST_ATTR_MAX,
377 };
378 
379 #define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)
380 
381 /*
382  * Attributes describing a sync daemon
383  *
384  * Used inside nested attribute IPVS_CMD_ATTR_DAEMON
385  */
386 enum {
387 	IPVS_DAEMON_ATTR_UNSPEC = 0,
388 	IPVS_DAEMON_ATTR_STATE,		/* sync daemon state (master/backup) */
389 	IPVS_DAEMON_ATTR_MCAST_IFN,	/* multicast interface name */
390 	IPVS_DAEMON_ATTR_SYNC_ID,	/* SyncID we belong to */
391 	__IPVS_DAEMON_ATTR_MAX,
392 };
393 
394 #define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)
395 
396 /*
397  * Attributes used to describe service or destination entry statistics
398  *
399  * Used inside nested attributes IPVS_SVC_ATTR_STATS and IPVS_DEST_ATTR_STATS
400  */
401 enum {
402 	IPVS_STATS_ATTR_UNSPEC = 0,
403 	IPVS_STATS_ATTR_CONNS,		/* connections scheduled */
404 	IPVS_STATS_ATTR_INPKTS,		/* incoming packets */
405 	IPVS_STATS_ATTR_OUTPKTS,	/* outgoing packets */
406 	IPVS_STATS_ATTR_INBYTES,	/* incoming bytes */
407 	IPVS_STATS_ATTR_OUTBYTES,	/* outgoing bytes */
408 
409 	IPVS_STATS_ATTR_CPS,		/* current connection rate */
410 	IPVS_STATS_ATTR_INPPS,		/* current in packet rate */
411 	IPVS_STATS_ATTR_OUTPPS,		/* current out packet rate */
412 	IPVS_STATS_ATTR_INBPS,		/* current in byte rate */
413 	IPVS_STATS_ATTR_OUTBPS,		/* current out byte rate */
414 	__IPVS_STATS_ATTR_MAX,
415 };
416 
417 #define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)
418 
419 /* Attributes used in response to IPVS_CMD_GET_INFO command */
420 enum {
421 	IPVS_INFO_ATTR_UNSPEC = 0,
422 	IPVS_INFO_ATTR_VERSION,		/* IPVS version number */
423 	IPVS_INFO_ATTR_CONN_TAB_SIZE,	/* size of connection hash table */
424 	__IPVS_INFO_ATTR_MAX,
425 };
426 
427 #define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
428 
429 #endif	/* _IP_VS_H */
430