ip_vs.h 13 KB

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