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@blackhole.kfki.hu>
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.
11 #ifndef _UAPI_IP_SET_H
12 #define _UAPI_IP_SET_H
14 #include <linux/types.h>
16 /* The protocol version */
17 #define IPSET_PROTOCOL 6
19 /* The max length of strings including NUL: set and type identifiers */
20 #define IPSET_MAXNAMELEN 32
22 /* The maximum permissible comment length we will accept over netlink */
23 #define IPSET_MAX_COMMENT_SIZE 255
25 /* Message types and commands */
28 IPSET_CMD_PROTOCOL, /* 1: Return protocol version */
29 IPSET_CMD_CREATE, /* 2: Create a new (empty) set */
30 IPSET_CMD_DESTROY, /* 3: Destroy a (empty) set */
31 IPSET_CMD_FLUSH, /* 4: Remove all elements from a set */
32 IPSET_CMD_RENAME, /* 5: Rename a set */
33 IPSET_CMD_SWAP, /* 6: Swap two sets */
34 IPSET_CMD_LIST, /* 7: List sets */
35 IPSET_CMD_SAVE, /* 8: Save sets */
36 IPSET_CMD_ADD, /* 9: Add an element to a set */
37 IPSET_CMD_DEL, /* 10: Delete an element from a set */
38 IPSET_CMD_TEST, /* 11: Test an element in a set */
39 IPSET_CMD_HEADER, /* 12: Get set header data only */
40 IPSET_CMD_TYPE, /* 13: Get set type */
41 IPSET_MSG_MAX, /* Netlink message commands */
43 /* Commands in userspace: */
44 IPSET_CMD_RESTORE = IPSET_MSG_MAX, /* 14: Enter restore mode */
45 IPSET_CMD_HELP, /* 15: Get help */
46 IPSET_CMD_VERSION, /* 16: Get program version */
47 IPSET_CMD_QUIT, /* 17: Quit from interactive mode */
51 IPSET_CMD_COMMIT = IPSET_CMD_MAX, /* 18: Commit buffered commands */
54 /* Attributes at command level */
57 IPSET_ATTR_PROTOCOL, /* 1: Protocol version */
58 IPSET_ATTR_SETNAME, /* 2: Name of the set */
59 IPSET_ATTR_TYPENAME, /* 3: Typename */
60 IPSET_ATTR_SETNAME2 = IPSET_ATTR_TYPENAME, /* Setname at rename/swap */
61 IPSET_ATTR_REVISION, /* 4: Settype revision */
62 IPSET_ATTR_FAMILY, /* 5: Settype family */
63 IPSET_ATTR_FLAGS, /* 6: Flags at command level */
64 IPSET_ATTR_DATA, /* 7: Nested attributes */
65 IPSET_ATTR_ADT, /* 8: Multiple data containers */
66 IPSET_ATTR_LINENO, /* 9: Restore lineno */
67 IPSET_ATTR_PROTOCOL_MIN, /* 10: Minimal supported version number */
68 IPSET_ATTR_REVISION_MIN = IPSET_ATTR_PROTOCOL_MIN, /* type rev min */
71 #define IPSET_ATTR_CMD_MAX (__IPSET_ATTR_CMD_MAX - 1)
73 /* CADT specific attributes */
75 IPSET_ATTR_IP = IPSET_ATTR_UNSPEC + 1,
76 IPSET_ATTR_IP_FROM = IPSET_ATTR_IP,
77 IPSET_ATTR_IP_TO, /* 2 */
78 IPSET_ATTR_CIDR, /* 3 */
79 IPSET_ATTR_PORT, /* 4 */
80 IPSET_ATTR_PORT_FROM = IPSET_ATTR_PORT,
81 IPSET_ATTR_PORT_TO, /* 5 */
82 IPSET_ATTR_TIMEOUT, /* 6 */
83 IPSET_ATTR_PROTO, /* 7 */
84 IPSET_ATTR_CADT_FLAGS, /* 8 */
85 IPSET_ATTR_CADT_LINENO = IPSET_ATTR_LINENO, /* 9 */
86 IPSET_ATTR_MARK, /* 10 */
87 IPSET_ATTR_MARKMASK, /* 11 */
88 /* Reserve empty slots */
89 IPSET_ATTR_CADT_MAX = 16,
90 /* Create-only specific attributes */
100 IPSET_ATTR_REFERENCES,
103 __IPSET_ATTR_CREATE_MAX,
105 #define IPSET_ATTR_CREATE_MAX (__IPSET_ATTR_CREATE_MAX - 1)
107 /* ADT specific attributes */
109 IPSET_ATTR_ETHER = IPSET_ATTR_CADT_MAX + 1,
123 __IPSET_ATTR_ADT_MAX,
125 #define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
127 /* IP specific attributes */
129 IPSET_ATTR_IPADDR_IPV4 = IPSET_ATTR_UNSPEC + 1,
130 IPSET_ATTR_IPADDR_IPV6,
131 __IPSET_ATTR_IPADDR_MAX,
133 #define IPSET_ATTR_IPADDR_MAX (__IPSET_ATTR_IPADDR_MAX - 1)
137 IPSET_ERR_PRIVATE = 4096,
142 IPSET_ERR_EXIST_SETNAME2,
143 IPSET_ERR_TYPE_MISMATCH,
145 IPSET_ERR_INVALID_CIDR,
146 IPSET_ERR_INVALID_NETMASK,
147 IPSET_ERR_INVALID_FAMILY,
149 IPSET_ERR_REFERENCED,
150 IPSET_ERR_IPADDR_IPV4,
151 IPSET_ERR_IPADDR_IPV6,
154 IPSET_ERR_INVALID_MARKMASK,
157 /* Type specific error codes */
158 IPSET_ERR_TYPE_SPECIFIC = 4352,
161 /* Flags at command level or match/target flags, lower half of cmdattrs*/
162 enum ipset_cmd_flags {
163 IPSET_FLAG_BIT_EXIST = 0,
164 IPSET_FLAG_EXIST = (1 << IPSET_FLAG_BIT_EXIST),
165 IPSET_FLAG_BIT_LIST_SETNAME = 1,
166 IPSET_FLAG_LIST_SETNAME = (1 << IPSET_FLAG_BIT_LIST_SETNAME),
167 IPSET_FLAG_BIT_LIST_HEADER = 2,
168 IPSET_FLAG_LIST_HEADER = (1 << IPSET_FLAG_BIT_LIST_HEADER),
169 IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE = 3,
170 IPSET_FLAG_SKIP_COUNTER_UPDATE =
171 (1 << IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE),
172 IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE = 4,
173 IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE =
174 (1 << IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE),
175 IPSET_FLAG_BIT_MATCH_COUNTERS = 5,
176 IPSET_FLAG_MATCH_COUNTERS = (1 << IPSET_FLAG_BIT_MATCH_COUNTERS),
177 IPSET_FLAG_BIT_RETURN_NOMATCH = 7,
178 IPSET_FLAG_RETURN_NOMATCH = (1 << IPSET_FLAG_BIT_RETURN_NOMATCH),
179 IPSET_FLAG_BIT_MAP_SKBMARK = 8,
180 IPSET_FLAG_MAP_SKBMARK = (1 << IPSET_FLAG_BIT_MAP_SKBMARK),
181 IPSET_FLAG_BIT_MAP_SKBPRIO = 9,
182 IPSET_FLAG_MAP_SKBPRIO = (1 << IPSET_FLAG_BIT_MAP_SKBPRIO),
183 IPSET_FLAG_BIT_MAP_SKBQUEUE = 10,
184 IPSET_FLAG_MAP_SKBQUEUE = (1 << IPSET_FLAG_BIT_MAP_SKBQUEUE),
185 IPSET_FLAG_CMD_MAX = 15,
188 /* Flags at CADT attribute level, upper half of cmdattrs */
189 enum ipset_cadt_flags {
190 IPSET_FLAG_BIT_BEFORE = 0,
191 IPSET_FLAG_BEFORE = (1 << IPSET_FLAG_BIT_BEFORE),
192 IPSET_FLAG_BIT_PHYSDEV = 1,
193 IPSET_FLAG_PHYSDEV = (1 << IPSET_FLAG_BIT_PHYSDEV),
194 IPSET_FLAG_BIT_NOMATCH = 2,
195 IPSET_FLAG_NOMATCH = (1 << IPSET_FLAG_BIT_NOMATCH),
196 IPSET_FLAG_BIT_WITH_COUNTERS = 3,
197 IPSET_FLAG_WITH_COUNTERS = (1 << IPSET_FLAG_BIT_WITH_COUNTERS),
198 IPSET_FLAG_BIT_WITH_COMMENT = 4,
199 IPSET_FLAG_WITH_COMMENT = (1 << IPSET_FLAG_BIT_WITH_COMMENT),
200 IPSET_FLAG_BIT_WITH_FORCEADD = 5,
201 IPSET_FLAG_WITH_FORCEADD = (1 << IPSET_FLAG_BIT_WITH_FORCEADD),
202 IPSET_FLAG_BIT_WITH_SKBINFO = 6,
203 IPSET_FLAG_WITH_SKBINFO = (1 << IPSET_FLAG_BIT_WITH_SKBINFO),
204 IPSET_FLAG_CADT_MAX = 15,
207 /* The flag bits which correspond to the non-extension create flags */
208 enum ipset_create_flags {
209 IPSET_CREATE_FLAG_BIT_FORCEADD = 0,
210 IPSET_CREATE_FLAG_FORCEADD = (1 << IPSET_CREATE_FLAG_BIT_FORCEADD),
211 IPSET_CREATE_FLAG_BIT_MAX = 7,
214 /* Commands with settype-specific attributes */
220 IPSET_CREATE = IPSET_ADT_MAX,
224 /* Sets are identified by an index in kernel space. Tweak with ip_set_id_t
225 * and IPSET_INVALID_ID if you want to increase the max number of sets.
227 typedef __u16 ip_set_id_t;
229 #define IPSET_INVALID_ID 65535
236 /* Max dimension in elements.
237 * If changed, new revision of iptables match/target is required.
240 /* Backward compatibility: set match revision 2 */
241 IPSET_BIT_RETURN_NOMATCH = 7,
244 /* Option flags for kernel operations */
246 IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
247 IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
248 IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
249 IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
250 IPSET_RETURN_NOMATCH = (1 << IPSET_BIT_RETURN_NOMATCH),
254 IPSET_COUNTER_NONE = 0,
261 /* Backward compatibility for set match v3 */
262 struct ip_set_counter_match0 {
267 struct ip_set_counter_match {
272 /* Interface to iptables/ip6tables */
276 union ip_set_name_index {
277 char name[IPSET_MAXNAMELEN];
281 #define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
282 struct ip_set_req_get_set {
284 unsigned int version;
285 union ip_set_name_index set;
288 #define IP_SET_OP_GET_BYINDEX 0x00000007 /* Get set name by index */
289 /* Uses ip_set_req_get_set */
291 #define IP_SET_OP_GET_FNAME 0x00000008 /* Get set index and family */
292 struct ip_set_req_get_set_family {
294 unsigned int version;
296 union ip_set_name_index set;
299 #define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
300 struct ip_set_req_version {
302 unsigned int version;
305 #endif /* _UAPI_IP_SET_H */