net: Avoid extra wakeups of threads blocked in wait_for_packet()
[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
60c195c7
AB
4#include <linux/types.h>
5
2e4e6a17
HW
6#define XT_FUNCTION_MAXNAMELEN 30
7#define XT_TABLE_MAXNAMELEN 32
8
1e30a014
DM
9struct xt_entry_match
10{
11 union {
12 struct {
60c195c7 13 __u16 match_size;
1e30a014
DM
14
15 /* Used by userspace */
16 char name[XT_FUNCTION_MAXNAMELEN-1];
17
60c195c7 18 __u8 revision;
1e30a014
DM
19 } user;
20 struct {
60c195c7 21 __u16 match_size;
1e30a014
DM
22
23 /* Used inside the kernel */
24 struct xt_match *match;
25 } kernel;
26
27 /* Total length */
60c195c7 28 __u16 match_size;
1e30a014
DM
29 } u;
30
31 unsigned char data[0];
32};
33
34struct xt_entry_target
35{
36 union {
37 struct {
60c195c7 38 __u16 target_size;
1e30a014
DM
39
40 /* Used by userspace */
41 char name[XT_FUNCTION_MAXNAMELEN-1];
42
60c195c7 43 __u8 revision;
1e30a014
DM
44 } user;
45 struct {
60c195c7 46 __u16 target_size;
1e30a014
DM
47
48 /* Used inside the kernel */
49 struct xt_target *target;
50 } kernel;
51
52 /* Total length */
60c195c7 53 __u16 target_size;
1e30a014
DM
54 } u;
55
56 unsigned char data[0];
57};
58
3c2ad469
PM
59#define XT_TARGET_INIT(__name, __size) \
60{ \
61 .target.u.user = { \
62 .target_size = XT_ALIGN(__size), \
63 .name = __name, \
64 }, \
65}
66
1e30a014
DM
67struct xt_standard_target
68{
69 struct xt_entry_target target;
70 int verdict;
71};
72
2e4e6a17
HW
73/* The argument to IPT_SO_GET_REVISION_*. Returns highest revision
74 * kernel supports, if >= revision. */
75struct xt_get_revision
76{
77 char name[XT_FUNCTION_MAXNAMELEN-1];
78
60c195c7 79 __u8 revision;
2e4e6a17
HW
80};
81
82/* CONTINUE verdict for targets */
83#define XT_CONTINUE 0xFFFFFFFF
84
85/* For standard target */
86#define XT_RETURN (-NF_REPEAT - 1)
87
6fbfc968
DM
88/* this is a dummy structure to find out the alignment requirement for a struct
89 * containing all the fundamental data types that are used in ipt_entry,
90 * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my
91 * personal pleasure to remove it -HW
92 */
93struct _xt_align
94{
60c195c7
AB
95 __u8 u8;
96 __u16 u16;
97 __u32 u32;
98 __u64 u64;
6fbfc968
DM
99};
100
101#define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \
102 & ~(__alignof__(struct _xt_align)-1))
2e4e6a17
HW
103
104/* Standard return verdict, or do jump. */
105#define XT_STANDARD_TARGET ""
106/* Error verdict. */
107#define XT_ERROR_TARGET "ERROR"
108
2e4e6a17
HW
109#define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
110#define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
111
112struct xt_counters
113{
60c195c7 114 __u64 pcnt, bcnt; /* Packet and byte counters */
2e4e6a17
HW
115};
116
117/* The argument to IPT_SO_ADD_COUNTERS. */
118struct xt_counters_info
119{
120 /* Which table. */
121 char name[XT_TABLE_MAXNAMELEN];
122
123 unsigned int num_counters;
124
125 /* The counters (actually `number' of these). */
126 struct xt_counters counters[0];
127};
128
129#define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
130
89c002d6
PM
131/* fn returns 0 to continue iteration */
132#define XT_MATCH_ITERATE(type, e, fn, args...) \
133({ \
134 unsigned int __i; \
135 int __ret = 0; \
136 struct xt_entry_match *__m; \
137 \
138 for (__i = sizeof(type); \
139 __i < (e)->target_offset; \
140 __i += __m->u.match_size) { \
141 __m = (void *)e + __i; \
142 \
143 __ret = fn(__m , ## args); \
144 if (__ret != 0) \
145 break; \
146 } \
147 __ret; \
148})
149
150/* fn returns 0 to continue iteration */
151#define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \
152({ \
153 unsigned int __i, __n; \
154 int __ret = 0; \
155 type *__entry; \
156 \
157 for (__i = 0, __n = 0; __i < (size); \
158 __i += __entry->next_offset, __n++) { \
159 __entry = (void *)(entries) + __i; \
160 if (__n < n) \
161 continue; \
162 \
163 __ret = fn(__entry , ## args); \
164 if (__ret != 0) \
165 break; \
166 } \
167 __ret; \
168})
169
170/* fn returns 0 to continue iteration */
171#define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \
172 XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args)
173
2e4e6a17
HW
174#ifdef __KERNEL__
175
176#include <linux/netdevice.h>
177
f7108a20
JE
178/**
179 * struct xt_match_param - parameters for match extensions' match functions
180 *
181 * @in: input netdevice
182 * @out: output netdevice
183 * @match: struct xt_match through which this function was invoked
184 * @matchinfo: per-match data
185 * @fragoff: packet is a fragment, this is the data offset
186 * @thoff: position of transport header relative to skb->data
187 * @hotdrop: drop packet if we had inspection problems
916a917d
JE
188 * @family: Actual NFPROTO_* through which the function is invoked
189 * (helpful when match->family == NFPROTO_UNSPEC)
f7108a20
JE
190 */
191struct xt_match_param {
192 const struct net_device *in, *out;
193 const struct xt_match *match;
194 const void *matchinfo;
195 int fragoff;
196 unsigned int thoff;
197 bool *hotdrop;
916a917d 198 u_int8_t family;
f7108a20
JE
199};
200
9b4fce7a
JE
201/**
202 * struct xt_mtchk_param - parameters for match extensions'
203 * checkentry functions
204 *
205 * @table: table the rule is tried to be inserted into
206 * @entryinfo: the family-specific rule data
207 * (struct ipt_ip, ip6t_ip, ebt_entry)
208 * @match: struct xt_match through which this function was invoked
209 * @matchinfo: per-match data
210 * @hook_mask: via which hooks the new rule is reachable
211 */
212struct xt_mtchk_param {
213 const char *table;
214 const void *entryinfo;
215 const struct xt_match *match;
216 void *matchinfo;
217 unsigned int hook_mask;
916a917d 218 u_int8_t family;
9b4fce7a
JE
219};
220
6be3d859
JE
221/* Match destructor parameters */
222struct xt_mtdtor_param {
223 const struct xt_match *match;
224 void *matchinfo;
916a917d 225 u_int8_t family;
6be3d859
JE
226};
227
7eb35586
JE
228/**
229 * struct xt_target_param - parameters for target extensions' target functions
230 *
231 * @hooknum: hook through which this target was invoked
232 * @target: struct xt_target through which this function was invoked
233 * @targinfo: per-target data
234 *
235 * Other fields see above.
236 */
237struct xt_target_param {
238 const struct net_device *in, *out;
239 unsigned int hooknum;
240 const struct xt_target *target;
241 const void *targinfo;
916a917d 242 u_int8_t family;
7eb35586
JE
243};
244
af5d6dc2
JE
245/**
246 * struct xt_tgchk_param - parameters for target extensions'
247 * checkentry functions
248 *
249 * @entryinfo: the family-specific rule data
250 * (struct ipt_entry, ip6t_entry, arpt_entry, ebt_entry)
251 *
252 * Other fields see above.
253 */
254struct xt_tgchk_param {
255 const char *table;
f79fca55 256 const void *entryinfo;
af5d6dc2
JE
257 const struct xt_target *target;
258 void *targinfo;
259 unsigned int hook_mask;
916a917d 260 u_int8_t family;
af5d6dc2
JE
261};
262
a2df1648
JE
263/* Target destructor parameters */
264struct xt_tgdtor_param {
265 const struct xt_target *target;
266 void *targinfo;
916a917d 267 u_int8_t family;
a2df1648
JE
268};
269
2e4e6a17
HW
270struct xt_match
271{
272 struct list_head list;
273
274 const char name[XT_FUNCTION_MAXNAMELEN-1];
daaf83d2 275 u_int8_t revision;
2e4e6a17 276
2e4e6a17
HW
277 /* Return true or false: return FALSE and set *hotdrop = 1 to
278 force immediate packet drop. */
279 /* Arguments changed since 2.6.9, as this must now handle
280 non-linear skb, using skb_header_pointer and
281 skb_ip_make_writable. */
1d93a9cb 282 bool (*match)(const struct sk_buff *skb,
f7108a20 283 const struct xt_match_param *);
2e4e6a17
HW
284
285 /* Called when user tries to insert an entry of this type. */
9b4fce7a 286 bool (*checkentry)(const struct xt_mtchk_param *);
2e4e6a17
HW
287
288 /* Called when entry of this type deleted. */
6be3d859 289 void (*destroy)(const struct xt_mtdtor_param *);
2e4e6a17 290
2722971c 291 /* Called when userspace align differs from kernel space one */
9fa492cd
PM
292 void (*compat_from_user)(void *dst, void *src);
293 int (*compat_to_user)(void __user *dst, void *src);
2722971c 294
2e4e6a17
HW
295 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
296 struct module *me;
37f9f733 297
91270cf8
PM
298 /* Free to use by each match */
299 unsigned long data;
300
ecb6f85e 301 const char *table;
37f9f733 302 unsigned int matchsize;
9fa492cd 303 unsigned int compatsize;
37f9f733
PM
304 unsigned int hooks;
305 unsigned short proto;
c4b88513
PM
306
307 unsigned short family;
2e4e6a17
HW
308};
309
310/* Registration hooks for targets. */
311struct xt_target
312{
313 struct list_head list;
314
315 const char name[XT_FUNCTION_MAXNAMELEN-1];
316
2e4e6a17
HW
317 /* Returns verdict. Argument order changed since 2.6.9, as this
318 must now handle non-linear skbs, using skb_copy_bits and
319 skb_ip_make_writable. */
3db05fea 320 unsigned int (*target)(struct sk_buff *skb,
7eb35586 321 const struct xt_target_param *);
2e4e6a17
HW
322
323 /* Called when user tries to insert an entry of this type:
324 hook_mask is a bitmask of hooks from which it can be
325 called. */
326 /* Should return true or false. */
af5d6dc2 327 bool (*checkentry)(const struct xt_tgchk_param *);
2e4e6a17
HW
328
329 /* Called when entry of this type deleted. */
a2df1648 330 void (*destroy)(const struct xt_tgdtor_param *);
2e4e6a17 331
2722971c 332 /* Called when userspace align differs from kernel space one */
9fa492cd
PM
333 void (*compat_from_user)(void *dst, void *src);
334 int (*compat_to_user)(void __user *dst, void *src);
2722971c 335
2e4e6a17
HW
336 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
337 struct module *me;
37f9f733 338
ecb6f85e 339 const char *table;
37f9f733 340 unsigned int targetsize;
9fa492cd 341 unsigned int compatsize;
37f9f733
PM
342 unsigned int hooks;
343 unsigned short proto;
c4b88513
PM
344
345 unsigned short family;
37f9f733 346 u_int8_t revision;
2e4e6a17
HW
347};
348
349/* Furniture shopping... */
350struct xt_table
351{
352 struct list_head list;
353
2e4e6a17
HW
354 /* What hooks you will enter on */
355 unsigned int valid_hooks;
356
357 /* Lock for the curtain */
78454473 358 struct mutex lock;
2e4e6a17
HW
359
360 /* Man behind the curtain... */
4a2f965c 361 struct xt_table_info *private;
2e4e6a17
HW
362
363 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
364 struct module *me;
365
76108cea 366 u_int8_t af; /* address/protocol family */
4a2f965c
SH
367
368 /* A unique name... */
369 const char name[XT_TABLE_MAXNAMELEN];
2e4e6a17
HW
370};
371
372#include <linux/netfilter_ipv4.h>
373
374/* The table itself */
375struct xt_table_info
376{
377 /* Size per table */
378 unsigned int size;
379 /* Number of entries: FIXME. --RR */
380 unsigned int number;
381 /* Initial number of entries. Needed for module usage count */
382 unsigned int initial_entries;
383
384 /* Entry points and underflows */
6e23ae2a
PM
385 unsigned int hook_entry[NF_INET_NUMHOOKS];
386 unsigned int underflow[NF_INET_NUMHOOKS];
2e4e6a17
HW
387
388 /* ipt_entry tables: one per CPU */
259d4e41 389 /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
78454473 390 void *entries[1];
2e4e6a17
HW
391};
392
259d4e41
ED
393#define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \
394 + nr_cpu_ids * sizeof(char *))
a45049c5
PNA
395extern int xt_register_target(struct xt_target *target);
396extern void xt_unregister_target(struct xt_target *target);
52d9c42e
PM
397extern int xt_register_targets(struct xt_target *target, unsigned int n);
398extern void xt_unregister_targets(struct xt_target *target, unsigned int n);
399
a45049c5
PNA
400extern int xt_register_match(struct xt_match *target);
401extern void xt_unregister_match(struct xt_match *target);
52d9c42e
PM
402extern int xt_register_matches(struct xt_match *match, unsigned int n);
403extern void xt_unregister_matches(struct xt_match *match, unsigned int n);
2e4e6a17 404
916a917d 405extern int xt_check_match(struct xt_mtchk_param *,
9b4fce7a 406 unsigned int size, u_int8_t proto, bool inv_proto);
916a917d 407extern int xt_check_target(struct xt_tgchk_param *,
af5d6dc2 408 unsigned int size, u_int8_t proto, bool inv_proto);
37f9f733 409
8d870052
AD
410extern struct xt_table *xt_register_table(struct net *net,
411 struct xt_table *table,
a98da11d
AD
412 struct xt_table_info *bootstrap,
413 struct xt_table_info *newinfo);
2e4e6a17
HW
414extern void *xt_unregister_table(struct xt_table *table);
415
416extern struct xt_table_info *xt_replace_table(struct xt_table *table,
417 unsigned int num_counters,
418 struct xt_table_info *newinfo,
419 int *error);
420
76108cea
JE
421extern struct xt_match *xt_find_match(u8 af, const char *name, u8 revision);
422extern struct xt_target *xt_find_target(u8 af, const char *name, u8 revision);
423extern struct xt_target *xt_request_find_target(u8 af, const char *name,
2e4e6a17 424 u8 revision);
76108cea
JE
425extern int xt_find_revision(u8 af, const char *name, u8 revision,
426 int target, int *err);
2e4e6a17 427
76108cea 428extern struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
8d870052 429 const char *name);
2e4e6a17
HW
430extern void xt_table_unlock(struct xt_table *t);
431
76108cea
JE
432extern int xt_proto_init(struct net *net, u_int8_t af);
433extern void xt_proto_fini(struct net *net, u_int8_t af);
2e4e6a17
HW
434
435extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
436extern void xt_free_table_info(struct xt_table_info *info);
78454473
SH
437extern void xt_table_entry_swap_rcu(struct xt_table_info *old,
438 struct xt_table_info *new);
2e4e6a17 439
b8dfe498
ED
440/*
441 * This helper is performance critical and must be inlined
442 */
443static inline unsigned long ifname_compare_aligned(const char *_a,
444 const char *_b,
445 const char *_mask)
446{
447 const unsigned long *a = (const unsigned long *)_a;
448 const unsigned long *b = (const unsigned long *)_b;
449 const unsigned long *mask = (const unsigned long *)_mask;
450 unsigned long ret;
451
452 ret = (a[0] ^ b[0]) & mask[0];
453 if (IFNAMSIZ > sizeof(unsigned long))
454 ret |= (a[1] ^ b[1]) & mask[1];
455 if (IFNAMSIZ > 2 * sizeof(unsigned long))
456 ret |= (a[2] ^ b[2]) & mask[2];
457 if (IFNAMSIZ > 3 * sizeof(unsigned long))
458 ret |= (a[3] ^ b[3]) & mask[3];
459 BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
460 return ret;
461}
462
2722971c
DM
463#ifdef CONFIG_COMPAT
464#include <net/compat.h>
465
466struct compat_xt_entry_match
467{
468 union {
469 struct {
470 u_int16_t match_size;
471 char name[XT_FUNCTION_MAXNAMELEN - 1];
472 u_int8_t revision;
473 } user;
46c5ea3c
PM
474 struct {
475 u_int16_t match_size;
476 compat_uptr_t match;
477 } kernel;
2722971c
DM
478 u_int16_t match_size;
479 } u;
480 unsigned char data[0];
481};
482
483struct compat_xt_entry_target
484{
485 union {
486 struct {
487 u_int16_t target_size;
488 char name[XT_FUNCTION_MAXNAMELEN - 1];
489 u_int8_t revision;
490 } user;
46c5ea3c
PM
491 struct {
492 u_int16_t target_size;
493 compat_uptr_t target;
494 } kernel;
2722971c
DM
495 u_int16_t target_size;
496 } u;
497 unsigned char data[0];
498};
499
500/* FIXME: this works only on 32 bit tasks
501 * need to change whole approach in order to calculate align as function of
502 * current task alignment */
503
504struct compat_xt_counters
505{
55fe5866 506#if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
2722971c 507 u_int32_t cnt[4];
55fe5866
PM
508#else
509 u_int64_t cnt[2];
510#endif
2722971c
DM
511};
512
513struct compat_xt_counters_info
514{
515 char name[XT_TABLE_MAXNAMELEN];
516 compat_uint_t num_counters;
517 struct compat_xt_counters counters[0];
518};
519
520#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
521 & ~(__alignof__(struct compat_xt_counters)-1))
522
76108cea
JE
523extern void xt_compat_lock(u_int8_t af);
524extern void xt_compat_unlock(u_int8_t af);
9fa492cd 525
76108cea
JE
526extern int xt_compat_add_offset(u_int8_t af, unsigned int offset, short delta);
527extern void xt_compat_flush_offsets(u_int8_t af);
528extern short xt_compat_calc_jump(u_int8_t af, unsigned int offset);
b386d9f5 529
5452e425 530extern int xt_compat_match_offset(const struct xt_match *match);
89566951 531extern int xt_compat_match_from_user(struct xt_entry_match *m,
b0a6363c 532 void **dstptr, unsigned int *size);
9fa492cd 533extern int xt_compat_match_to_user(struct xt_entry_match *m,
b0a6363c 534 void __user **dstptr, unsigned int *size);
9fa492cd 535
5452e425 536extern int xt_compat_target_offset(const struct xt_target *target);
9fa492cd 537extern void xt_compat_target_from_user(struct xt_entry_target *t,
b0a6363c 538 void **dstptr, unsigned int *size);
9fa492cd 539extern int xt_compat_target_to_user(struct xt_entry_target *t,
b0a6363c 540 void __user **dstptr, unsigned int *size);
2722971c
DM
541
542#endif /* CONFIG_COMPAT */
2e4e6a17
HW
543#endif /* __KERNEL__ */
544
545#endif /* _X_TABLES_H */