1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
4 * data structure and functionality definitions
10 #include <linux/types.h> /* For __beXX types in userland */
12 #define IP_VS_VERSION_CODE 0x010201
13 #define NVERSION(version) \
14 (version >> 16) & 0xFF, \
15 (version >> 8) & 0xFF, \
19 * Virtual Service Flags
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 */
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 */
32 * Destination Server Flags
34 #define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */
35 #define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */
38 * IPVS sync daemon states
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 */
47 #define IP_VS_BASE_CTL (64+1024+64) /* base */
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
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
79 * IPVS Connection Flags
80 * Only flags 0..15 are sent to backup server
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 */
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 \
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)
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 */
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 | \
121 #define IP_VS_SCHEDNAME_MAXLEN 16
122 #define IP_VS_PENAME_MAXLEN 16
123 #define IP_VS_IFNAME_MAXLEN 16
125 #define IP_VS_PEDATA_MAXLEN 255
128 * The struct ip_vs_service_user and struct ip_vs_dest_user are
129 * used to set IPVS rules through setsockopt.
131 struct ip_vs_service_user
{
132 /* virtual service addresses */
134 __be32 addr
; /* virtual ip address */
136 __u32 fwmark
; /* firwall mark of service */
138 /* virtual service options */
139 char sched_name
[IP_VS_SCHEDNAME_MAXLEN
];
140 unsigned int flags
; /* virtual service flags */
141 unsigned int timeout
; /* persistent timeout in sec */
142 __be32 netmask
; /* persistent netmask */
146 struct ip_vs_dest_user
{
147 /* destination server address */
151 /* real server options */
152 unsigned int conn_flags
; /* connection flags */
153 int weight
; /* destination weight */
155 /* thresholds for active connections */
156 __u32 u_threshold
; /* upper threshold */
157 __u32 l_threshold
; /* lower threshold */
162 * IPVS statistics object (for user space)
164 struct ip_vs_stats_user
{
165 __u32 conns
; /* connections scheduled */
166 __u32 inpkts
; /* incoming packets */
167 __u32 outpkts
; /* outgoing packets */
168 __u64 inbytes
; /* incoming bytes */
169 __u64 outbytes
; /* outgoing bytes */
171 __u32 cps
; /* current connection rate */
172 __u32 inpps
; /* current in packet rate */
173 __u32 outpps
; /* current out packet rate */
174 __u32 inbps
; /* current in byte rate */
175 __u32 outbps
; /* current out byte rate */
179 /* The argument to IP_VS_SO_GET_INFO */
180 struct ip_vs_getinfo
{
182 unsigned int version
;
184 /* size of connection hash table */
187 /* number of virtual services */
188 unsigned int num_services
;
192 /* The argument to IP_VS_SO_GET_SERVICE */
193 struct ip_vs_service_entry
{
194 /* which service: user fills in these */
196 __be32 addr
; /* virtual address */
198 __u32 fwmark
; /* firwall mark of service */
200 /* service options */
201 char sched_name
[IP_VS_SCHEDNAME_MAXLEN
];
202 unsigned int flags
; /* virtual service flags */
203 unsigned int timeout
; /* persistent timeout */
204 __be32 netmask
; /* persistent netmask */
206 /* number of real servers */
207 unsigned int num_dests
;
210 struct ip_vs_stats_user stats
;
214 struct ip_vs_dest_entry
{
215 __be32 addr
; /* destination address */
217 unsigned int conn_flags
; /* connection flags */
218 int weight
; /* destination weight */
220 __u32 u_threshold
; /* upper threshold */
221 __u32 l_threshold
; /* lower threshold */
223 __u32 activeconns
; /* active connections */
224 __u32 inactconns
; /* inactive connections */
225 __u32 persistconns
; /* persistent connections */
228 struct ip_vs_stats_user stats
;
232 /* The argument to IP_VS_SO_GET_DESTS */
233 struct ip_vs_get_dests
{
234 /* which service: user fills in these */
236 __be32 addr
; /* virtual address */
238 __u32 fwmark
; /* firwall mark of service */
240 /* number of real servers */
241 unsigned int num_dests
;
243 /* the real servers */
244 struct ip_vs_dest_entry entrytable
[0];
248 /* The argument to IP_VS_SO_GET_SERVICES */
249 struct ip_vs_get_services
{
250 /* number of virtual services */
251 unsigned int num_services
;
254 struct ip_vs_service_entry entrytable
[0];
258 /* The argument to IP_VS_SO_GET_TIMEOUT */
259 struct ip_vs_timeout_user
{
266 /* The argument to IP_VS_SO_GET_DAEMON */
267 struct ip_vs_daemon_user
{
268 /* sync daemon state (master/backup) */
271 /* multicast interface name */
272 char mcast_ifn
[IP_VS_IFNAME_MAXLEN
];
274 /* SyncID we belong to */
280 * IPVS Generic Netlink interface definitions
284 /* Generic Netlink family info */
286 #define IPVS_GENL_NAME "IPVS"
287 #define IPVS_GENL_VERSION 0x1
294 /* Generic Netlink command attributes */
298 IPVS_CMD_NEW_SERVICE
, /* add service */
299 IPVS_CMD_SET_SERVICE
, /* modify service */
300 IPVS_CMD_DEL_SERVICE
, /* delete service */
301 IPVS_CMD_GET_SERVICE
, /* get service info */
303 IPVS_CMD_NEW_DEST
, /* add destination */
304 IPVS_CMD_SET_DEST
, /* modify destination */
305 IPVS_CMD_DEL_DEST
, /* delete destination */
306 IPVS_CMD_GET_DEST
, /* get destination info */
308 IPVS_CMD_NEW_DAEMON
, /* start sync daemon */
309 IPVS_CMD_DEL_DAEMON
, /* stop sync daemon */
310 IPVS_CMD_GET_DAEMON
, /* get sync daemon status */
312 IPVS_CMD_SET_CONFIG
, /* set config settings */
313 IPVS_CMD_GET_CONFIG
, /* get config settings */
315 IPVS_CMD_SET_INFO
, /* only used in GET_INFO reply */
316 IPVS_CMD_GET_INFO
, /* get general IPVS info */
318 IPVS_CMD_ZERO
, /* zero all counters and stats */
319 IPVS_CMD_FLUSH
, /* flush services and dests */
324 #define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)
326 /* Attributes used in the first level of commands */
328 IPVS_CMD_ATTR_UNSPEC
= 0,
329 IPVS_CMD_ATTR_SERVICE
, /* nested service attribute */
330 IPVS_CMD_ATTR_DEST
, /* nested destination attribute */
331 IPVS_CMD_ATTR_DAEMON
, /* nested sync daemon attribute */
332 IPVS_CMD_ATTR_TIMEOUT_TCP
, /* TCP connection timeout */
333 IPVS_CMD_ATTR_TIMEOUT_TCP_FIN
, /* TCP FIN wait timeout */
334 IPVS_CMD_ATTR_TIMEOUT_UDP
, /* UDP timeout */
338 #define IPVS_CMD_ATTR_MAX (__IPVS_CMD_ATTR_MAX - 1)
341 * Attributes used to describe a service
343 * Used inside nested attribute IPVS_CMD_ATTR_SERVICE
346 IPVS_SVC_ATTR_UNSPEC
= 0,
347 IPVS_SVC_ATTR_AF
, /* address family */
348 IPVS_SVC_ATTR_PROTOCOL
, /* virtual service protocol */
349 IPVS_SVC_ATTR_ADDR
, /* virtual service address */
350 IPVS_SVC_ATTR_PORT
, /* virtual service port */
351 IPVS_SVC_ATTR_FWMARK
, /* firewall mark of service */
353 IPVS_SVC_ATTR_SCHED_NAME
, /* name of scheduler */
354 IPVS_SVC_ATTR_FLAGS
, /* virtual service flags */
355 IPVS_SVC_ATTR_TIMEOUT
, /* persistent timeout */
356 IPVS_SVC_ATTR_NETMASK
, /* persistent netmask */
358 IPVS_SVC_ATTR_STATS
, /* nested attribute for service stats */
360 IPVS_SVC_ATTR_PE_NAME
, /* name of ct retriever */
362 IPVS_SVC_ATTR_STATS64
, /* nested attribute for service stats */
367 #define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
370 * Attributes used to describe a destination (real server)
372 * Used inside nested attribute IPVS_CMD_ATTR_DEST
375 IPVS_DEST_ATTR_UNSPEC
= 0,
376 IPVS_DEST_ATTR_ADDR
, /* real server address */
377 IPVS_DEST_ATTR_PORT
, /* real server port */
379 IPVS_DEST_ATTR_FWD_METHOD
, /* forwarding method */
380 IPVS_DEST_ATTR_WEIGHT
, /* destination weight */
382 IPVS_DEST_ATTR_U_THRESH
, /* upper threshold */
383 IPVS_DEST_ATTR_L_THRESH
, /* lower threshold */
385 IPVS_DEST_ATTR_ACTIVE_CONNS
, /* active connections */
386 IPVS_DEST_ATTR_INACT_CONNS
, /* inactive connections */
387 IPVS_DEST_ATTR_PERSIST_CONNS
, /* persistent connections */
389 IPVS_DEST_ATTR_STATS
, /* nested attribute for dest stats */
391 IPVS_DEST_ATTR_ADDR_FAMILY
, /* Address family of address */
393 IPVS_DEST_ATTR_STATS64
, /* nested attribute for dest stats */
395 __IPVS_DEST_ATTR_MAX
,
398 #define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)
401 * Attributes describing a sync daemon
403 * Used inside nested attribute IPVS_CMD_ATTR_DAEMON
406 IPVS_DAEMON_ATTR_UNSPEC
= 0,
407 IPVS_DAEMON_ATTR_STATE
, /* sync daemon state (master/backup) */
408 IPVS_DAEMON_ATTR_MCAST_IFN
, /* multicast interface name */
409 IPVS_DAEMON_ATTR_SYNC_ID
, /* SyncID we belong to */
410 IPVS_DAEMON_ATTR_SYNC_MAXLEN
, /* UDP Payload Size */
411 IPVS_DAEMON_ATTR_MCAST_GROUP
, /* IPv4 Multicast Address */
412 IPVS_DAEMON_ATTR_MCAST_GROUP6
, /* IPv6 Multicast Address */
413 IPVS_DAEMON_ATTR_MCAST_PORT
, /* Multicast Port (base) */
414 IPVS_DAEMON_ATTR_MCAST_TTL
, /* Multicast TTL */
415 __IPVS_DAEMON_ATTR_MAX
,
418 #define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)
421 * Attributes used to describe service or destination entry statistics
423 * Used inside nested attributes IPVS_SVC_ATTR_STATS, IPVS_DEST_ATTR_STATS,
424 * IPVS_SVC_ATTR_STATS64 and IPVS_DEST_ATTR_STATS64.
427 IPVS_STATS_ATTR_UNSPEC
= 0,
428 IPVS_STATS_ATTR_CONNS
, /* connections scheduled */
429 IPVS_STATS_ATTR_INPKTS
, /* incoming packets */
430 IPVS_STATS_ATTR_OUTPKTS
, /* outgoing packets */
431 IPVS_STATS_ATTR_INBYTES
, /* incoming bytes */
432 IPVS_STATS_ATTR_OUTBYTES
, /* outgoing bytes */
434 IPVS_STATS_ATTR_CPS
, /* current connection rate */
435 IPVS_STATS_ATTR_INPPS
, /* current in packet rate */
436 IPVS_STATS_ATTR_OUTPPS
, /* current out packet rate */
437 IPVS_STATS_ATTR_INBPS
, /* current in byte rate */
438 IPVS_STATS_ATTR_OUTBPS
, /* current out byte rate */
440 __IPVS_STATS_ATTR_MAX
,
443 #define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)
445 /* Attributes used in response to IPVS_CMD_GET_INFO command */
447 IPVS_INFO_ATTR_UNSPEC
= 0,
448 IPVS_INFO_ATTR_VERSION
, /* IPVS version number */
449 IPVS_INFO_ATTR_CONN_TAB_SIZE
, /* size of connection hash table */
450 __IPVS_INFO_ATTR_MAX
,
453 #define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
455 #endif /* _IP_VS_H */