blob: 528697b3c1524d1e7e071986231e2d14979018c2 [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,
Jozsef Kadlecsik3e0304a2012-09-21 22:02:36 +0200193 IPSET_BIT_RETURN_NOMATCH = 7,
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100194};
195
196/* Option flags for kernel operations */
197enum ip_set_kopt {
198 IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
199 IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
200 IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
201 IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
Jozsef Kadlecsik3e0304a2012-09-21 22:02:36 +0200202 IPSET_RETURN_NOMATCH = (1 << IPSET_BIT_RETURN_NOMATCH),
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100203};
204
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100205#ifdef __KERNEL__
206#include <linux/ip.h>
207#include <linux/ipv6.h>
208#include <linux/netlink.h>
209#include <linux/netfilter.h>
210#include <linux/netfilter/x_tables.h>
Jozsef Kadlecsik10111a62012-09-21 21:59:32 +0200211#include <linux/stringify.h>
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100212#include <linux/vmalloc.h>
213#include <net/netlink.h>
214
Jozsef Kadlecsik10111a62012-09-21 21:59:32 +0200215#define _IP_SET_MODULE_DESC(a, b, c) \
216 MODULE_DESCRIPTION(a " type of IP sets, revisions " b "-" c)
217#define IP_SET_MODULE_DESC(a, b, c) \
218 _IP_SET_MODULE_DESC(a, __stringify(b), __stringify(c))
219
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100220/* Set features */
221enum ip_set_feature {
222 IPSET_TYPE_IP_FLAG = 0,
223 IPSET_TYPE_IP = (1 << IPSET_TYPE_IP_FLAG),
224 IPSET_TYPE_PORT_FLAG = 1,
225 IPSET_TYPE_PORT = (1 << IPSET_TYPE_PORT_FLAG),
226 IPSET_TYPE_MAC_FLAG = 2,
227 IPSET_TYPE_MAC = (1 << IPSET_TYPE_MAC_FLAG),
228 IPSET_TYPE_IP2_FLAG = 3,
229 IPSET_TYPE_IP2 = (1 << IPSET_TYPE_IP2_FLAG),
230 IPSET_TYPE_NAME_FLAG = 4,
231 IPSET_TYPE_NAME = (1 << IPSET_TYPE_NAME_FLAG),
Jozsef Kadlecsike3853572011-06-16 19:00:48 +0200232 IPSET_TYPE_IFACE_FLAG = 5,
233 IPSET_TYPE_IFACE = (1 << IPSET_TYPE_IFACE_FLAG),
Jozsef Kadlecsik3e0304a2012-09-21 22:02:36 +0200234 IPSET_TYPE_NOMATCH_FLAG = 6,
235 IPSET_TYPE_NOMATCH = (1 << IPSET_TYPE_NOMATCH_FLAG),
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100236 /* Strictly speaking not a feature, but a flag for dumping:
237 * this settype must be dumped last */
238 IPSET_DUMP_LAST_FLAG = 7,
239 IPSET_DUMP_LAST = (1 << IPSET_DUMP_LAST_FLAG),
240};
241
242struct ip_set;
243
Jozsef Kadlecsik54162192011-06-16 18:40:55 +0200244typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
245 u32 timeout, u32 flags);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100246
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200247/* Kernel API function options */
248struct ip_set_adt_opt {
249 u8 family; /* Actual protocol family */
250 u8 dim; /* Dimension of match/target */
251 u8 flags; /* Direction and negation flags */
252 u32 cmdflags; /* Command-like flags */
253 u32 timeout; /* Timeout value */
254};
255
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100256/* Set type, variant-specific part */
257struct ip_set_type_variant {
258 /* Kernelspace: test/add/del entries
259 * returns negative error code,
260 * zero for no match/success to add/delete
261 * positive for matching element */
Jozsef Kadlecsik3ace95c2012-09-21 22:01:45 +0200262 int (*kadt)(struct ip_set *set, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200263 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200264 enum ipset_adt adt, const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100265
266 /* Userspace: test/add/del entries
267 * returns negative error code,
268 * zero for no match/success to add/delete
269 * positive for matching element */
270 int (*uadt)(struct ip_set *set, struct nlattr *tb[],
Jozsef Kadlecsik3d14b172011-06-16 18:49:17 +0200271 enum ipset_adt adt, u32 *lineno, u32 flags, bool retried);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100272
273 /* Low level add/del/test functions */
274 ipset_adtfn adt[IPSET_ADT_MAX];
275
276 /* When adding entries and set is full, try to resize the set */
277 int (*resize)(struct ip_set *set, bool retried);
278 /* Destroy the set */
279 void (*destroy)(struct ip_set *set);
280 /* Flush the elements */
281 void (*flush)(struct ip_set *set);
282 /* Expire entries before listing */
283 void (*expire)(struct ip_set *set);
284 /* List set header data */
285 int (*head)(struct ip_set *set, struct sk_buff *skb);
286 /* List elements */
287 int (*list)(const struct ip_set *set, struct sk_buff *skb,
288 struct netlink_callback *cb);
289
290 /* Return true if "b" set is the same as "a"
291 * according to the create set parameters */
292 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
293};
294
295/* The core set type structure */
296struct ip_set_type {
297 struct list_head list;
298
299 /* Typename */
300 char name[IPSET_MAXNAMELEN];
301 /* Protocol version */
302 u8 protocol;
303 /* Set features to control swapping */
304 u8 features;
305 /* Set type dimension */
306 u8 dimension;
Jan Engelhardtc15f1c82012-02-14 00:24:10 +0100307 /*
308 * Supported family: may be NFPROTO_UNSPEC for both
309 * NFPROTO_IPV4/NFPROTO_IPV6.
310 */
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100311 u8 family;
Jozsef Kadlecsikf1e00b32011-06-16 18:51:41 +0200312 /* Type revisions */
313 u8 revision_min, revision_max;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100314
315 /* Create set */
316 int (*create)(struct ip_set *set, struct nlattr *tb[], u32 flags);
317
318 /* Attribute policies */
319 const struct nla_policy create_policy[IPSET_ATTR_CREATE_MAX + 1];
320 const struct nla_policy adt_policy[IPSET_ATTR_ADT_MAX + 1];
321
322 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
323 struct module *me;
324};
325
326/* register and unregister set type */
327extern int ip_set_type_register(struct ip_set_type *set_type);
328extern void ip_set_type_unregister(struct ip_set_type *set_type);
329
330/* A generic IP set */
331struct ip_set {
332 /* The name of the set */
333 char name[IPSET_MAXNAMELEN];
334 /* Lock protecting the set data */
335 rwlock_t lock;
336 /* References to the set */
Jozsef Kadlecsik2f9f28b2011-04-04 15:19:25 +0200337 u32 ref;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100338 /* The core set type */
339 struct ip_set_type *type;
340 /* The type variant doing the real job */
341 const struct ip_set_type_variant *variant;
342 /* The actual INET family of the set */
343 u8 family;
Jozsef Kadlecsikf1e00b32011-06-16 18:51:41 +0200344 /* The type revision */
345 u8 revision;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100346 /* The type specific data */
347 void *data;
348};
349
350/* register and unregister set references */
351extern ip_set_id_t ip_set_get_byname(const char *name, struct ip_set **set);
352extern void ip_set_put_byindex(ip_set_id_t index);
Jozsef Kadlecsik15b4d932011-06-16 19:01:26 +0200353extern const char *ip_set_name_byindex(ip_set_id_t index);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100354extern ip_set_id_t ip_set_nfnl_get(const char *name);
355extern ip_set_id_t ip_set_nfnl_get_byindex(ip_set_id_t index);
356extern void ip_set_nfnl_put(ip_set_id_t index);
357
358/* API for iptables set match, and SET target */
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200359
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100360extern int ip_set_add(ip_set_id_t id, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200361 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200362 const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100363extern int ip_set_del(ip_set_id_t id, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200364 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200365 const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100366extern int ip_set_test(ip_set_id_t id, const struct sk_buff *skb,
Jozsef Kadlecsikb66554c2011-06-16 18:56:47 +0200367 const struct xt_action_param *par,
Jozsef Kadlecsikac8cc922011-06-16 18:42:40 +0200368 const struct ip_set_adt_opt *opt);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100369
370/* Utility functions */
Jozsef Kadlecsik15b4d932011-06-16 19:01:26 +0200371extern void *ip_set_alloc(size_t size);
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100372extern void ip_set_free(void *members);
373extern int ip_set_get_ipaddr4(struct nlattr *nla, __be32 *ipaddr);
374extern int ip_set_get_ipaddr6(struct nlattr *nla, union nf_inet_addr *ipaddr);
375
376static inline int
377ip_set_get_hostipaddr4(struct nlattr *nla, u32 *ipaddr)
378{
379 __be32 ip;
380 int ret = ip_set_get_ipaddr4(nla, &ip);
Jozsef Kadlecsik15b4d932011-06-16 19:01:26 +0200381
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100382 if (ret)
383 return ret;
384 *ipaddr = ntohl(ip);
385 return 0;
386}
387
388/* Ignore IPSET_ERR_EXIST errors if asked to do so? */
389static inline bool
390ip_set_eexist(int ret, u32 flags)
391{
392 return ret == -IPSET_ERR_EXIST && (flags & IPSET_FLAG_EXIST);
393}
394
395/* Check the NLA_F_NET_BYTEORDER flag */
396static inline bool
397ip_set_attr_netorder(struct nlattr *tb[], int type)
398{
399 return tb[type] && (tb[type]->nla_type & NLA_F_NET_BYTEORDER);
400}
401
402static inline bool
403ip_set_optattr_netorder(struct nlattr *tb[], int type)
404{
405 return !tb[type] || (tb[type]->nla_type & NLA_F_NET_BYTEORDER);
406}
407
408/* Useful converters */
409static inline u32
410ip_set_get_h32(const struct nlattr *attr)
411{
412 return ntohl(nla_get_be32(attr));
413}
414
415static inline u16
416ip_set_get_h16(const struct nlattr *attr)
417{
418 return ntohs(nla_get_be16(attr));
419}
420
421#define ipset_nest_start(skb, attr) nla_nest_start(skb, attr | NLA_F_NESTED)
422#define ipset_nest_end(skb, start) nla_nest_end(skb, start)
423
David S. Miller7cf78992012-04-01 19:54:46 -0400424static inline int nla_put_ipaddr4(struct sk_buff *skb, int type, __be32 ipaddr)
425{
426 struct nlattr *__nested = ipset_nest_start(skb, type);
427 int ret;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100428
David S. Miller7cf78992012-04-01 19:54:46 -0400429 if (!__nested)
430 return -EMSGSIZE;
431 ret = nla_put_net32(skb, IPSET_ATTR_IPADDR_IPV4, ipaddr);
432 if (!ret)
433 ipset_nest_end(skb, __nested);
434 return ret;
435}
436
Jozsef Kadlecsik3ace95c2012-09-21 22:01:45 +0200437static inline int nla_put_ipaddr6(struct sk_buff *skb, int type,
438 const struct in6_addr *ipaddrptr)
David S. Miller7cf78992012-04-01 19:54:46 -0400439{
440 struct nlattr *__nested = ipset_nest_start(skb, type);
441 int ret;
442
443 if (!__nested)
444 return -EMSGSIZE;
445 ret = nla_put(skb, IPSET_ATTR_IPADDR_IPV6,
446 sizeof(struct in6_addr), ipaddrptr);
447 if (!ret)
448 ipset_nest_end(skb, __nested);
449 return ret;
450}
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100451
452/* Get address from skbuff */
453static inline __be32
454ip4addr(const struct sk_buff *skb, bool src)
455{
456 return src ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr;
457}
458
459static inline void
460ip4addrptr(const struct sk_buff *skb, bool src, __be32 *addr)
461{
462 *addr = src ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr;
463}
464
465static inline void
466ip6addrptr(const struct sk_buff *skb, bool src, struct in6_addr *addr)
467{
468 memcpy(addr, src ? &ipv6_hdr(skb)->saddr : &ipv6_hdr(skb)->daddr,
469 sizeof(*addr));
470}
471
472/* Calculate the bytes required to store the inclusive range of a-b */
473static inline int
474bitmap_bytes(u32 a, u32 b)
475{
476 return 4 * ((((b - a + 8) / 8) + 3) / 4);
477}
478
Jan Engelhardtae8ded12012-01-14 16:26:20 +0100479#endif /* __KERNEL__ */
480
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100481/* Interface to iptables/ip6tables */
482
483#define SO_IP_SET 83
484
485union ip_set_name_index {
486 char name[IPSET_MAXNAMELEN];
487 ip_set_id_t index;
488};
489
490#define IP_SET_OP_GET_BYNAME 0x00000006 /* Get set index by name */
491struct ip_set_req_get_set {
Eric Dumazet95c96172012-04-15 05:58:06 +0000492 unsigned int op;
493 unsigned int version;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100494 union ip_set_name_index set;
495};
496
497#define IP_SET_OP_GET_BYINDEX 0x00000007 /* Get set name by index */
498/* Uses ip_set_req_get_set */
499
500#define IP_SET_OP_VERSION 0x00000100 /* Ask kernel version */
501struct ip_set_req_version {
Eric Dumazet95c96172012-04-15 05:58:06 +0000502 unsigned int op;
503 unsigned int version;
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100504};
505
Jozsef Kadlecsika7b4f982011-02-01 15:28:35 +0100506#endif /*_IP_SET_H */