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