PageRenderTime 31ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/include/uapi/linux/netfilter/ipset/ip_set.h

https://github.com/mturquette/linux
C Header | 304 lines | 232 code | 34 blank | 38 comment | 0 complexity | 43aadbe6d14ec136f3e79e3bda7933b4 MD5 | raw file
  1. /* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
  2. * Patrick Schaaf <bof@bof.de>
  3. * Martin Josefsson <gandalf@wlug.westbo.se>
  4. * Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef _UAPI_IP_SET_H
  11. #define _UAPI_IP_SET_H
  12. #include <linux/types.h>
  13. /* The protocol version */
  14. #define IPSET_PROTOCOL 6
  15. /* The max length of strings including NUL: set and type identifiers */
  16. #define IPSET_MAXNAMELEN 32
  17. /* The maximum permissible comment length we will accept over netlink */
  18. #define IPSET_MAX_COMMENT_SIZE 255
  19. /* Message types and commands */
  20. enum ipset_cmd {
  21. IPSET_CMD_NONE,
  22. IPSET_CMD_PROTOCOL, /* 1: Return protocol version */
  23. IPSET_CMD_CREATE, /* 2: Create a new (empty) set */
  24. IPSET_CMD_DESTROY, /* 3: Destroy a (empty) set */
  25. IPSET_CMD_FLUSH, /* 4: Remove all elements from a set */
  26. IPSET_CMD_RENAME, /* 5: Rename a set */
  27. IPSET_CMD_SWAP, /* 6: Swap two sets */
  28. IPSET_CMD_LIST, /* 7: List sets */
  29. IPSET_CMD_SAVE, /* 8: Save sets */
  30. IPSET_CMD_ADD, /* 9: Add an element to a set */
  31. IPSET_CMD_DEL, /* 10: Delete an element from a set */
  32. IPSET_CMD_TEST, /* 11: Test an element in a set */
  33. IPSET_CMD_HEADER, /* 12: Get set header data only */
  34. IPSET_CMD_TYPE, /* 13: Get set type */
  35. IPSET_MSG_MAX, /* Netlink message commands */
  36. /* Commands in userspace: */
  37. IPSET_CMD_RESTORE = IPSET_MSG_MAX, /* 14: Enter restore mode */
  38. IPSET_CMD_HELP, /* 15: Get help */
  39. IPSET_CMD_VERSION, /* 16: Get program version */
  40. IPSET_CMD_QUIT, /* 17: Quit from interactive mode */
  41. IPSET_CMD_MAX,
  42. IPSET_CMD_COMMIT = IPSET_CMD_MAX, /* 18: Commit buffered commands */
  43. };
  44. /* Attributes at command level */
  45. enum {
  46. IPSET_ATTR_UNSPEC,
  47. IPSET_ATTR_PROTOCOL, /* 1: Protocol version */
  48. IPSET_ATTR_SETNAME, /* 2: Name of the set */
  49. IPSET_ATTR_TYPENAME, /* 3: Typename */
  50. IPSET_ATTR_SETNAME2 = IPSET_ATTR_TYPENAME, /* Setname at rename/swap */
  51. IPSET_ATTR_REVISION, /* 4: Settype revision */
  52. IPSET_ATTR_FAMILY, /* 5: Settype family */
  53. IPSET_ATTR_FLAGS, /* 6: Flags at command level */
  54. IPSET_ATTR_DATA, /* 7: Nested attributes */
  55. IPSET_ATTR_ADT, /* 8: Multiple data containers */
  56. IPSET_ATTR_LINENO, /* 9: Restore lineno */
  57. IPSET_ATTR_PROTOCOL_MIN, /* 10: Minimal supported version number */
  58. IPSET_ATTR_REVISION_MIN = IPSET_ATTR_PROTOCOL_MIN, /* type rev min */
  59. __IPSET_ATTR_CMD_MAX,
  60. };
  61. #define IPSET_ATTR_CMD_MAX (__IPSET_ATTR_CMD_MAX - 1)
  62. /* CADT specific attributes */
  63. enum {
  64. IPSET_ATTR_IP = IPSET_ATTR_UNSPEC + 1,
  65. IPSET_ATTR_IP_FROM = IPSET_ATTR_IP,
  66. IPSET_ATTR_IP_TO, /* 2 */
  67. IPSET_ATTR_CIDR, /* 3 */
  68. IPSET_ATTR_PORT, /* 4 */
  69. IPSET_ATTR_PORT_FROM = IPSET_ATTR_PORT,
  70. IPSET_ATTR_PORT_TO, /* 5 */
  71. IPSET_ATTR_TIMEOUT, /* 6 */
  72. IPSET_ATTR_PROTO, /* 7 */
  73. IPSET_ATTR_CADT_FLAGS, /* 8 */
  74. IPSET_ATTR_CADT_LINENO = IPSET_ATTR_LINENO, /* 9 */
  75. IPSET_ATTR_MARK, /* 10 */
  76. IPSET_ATTR_MARKMASK, /* 11 */
  77. /* Reserve empty slots */
  78. IPSET_ATTR_CADT_MAX = 16,
  79. /* Create-only specific attributes */
  80. IPSET_ATTR_GC,
  81. IPSET_ATTR_HASHSIZE,
  82. IPSET_ATTR_MAXELEM,
  83. IPSET_ATTR_NETMASK,
  84. IPSET_ATTR_PROBES,
  85. IPSET_ATTR_RESIZE,
  86. IPSET_ATTR_SIZE,
  87. /* Kernel-only */
  88. IPSET_ATTR_ELEMENTS,
  89. IPSET_ATTR_REFERENCES,
  90. IPSET_ATTR_MEMSIZE,
  91. __IPSET_ATTR_CREATE_MAX,
  92. };
  93. #define IPSET_ATTR_CREATE_MAX (__IPSET_ATTR_CREATE_MAX - 1)
  94. /* ADT specific attributes */
  95. enum {
  96. IPSET_ATTR_ETHER = IPSET_ATTR_CADT_MAX + 1,
  97. IPSET_ATTR_NAME,
  98. IPSET_ATTR_NAMEREF,
  99. IPSET_ATTR_IP2,
  100. IPSET_ATTR_CIDR2,
  101. IPSET_ATTR_IP2_TO,
  102. IPSET_ATTR_IFACE,
  103. IPSET_ATTR_BYTES,
  104. IPSET_ATTR_PACKETS,
  105. IPSET_ATTR_COMMENT,
  106. IPSET_ATTR_SKBMARK,
  107. IPSET_ATTR_SKBPRIO,
  108. IPSET_ATTR_SKBQUEUE,
  109. IPSET_ATTR_PAD,
  110. __IPSET_ATTR_ADT_MAX,
  111. };
  112. #define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
  113. /* IP specific attributes */
  114. enum {
  115. IPSET_ATTR_IPADDR_IPV4 = IPSET_ATTR_UNSPEC + 1,
  116. IPSET_ATTR_IPADDR_IPV6,
  117. __IPSET_ATTR_IPADDR_MAX,
  118. };
  119. #define IPSET_ATTR_IPADDR_MAX (__IPSET_ATTR_IPADDR_MAX - 1)
  120. /* Error codes */
  121. enum ipset_errno {
  122. IPSET_ERR_PRIVATE = 4096,
  123. IPSET_ERR_PROTOCOL,
  124. IPSET_ERR_FIND_TYPE,
  125. IPSET_ERR_MAX_SETS,
  126. IPSET_ERR_BUSY,
  127. IPSET_ERR_EXIST_SETNAME2,
  128. IPSET_ERR_TYPE_MISMATCH,
  129. IPSET_ERR_EXIST,
  130. IPSET_ERR_INVALID_CIDR,
  131. IPSET_ERR_INVALID_NETMASK,
  132. IPSET_ERR_INVALID_FAMILY,
  133. IPSET_ERR_TIMEOUT,
  134. IPSET_ERR_REFERENCED,
  135. IPSET_ERR_IPADDR_IPV4,
  136. IPSET_ERR_IPADDR_IPV6,
  137. IPSET_ERR_COUNTER,
  138. IPSET_ERR_COMMENT,
  139. IPSET_ERR_INVALID_MARKMASK,
  140. IPSET_ERR_SKBINFO,
  141. /* Type specific error codes */
  142. IPSET_ERR_TYPE_SPECIFIC = 4352,
  143. };
  144. /* Flags at command level or match/target flags, lower half of cmdattrs*/
  145. enum ipset_cmd_flags {
  146. IPSET_FLAG_BIT_EXIST = 0,
  147. IPSET_FLAG_EXIST = (1 << IPSET_FLAG_BIT_EXIST),
  148. IPSET_FLAG_BIT_LIST_SETNAME = 1,
  149. IPSET_FLAG_LIST_SETNAME = (1 << IPSET_FLAG_BIT_LIST_SETNAME),
  150. IPSET_FLAG_BIT_LIST_HEADER = 2,
  151. IPSET_FLAG_LIST_HEADER = (1 << IPSET_FLAG_BIT_LIST_HEADER),
  152. IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE = 3,
  153. IPSET_FLAG_SKIP_COUNTER_UPDATE =
  154. (1 << IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE),
  155. IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE = 4,
  156. IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE =
  157. (1 << IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE),
  158. IPSET_FLAG_BIT_MATCH_COUNTERS = 5,
  159. IPSET_FLAG_MATCH_COUNTERS = (1 << IPSET_FLAG_BIT_MATCH_COUNTERS),
  160. IPSET_FLAG_BIT_RETURN_NOMATCH = 7,
  161. IPSET_FLAG_RETURN_NOMATCH = (1 << IPSET_FLAG_BIT_RETURN_NOMATCH),
  162. IPSET_FLAG_BIT_MAP_SKBMARK = 8,
  163. IPSET_FLAG_MAP_SKBMARK = (1 << IPSET_FLAG_BIT_MAP_SKBMARK),
  164. IPSET_FLAG_BIT_MAP_SKBPRIO = 9,
  165. IPSET_FLAG_MAP_SKBPRIO = (1 << IPSET_FLAG_BIT_MAP_SKBPRIO),
  166. IPSET_FLAG_BIT_MAP_SKBQUEUE = 10,
  167. IPSET_FLAG_MAP_SKBQUEUE = (1 << IPSET_FLAG_BIT_MAP_SKBQUEUE),
  168. IPSET_FLAG_CMD_MAX = 15,
  169. };
  170. /* Flags at CADT attribute level, upper half of cmdattrs */
  171. enum ipset_cadt_flags {
  172. IPSET_FLAG_BIT_BEFORE = 0,
  173. IPSET_FLAG_BEFORE = (1 << IPSET_FLAG_BIT_BEFORE),
  174. IPSET_FLAG_BIT_PHYSDEV = 1,
  175. IPSET_FLAG_PHYSDEV = (1 << IPSET_FLAG_BIT_PHYSDEV),
  176. IPSET_FLAG_BIT_NOMATCH = 2,
  177. IPSET_FLAG_NOMATCH = (1 << IPSET_FLAG_BIT_NOMATCH),
  178. IPSET_FLAG_BIT_WITH_COUNTERS = 3,
  179. IPSET_FLAG_WITH_COUNTERS = (1 << IPSET_FLAG_BIT_WITH_COUNTERS),
  180. IPSET_FLAG_BIT_WITH_COMMENT = 4,
  181. IPSET_FLAG_WITH_COMMENT = (1 << IPSET_FLAG_BIT_WITH_COMMENT),
  182. IPSET_FLAG_BIT_WITH_FORCEADD = 5,
  183. IPSET_FLAG_WITH_FORCEADD = (1 << IPSET_FLAG_BIT_WITH_FORCEADD),
  184. IPSET_FLAG_BIT_WITH_SKBINFO = 6,
  185. IPSET_FLAG_WITH_SKBINFO = (1 << IPSET_FLAG_BIT_WITH_SKBINFO),
  186. IPSET_FLAG_CADT_MAX = 15,
  187. };
  188. /* The flag bits which correspond to the non-extension create flags */
  189. enum ipset_create_flags {
  190. IPSET_CREATE_FLAG_BIT_FORCEADD = 0,
  191. IPSET_CREATE_FLAG_FORCEADD = (1 << IPSET_CREATE_FLAG_BIT_FORCEADD),
  192. IPSET_CREATE_FLAG_BIT_MAX = 7,
  193. };
  194. /* Commands with settype-specific attributes */
  195. enum ipset_adt {
  196. IPSET_ADD,
  197. IPSET_DEL,
  198. IPSET_TEST,
  199. IPSET_ADT_MAX,
  200. IPSET_CREATE = IPSET_ADT_MAX,
  201. IPSET_CADT_MAX,
  202. };
  203. /* Sets are identified by an index in kernel space. Tweak with ip_set_id_t
  204. * and IPSET_INVALID_ID if you want to increase the max number of sets.
  205. */
  206. typedef __u16 ip_set_id_t;
  207. #define IPSET_INVALID_ID 65535
  208. enum ip_set_dim {
  209. IPSET_DIM_ZERO = 0,
  210. IPSET_DIM_ONE,
  211. IPSET_DIM_TWO,
  212. IPSET_DIM_THREE,
  213. /* Max dimension in elements.
  214. * If changed, new revision of iptables match/target is required.
  215. */
  216. IPSET_DIM_MAX = 6,
  217. /* Backward compatibility: set match revision 2 */
  218. IPSET_BIT_RETURN_NOMATCH = 7,
  219. };
  220. /* Option flags for kernel operations */
  221. enum ip_set_kopt {
  222. IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
  223. IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
  224. IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
  225. IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
  226. IPSET_RETURN_NOMATCH = (1 << IPSET_BIT_RETURN_NOMATCH),
  227. };
  228. enum {
  229. IPSET_COUNTER_NONE = 0,
  230. IPSET_COUNTER_EQ,
  231. IPSET_COUNTER_NE,
  232. IPSET_COUNTER_LT,
  233. IPSET_COUNTER_GT,
  234. };
  235. /* Backward compatibility for set match v3 */
  236. struct ip_set_counter_match0 {
  237. __u8 op;
  238. __u64 value;
  239. };
  240. struct ip_set_counter_match {
  241. __aligned_u64 value;
  242. __u8 op;
  243. };
  244. /* Interface to iptables/ip6tables */
  245. #define SO_IP_SET 83
  246. union ip_set_name_index {
  247. char name[IPSET_MAXNAMELEN];
  248. ip_set_id_t index;
  249. };
  250. #define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
  251. struct ip_set_req_get_set {
  252. unsigned int op;
  253. unsigned int version;
  254. union ip_set_name_index set;
  255. };
  256. #define IP_SET_OP_GET_BYINDEX 0x00000007 /* Get set name by index */
  257. /* Uses ip_set_req_get_set */
  258. #define IP_SET_OP_GET_FNAME 0x00000008 /* Get set index and family */
  259. struct ip_set_req_get_set_family {
  260. unsigned int op;
  261. unsigned int version;
  262. unsigned int family;
  263. union ip_set_name_index set;
  264. };
  265. #define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
  266. struct ip_set_req_version {
  267. unsigned int op;
  268. unsigned int version;
  269. };
  270. #endif /* _UAPI_IP_SET_H */