Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 1 | /* |
| 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 */ |
| 22 | |
| 23 | /* |
| 24 | * Destination Server Flags |
| 25 | */ |
| 26 | #define IP_VS_DEST_F_AVAILABLE 0x0001 /* server is available */ |
| 27 | #define IP_VS_DEST_F_OVERLOAD 0x0002 /* server is overloaded */ |
| 28 | |
| 29 | /* |
| 30 | * IPVS sync daemon states |
| 31 | */ |
| 32 | #define IP_VS_STATE_NONE 0x0000 /* daemon is stopped */ |
| 33 | #define IP_VS_STATE_MASTER 0x0001 /* started as master */ |
| 34 | #define IP_VS_STATE_BACKUP 0x0002 /* started as backup */ |
| 35 | |
| 36 | /* |
| 37 | * IPVS socket options |
| 38 | */ |
| 39 | #define IP_VS_BASE_CTL (64+1024+64) /* base */ |
| 40 | |
| 41 | #define IP_VS_SO_SET_NONE IP_VS_BASE_CTL /* just peek */ |
| 42 | #define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1) |
| 43 | #define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2) |
| 44 | #define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3) |
| 45 | #define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4) |
| 46 | #define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5) |
| 47 | #define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6) |
| 48 | #define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7) |
| 49 | #define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8) |
| 50 | #define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9) |
| 51 | #define IP_VS_SO_SET_TIMEOUT (IP_VS_BASE_CTL+10) |
| 52 | #define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11) |
| 53 | #define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12) |
| 54 | #define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13) |
| 55 | #define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14) |
| 56 | #define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15) |
| 57 | #define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO |
| 58 | |
| 59 | #define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL |
| 60 | #define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1) |
| 61 | #define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2) |
| 62 | #define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3) |
| 63 | #define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4) |
| 64 | #define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5) /* not used now */ |
| 65 | #define IP_VS_SO_GET_TIMEOUT (IP_VS_BASE_CTL+6) |
| 66 | #define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7) |
| 67 | #define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * IPVS Connection Flags |
| 72 | */ |
| 73 | #define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */ |
| 74 | #define IP_VS_CONN_F_MASQ 0x0000 /* masquerading/NAT */ |
| 75 | #define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */ |
| 76 | #define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */ |
| 77 | #define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */ |
| 78 | #define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */ |
| 79 | #define IP_VS_CONN_F_SYNC 0x0020 /* entry created by sync */ |
| 80 | #define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */ |
| 81 | #define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */ |
| 82 | #define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */ |
| 83 | #define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */ |
| 84 | #define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */ |
| 85 | #define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */ |
| 86 | #define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */ |
| 87 | #define IP_VS_CONN_F_TEMPLATE 0x1000 /* template, not connection */ |
| 88 | |
| 89 | #define IP_VS_SCHEDNAME_MAXLEN 16 |
| 90 | #define IP_VS_IFNAME_MAXLEN 16 |
| 91 | |
| 92 | |
| 93 | /* |
| 94 | * The struct ip_vs_service_user and struct ip_vs_dest_user are |
| 95 | * used to set IPVS rules through setsockopt. |
| 96 | */ |
| 97 | struct ip_vs_service_user { |
| 98 | /* virtual service addresses */ |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 99 | __u16 protocol; |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 100 | __be32 addr; /* virtual ip address */ |
| 101 | __be16 port; |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 102 | __u32 fwmark; /* firwall mark of service */ |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 103 | |
| 104 | /* virtual service options */ |
| 105 | char sched_name[IP_VS_SCHEDNAME_MAXLEN]; |
| 106 | unsigned flags; /* virtual service flags */ |
| 107 | unsigned timeout; /* persistent timeout in sec */ |
| 108 | __be32 netmask; /* persistent netmask */ |
| 109 | }; |
| 110 | |
| 111 | |
| 112 | struct ip_vs_dest_user { |
| 113 | /* destination server address */ |
| 114 | __be32 addr; |
| 115 | __be16 port; |
| 116 | |
| 117 | /* real server options */ |
| 118 | unsigned conn_flags; /* connection flags */ |
| 119 | int weight; /* destination weight */ |
| 120 | |
| 121 | /* thresholds for active connections */ |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 122 | __u32 u_threshold; /* upper threshold */ |
| 123 | __u32 l_threshold; /* lower threshold */ |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | |
| 127 | /* |
| 128 | * IPVS statistics object (for user space) |
| 129 | */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 130 | struct ip_vs_stats_user { |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 131 | __u32 conns; /* connections scheduled */ |
| 132 | __u32 inpkts; /* incoming packets */ |
| 133 | __u32 outpkts; /* outgoing packets */ |
| 134 | __u64 inbytes; /* incoming bytes */ |
| 135 | __u64 outbytes; /* outgoing bytes */ |
| 136 | |
| 137 | __u32 cps; /* current connection rate */ |
| 138 | __u32 inpps; /* current in packet rate */ |
| 139 | __u32 outpps; /* current out packet rate */ |
| 140 | __u32 inbps; /* current in byte rate */ |
| 141 | __u32 outbps; /* current out byte rate */ |
| 142 | }; |
| 143 | |
| 144 | |
| 145 | /* The argument to IP_VS_SO_GET_INFO */ |
| 146 | struct ip_vs_getinfo { |
| 147 | /* version number */ |
| 148 | unsigned int version; |
| 149 | |
| 150 | /* size of connection hash table */ |
| 151 | unsigned int size; |
| 152 | |
| 153 | /* number of virtual services */ |
| 154 | unsigned int num_services; |
| 155 | }; |
| 156 | |
| 157 | |
| 158 | /* The argument to IP_VS_SO_GET_SERVICE */ |
| 159 | struct ip_vs_service_entry { |
| 160 | /* which service: user fills in these */ |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 161 | __u16 protocol; |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 162 | __be32 addr; /* virtual address */ |
| 163 | __be16 port; |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 164 | __u32 fwmark; /* firwall mark of service */ |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 165 | |
| 166 | /* service options */ |
| 167 | char sched_name[IP_VS_SCHEDNAME_MAXLEN]; |
| 168 | unsigned flags; /* virtual service flags */ |
| 169 | unsigned timeout; /* persistent timeout */ |
| 170 | __be32 netmask; /* persistent netmask */ |
| 171 | |
| 172 | /* number of real servers */ |
| 173 | unsigned int num_dests; |
| 174 | |
| 175 | /* statistics */ |
| 176 | struct ip_vs_stats_user stats; |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | struct ip_vs_dest_entry { |
| 181 | __be32 addr; /* destination address */ |
| 182 | __be16 port; |
| 183 | unsigned conn_flags; /* connection flags */ |
| 184 | int weight; /* destination weight */ |
| 185 | |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 186 | __u32 u_threshold; /* upper threshold */ |
| 187 | __u32 l_threshold; /* lower threshold */ |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 188 | |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 189 | __u32 activeconns; /* active connections */ |
| 190 | __u32 inactconns; /* inactive connections */ |
| 191 | __u32 persistconns; /* persistent connections */ |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 192 | |
| 193 | /* statistics */ |
| 194 | struct ip_vs_stats_user stats; |
| 195 | }; |
| 196 | |
| 197 | |
| 198 | /* The argument to IP_VS_SO_GET_DESTS */ |
| 199 | struct ip_vs_get_dests { |
| 200 | /* which service: user fills in these */ |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 201 | __u16 protocol; |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 202 | __be32 addr; /* virtual address */ |
| 203 | __be16 port; |
Arnd Bergmann | 9adfbfb | 2009-02-26 00:51:40 +0100 | [diff] [blame] | 204 | __u32 fwmark; /* firwall mark of service */ |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 205 | |
| 206 | /* number of real servers */ |
| 207 | unsigned int num_dests; |
| 208 | |
| 209 | /* the real servers */ |
| 210 | struct ip_vs_dest_entry entrytable[0]; |
| 211 | }; |
| 212 | |
| 213 | |
| 214 | /* The argument to IP_VS_SO_GET_SERVICES */ |
| 215 | struct ip_vs_get_services { |
| 216 | /* number of virtual services */ |
| 217 | unsigned int num_services; |
| 218 | |
| 219 | /* service table */ |
| 220 | struct ip_vs_service_entry entrytable[0]; |
| 221 | }; |
| 222 | |
| 223 | |
| 224 | /* The argument to IP_VS_SO_GET_TIMEOUT */ |
| 225 | struct ip_vs_timeout_user { |
| 226 | int tcp_timeout; |
| 227 | int tcp_fin_timeout; |
| 228 | int udp_timeout; |
| 229 | }; |
| 230 | |
| 231 | |
| 232 | /* The argument to IP_VS_SO_GET_DAEMON */ |
| 233 | struct ip_vs_daemon_user { |
| 234 | /* sync daemon state (master/backup) */ |
| 235 | int state; |
| 236 | |
| 237 | /* multicast interface name */ |
| 238 | char mcast_ifn[IP_VS_IFNAME_MAXLEN]; |
| 239 | |
| 240 | /* SyncID we belong to */ |
| 241 | int syncid; |
| 242 | }; |
| 243 | |
Julius Volz | c1bc667 | 2008-08-07 16:43:38 +0200 | [diff] [blame] | 244 | /* |
| 245 | * |
| 246 | * IPVS Generic Netlink interface definitions |
| 247 | * |
| 248 | */ |
| 249 | |
| 250 | /* Generic Netlink family info */ |
| 251 | |
| 252 | #define IPVS_GENL_NAME "IPVS" |
| 253 | #define IPVS_GENL_VERSION 0x1 |
| 254 | |
| 255 | struct ip_vs_flags { |
| 256 | __be32 flags; |
| 257 | __be32 mask; |
| 258 | }; |
| 259 | |
| 260 | /* Generic Netlink command attributes */ |
| 261 | enum { |
| 262 | IPVS_CMD_UNSPEC = 0, |
| 263 | |
| 264 | IPVS_CMD_NEW_SERVICE, /* add service */ |
| 265 | IPVS_CMD_SET_SERVICE, /* modify service */ |
| 266 | IPVS_CMD_DEL_SERVICE, /* delete service */ |
| 267 | IPVS_CMD_GET_SERVICE, /* get service info */ |
| 268 | |
| 269 | IPVS_CMD_NEW_DEST, /* add destination */ |
| 270 | IPVS_CMD_SET_DEST, /* modify destination */ |
| 271 | IPVS_CMD_DEL_DEST, /* delete destination */ |
| 272 | IPVS_CMD_GET_DEST, /* get destination info */ |
| 273 | |
| 274 | IPVS_CMD_NEW_DAEMON, /* start sync daemon */ |
| 275 | IPVS_CMD_DEL_DAEMON, /* stop sync daemon */ |
| 276 | IPVS_CMD_GET_DAEMON, /* get sync daemon status */ |
| 277 | |
| 278 | IPVS_CMD_SET_CONFIG, /* set config settings */ |
| 279 | IPVS_CMD_GET_CONFIG, /* get config settings */ |
| 280 | |
| 281 | IPVS_CMD_SET_INFO, /* only used in GET_INFO reply */ |
| 282 | IPVS_CMD_GET_INFO, /* get general IPVS info */ |
| 283 | |
| 284 | IPVS_CMD_ZERO, /* zero all counters and stats */ |
| 285 | IPVS_CMD_FLUSH, /* flush services and dests */ |
| 286 | |
| 287 | __IPVS_CMD_MAX, |
| 288 | }; |
| 289 | |
| 290 | #define IPVS_CMD_MAX (__IPVS_CMD_MAX - 1) |
| 291 | |
| 292 | /* Attributes used in the first level of commands */ |
| 293 | enum { |
| 294 | IPVS_CMD_ATTR_UNSPEC = 0, |
| 295 | IPVS_CMD_ATTR_SERVICE, /* nested service attribute */ |
| 296 | IPVS_CMD_ATTR_DEST, /* nested destination attribute */ |
| 297 | IPVS_CMD_ATTR_DAEMON, /* nested sync daemon attribute */ |
| 298 | IPVS_CMD_ATTR_TIMEOUT_TCP, /* TCP connection timeout */ |
| 299 | IPVS_CMD_ATTR_TIMEOUT_TCP_FIN, /* TCP FIN wait timeout */ |
| 300 | IPVS_CMD_ATTR_TIMEOUT_UDP, /* UDP timeout */ |
| 301 | __IPVS_CMD_ATTR_MAX, |
| 302 | }; |
| 303 | |
| 304 | #define IPVS_CMD_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1) |
| 305 | |
| 306 | /* |
| 307 | * Attributes used to describe a service |
| 308 | * |
| 309 | * Used inside nested attribute IPVS_CMD_ATTR_SERVICE |
| 310 | */ |
| 311 | enum { |
| 312 | IPVS_SVC_ATTR_UNSPEC = 0, |
| 313 | IPVS_SVC_ATTR_AF, /* address family */ |
| 314 | IPVS_SVC_ATTR_PROTOCOL, /* virtual service protocol */ |
| 315 | IPVS_SVC_ATTR_ADDR, /* virtual service address */ |
| 316 | IPVS_SVC_ATTR_PORT, /* virtual service port */ |
| 317 | IPVS_SVC_ATTR_FWMARK, /* firewall mark of service */ |
| 318 | |
| 319 | IPVS_SVC_ATTR_SCHED_NAME, /* name of scheduler */ |
| 320 | IPVS_SVC_ATTR_FLAGS, /* virtual service flags */ |
| 321 | IPVS_SVC_ATTR_TIMEOUT, /* persistent timeout */ |
| 322 | IPVS_SVC_ATTR_NETMASK, /* persistent netmask */ |
| 323 | |
| 324 | IPVS_SVC_ATTR_STATS, /* nested attribute for service stats */ |
| 325 | __IPVS_SVC_ATTR_MAX, |
| 326 | }; |
| 327 | |
| 328 | #define IPVS_SVC_ATTR_MAX (__IPVS_SVC_ATTR_MAX - 1) |
| 329 | |
| 330 | /* |
| 331 | * Attributes used to describe a destination (real server) |
| 332 | * |
| 333 | * Used inside nested attribute IPVS_CMD_ATTR_DEST |
| 334 | */ |
| 335 | enum { |
| 336 | IPVS_DEST_ATTR_UNSPEC = 0, |
| 337 | IPVS_DEST_ATTR_ADDR, /* real server address */ |
| 338 | IPVS_DEST_ATTR_PORT, /* real server port */ |
| 339 | |
| 340 | IPVS_DEST_ATTR_FWD_METHOD, /* forwarding method */ |
| 341 | IPVS_DEST_ATTR_WEIGHT, /* destination weight */ |
| 342 | |
| 343 | IPVS_DEST_ATTR_U_THRESH, /* upper threshold */ |
| 344 | IPVS_DEST_ATTR_L_THRESH, /* lower threshold */ |
| 345 | |
| 346 | IPVS_DEST_ATTR_ACTIVE_CONNS, /* active connections */ |
| 347 | IPVS_DEST_ATTR_INACT_CONNS, /* inactive connections */ |
| 348 | IPVS_DEST_ATTR_PERSIST_CONNS, /* persistent connections */ |
| 349 | |
| 350 | IPVS_DEST_ATTR_STATS, /* nested attribute for dest stats */ |
| 351 | __IPVS_DEST_ATTR_MAX, |
| 352 | }; |
| 353 | |
| 354 | #define IPVS_DEST_ATTR_MAX (__IPVS_DEST_ATTR_MAX - 1) |
| 355 | |
| 356 | /* |
| 357 | * Attributes describing a sync daemon |
| 358 | * |
| 359 | * Used inside nested attribute IPVS_CMD_ATTR_DAEMON |
| 360 | */ |
| 361 | enum { |
| 362 | IPVS_DAEMON_ATTR_UNSPEC = 0, |
| 363 | IPVS_DAEMON_ATTR_STATE, /* sync daemon state (master/backup) */ |
| 364 | IPVS_DAEMON_ATTR_MCAST_IFN, /* multicast interface name */ |
| 365 | IPVS_DAEMON_ATTR_SYNC_ID, /* SyncID we belong to */ |
| 366 | __IPVS_DAEMON_ATTR_MAX, |
| 367 | }; |
| 368 | |
| 369 | #define IPVS_DAEMON_ATTR_MAX (__IPVS_DAEMON_ATTR_MAX - 1) |
| 370 | |
| 371 | /* |
| 372 | * Attributes used to describe service or destination entry statistics |
| 373 | * |
| 374 | * Used inside nested attributes IPVS_SVC_ATTR_STATS and IPVS_DEST_ATTR_STATS |
| 375 | */ |
| 376 | enum { |
| 377 | IPVS_STATS_ATTR_UNSPEC = 0, |
| 378 | IPVS_STATS_ATTR_CONNS, /* connections scheduled */ |
| 379 | IPVS_STATS_ATTR_INPKTS, /* incoming packets */ |
| 380 | IPVS_STATS_ATTR_OUTPKTS, /* outgoing packets */ |
| 381 | IPVS_STATS_ATTR_INBYTES, /* incoming bytes */ |
| 382 | IPVS_STATS_ATTR_OUTBYTES, /* outgoing bytes */ |
| 383 | |
| 384 | IPVS_STATS_ATTR_CPS, /* current connection rate */ |
| 385 | IPVS_STATS_ATTR_INPPS, /* current in packet rate */ |
| 386 | IPVS_STATS_ATTR_OUTPPS, /* current out packet rate */ |
| 387 | IPVS_STATS_ATTR_INBPS, /* current in byte rate */ |
| 388 | IPVS_STATS_ATTR_OUTBPS, /* current out byte rate */ |
| 389 | __IPVS_STATS_ATTR_MAX, |
| 390 | }; |
| 391 | |
| 392 | #define IPVS_STATS_ATTR_MAX (__IPVS_STATS_ATTR_MAX - 1) |
| 393 | |
| 394 | /* Attributes used in response to IPVS_CMD_GET_INFO command */ |
| 395 | enum { |
| 396 | IPVS_INFO_ATTR_UNSPEC = 0, |
| 397 | IPVS_INFO_ATTR_VERSION, /* IPVS version number */ |
| 398 | IPVS_INFO_ATTR_CONN_TAB_SIZE, /* size of connection hash table */ |
| 399 | __IPVS_INFO_ATTR_MAX, |
| 400 | }; |
| 401 | |
| 402 | #define IPVS_INFO_ATTR_MAX (__IPVS_INFO_ATTR_MAX - 1) |
| 403 | |
Julius Volz | bc4768e | 2008-07-31 20:45:24 -0700 | [diff] [blame] | 404 | #endif /* _IP_VS_H */ |