blob: 9708de265bb1e24f1b6130c2f0ca3ace1b249dfc [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
73 */
74#define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */
75#define IP_VS_CONN_F_MASQ 0x0000 /* masquerading/NAT */
76#define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */
77#define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */
78#define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */
79#define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */
80#define IP_VS_CONN_F_SYNC 0x0020 /* entry created by sync */
81#define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */
82#define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */
83#define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */
84#define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */
85#define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */
86#define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */
87#define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
88#define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */
Nick Chalk26ec0372010-06-22 08:07:01 +020089#define IP_VS_CONN_F_ONE_PACKET 0x2000 /* forward only one packet */
Julius Volzbc4768e2008-07-31 20:45:24 -070090
91#define IP_VS_SCHEDNAME_MAXLEN 16
92#define IP_VS_IFNAME_MAXLEN 16
93
94
95/*
96 * The struct ip_vs_service_user and struct ip_vs_dest_user are
97 * used to set IPVS rules through setsockopt.
98 */
99struct ip_vs_service_user {
100 /* virtual service addresses */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100101 __u16 protocol;
Julius Volzbc4768e2008-07-31 20:45:24 -0700102 __be32 addr; /* virtual ip address */
103 __be16 port;
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100104 __u32 fwmark; /* firwall mark of service */
Julius Volzbc4768e2008-07-31 20:45:24 -0700105
106 /* virtual service options */
107 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
108 unsigned flags; /* virtual service flags */
109 unsigned timeout; /* persistent timeout in sec */
110 __be32 netmask; /* persistent netmask */
111};
112
113
114struct ip_vs_dest_user {
115 /* destination server address */
116 __be32 addr;
117 __be16 port;
118
119 /* real server options */
120 unsigned conn_flags; /* connection flags */
121 int weight; /* destination weight */
122
123 /* thresholds for active connections */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100124 __u32 u_threshold; /* upper threshold */
125 __u32 l_threshold; /* lower threshold */
Julius Volzbc4768e2008-07-31 20:45:24 -0700126};
127
128
129/*
130 * IPVS statistics object (for user space)
131 */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800132struct ip_vs_stats_user {
Julius Volzbc4768e2008-07-31 20:45:24 -0700133 __u32 conns; /* connections scheduled */
134 __u32 inpkts; /* incoming packets */
135 __u32 outpkts; /* outgoing packets */
136 __u64 inbytes; /* incoming bytes */
137 __u64 outbytes; /* outgoing bytes */
138
139 __u32 cps; /* current connection rate */
140 __u32 inpps; /* current in packet rate */
141 __u32 outpps; /* current out packet rate */
142 __u32 inbps; /* current in byte rate */
143 __u32 outbps; /* current out byte rate */
144};
145
146
147/* The argument to IP_VS_SO_GET_INFO */
148struct ip_vs_getinfo {
149 /* version number */
150 unsigned int version;
151
152 /* size of connection hash table */
153 unsigned int size;
154
155 /* number of virtual services */
156 unsigned int num_services;
157};
158
159
160/* The argument to IP_VS_SO_GET_SERVICE */
161struct ip_vs_service_entry {
162 /* which service: user fills in these */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100163 __u16 protocol;
Julius Volzbc4768e2008-07-31 20:45:24 -0700164 __be32 addr; /* virtual address */
165 __be16 port;
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100166 __u32 fwmark; /* firwall mark of service */
Julius Volzbc4768e2008-07-31 20:45:24 -0700167
168 /* service options */
169 char sched_name[IP_VS_SCHEDNAME_MAXLEN];
170 unsigned flags; /* virtual service flags */
171 unsigned timeout; /* persistent timeout */
172 __be32 netmask; /* persistent netmask */
173
174 /* number of real servers */
175 unsigned int num_dests;
176
177 /* statistics */
178 struct ip_vs_stats_user stats;
179};
180
181
182struct ip_vs_dest_entry {
183 __be32 addr; /* destination address */
184 __be16 port;
185 unsigned conn_flags; /* connection flags */
186 int weight; /* destination weight */
187
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100188 __u32 u_threshold; /* upper threshold */
189 __u32 l_threshold; /* lower threshold */
Julius Volzbc4768e2008-07-31 20:45:24 -0700190
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100191 __u32 activeconns; /* active connections */
192 __u32 inactconns; /* inactive connections */
193 __u32 persistconns; /* persistent connections */
Julius Volzbc4768e2008-07-31 20:45:24 -0700194
195 /* statistics */
196 struct ip_vs_stats_user stats;
197};
198
199
200/* The argument to IP_VS_SO_GET_DESTS */
201struct ip_vs_get_dests {
202 /* which service: user fills in these */
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100203 __u16 protocol;
Julius Volzbc4768e2008-07-31 20:45:24 -0700204 __be32 addr; /* virtual address */
205 __be16 port;
Arnd Bergmann9adfbfb2009-02-26 00:51:40 +0100206 __u32 fwmark; /* firwall mark of service */
Julius Volzbc4768e2008-07-31 20:45:24 -0700207
208 /* number of real servers */
209 unsigned int num_dests;
210
211 /* the real servers */
212 struct ip_vs_dest_entry entrytable[0];
213};
214
215
216/* The argument to IP_VS_SO_GET_SERVICES */
217struct ip_vs_get_services {
218 /* number of virtual services */
219 unsigned int num_services;
220
221 /* service table */
222 struct ip_vs_service_entry entrytable[0];
223};
224
225
226/* The argument to IP_VS_SO_GET_TIMEOUT */
227struct ip_vs_timeout_user {
228 int tcp_timeout;
229 int tcp_fin_timeout;
230 int udp_timeout;
231};
232
233
234/* The argument to IP_VS_SO_GET_DAEMON */
235struct ip_vs_daemon_user {
236 /* sync daemon state (master/backup) */
237 int state;
238
239 /* multicast interface name */
240 char mcast_ifn[IP_VS_IFNAME_MAXLEN];
241
242 /* SyncID we belong to */
243 int syncid;
244};
245
Julius Volzc1bc6672008-08-07 16:43:38 +0200246/*
247 *
248 * IPVS Generic Netlink interface definitions
249 *
250 */
251
252/* Generic Netlink family info */
253
254#define IPVS_GENL_NAME "IPVS"
255#define IPVS_GENL_VERSION 0x1
256
257struct ip_vs_flags {
258 __be32 flags;
259 __be32 mask;
260};
261
262/* Generic Netlink command attributes */
263enum {
264 IPVS_CMD_UNSPEC = 0,
265
266 IPVS_CMD_NEW_SERVICE, /* add service */
267 IPVS_CMD_SET_SERVICE, /* modify service */
268 IPVS_CMD_DEL_SERVICE, /* delete service */
269 IPVS_CMD_GET_SERVICE, /* get service info */
270
271 IPVS_CMD_NEW_DEST, /* add destination */
272 IPVS_CMD_SET_DEST, /* modify destination */
273 IPVS_CMD_DEL_DEST, /* delete destination */
274 IPVS_CMD_GET_DEST, /* get destination info */
275
276 IPVS_CMD_NEW_DAEMON, /* start sync daemon */
277 IPVS_CMD_DEL_DAEMON, /* stop sync daemon */
278 IPVS_CMD_GET_DAEMON, /* get sync daemon status */
279
280 IPVS_CMD_SET_CONFIG, /* set config settings */
281 IPVS_CMD_GET_CONFIG, /* get config settings */
282
283 IPVS_CMD_SET_INFO, /* only used in GET_INFO reply */
284 IPVS_CMD_GET_INFO, /* get general IPVS info */
285
286 IPVS_CMD_ZERO, /* zero all counters and stats */
287 IPVS_CMD_FLUSH, /* flush services and dests */
288
289 __IPVS_CMD_MAX,
290};
291
292#define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1)
293
294/* Attributes used in the first level of commands */
295enum {
296 IPVS_CMD_ATTR_UNSPEC = 0,
297 IPVS_CMD_ATTR_SERVICE, /* nested service attribute */
298 IPVS_CMD_ATTR_DEST, /* nested destination attribute */
299 IPVS_CMD_ATTR_DAEMON, /* nested sync daemon attribute */
300 IPVS_CMD_ATTR_TIMEOUT_TCP, /* TCP connection timeout */
301 IPVS_CMD_ATTR_TIMEOUT_TCP_FIN, /* TCP FIN wait timeout */
302 IPVS_CMD_ATTR_TIMEOUT_UDP, /* UDP timeout */
303 __IPVS_CMD_ATTR_MAX,
304};
305
306#define IPVS_CMD_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
307
308/*
309 * Attributes used to describe a service
310 *
311 * Used inside nested attribute IPVS_CMD_ATTR_SERVICE
312 */
313enum {
314 IPVS_SVC_ATTR_UNSPEC = 0,
315 IPVS_SVC_ATTR_AF, /* address family */
316 IPVS_SVC_ATTR_PROTOCOL, /* virtual service protocol */
317 IPVS_SVC_ATTR_ADDR, /* virtual service address */
318 IPVS_SVC_ATTR_PORT, /* virtual service port */
319 IPVS_SVC_ATTR_FWMARK, /* firewall mark of service */
320
321 IPVS_SVC_ATTR_SCHED_NAME, /* name of scheduler */
322 IPVS_SVC_ATTR_FLAGS, /* virtual service flags */
323 IPVS_SVC_ATTR_TIMEOUT, /* persistent timeout */
324 IPVS_SVC_ATTR_NETMASK, /* persistent netmask */
325
326 IPVS_SVC_ATTR_STATS, /* nested attribute for service stats */
327 __IPVS_SVC_ATTR_MAX,
328};
329
330#define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1)
331
332/*
333 * Attributes used to describe a destination (real server)
334 *
335 * Used inside nested attribute IPVS_CMD_ATTR_DEST
336 */
337enum {
338 IPVS_DEST_ATTR_UNSPEC = 0,
339 IPVS_DEST_ATTR_ADDR, /* real server address */
340 IPVS_DEST_ATTR_PORT, /* real server port */
341
342 IPVS_DEST_ATTR_FWD_METHOD, /* forwarding method */
343 IPVS_DEST_ATTR_WEIGHT, /* destination weight */
344
345 IPVS_DEST_ATTR_U_THRESH, /* upper threshold */
346 IPVS_DEST_ATTR_L_THRESH, /* lower threshold */
347
348 IPVS_DEST_ATTR_ACTIVE_CONNS, /* active connections */
349 IPVS_DEST_ATTR_INACT_CONNS, /* inactive connections */
350 IPVS_DEST_ATTR_PERSIST_CONNS, /* persistent connections */
351
352 IPVS_DEST_ATTR_STATS, /* nested attribute for dest stats */
353 __IPVS_DEST_ATTR_MAX,
354};
355
356#define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1)
357
358/*
359 * Attributes describing a sync daemon
360 *
361 * Used inside nested attribute IPVS_CMD_ATTR_DAEMON
362 */
363enum {
364 IPVS_DAEMON_ATTR_UNSPEC = 0,
365 IPVS_DAEMON_ATTR_STATE, /* sync daemon state (master/backup) */
366 IPVS_DAEMON_ATTR_MCAST_IFN, /* multicast interface name */
367 IPVS_DAEMON_ATTR_SYNC_ID, /* SyncID we belong to */
368 __IPVS_DAEMON_ATTR_MAX,
369};
370
371#define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1)
372
373/*
374 * Attributes used to describe service or destination entry statistics
375 *
376 * Used inside nested attributes IPVS_SVC_ATTR_STATS and IPVS_DEST_ATTR_STATS
377 */
378enum {
379 IPVS_STATS_ATTR_UNSPEC = 0,
380 IPVS_STATS_ATTR_CONNS, /* connections scheduled */
381 IPVS_STATS_ATTR_INPKTS, /* incoming packets */
382 IPVS_STATS_ATTR_OUTPKTS, /* outgoing packets */
383 IPVS_STATS_ATTR_INBYTES, /* incoming bytes */
384 IPVS_STATS_ATTR_OUTBYTES, /* outgoing bytes */
385
386 IPVS_STATS_ATTR_CPS, /* current connection rate */
387 IPVS_STATS_ATTR_INPPS, /* current in packet rate */
388 IPVS_STATS_ATTR_OUTPPS, /* current out packet rate */
389 IPVS_STATS_ATTR_INBPS, /* current in byte rate */
390 IPVS_STATS_ATTR_OUTBPS, /* current out byte rate */
391 __IPVS_STATS_ATTR_MAX,
392};
393
394#define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1)
395
396/* Attributes used in response to IPVS_CMD_GET_INFO command */
397enum {
398 IPVS_INFO_ATTR_UNSPEC = 0,
399 IPVS_INFO_ATTR_VERSION, /* IPVS version number */
400 IPVS_INFO_ATTR_CONN_TAB_SIZE, /* size of connection hash table */
401 __IPVS_INFO_ATTR_MAX,
402};
403
404#define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1)
405
Julius Volzbc4768e2008-07-31 20:45:24 -0700406#endif /* _IP_VS_H */