Git init
[profile/ivi/iptables.git] / include / linux / netfilter / x_tables.h
1 #ifndef _X_TABLES_H
2 #define _X_TABLES_H
3 #include <linux/kernel.h>
4 #include <linux/types.h>
5
6 #define XT_FUNCTION_MAXNAMELEN 30
7 #define XT_EXTENSION_MAXNAMELEN 29
8 #define XT_TABLE_MAXNAMELEN 32
9
10 struct xt_entry_match {
11         union {
12                 struct {
13                         __u16 match_size;
14
15                         /* Used by userspace */
16                         char name[XT_EXTENSION_MAXNAMELEN];
17                         __u8 revision;
18                 } user;
19                 struct {
20                         __u16 match_size;
21
22                         /* Used inside the kernel */
23                         struct xt_match *match;
24                 } kernel;
25
26                 /* Total length */
27                 __u16 match_size;
28         } u;
29
30         unsigned char data[0];
31 };
32
33 struct xt_entry_target {
34         union {
35                 struct {
36                         __u16 target_size;
37
38                         /* Used by userspace */
39                         char name[XT_EXTENSION_MAXNAMELEN];
40                         __u8 revision;
41                 } user;
42                 struct {
43                         __u16 target_size;
44
45                         /* Used inside the kernel */
46                         struct xt_target *target;
47                 } kernel;
48
49                 /* Total length */
50                 __u16 target_size;
51         } u;
52
53         unsigned char data[0];
54 };
55
56 #define XT_TARGET_INIT(__name, __size)                                         \
57 {                                                                              \
58         .target.u.user = {                                                     \
59                 .target_size    = XT_ALIGN(__size),                            \
60                 .name           = __name,                                      \
61         },                                                                     \
62 }
63
64 struct xt_standard_target {
65         struct xt_entry_target target;
66         int verdict;
67 };
68
69 /* The argument to IPT_SO_GET_REVISION_*.  Returns highest revision
70  * kernel supports, if >= revision. */
71 struct xt_get_revision {
72         char name[XT_EXTENSION_MAXNAMELEN];
73         __u8 revision;
74 };
75
76 /* CONTINUE verdict for targets */
77 #define XT_CONTINUE 0xFFFFFFFF
78
79 /* For standard target */
80 #define XT_RETURN (-NF_REPEAT - 1)
81
82 /* this is a dummy structure to find out the alignment requirement for a struct
83  * containing all the fundamental data types that are used in ipt_entry,
84  * ip6t_entry and arpt_entry.  This sucks, and it is a hack.  It will be my
85  * personal pleasure to remove it -HW
86  */
87 struct _xt_align {
88         __u8 u8;
89         __u16 u16;
90         __u32 u32;
91         __u64 u64;
92 };
93
94 #define XT_ALIGN(s) __ALIGN_KERNEL((s), __alignof__(struct _xt_align))
95
96 /* Standard return verdict, or do jump. */
97 #define XT_STANDARD_TARGET ""
98 /* Error verdict. */
99 #define XT_ERROR_TARGET "ERROR"
100
101 #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
102 #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
103
104 struct xt_counters {
105         __u64 pcnt, bcnt;                       /* Packet and byte counters */
106 };
107
108 /* The argument to IPT_SO_ADD_COUNTERS. */
109 struct xt_counters_info {
110         /* Which table. */
111         char name[XT_TABLE_MAXNAMELEN];
112
113         unsigned int num_counters;
114
115         /* The counters (actually `number' of these). */
116         struct xt_counters counters[0];
117 };
118
119 #define XT_INV_PROTO            0x40    /* Invert the sense of PROTO. */
120
121 /* fn returns 0 to continue iteration */
122 #define XT_MATCH_ITERATE(type, e, fn, args...)                  \
123 ({                                                              \
124         unsigned int __i;                                       \
125         int __ret = 0;                                          \
126         struct xt_entry_match *__m;                             \
127                                                                 \
128         for (__i = sizeof(type);                                \
129              __i < (e)->target_offset;                          \
130              __i += __m->u.match_size) {                        \
131                 __m = (void *)e + __i;                          \
132                                                                 \
133                 __ret = fn(__m , ## args);                      \
134                 if (__ret != 0)                                 \
135                         break;                                  \
136         }                                                       \
137         __ret;                                                  \
138 })
139
140 /* fn returns 0 to continue iteration */
141 #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \
142 ({                                                              \
143         unsigned int __i, __n;                                  \
144         int __ret = 0;                                          \
145         type *__entry;                                          \
146                                                                 \
147         for (__i = 0, __n = 0; __i < (size);                    \
148              __i += __entry->next_offset, __n++) {              \
149                 __entry = (void *)(entries) + __i;              \
150                 if (__n < n)                                    \
151                         continue;                               \
152                                                                 \
153                 __ret = fn(__entry , ## args);                  \
154                 if (__ret != 0)                                 \
155                         break;                                  \
156         }                                                       \
157         __ret;                                                  \
158 })
159
160 /* fn returns 0 to continue iteration */
161 #define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \
162         XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args)
163
164
165 /* pos is normally a struct ipt_entry/ip6t_entry/etc. */
166 #define xt_entry_foreach(pos, ehead, esize) \
167         for ((pos) = (typeof(pos))(ehead); \
168              (pos) < (typeof(pos))((char *)(ehead) + (esize)); \
169              (pos) = (typeof(pos))((char *)(pos) + (pos)->next_offset))
170
171 /* can only be xt_entry_match, so no use of typeof here */
172 #define xt_ematch_foreach(pos, entry) \
173         for ((pos) = (struct xt_entry_match *)entry->elems; \
174              (pos) < (struct xt_entry_match *)((char *)(entry) + \
175                      (entry)->target_offset); \
176              (pos) = (struct xt_entry_match *)((char *)(pos) + \
177                      (pos)->u.match_size))
178
179
180 #endif /* _X_TABLES_H */