blob: 1d954c6c4e08c08e5d1784a47c06b996d945f53a [file] [log] [blame]
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +01001#ifndef _IP_SET_H
2#define _IP_SET_H
3
4/* Copyright (C) 2000-2002 Joakim Axelsson <gozem@linux.nu>
5 * Patrick Schaaf <bof@bof.de>
6 * Martin Josefsson <gandalf@wlug.westbo.se>
7 * Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Jan Engelhardtae8ded12012-01-14 16:26:20 +010014#include <linux/types.h>
15
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +010016/* The protocol version */
17#define IPSET_PROTOCOL 6
18
19/* The max length of strings including NUL: set and type identifiers */
20#define IPSET_MAXNAMELEN 32
21
22/* Message types and commands */
23enum ipset_cmd {
24 IPSET_CMD_NONE,
25 IPSET_CMD_PROTOCOL, /* 1: Return protocol version */
26 IPSET_CMD_CREATE, /* 2: Create a new (empty) set */
27 IPSET_CMD_DESTROY, /* 3: Destroy a (empty) set */
28 IPSET_CMD_FLUSH, /* 4: Remove all elements from a set */
29 IPSET_CMD_RENAME, /* 5: Rename a set */
30 IPSET_CMD_SWAP, /* 6: Swap two sets */
31 IPSET_CMD_LIST, /* 7: List sets */
32 IPSET_CMD_SAVE, /* 8: Save sets */
33 IPSET_CMD_ADD, /* 9: Add an element to a set */
34 IPSET_CMD_DEL, /* 10: Delete an element from a set */
35 IPSET_CMD_TEST, /* 11: Test an element in a set */
36 IPSET_CMD_HEADER, /* 12: Get set header data only */
37 IPSET_CMD_TYPE, /* 13: Get set type */
38 IPSET_MSG_MAX, /* Netlink message commands */
39
40 /* Commands in userspace: */
41 IPSET_CMD_RESTORE = IPSET_MSG_MAX, /* 14: Enter restore mode */
42 IPSET_CMD_HELP, /* 15: Get help */
43 IPSET_CMD_VERSION, /* 16: Get program version */
44 IPSET_CMD_QUIT, /* 17: Quit from interactive mode */
45
46 IPSET_CMD_MAX,
47
48 IPSET_CMD_COMMIT = IPSET_CMD_MAX, /* 18: Commit buffered commands */
49};
50
51/* Attributes at command level */
52enum {
53 IPSET_ATTR_UNSPEC,
54 IPSET_ATTR_PROTOCOL, /* 1: Protocol version */
55 IPSET_ATTR_SETNAME, /* 2: Name of the set */
56 IPSET_ATTR_TYPENAME, /* 3: Typename */
57 IPSET_ATTR_SETNAME2 = IPSET_ATTR_TYPENAME, /* Setname at rename/swap */
58 IPSET_ATTR_REVISION, /* 4: Settype revision */
59 IPSET_ATTR_FAMILY, /* 5: Settype family */
60 IPSET_ATTR_FLAGS, /* 6: Flags at command level */
61 IPSET_ATTR_DATA, /* 7: Nested attributes */
62 IPSET_ATTR_ADT, /* 8: Multiple data containers */
63 IPSET_ATTR_LINENO, /* 9: Restore lineno */
64 IPSET_ATTR_PROTOCOL_MIN, /* 10: Minimal supported version number */
65 IPSET_ATTR_REVISION_MIN = IPSET_ATTR_PROTOCOL_MIN, /* type rev min */
66 __IPSET_ATTR_CMD_MAX,
67};
68#define IPSET_ATTR_CMD_MAX (__IPSET_ATTR_CMD_MAX - 1)
69
70/* CADT specific attributes */
71enum {
72 IPSET_ATTR_IP = IPSET_ATTR_UNSPEC + 1,
73 IPSET_ATTR_IP_FROM = IPSET_ATTR_IP,
74 IPSET_ATTR_IP_TO, /* 2 */
75 IPSET_ATTR_CIDR, /* 3 */
76 IPSET_ATTR_PORT, /* 4 */
77 IPSET_ATTR_PORT_FROM = IPSET_ATTR_PORT,
78 IPSET_ATTR_PORT_TO, /* 5 */
79 IPSET_ATTR_TIMEOUT, /* 6 */
80 IPSET_ATTR_PROTO, /* 7 */
81 IPSET_ATTR_CADT_FLAGS, /* 8 */
82 IPSET_ATTR_CADT_LINENO = IPSET_ATTR_LINENO, /* 9 */
83 /* Reserve empty slots */
84 IPSET_ATTR_CADT_MAX = 16,
85 /* Create-only specific attributes */
86 IPSET_ATTR_GC,
87 IPSET_ATTR_HASHSIZE,
88 IPSET_ATTR_MAXELEM,
89 IPSET_ATTR_NETMASK,
90 IPSET_ATTR_PROBES,
91 IPSET_ATTR_RESIZE,
92 IPSET_ATTR_SIZE,
93 /* Kernel-only */
94 IPSET_ATTR_ELEMENTS,
95 IPSET_ATTR_REFERENCES,
96 IPSET_ATTR_MEMSIZE,
97
98 __IPSET_ATTR_CREATE_MAX,
99};
100#define IPSET_ATTR_CREATE_MAX (__IPSET_ATTR_CREATE_MAX - 1)
101
102/* ADT specific attributes */
103enum {
104 IPSET_ATTR_ETHER = IPSET_ATTR_CADT_MAX + 1,
105 IPSET_ATTR_NAME,
106 IPSET_ATTR_NAMEREF,
107 IPSET_ATTR_IP2,
108 IPSET_ATTR_CIDR2,
Jozsef Kadlecsikd0d9e0a2011-06-16 18:52:41 +0200109 IPSET_ATTR_IP2_TO,
Jozsef Kadlecsike3853572011-06-16 19:00:48 +0200110 IPSET_ATTR_IFACE,
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100111 __IPSET_ATTR_ADT_MAX,
112};
113#define IPSET_ATTR_ADT_MAX (__IPSET_ATTR_ADT_MAX - 1)
114
115/* IP specific attributes */
116enum {
117 IPSET_ATTR_IPADDR_IPV4 = IPSET_ATTR_UNSPEC + 1,
118 IPSET_ATTR_IPADDR_IPV6,
119 __IPSET_ATTR_IPADDR_MAX,
120};
121#define IPSET_ATTR_IPADDR_MAX (__IPSET_ATTR_IPADDR_MAX - 1)
122
123/* Error codes */
124enum ipset_errno {
125 IPSET_ERR_PRIVATE = 4096,
126 IPSET_ERR_PROTOCOL,
127 IPSET_ERR_FIND_TYPE,
128 IPSET_ERR_MAX_SETS,
129 IPSET_ERR_BUSY,
130 IPSET_ERR_EXIST_SETNAME2,
131 IPSET_ERR_TYPE_MISMATCH,
132 IPSET_ERR_EXIST,
133 IPSET_ERR_INVALID_CIDR,
134 IPSET_ERR_INVALID_NETMASK,
135 IPSET_ERR_INVALID_FAMILY,
136 IPSET_ERR_TIMEOUT,
137 IPSET_ERR_REFERENCED,
138 IPSET_ERR_IPADDR_IPV4,
139 IPSET_ERR_IPADDR_IPV6,
140
141 /* Type specific error codes */
142 IPSET_ERR_TYPE_SPECIFIC = 4352,
143};
144
145/* Flags at command level */
146enum ipset_cmd_flags {
147 IPSET_FLAG_BIT_EXIST = 0,
148 IPSET_FLAG_EXIST = (1 << IPSET_FLAG_BIT_EXIST),
Jozsef Kadlecsikc1e2e042011-06-16 18:47:07 +0200149 IPSET_FLAG_BIT_LIST_SETNAME = 1,
150 IPSET_FLAG_LIST_SETNAME = (1 << IPSET_FLAG_BIT_LIST_SETNAME),
151 IPSET_FLAG_BIT_LIST_HEADER = 2,
152 IPSET_FLAG_LIST_HEADER = (1 << IPSET_FLAG_BIT_LIST_HEADER),
Jozsef Kadlecsik2a7cef22012-01-14 17:16:36 +0100153 IPSET_FLAG_CMD_MAX = 15, /* Lower half */
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100154};
155
156/* Flags at CADT attribute level */
157enum ipset_cadt_flags {
158 IPSET_FLAG_BIT_BEFORE = 0,
159 IPSET_FLAG_BEFORE = (1 << IPSET_FLAG_BIT_BEFORE),
Jozsef Kadlecsike3853572011-06-16 19:00:48 +0200160 IPSET_FLAG_BIT_PHYSDEV = 1,
161 IPSET_FLAG_PHYSDEV = (1 << IPSET_FLAG_BIT_PHYSDEV),
Jozsef Kadlecsik2a7cef22012-01-14 17:16:36 +0100162 IPSET_FLAG_BIT_NOMATCH = 2,
163 IPSET_FLAG_NOMATCH = (1 << IPSET_FLAG_BIT_NOMATCH),
164 IPSET_FLAG_CADT_MAX = 15, /* Upper half */
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100165};
166
167/* Commands with settype-specific attributes */
168enum ipset_adt {
169 IPSET_ADD,
170 IPSET_DEL,
171 IPSET_TEST,
172 IPSET_ADT_MAX,
173 IPSET_CREATE = IPSET_ADT_MAX,
174 IPSET_CADT_MAX,
175};
176
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100177/* Sets are identified by an index in kernel space. Tweak with ip_set_id_t
178 * and IPSET_INVALID_ID if you want to increase the max number of sets.
179 */
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100180typedef __u16 ip_set_id_t;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100181
182#define IPSET_INVALID_ID 65535
183
184enum ip_set_dim {
185 IPSET_DIM_ZERO = 0,
186 IPSET_DIM_ONE,
187 IPSET_DIM_TWO,
188 IPSET_DIM_THREE,
189 /* Max dimension in elements.
190 * If changed, new revision of iptables match/target is required.
191 */
192 IPSET_DIM_MAX = 6,
193};
194
195/* Option flags for kernel operations */
196enum ip_set_kopt {
197 IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
198 IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
199 IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
200 IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
201};
202
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100203#ifdef __KERNEL__
204#include <linux/ip.h>
205#include <linux/ipv6.h>
206#include <linux/netlink.h>
207#include <linux/netfilter.h>
208#include <linux/netfilter/x_tables.h>
Jozsef Kadlecsik10111a62012-09-21 21:59:32 +0200209#include <linux/stringify.h>
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100210#include <linux/vmalloc.h>
211#include <net/netlink.h>
212
Jozsef Kadlecsik10111a62012-09-21 21:59:32 +0200213#define _IP_SET_MODULE_DESC(a, b, c) \
214 MODULE_DESCRIPTION(a " type of IP sets, revisions " b "-" c)
215#define IP_SET_MODULE_DESC(a, b, c) \
216 _IP_SET_MODULE_DESC(a, __stringify(b), __stringify(c))
217
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100218/* Set features */
219enum ip_set_feature {
220 IPSET_TYPE_IP_FLAG = 0,
221 IPSET_TYPE_IP = (1 << IPSET_TYPE_IP_FLAG),
222 IPSET_TYPE_PORT_FLAG = 1,
223 IPSET_TYPE_PORT = (1 << IPSET_TYPE_PORT_FLAG),
224 IPSET_TYPE_MAC_FLAG = 2,
225 IPSET_TYPE_MAC = (1 << IPSET_TYPE_MAC_FLAG),
226 IPSET_TYPE_IP2_FLAG = 3,
227 IPSET_TYPE_IP2 = (1 << IPSET_TYPE_IP2_FLAG),
228 IPSET_TYPE_NAME_FLAG = 4,
229 IPSET_TYPE_NAME = (1 << IPSET_TYPE_NAME_FLAG),
Jozsef Kadlecsike3853572011-06-16 19:00:48 +0200230 IPSET_TYPE_IFACE_FLAG = 5,
231 IPSET_TYPE_IFACE = (1 << IPSET_TYPE_IFACE_FLAG),
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100232 /* Strictly speaking not a feature, but a flag for dumping:
233 * this settype must be dumped last */
234 IPSET_DUMP_LAST_FLAG = 7,
235 IPSET_DUMP_LAST = (1 << IPSET_DUMP_LAST_FLAG),
236};
237
238struct ip_set;
239
Jozsef Kadlecsik54162192011-06-16 18:40:55 +0200240typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
241 u32 timeout, u32 flags);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100242
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200243/* Kernel API function options */
244struct ip_set_adt_opt {
245 u8 family; /* Actual protocol family */
246 u8 dim; /* Dimension of match/target */
247 u8 flags; /* Direction and negation flags */
248 u32 cmdflags; /* Command-like flags */
249 u32 timeout; /* Timeout value */
250};
251
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100252/* Set type, variant-specific part */
253struct ip_set_type_variant {
254 /* Kernelspace: test/add/del entries
255 * returns negative error code,
256 * zero for no match/success to add/delete
257 * positive for matching element */
258 int (*kadt)(struct ip_set *set, const struct sk_buff * skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200259 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200260 enum ipset_adt adt, const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100261
262 /* Userspace: test/add/del entries
263 * returns negative error code,
264 * zero for no match/success to add/delete
265 * positive for matching element */
266 int (*uadt)(struct ip_set *set, struct nlattr *tb[],
Jozsef Kadlecsik3d14b172011-06-16 18:49:17 +0200267 enum ipset_adt adt, u32 *lineno, u32 flags, bool retried);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100268
269 /* Low level add/del/test functions */
270 ipset_adtfn adt[IPSET_ADT_MAX];
271
272 /* When adding entries and set is full, try to resize the set */
273 int (*resize)(struct ip_set *set, bool retried);
274 /* Destroy the set */
275 void (*destroy)(struct ip_set *set);
276 /* Flush the elements */
277 void (*flush)(struct ip_set *set);
278 /* Expire entries before listing */
279 void (*expire)(struct ip_set *set);
280 /* List set header data */
281 int (*head)(struct ip_set *set, struct sk_buff *skb);
282 /* List elements */
283 int (*list)(const struct ip_set *set, struct sk_buff *skb,
284 struct netlink_callback *cb);
285
286 /* Return true if "b" set is the same as "a"
287 * according to the create set parameters */
288 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
289};
290
291/* The core set type structure */
292struct ip_set_type {
293 struct list_head list;
294
295 /* Typename */
296 char name[IPSET_MAXNAMELEN];
297 /* Protocol version */
298 u8 protocol;
299 /* Set features to control swapping */
300 u8 features;
301 /* Set type dimension */
302 u8 dimension;
Jan Engelhardtc15f1c82012-02-14 00:24:10 +0100303 /*
304 * Supported family: may be NFPROTO_UNSPEC for both
305 * NFPROTO_IPV4/NFPROTO_IPV6.
306 */
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100307 u8 family;
Jozsef Kadlecsikf1e00b32011-06-16 18:51:41 +0200308 /* Type revisions */
309 u8 revision_min, revision_max;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100310
311 /* Create set */
312 int (*create)(struct ip_set *set, struct nlattr *tb[], u32 flags);
313
314 /* Attribute policies */
315 const struct nla_policy create_policy[IPSET_ATTR_CREATE_MAX + 1];
316 const struct nla_policy adt_policy[IPSET_ATTR_ADT_MAX + 1];
317
318 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
319 struct module *me;
320};
321
322/* register and unregister set type */
323extern int ip_set_type_register(struct ip_set_type *set_type);
324extern void ip_set_type_unregister(struct ip_set_type *set_type);
325
326/* A generic IP set */
327struct ip_set {
328 /* The name of the set */
329 char name[IPSET_MAXNAMELEN];
330 /* Lock protecting the set data */
331 rwlock_t lock;
332 /* References to the set */
Jozsef Kadlecsik2f9f28b2011-04-04 15:19:25 +0200333 u32 ref;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100334 /* The core set type */
335 struct ip_set_type *type;
336 /* The type variant doing the real job */
337 const struct ip_set_type_variant *variant;
338 /* The actual INET family of the set */
339 u8 family;
Jozsef Kadlecsikf1e00b32011-06-16 18:51:41 +0200340 /* The type revision */
341 u8 revision;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100342 /* The type specific data */
343 void *data;
344};
345
346/* register and unregister set references */
347extern ip_set_id_t ip_set_get_byname(const char *name, struct ip_set **set);
348extern void ip_set_put_byindex(ip_set_id_t index);
Jozsef Kadlecsik15b4d932011-06-16 19:01:26 +0200349extern const char *ip_set_name_byindex(ip_set_id_t index);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100350extern ip_set_id_t ip_set_nfnl_get(const char *name);
351extern ip_set_id_t ip_set_nfnl_get_byindex(ip_set_id_t index);
352extern void ip_set_nfnl_put(ip_set_id_t index);
353
354/* API for iptables set match, and SET target */
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200355
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100356extern int ip_set_add(ip_set_id_t id, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200357 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200358 const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100359extern int ip_set_del(ip_set_id_t id, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200360 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200361 const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100362extern int ip_set_test(ip_set_id_t id, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200363 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200364 const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100365
366/* Utility functions */
Jozsef Kadlecsik15b4d932011-06-16 19:01:26 +0200367extern void *ip_set_alloc(size_t size);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100368extern void ip_set_free(void *members);
369extern int ip_set_get_ipaddr4(struct nlattr *nla, __be32 *ipaddr);
370extern int ip_set_get_ipaddr6(struct nlattr *nla, union nf_inet_addr *ipaddr);
371
372static inline int
373ip_set_get_hostipaddr4(struct nlattr *nla, u32 *ipaddr)
374{
375 __be32 ip;
376 int ret = ip_set_get_ipaddr4(nla, &ip);
Jozsef Kadlecsik15b4d932011-06-16 19:01:26 +0200377
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100378 if (ret)
379 return ret;
380 *ipaddr = ntohl(ip);
381 return 0;
382}
383
384/* Ignore IPSET_ERR_EXIST errors if asked to do so? */
385static inline bool
386ip_set_eexist(int ret, u32 flags)
387{
388 return ret == -IPSET_ERR_EXIST && (flags & IPSET_FLAG_EXIST);
389}
390
391/* Check the NLA_F_NET_BYTEORDER flag */
392static inline bool
393ip_set_attr_netorder(struct nlattr *tb[], int type)
394{
395 return tb[type] && (tb[type]->nla_type & NLA_F_NET_BYTEORDER);
396}
397
398static inline bool
399ip_set_optattr_netorder(struct nlattr *tb[], int type)
400{
401 return !tb[type] || (tb[type]->nla_type & NLA_F_NET_BYTEORDER);
402}
403
404/* Useful converters */
405static inline u32
406ip_set_get_h32(const struct nlattr *attr)
407{
408 return ntohl(nla_get_be32(attr));
409}
410
411static inline u16
412ip_set_get_h16(const struct nlattr *attr)
413{
414 return ntohs(nla_get_be16(attr));
415}
416
417#define ipset_nest_start(skb, attr) nla_nest_start(skb, attr | NLA_F_NESTED)
418#define ipset_nest_end(skb, start) nla_nest_end(skb, start)
419
David S. Miller7cf78992012-04-01 19:54:46 -0400420static inline int nla_put_ipaddr4(struct sk_buff *skb, int type, __be32 ipaddr)
421{
422 struct nlattr *__nested = ipset_nest_start(skb, type);
423 int ret;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100424
David S. Miller7cf78992012-04-01 19:54:46 -0400425 if (!__nested)
426 return -EMSGSIZE;
427 ret = nla_put_net32(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr);
428 if (!ret)
429 ipset_nest_end(skb, __nested);
430 return ret;
431}
432
433static inline int nla_put_ipaddr6(struct sk_buff *skb, int type, const struct in6_addr *ipaddrptr)
434{
435 struct nlattr *__nested = ipset_nest_start(skb, type);
436 int ret;
437
438 if (!__nested)
439 return -EMSGSIZE;
440 ret = nla_put(skb, IPSET_ATTR_IPADDR_IPV6,
441 sizeof(struct in6_addr), ipaddrptr);
442 if (!ret)
443 ipset_nest_end(skb, __nested);
444 return ret;
445}
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100446
447/* Get address from skbuff */
448static inline __be32
449ip4addr(const struct sk_buff *skb, bool src)
450{
451 return src ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr;
452}
453
454static inline void
455ip4addrptr(const struct sk_buff *skb, bool src, __be32 *addr)
456{
457 *addr = src ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr;
458}
459
460static inline void
461ip6addrptr(const struct sk_buff *skb, bool src, struct in6_addr *addr)
462{
463 memcpy(addr, src ? &ipv6_hdr(skb)->saddr : &ipv6_hdr(skb)->daddr,
464 sizeof(*addr));
465}
466
467/* Calculate the bytes required to store the inclusive range of a-b */
468static inline int
469bitmap_bytes(u32 a, u32 b)
470{
471 return 4 * ((((b - a + 8) / 8) + 3) / 4);
472}
473
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100474#endif /* __KERNEL__ */
475
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100476/* Interface to iptables/ip6tables */
477
478#define SO_IP_SET 83
479
480union ip_set_name_index {
481 char name[IPSET_MAXNAMELEN];
482 ip_set_id_t index;
483};
484
485#define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
486struct ip_set_req_get_set {
Eric Dumazet95c96172012-04-15 05:58:06 +0000487 unsigned int op;
488 unsigned int version;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100489 union ip_set_name_index set;
490};
491
492#define IP_SET_OP_GET_BYINDEX 0x00000007 /* Get set name by index */
493/* Uses ip_set_req_get_set */
494
495#define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
496struct ip_set_req_version {
Eric Dumazet95c96172012-04-15 05:58:06 +0000497 unsigned int op;
498 unsigned int version;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100499};
500
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100501#endif /*_IP_SET_H */