[NETFILTER]: x_tables: simplify compat API
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / netfilter / x_tables.h
CommitLineData
2e4e6a17
HW
1#ifndef _X_TABLES_H
2#define _X_TABLES_H
3
4#define XT_FUNCTION_MAXNAMELEN 30
5#define XT_TABLE_MAXNAMELEN 32
6
1e30a014
DM
7struct xt_entry_match
8{
9 union {
10 struct {
11 u_int16_t match_size;
12
13 /* Used by userspace */
14 char name[XT_FUNCTION_MAXNAMELEN-1];
15
16 u_int8_t revision;
17 } user;
18 struct {
19 u_int16_t match_size;
20
21 /* Used inside the kernel */
22 struct xt_match *match;
23 } kernel;
24
25 /* Total length */
26 u_int16_t match_size;
27 } u;
28
29 unsigned char data[0];
30};
31
32struct xt_entry_target
33{
34 union {
35 struct {
36 u_int16_t target_size;
37
38 /* Used by userspace */
39 char name[XT_FUNCTION_MAXNAMELEN-1];
40
41 u_int8_t revision;
42 } user;
43 struct {
44 u_int16_t target_size;
45
46 /* Used inside the kernel */
47 struct xt_target *target;
48 } kernel;
49
50 /* Total length */
51 u_int16_t target_size;
52 } u;
53
54 unsigned char data[0];
55};
56
57struct xt_standard_target
58{
59 struct xt_entry_target target;
60 int verdict;
61};
62
2e4e6a17
HW
63/* The argument to IPT_SO_GET_REVISION_*. Returns highest revision
64 * kernel supports, if >= revision. */
65struct xt_get_revision
66{
67 char name[XT_FUNCTION_MAXNAMELEN-1];
68
69 u_int8_t revision;
70};
71
72/* CONTINUE verdict for targets */
73#define XT_CONTINUE 0xFFFFFFFF
74
75/* For standard target */
76#define XT_RETURN (-NF_REPEAT - 1)
77
6fbfc968
DM
78/* this is a dummy structure to find out the alignment requirement for a struct
79 * containing all the fundamental data types that are used in ipt_entry,
80 * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my
81 * personal pleasure to remove it -HW
82 */
83struct _xt_align
84{
85 u_int8_t u8;
86 u_int16_t u16;
87 u_int32_t u32;
88 u_int64_t u64;
89};
90
91#define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \
92 & ~(__alignof__(struct _xt_align)-1))
2e4e6a17
HW
93
94/* Standard return verdict, or do jump. */
95#define XT_STANDARD_TARGET ""
96/* Error verdict. */
97#define XT_ERROR_TARGET "ERROR"
98
99/*
100 * New IP firewall options for [gs]etsockopt at the RAW IP level.
101 * Unlike BSD Linux inherits IP options so you don't have to use a raw
102 * socket for this. Instead we check rights in the calls. */
103#define XT_BASE_CTL 64 /* base for firewall socket options */
104
105#define XT_SO_SET_REPLACE (XT_BASE_CTL)
106#define XT_SO_SET_ADD_COUNTERS (XT_BASE_CTL + 1)
107#define XT_SO_SET_MAX XT_SO_SET_ADD_COUNTERS
108
109#define XT_SO_GET_INFO (XT_BASE_CTL)
110#define XT_SO_GET_ENTRIES (XT_BASE_CTL + 1)
111#define XT_SO_GET_REVISION_MATCH (XT_BASE_CTL + 2)
112#define XT_SO_GET_REVISION_TARGET (XT_BASE_CTL + 3)
113#define XT_SO_GET_MAX XT_SO_GET_REVISION_TARGET
114
115#define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
116#define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
117
118struct xt_counters
119{
120 u_int64_t pcnt, bcnt; /* Packet and byte counters */
121};
122
123/* The argument to IPT_SO_ADD_COUNTERS. */
124struct xt_counters_info
125{
126 /* Which table. */
127 char name[XT_TABLE_MAXNAMELEN];
128
129 unsigned int num_counters;
130
131 /* The counters (actually `number' of these). */
132 struct xt_counters counters[0];
133};
134
135#define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
136
137#ifdef __KERNEL__
138
139#include <linux/netdevice.h>
140
2e4e6a17
HW
141struct xt_match
142{
143 struct list_head list;
144
145 const char name[XT_FUNCTION_MAXNAMELEN-1];
146
2e4e6a17
HW
147 /* Return true or false: return FALSE and set *hotdrop = 1 to
148 force immediate packet drop. */
149 /* Arguments changed since 2.6.9, as this must now handle
150 non-linear skb, using skb_header_pointer and
151 skb_ip_make_writable. */
152 int (*match)(const struct sk_buff *skb,
153 const struct net_device *in,
154 const struct net_device *out,
1c524830 155 const struct xt_match *match,
2e4e6a17
HW
156 const void *matchinfo,
157 int offset,
158 unsigned int protoff,
159 int *hotdrop);
160
161 /* Called when user tries to insert an entry of this type. */
162 /* Should return true or false. */
163 int (*checkentry)(const char *tablename,
164 const void *ip,
1c524830 165 const struct xt_match *match,
2e4e6a17 166 void *matchinfo,
2e4e6a17
HW
167 unsigned int hook_mask);
168
169 /* Called when entry of this type deleted. */
efa74165 170 void (*destroy)(const struct xt_match *match, void *matchinfo);
2e4e6a17 171
2722971c 172 /* Called when userspace align differs from kernel space one */
9fa492cd
PM
173 void (*compat_from_user)(void *dst, void *src);
174 int (*compat_to_user)(void __user *dst, void *src);
2722971c 175
2e4e6a17
HW
176 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
177 struct module *me;
37f9f733 178
91270cf8
PM
179 /* Free to use by each match */
180 unsigned long data;
181
37f9f733
PM
182 char *table;
183 unsigned int matchsize;
9fa492cd 184 unsigned int compatsize;
37f9f733
PM
185 unsigned int hooks;
186 unsigned short proto;
c4b88513
PM
187
188 unsigned short family;
37f9f733 189 u_int8_t revision;
2e4e6a17
HW
190};
191
192/* Registration hooks for targets. */
193struct xt_target
194{
195 struct list_head list;
196
197 const char name[XT_FUNCTION_MAXNAMELEN-1];
198
2e4e6a17
HW
199 /* Returns verdict. Argument order changed since 2.6.9, as this
200 must now handle non-linear skbs, using skb_copy_bits and
201 skb_ip_make_writable. */
202 unsigned int (*target)(struct sk_buff **pskb,
203 const struct net_device *in,
204 const struct net_device *out,
205 unsigned int hooknum,
1c524830 206 const struct xt_target *target,
fe1cb108 207 const void *targinfo);
2e4e6a17
HW
208
209 /* Called when user tries to insert an entry of this type:
210 hook_mask is a bitmask of hooks from which it can be
211 called. */
212 /* Should return true or false. */
213 int (*checkentry)(const char *tablename,
214 const void *entry,
1c524830 215 const struct xt_target *target,
2e4e6a17 216 void *targinfo,
2e4e6a17
HW
217 unsigned int hook_mask);
218
219 /* Called when entry of this type deleted. */
efa74165 220 void (*destroy)(const struct xt_target *target, void *targinfo);
2e4e6a17 221
2722971c 222 /* Called when userspace align differs from kernel space one */
9fa492cd
PM
223 void (*compat_from_user)(void *dst, void *src);
224 int (*compat_to_user)(void __user *dst, void *src);
2722971c 225
2e4e6a17
HW
226 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
227 struct module *me;
37f9f733
PM
228
229 char *table;
230 unsigned int targetsize;
9fa492cd 231 unsigned int compatsize;
37f9f733
PM
232 unsigned int hooks;
233 unsigned short proto;
c4b88513
PM
234
235 unsigned short family;
37f9f733 236 u_int8_t revision;
2e4e6a17
HW
237};
238
239/* Furniture shopping... */
240struct xt_table
241{
242 struct list_head list;
243
244 /* A unique name... */
245 char name[XT_TABLE_MAXNAMELEN];
246
247 /* What hooks you will enter on */
248 unsigned int valid_hooks;
249
250 /* Lock for the curtain */
251 rwlock_t lock;
252
253 /* Man behind the curtain... */
254 //struct ip6t_table_info *private;
255 void *private;
256
257 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
258 struct module *me;
259
260 int af; /* address/protocol family */
261};
262
263#include <linux/netfilter_ipv4.h>
264
265/* The table itself */
266struct xt_table_info
267{
268 /* Size per table */
269 unsigned int size;
270 /* Number of entries: FIXME. --RR */
271 unsigned int number;
272 /* Initial number of entries. Needed for module usage count */
273 unsigned int initial_entries;
274
275 /* Entry points and underflows */
276 unsigned int hook_entry[NF_IP_NUMHOOKS];
277 unsigned int underflow[NF_IP_NUMHOOKS];
278
279 /* ipt_entry tables: one per CPU */
280 char *entries[NR_CPUS];
281};
282
a45049c5
PNA
283extern int xt_register_target(struct xt_target *target);
284extern void xt_unregister_target(struct xt_target *target);
52d9c42e
PM
285extern int xt_register_targets(struct xt_target *target, unsigned int n);
286extern void xt_unregister_targets(struct xt_target *target, unsigned int n);
287
a45049c5
PNA
288extern int xt_register_match(struct xt_match *target);
289extern void xt_unregister_match(struct xt_match *target);
52d9c42e
PM
290extern int xt_register_matches(struct xt_match *match, unsigned int n);
291extern void xt_unregister_matches(struct xt_match *match, unsigned int n);
2e4e6a17 292
37f9f733
PM
293extern int xt_check_match(const struct xt_match *match, unsigned short family,
294 unsigned int size, const char *table, unsigned int hook,
295 unsigned short proto, int inv_proto);
296extern int xt_check_target(const struct xt_target *target, unsigned short family,
297 unsigned int size, const char *table, unsigned int hook,
298 unsigned short proto, int inv_proto);
299
2e4e6a17
HW
300extern int xt_register_table(struct xt_table *table,
301 struct xt_table_info *bootstrap,
302 struct xt_table_info *newinfo);
303extern void *xt_unregister_table(struct xt_table *table);
304
305extern struct xt_table_info *xt_replace_table(struct xt_table *table,
306 unsigned int num_counters,
307 struct xt_table_info *newinfo,
308 int *error);
309
310extern struct xt_match *xt_find_match(int af, const char *name, u8 revision);
311extern struct xt_target *xt_find_target(int af, const char *name, u8 revision);
312extern struct xt_target *xt_request_find_target(int af, const char *name,
313 u8 revision);
314extern int xt_find_revision(int af, const char *name, u8 revision, int target,
315 int *err);
316
317extern struct xt_table *xt_find_table_lock(int af, const char *name);
318extern void xt_table_unlock(struct xt_table *t);
319
320extern int xt_proto_init(int af);
321extern void xt_proto_fini(int af);
322
323extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
324extern void xt_free_table_info(struct xt_table_info *info);
325
2722971c
DM
326#ifdef CONFIG_COMPAT
327#include <net/compat.h>
328
329struct compat_xt_entry_match
330{
331 union {
332 struct {
333 u_int16_t match_size;
334 char name[XT_FUNCTION_MAXNAMELEN - 1];
335 u_int8_t revision;
336 } user;
46c5ea3c
PM
337 struct {
338 u_int16_t match_size;
339 compat_uptr_t match;
340 } kernel;
2722971c
DM
341 u_int16_t match_size;
342 } u;
343 unsigned char data[0];
344};
345
346struct compat_xt_entry_target
347{
348 union {
349 struct {
350 u_int16_t target_size;
351 char name[XT_FUNCTION_MAXNAMELEN - 1];
352 u_int8_t revision;
353 } user;
46c5ea3c
PM
354 struct {
355 u_int16_t target_size;
356 compat_uptr_t target;
357 } kernel;
2722971c
DM
358 u_int16_t target_size;
359 } u;
360 unsigned char data[0];
361};
362
363/* FIXME: this works only on 32 bit tasks
364 * need to change whole approach in order to calculate align as function of
365 * current task alignment */
366
367struct compat_xt_counters
368{
55fe5866 369#if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2722971c 370 u_int32_t cnt[4];
55fe5866
PM
371#else
372 u_int64_t cnt[2];
373#endif
2722971c
DM
374};
375
376struct compat_xt_counters_info
377{
378 char name[XT_TABLE_MAXNAMELEN];
379 compat_uint_t num_counters;
380 struct compat_xt_counters counters[0];
381};
382
383#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
384 & ~(__alignof__(struct compat_xt_counters)-1))
385
386extern void xt_compat_lock(int af);
387extern void xt_compat_unlock(int af);
9fa492cd
PM
388
389extern int xt_compat_match_offset(struct xt_match *match);
390extern void xt_compat_match_from_user(struct xt_entry_match *m,
391 void **dstptr, int *size);
392extern int xt_compat_match_to_user(struct xt_entry_match *m,
393 void * __user *dstptr, int *size);
394
395extern int xt_compat_target_offset(struct xt_target *target);
396extern void xt_compat_target_from_user(struct xt_entry_target *t,
397 void **dstptr, int *size);
398extern int xt_compat_target_to_user(struct xt_entry_target *t,
399 void * __user *dstptr, int *size);
2722971c
DM
400
401#endif /* CONFIG_COMPAT */
2e4e6a17
HW
402#endif /* __KERNEL__ */
403
404#endif /* _X_TABLES_H */