PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

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