]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/uapi/linux/netfilter/ipset/ip_set.h
Merge remote-tracking branch 'slave-dma/next'
[karo-tx-linux.git] / include / uapi / linux / netfilter / ipset / ip_set.h
1 /* 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 _UAPI_IP_SET_H
11 #define _UAPI_IP_SET_H
12
13
14 #include <linux/types.h>
15
16 /* 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 */
23 enum 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 */
52 enum {
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 */
71 enum {
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 */
103 enum {
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,
109         IPSET_ATTR_IP2_TO,
110         IPSET_ATTR_IFACE,
111         IPSET_ATTR_BYTES,
112         IPSET_ATTR_PACKETS,
113         __IPSET_ATTR_ADT_MAX,
114 };
115 #define IPSET_ATTR_ADT_MAX      (__IPSET_ATTR_ADT_MAX - 1)
116
117 /* IP specific attributes */
118 enum {
119         IPSET_ATTR_IPADDR_IPV4 = IPSET_ATTR_UNSPEC + 1,
120         IPSET_ATTR_IPADDR_IPV6,
121         __IPSET_ATTR_IPADDR_MAX,
122 };
123 #define IPSET_ATTR_IPADDR_MAX   (__IPSET_ATTR_IPADDR_MAX - 1)
124
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
144         /* Type specific error codes */
145         IPSET_ERR_TYPE_SPECIFIC = 4352,
146 };
147
148 /* Flags at command level or match/target flags, lower half of cmdattrs*/
149 enum ipset_cmd_flags {
150         IPSET_FLAG_BIT_EXIST    = 0,
151         IPSET_FLAG_EXIST        = (1 << IPSET_FLAG_BIT_EXIST),
152         IPSET_FLAG_BIT_LIST_SETNAME = 1,
153         IPSET_FLAG_LIST_SETNAME = (1 << IPSET_FLAG_BIT_LIST_SETNAME),
154         IPSET_FLAG_BIT_LIST_HEADER = 2,
155         IPSET_FLAG_LIST_HEADER  = (1 << IPSET_FLAG_BIT_LIST_HEADER),
156         IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE = 3,
157         IPSET_FLAG_SKIP_COUNTER_UPDATE =
158                 (1 << IPSET_FLAG_BIT_SKIP_COUNTER_UPDATE),
159         IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE = 4,
160         IPSET_FLAG_SKIP_SUBCOUNTER_UPDATE =
161                 (1 << IPSET_FLAG_BIT_SKIP_SUBCOUNTER_UPDATE),
162         IPSET_FLAG_BIT_MATCH_COUNTERS = 5,
163         IPSET_FLAG_MATCH_COUNTERS = (1 << IPSET_FLAG_BIT_MATCH_COUNTERS),
164         IPSET_FLAG_BIT_RETURN_NOMATCH = 7,
165         IPSET_FLAG_RETURN_NOMATCH = (1 << IPSET_FLAG_BIT_RETURN_NOMATCH),
166         IPSET_FLAG_CMD_MAX = 15,
167 };
168
169 /* Flags at CADT attribute level, upper half of cmdattrs */
170 enum ipset_cadt_flags {
171         IPSET_FLAG_BIT_BEFORE   = 0,
172         IPSET_FLAG_BEFORE       = (1 << IPSET_FLAG_BIT_BEFORE),
173         IPSET_FLAG_BIT_PHYSDEV  = 1,
174         IPSET_FLAG_PHYSDEV      = (1 << IPSET_FLAG_BIT_PHYSDEV),
175         IPSET_FLAG_BIT_NOMATCH  = 2,
176         IPSET_FLAG_NOMATCH      = (1 << IPSET_FLAG_BIT_NOMATCH),
177         IPSET_FLAG_BIT_WITH_COUNTERS = 3,
178         IPSET_FLAG_WITH_COUNTERS = (1 << IPSET_FLAG_BIT_WITH_COUNTERS),
179         IPSET_FLAG_CADT_MAX     = 15,
180 };
181
182 /* Commands with settype-specific attributes */
183 enum ipset_adt {
184         IPSET_ADD,
185         IPSET_DEL,
186         IPSET_TEST,
187         IPSET_ADT_MAX,
188         IPSET_CREATE = IPSET_ADT_MAX,
189         IPSET_CADT_MAX,
190 };
191
192 /* Sets are identified by an index in kernel space. Tweak with ip_set_id_t
193  * and IPSET_INVALID_ID if you want to increase the max number of sets.
194  */
195 typedef __u16 ip_set_id_t;
196
197 #define IPSET_INVALID_ID                65535
198
199 enum ip_set_dim {
200         IPSET_DIM_ZERO = 0,
201         IPSET_DIM_ONE,
202         IPSET_DIM_TWO,
203         IPSET_DIM_THREE,
204         /* Max dimension in elements.
205          * If changed, new revision of iptables match/target is required.
206          */
207         IPSET_DIM_MAX = 6,
208         /* Backward compatibility: set match revision 2 */
209         IPSET_BIT_RETURN_NOMATCH = 7,
210 };
211
212 /* Option flags for kernel operations */
213 enum ip_set_kopt {
214         IPSET_INV_MATCH = (1 << IPSET_DIM_ZERO),
215         IPSET_DIM_ONE_SRC = (1 << IPSET_DIM_ONE),
216         IPSET_DIM_TWO_SRC = (1 << IPSET_DIM_TWO),
217         IPSET_DIM_THREE_SRC = (1 << IPSET_DIM_THREE),
218         IPSET_RETURN_NOMATCH = (1 << IPSET_BIT_RETURN_NOMATCH),
219 };
220
221 enum {
222         IPSET_COUNTER_NONE = 0,
223         IPSET_COUNTER_EQ,
224         IPSET_COUNTER_NE,
225         IPSET_COUNTER_LT,
226         IPSET_COUNTER_GT,
227 };
228
229 struct ip_set_counter_match {
230         __u8 op;
231         __u64 value;
232 };
233
234 /* Interface to iptables/ip6tables */
235
236 #define SO_IP_SET               83
237
238 union ip_set_name_index {
239         char name[IPSET_MAXNAMELEN];
240         ip_set_id_t index;
241 };
242
243 #define IP_SET_OP_GET_BYNAME    0x00000006      /* Get set index by name */
244 struct ip_set_req_get_set {
245         unsigned int op;
246         unsigned int version;
247         union ip_set_name_index set;
248 };
249
250 #define IP_SET_OP_GET_BYINDEX   0x00000007      /* Get set name by index */
251 /* Uses ip_set_req_get_set */
252
253 #define IP_SET_OP_VERSION       0x00000100      /* Ask kernel version */
254 struct ip_set_req_version {
255         unsigned int op;
256         unsigned int version;
257 };
258
259 #endif /* _UAPI_IP_SET_H */