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