ip_vs.h 13 KB

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