blob: 8a2d438dc4999bfbb35b52a60325affdae7d9347 [file] [log] [blame]
Julius Volzbc4768e2008-07-31 20:45:24 -07001/*
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 */
Nick Chalk26ec0372010-06-22 08:07:01 +020022#define IP_VS_SVC_F_ONEPACKET 0x0004 /* one-packet scheduling */
Julius Volzbc4768e2008-07-31 20:45:24 -070023
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
Julian Anastasov35757922010-09-17 14:18:16 +020073 * Only flags 0..15 are sent to backup server
Julius Volzbc4768e2008-07-31 20:45:24 -070074 */
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 */
Nick Chalk26ec0372010-06-22 08:07:01 +020090#define IP_VS_CONN_F_ONE_PACKET 0x2000 /* forward only one packet */
Julius Volzbc4768e2008-07-31 20:45:24 -070091
Julian Anastasovcdcc5e92012-04-24 23:46:38 +030092/* Initial bits allowed in backup server */
Hans Schillstromfe5e7a12010-11-19 14:25:12 +010093#define IP_VS_CONN_F_BACKUP_MASK (IP_VS_CONN_F_FWD_MASK | \
94 IP_VS_CONN_F_NOOUTPUT | \
95 IP_VS_CONN_F_INACTIVE | \
96 IP_VS_CONN_F_SEQ_MASK | \
97 IP_VS_CONN_F_NO_CPORT | \
98 IP_VS_CONN_F_TEMPLATE \
99 )
100
Julian Anastasovcdcc5e92012-04-24 23:46:38 +0300101/* Bits allowed to update in backup server */
102#define IP_VS_CONN_F_BACKUP_UPD_MASK (IP_VS_CONN_F_INACTIVE | \
103 IP_VS_CONN_F_SEQ_MASK)
104
Julian Anastasov35757922010-09-17 14:18:16 +0200105/* Flags that are not sent to backup server start from bit 16 */
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200106#define IP_VS_CONN_F_NFCT (1 << 16) /* use netfilter conntrack */
Julian Anastasov35757922010-09-17 14:18:16 +0200107
108/* Connection flags from destination that can be changed by user space */
109#define IP_VS_CONN_F_DEST_MASK (IP_VS_CONN_F_FWD_MASK | \
110 IP_VS_CONN_F_ONE_PACKET | \
Julian Anastasovf4bc17c2010-09-21 17:35:41 +0200111 IP_VS_CONN_F_NFCT | \
Julian Anastasov35757922010-09-17 14:18:16 +0200112 0)
113
Julius Volzbc4768e2008-07-31 20:45:24 -0700114#define IP_VS_SCHEDNAME_MAXLEN 16
Simon Horman85999282010-08-22 21:37:53 +0900115#define IP_VS_PENAME_MAXLEN 16
Julius Volzbc4768e2008-07-31 20:45:24 -0700116#define IP_VS_IFNAME_MAXLEN 16
117
Simon Horman85999282010-08-22 21:37:53 +0900118#define IP_VS_PEDATA_MAXLEN 255
Julius Volzbc4768e2008-07-31 20:45:24 -0700119
120/*
121 * The struct ip_vs_service_user and struct ip_vs_dest_user are
122 * used to set IPVS rules through setsockopt.
123 */
124struct ip_vs_service_user {
125 /* virtual service addresses */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100126 __u16 protocol;
Julius Volzbc4768e2008-07-31 20:45:24 -0700127 __be32 addr; /* virtual ip address */
128 __be16 port;
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100129 __u32 fwmark; /* firwall mark of service */
Julius Volzbc4768e2008-07-31 20:45:24 -0700130
131 /* virtual service options */
132 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
Eric Dumazet95c96172012-04-15 05:58:06 +0000133 unsigned int flags; /* virtual service flags */
134 unsigned int timeout; /* persistent timeout in sec */
Julius Volzbc4768e2008-07-31 20:45:24 -0700135 __be32 netmask; /* persistent netmask */
136};
137
138
139struct ip_vs_dest_user {
140 /* destination server address */
141 __be32 addr;
142 __be16 port;
143
144 /* real server options */
Eric Dumazet95c96172012-04-15 05:58:06 +0000145 unsigned int conn_flags; /* connection flags */
Julius Volzbc4768e2008-07-31 20:45:24 -0700146 int weight; /* destination weight */
147
148 /* thresholds for active connections */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100149 __u32 u_threshold; /* upper threshold */
150 __u32 l_threshold; /* lower threshold */
Julius Volzbc4768e2008-07-31 20:45:24 -0700151};
152
153
154/*
155 * IPVS statistics object (for user space)
156 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800157struct ip_vs_stats_user {
Julius Volzbc4768e2008-07-31 20:45:24 -0700158 __u32 conns; /* connections scheduled */
159 __u32 inpkts; /* incoming packets */
160 __u32 outpkts; /* outgoing packets */
161 __u64 inbytes; /* incoming bytes */
162 __u64 outbytes; /* outgoing bytes */
163
164 __u32 cps; /* current connection rate */
165 __u32 inpps; /* current in packet rate */
166 __u32 outpps; /* current out packet rate */
167 __u32 inbps; /* current in byte rate */
168 __u32 outbps; /* current out byte rate */
169};
170
171
172/* The argument to IP_VS_SO_GET_INFO */
173struct ip_vs_getinfo {
174 /* version number */
175 unsigned int version;
176
177 /* size of connection hash table */
178 unsigned int size;
179
180 /* number of virtual services */
181 unsigned int num_services;
182};
183
184
185/* The argument to IP_VS_SO_GET_SERVICE */
186struct ip_vs_service_entry {
187 /* which service: user fills in these */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100188 __u16 protocol;
Julius Volzbc4768e2008-07-31 20:45:24 -0700189 __be32 addr; /* virtual address */
190 __be16 port;
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100191 __u32 fwmark; /* firwall mark of service */
Julius Volzbc4768e2008-07-31 20:45:24 -0700192
193 /* service options */
194 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
Eric Dumazet95c96172012-04-15 05:58:06 +0000195 unsigned int flags; /* virtual service flags */
196 unsigned int timeout; /* persistent timeout */
Julius Volzbc4768e2008-07-31 20:45:24 -0700197 __be32 netmask; /* persistent netmask */
198
199 /* number of real servers */
200 unsigned int num_dests;
201
202 /* statistics */
203 struct ip_vs_stats_user stats;
204};
205
206
207struct ip_vs_dest_entry {
208 __be32 addr; /* destination address */
209 __be16 port;
Eric Dumazet95c96172012-04-15 05:58:06 +0000210 unsigned int conn_flags; /* connection flags */
Julius Volzbc4768e2008-07-31 20:45:24 -0700211 int weight; /* destination weight */
212
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100213 __u32 u_threshold; /* upper threshold */
214 __u32 l_threshold; /* lower threshold */
Julius Volzbc4768e2008-07-31 20:45:24 -0700215
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100216 __u32 activeconns; /* active connections */
217 __u32 inactconns; /* inactive connections */
218 __u32 persistconns; /* persistent connections */
Julius Volzbc4768e2008-07-31 20:45:24 -0700219
220 /* statistics */
221 struct ip_vs_stats_user stats;
222};
223
224
225/* The argument to IP_VS_SO_GET_DESTS */
226struct ip_vs_get_dests {
227 /* which service: user fills in these */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100228 __u16 protocol;
Julius Volzbc4768e2008-07-31 20:45:24 -0700229 __be32 addr; /* virtual address */
230 __be16 port;
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100231 __u32 fwmark; /* firwall mark of service */
Julius Volzbc4768e2008-07-31 20:45:24 -0700232
233 /* number of real servers */
234 unsigned int num_dests;
235
236 /* the real servers */
237 struct ip_vs_dest_entry entrytable[0];
238};
239
240
241/* The argument to IP_VS_SO_GET_SERVICES */
242struct ip_vs_get_services {
243 /* number of virtual services */
244 unsigned int num_services;
245
246 /* service table */
247 struct ip_vs_service_entry entrytable[0];
248};
249
250
251/* The argument to IP_VS_SO_GET_TIMEOUT */
252struct ip_vs_timeout_user {
253 int tcp_timeout;
254 int tcp_fin_timeout;
255 int udp_timeout;
256};
257
258
259/* The argument to IP_VS_SO_GET_DAEMON */
260struct ip_vs_daemon_user {
261 /* sync daemon state (master/backup) */
262 int state;
263
264 /* multicast interface name */
265 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
266
267 /* SyncID we belong to */
268 int syncid;
269};
270
Julius Volzc1bc6672008-08-07 16:43:38 +0200271/*
272 *
273 * IPVS Generic Netlink interface definitions
274 *
275 */
276
277/* Generic Netlink family info */
278
279#define IPVS_GENL_NAME "IPVS"
280#define IPVS_GENL_VERSION 0x1
281
282struct ip_vs_flags {
283 __be32 flags;
284 __be32 mask;
285};
286
287/* Generic Netlink command attributes */
288enum {
289 IPVS_CMD_UNSPEC = 0,
290
291 IPVS_CMD_NEW_SERVICE, /* add service */
292 IPVS_CMD_SET_SERVICE, /* modify service */
293 IPVS_CMD_DEL_SERVICE, /* delete service */
294 IPVS_CMD_GET_SERVICE, /* get service info */
295
296 IPVS_CMD_NEW_DEST, /* add destination */
297 IPVS_CMD_SET_DEST, /* modify destination */
298 IPVS_CMD_DEL_DEST, /* delete destination */
299 IPVS_CMD_GET_DEST, /* get destination info */
300
301 IPVS_CMD_NEW_DAEMON, /* start sync daemon */
302 IPVS_CMD_DEL_DAEMON, /* stop sync daemon */
303 IPVS_CMD_GET_DAEMON, /* get sync daemon status */
304
305 IPVS_CMD_SET_CONFIG, /* set config settings */
306 IPVS_CMD_GET_CONFIG, /* get config settings */
307
308 IPVS_CMD_SET_INFO, /* only used in GET_INFO reply */
309 IPVS_CMD_GET_INFO, /* get general IPVS info */
310
311 IPVS_CMD_ZERO, /* zero all counters and stats */
312 IPVS_CMD_FLUSH, /* flush services and dests */
313
314 __IPVS_CMD_MAX,
315};
316
317#define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)
318
319/* Attributes used in the first level of commands */
320enum {
321 IPVS_CMD_ATTR_UNSPEC = 0,
322 IPVS_CMD_ATTR_SERVICE, /* nested service attribute */
323 IPVS_CMD_ATTR_DEST, /* nested destination attribute */
324 IPVS_CMD_ATTR_DAEMON, /* nested sync daemon attribute */
325 IPVS_CMD_ATTR_TIMEOUT_TCP, /* TCP connection timeout */
326 IPVS_CMD_ATTR_TIMEOUT_TCP_FIN, /* TCP FIN wait timeout */
327 IPVS_CMD_ATTR_TIMEOUT_UDP, /* UDP timeout */
328 __IPVS_CMD_ATTR_MAX,
329};
330
331#define IPVS_CMD_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
332
333/*
334 * Attributes used to describe a service
335 *
336 * Used inside nested attribute IPVS_CMD_ATTR_SERVICE
337 */
338enum {
339 IPVS_SVC_ATTR_UNSPEC = 0,
340 IPVS_SVC_ATTR_AF, /* address family */
341 IPVS_SVC_ATTR_PROTOCOL, /* virtual service protocol */
342 IPVS_SVC_ATTR_ADDR, /* virtual service address */
343 IPVS_SVC_ATTR_PORT, /* virtual service port */
344 IPVS_SVC_ATTR_FWMARK, /* firewall mark of service */
345
346 IPVS_SVC_ATTR_SCHED_NAME, /* name of scheduler */
347 IPVS_SVC_ATTR_FLAGS, /* virtual service flags */
348 IPVS_SVC_ATTR_TIMEOUT, /* persistent timeout */
349 IPVS_SVC_ATTR_NETMASK, /* persistent netmask */
350
351 IPVS_SVC_ATTR_STATS, /* nested attribute for service stats */
Simon Horman0d1e71b2010-08-22 21:37:54 +0900352
353 IPVS_SVC_ATTR_PE_NAME, /* name of ct retriever */
354
Julius Volzc1bc6672008-08-07 16:43:38 +0200355 __IPVS_SVC_ATTR_MAX,
356};
357
358#define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
359
360/*
361 * Attributes used to describe a destination (real server)
362 *
363 * Used inside nested attribute IPVS_CMD_ATTR_DEST
364 */
365enum {
366 IPVS_DEST_ATTR_UNSPEC = 0,
367 IPVS_DEST_ATTR_ADDR, /* real server address */
368 IPVS_DEST_ATTR_PORT, /* real server port */
369
370 IPVS_DEST_ATTR_FWD_METHOD, /* forwarding method */
371 IPVS_DEST_ATTR_WEIGHT, /* destination weight */
372
373 IPVS_DEST_ATTR_U_THRESH, /* upper threshold */
374 IPVS_DEST_ATTR_L_THRESH, /* lower threshold */
375
376 IPVS_DEST_ATTR_ACTIVE_CONNS, /* active connections */
377 IPVS_DEST_ATTR_INACT_CONNS, /* inactive connections */
378 IPVS_DEST_ATTR_PERSIST_CONNS, /* persistent connections */
379
380 IPVS_DEST_ATTR_STATS, /* nested attribute for dest stats */
381 __IPVS_DEST_ATTR_MAX,
382};
383
384#define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)
385
386/*
387 * Attributes describing a sync daemon
388 *
389 * Used inside nested attribute IPVS_CMD_ATTR_DAEMON
390 */
391enum {
392 IPVS_DAEMON_ATTR_UNSPEC = 0,
393 IPVS_DAEMON_ATTR_STATE, /* sync daemon state (master/backup) */
394 IPVS_DAEMON_ATTR_MCAST_IFN, /* multicast interface name */
395 IPVS_DAEMON_ATTR_SYNC_ID, /* SyncID we belong to */
396 __IPVS_DAEMON_ATTR_MAX,
397};
398
399#define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)
400
401/*
402 * Attributes used to describe service or destination entry statistics
403 *
404 * Used inside nested attributes IPVS_SVC_ATTR_STATS and IPVS_DEST_ATTR_STATS
405 */
406enum {
407 IPVS_STATS_ATTR_UNSPEC = 0,
408 IPVS_STATS_ATTR_CONNS, /* connections scheduled */
409 IPVS_STATS_ATTR_INPKTS, /* incoming packets */
410 IPVS_STATS_ATTR_OUTPKTS, /* outgoing packets */
411 IPVS_STATS_ATTR_INBYTES, /* incoming bytes */
412 IPVS_STATS_ATTR_OUTBYTES, /* outgoing bytes */
413
414 IPVS_STATS_ATTR_CPS, /* current connection rate */
415 IPVS_STATS_ATTR_INPPS, /* current in packet rate */
416 IPVS_STATS_ATTR_OUTPPS, /* current out packet rate */
417 IPVS_STATS_ATTR_INBPS, /* current in byte rate */
418 IPVS_STATS_ATTR_OUTBPS, /* current out byte rate */
419 __IPVS_STATS_ATTR_MAX,
420};
421
422#define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)
423
424/* Attributes used in response to IPVS_CMD_GET_INFO command */
425enum {
426 IPVS_INFO_ATTR_UNSPEC = 0,
427 IPVS_INFO_ATTR_VERSION, /* IPVS version number */
428 IPVS_INFO_ATTR_CONN_TAB_SIZE, /* size of connection hash table */
429 __IPVS_INFO_ATTR_MAX,
430};
431
432#define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
433
Julius Volzbc4768e2008-07-31 20:45:24 -0700434#endif /* _IP_VS_H */