[NETFILTER]: ip6_tables: fixed conflicted optname for getsockopt
[safe/jmp/linux-2.6] / include / linux / netfilter / x_tables.h
1 #ifndef _X_TABLES_H
2 #define _X_TABLES_H
3
4 #define XT_FUNCTION_MAXNAMELEN 30
5 #define XT_TABLE_MAXNAMELEN 32
6
7 struct 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
32 struct 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
57 struct xt_standard_target
58 {
59         struct xt_entry_target target;
60         int verdict;
61 };
62
63 /* The argument to IPT_SO_GET_REVISION_*.  Returns highest revision
64  * kernel supports, if >= revision. */
65 struct 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
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  */
83 struct _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))
93
94 /* Standard return verdict, or do jump. */
95 #define XT_STANDARD_TARGET ""
96 /* Error verdict. */
97 #define XT_ERROR_TARGET "ERROR"
98
99 #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
100 #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
101
102 struct xt_counters
103 {
104         u_int64_t pcnt, bcnt;                   /* Packet and byte counters */
105 };
106
107 /* The argument to IPT_SO_ADD_COUNTERS. */
108 struct xt_counters_info
109 {
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 #ifdef __KERNEL__
122
123 #include <linux/netdevice.h>
124
125 struct xt_match
126 {
127         struct list_head list;
128
129         const char name[XT_FUNCTION_MAXNAMELEN-1];
130
131         /* Return true or false: return FALSE and set *hotdrop = 1 to
132            force immediate packet drop. */
133         /* Arguments changed since 2.6.9, as this must now handle
134            non-linear skb, using skb_header_pointer and
135            skb_ip_make_writable. */
136         int (*match)(const struct sk_buff *skb,
137                      const struct net_device *in,
138                      const struct net_device *out,
139                      const struct xt_match *match,
140                      const void *matchinfo,
141                      int offset,
142                      unsigned int protoff,
143                      int *hotdrop);
144
145         /* Called when user tries to insert an entry of this type. */
146         /* Should return true or false. */
147         int (*checkentry)(const char *tablename,
148                           const void *ip,
149                           const struct xt_match *match,
150                           void *matchinfo,
151                           unsigned int hook_mask);
152
153         /* Called when entry of this type deleted. */
154         void (*destroy)(const struct xt_match *match, void *matchinfo);
155
156         /* Called when userspace align differs from kernel space one */
157         void (*compat_from_user)(void *dst, void *src);
158         int (*compat_to_user)(void __user *dst, void *src);
159
160         /* Set this to THIS_MODULE if you are a module, otherwise NULL */
161         struct module *me;
162
163         /* Free to use by each match */
164         unsigned long data;
165
166         char *table;
167         unsigned int matchsize;
168         unsigned int compatsize;
169         unsigned int hooks;
170         unsigned short proto;
171
172         unsigned short family;
173         u_int8_t revision;
174 };
175
176 /* Registration hooks for targets. */
177 struct xt_target
178 {
179         struct list_head list;
180
181         const char name[XT_FUNCTION_MAXNAMELEN-1];
182
183         /* Returns verdict. Argument order changed since 2.6.9, as this
184            must now handle non-linear skbs, using skb_copy_bits and
185            skb_ip_make_writable. */
186         unsigned int (*target)(struct sk_buff **pskb,
187                                const struct net_device *in,
188                                const struct net_device *out,
189                                unsigned int hooknum,
190                                const struct xt_target *target,
191                                const void *targinfo);
192
193         /* Called when user tries to insert an entry of this type:
194            hook_mask is a bitmask of hooks from which it can be
195            called. */
196         /* Should return true or false. */
197         int (*checkentry)(const char *tablename,
198                           const void *entry,
199                           const struct xt_target *target,
200                           void *targinfo,
201                           unsigned int hook_mask);
202
203         /* Called when entry of this type deleted. */
204         void (*destroy)(const struct xt_target *target, void *targinfo);
205
206         /* Called when userspace align differs from kernel space one */
207         void (*compat_from_user)(void *dst, void *src);
208         int (*compat_to_user)(void __user *dst, void *src);
209
210         /* Set this to THIS_MODULE if you are a module, otherwise NULL */
211         struct module *me;
212
213         char *table;
214         unsigned int targetsize;
215         unsigned int compatsize;
216         unsigned int hooks;
217         unsigned short proto;
218
219         unsigned short family;
220         u_int8_t revision;
221 };
222
223 /* Furniture shopping... */
224 struct xt_table
225 {
226         struct list_head list;
227
228         /* A unique name... */
229         char name[XT_TABLE_MAXNAMELEN];
230
231         /* What hooks you will enter on */
232         unsigned int valid_hooks;
233
234         /* Lock for the curtain */
235         rwlock_t lock;
236
237         /* Man behind the curtain... */
238         //struct ip6t_table_info *private;
239         void *private;
240
241         /* Set this to THIS_MODULE if you are a module, otherwise NULL */
242         struct module *me;
243
244         int af;         /* address/protocol family */
245 };
246
247 #include <linux/netfilter_ipv4.h>
248
249 /* The table itself */
250 struct xt_table_info
251 {
252         /* Size per table */
253         unsigned int size;
254         /* Number of entries: FIXME. --RR */
255         unsigned int number;
256         /* Initial number of entries. Needed for module usage count */
257         unsigned int initial_entries;
258
259         /* Entry points and underflows */
260         unsigned int hook_entry[NF_IP_NUMHOOKS];
261         unsigned int underflow[NF_IP_NUMHOOKS];
262
263         /* ipt_entry tables: one per CPU */
264         char *entries[NR_CPUS];
265 };
266
267 extern int xt_register_target(struct xt_target *target);
268 extern void xt_unregister_target(struct xt_target *target);
269 extern int xt_register_targets(struct xt_target *target, unsigned int n);
270 extern void xt_unregister_targets(struct xt_target *target, unsigned int n);
271
272 extern int xt_register_match(struct xt_match *target);
273 extern void xt_unregister_match(struct xt_match *target);
274 extern int xt_register_matches(struct xt_match *match, unsigned int n);
275 extern void xt_unregister_matches(struct xt_match *match, unsigned int n);
276
277 extern int xt_check_match(const struct xt_match *match, unsigned short family,
278                           unsigned int size, const char *table, unsigned int hook,
279                           unsigned short proto, int inv_proto);
280 extern int xt_check_target(const struct xt_target *target, unsigned short family,
281                            unsigned int size, const char *table, unsigned int hook,
282                            unsigned short proto, int inv_proto);
283
284 extern int xt_register_table(struct xt_table *table,
285                              struct xt_table_info *bootstrap,
286                              struct xt_table_info *newinfo);
287 extern void *xt_unregister_table(struct xt_table *table);
288
289 extern struct xt_table_info *xt_replace_table(struct xt_table *table,
290                                               unsigned int num_counters,
291                                               struct xt_table_info *newinfo,
292                                               int *error);
293
294 extern struct xt_match *xt_find_match(int af, const char *name, u8 revision);
295 extern struct xt_target *xt_find_target(int af, const char *name, u8 revision);
296 extern struct xt_target *xt_request_find_target(int af, const char *name, 
297                                                 u8 revision);
298 extern int xt_find_revision(int af, const char *name, u8 revision, int target,
299                             int *err);
300
301 extern struct xt_table *xt_find_table_lock(int af, const char *name);
302 extern void xt_table_unlock(struct xt_table *t);
303
304 extern int xt_proto_init(int af);
305 extern void xt_proto_fini(int af);
306
307 extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
308 extern void xt_free_table_info(struct xt_table_info *info);
309
310 #ifdef CONFIG_COMPAT
311 #include <net/compat.h>
312
313 struct compat_xt_entry_match
314 {
315         union {
316                 struct {
317                         u_int16_t match_size;
318                         char name[XT_FUNCTION_MAXNAMELEN - 1];
319                         u_int8_t revision;
320                 } user;
321                 struct {
322                         u_int16_t match_size;
323                         compat_uptr_t match;
324                 } kernel;
325                 u_int16_t match_size;
326         } u;
327         unsigned char data[0];
328 };
329
330 struct compat_xt_entry_target
331 {
332         union {
333                 struct {
334                         u_int16_t target_size;
335                         char name[XT_FUNCTION_MAXNAMELEN - 1];
336                         u_int8_t revision;
337                 } user;
338                 struct {
339                         u_int16_t target_size;
340                         compat_uptr_t target;
341                 } kernel;
342                 u_int16_t target_size;
343         } u;
344         unsigned char data[0];
345 };
346
347 /* FIXME: this works only on 32 bit tasks
348  * need to change whole approach in order to calculate align as function of
349  * current task alignment */
350
351 struct compat_xt_counters
352 {
353 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
354         u_int32_t cnt[4];
355 #else
356         u_int64_t cnt[2];
357 #endif
358 };
359
360 struct compat_xt_counters_info
361 {
362         char name[XT_TABLE_MAXNAMELEN];
363         compat_uint_t num_counters;
364         struct compat_xt_counters counters[0];
365 };
366
367 #define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
368                 & ~(__alignof__(struct compat_xt_counters)-1))
369
370 extern void xt_compat_lock(int af);
371 extern void xt_compat_unlock(int af);
372
373 extern int xt_compat_match_offset(struct xt_match *match);
374 extern void xt_compat_match_from_user(struct xt_entry_match *m,
375                                       void **dstptr, int *size);
376 extern int xt_compat_match_to_user(struct xt_entry_match *m,
377                                    void __user **dstptr, int *size);
378
379 extern int xt_compat_target_offset(struct xt_target *target);
380 extern void xt_compat_target_from_user(struct xt_entry_target *t,
381                                        void **dstptr, int *size);
382 extern int xt_compat_target_to_user(struct xt_entry_target *t,
383                                     void __user **dstptr, int *size);
384
385 #endif /* CONFIG_COMPAT */
386 #endif /* __KERNEL__ */
387
388 #endif /* _X_TABLES_H */