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
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
,
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)
141 * The struct ip_vs_service_user and struct ip_vs_dest_user are
142 * used to set IPVS rules through setsockopt.
144 struct ip_vs_service_user
{
145 /* virtual service addresses */
147 __be32 addr
; /* virtual ip address */
149 __u32 fwmark
; /* firwall mark of service */
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 */
159 struct ip_vs_dest_user
{
160 /* destination server address */
164 /* real server options */
165 unsigned int conn_flags
; /* connection flags */
166 int weight
; /* destination weight */
168 /* thresholds for active connections */
169 __u32 u_threshold
; /* upper threshold */
170 __u32 l_threshold
; /* lower threshold */
175 * IPVS statistics object (for user space)
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 */
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 */
192 /* The argument to IP_VS_SO_GET_INFO */
193 struct ip_vs_getinfo
{
195 unsigned int version
;
197 /* size of connection hash table */
200 /* number of virtual services */
201 unsigned int num_services
;
205 /* The argument to IP_VS_SO_GET_SERVICE */
206 struct ip_vs_service_entry
{
207 /* which service: user fills in these */
209 __be32 addr
; /* virtual address */
211 __u32 fwmark
; /* firwall mark of service */
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 */
219 /* number of real servers */
220 unsigned int num_dests
;
223 struct ip_vs_stats_user stats
;
227 struct ip_vs_dest_entry
{
228 __be32 addr
; /* destination address */
230 unsigned int conn_flags
; /* connection flags */
231 int weight
; /* destination weight */
233 __u32 u_threshold
; /* upper threshold */
234 __u32 l_threshold
; /* lower threshold */
236 __u32 activeconns
; /* active connections */
237 __u32 inactconns
; /* inactive connections */
238 __u32 persistconns
; /* persistent connections */
241 struct ip_vs_stats_user stats
;
245 /* The argument to IP_VS_SO_GET_DESTS */
246 struct ip_vs_get_dests
{
247 /* which service: user fills in these */
249 __be32 addr
; /* virtual address */
251 __u32 fwmark
; /* firwall mark of service */
253 /* number of real servers */
254 unsigned int num_dests
;
256 /* the real servers */
257 struct ip_vs_dest_entry entrytable
[];
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
;
267 struct ip_vs_service_entry entrytable
[];
271 /* The argument to IP_VS_SO_GET_TIMEOUT */
272 struct ip_vs_timeout_user
{
279 /* The argument to IP_VS_SO_GET_DAEMON */
280 struct ip_vs_daemon_user
{
281 /* sync daemon state (master/backup) */
284 /* multicast interface name */
285 char mcast_ifn
[IP_VS_IFNAME_MAXLEN
];
287 /* SyncID we belong to */
293 * IPVS Generic Netlink interface definitions
297 /* Generic Netlink family info */
299 #define IPVS_GENL_NAME "IPVS"
300 #define IPVS_GENL_VERSION 0x1
307 /* Generic Netlink command attributes */
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 */
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 */
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 */
325 IPVS_CMD_SET_CONFIG
, /* set config settings */
326 IPVS_CMD_GET_CONFIG
, /* get config settings */
328 IPVS_CMD_SET_INFO
, /* only used in GET_INFO reply */
329 IPVS_CMD_GET_INFO
, /* get general IPVS info */
331 IPVS_CMD_ZERO
, /* zero all counters and stats */
332 IPVS_CMD_FLUSH
, /* flush services and dests */
337 #define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)
339 /* Attributes used in the first level of commands */
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 */
351 #define IPVS_CMD_ATTR_MAX (__IPVS_CMD_ATTR_MAX - 1)
354 * Attributes used to describe a service
356 * Used inside nested attribute IPVS_CMD_ATTR_SERVICE
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 */
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 */
371 IPVS_SVC_ATTR_STATS
, /* nested attribute for service stats */
373 IPVS_SVC_ATTR_PE_NAME
, /* name of ct retriever */
375 IPVS_SVC_ATTR_STATS64
, /* nested attribute for service stats */
380 #define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
383 * Attributes used to describe a destination (real server)
385 * Used inside nested attribute IPVS_CMD_ATTR_DEST
388 IPVS_DEST_ATTR_UNSPEC
= 0,
389 IPVS_DEST_ATTR_ADDR
, /* real server address */
390 IPVS_DEST_ATTR_PORT
, /* real server port */
392 IPVS_DEST_ATTR_FWD_METHOD
, /* forwarding method */
393 IPVS_DEST_ATTR_WEIGHT
, /* destination weight */
395 IPVS_DEST_ATTR_U_THRESH
, /* upper threshold */
396 IPVS_DEST_ATTR_L_THRESH
, /* lower threshold */
398 IPVS_DEST_ATTR_ACTIVE_CONNS
, /* active connections */
399 IPVS_DEST_ATTR_INACT_CONNS
, /* inactive connections */
400 IPVS_DEST_ATTR_PERSIST_CONNS
, /* persistent connections */
402 IPVS_DEST_ATTR_STATS
, /* nested attribute for dest stats */
404 IPVS_DEST_ATTR_ADDR_FAMILY
, /* Address family of address */
406 IPVS_DEST_ATTR_STATS64
, /* nested attribute for dest stats */
408 IPVS_DEST_ATTR_TUN_TYPE
, /* tunnel type */
410 IPVS_DEST_ATTR_TUN_PORT
, /* tunnel port */
412 IPVS_DEST_ATTR_TUN_FLAGS
, /* tunnel flags */
414 __IPVS_DEST_ATTR_MAX
,
417 #define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)
420 * Attributes describing a sync daemon
422 * Used inside nested attribute IPVS_CMD_ATTR_DAEMON
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
,
437 #define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)
440 * Attributes used to describe service or destination entry statistics
442 * Used inside nested attributes IPVS_SVC_ATTR_STATS, IPVS_DEST_ATTR_STATS,
443 * IPVS_SVC_ATTR_STATS64 and IPVS_DEST_ATTR_STATS64.
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 */
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 */
459 __IPVS_STATS_ATTR_MAX
,
462 #define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)
464 /* Attributes used in response to IPVS_CMD_GET_INFO command */
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
,
472 #define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
474 #endif /* _IP_VS_H */