blob: 1b2e43502ef77b63e50a428a3b61dcfa956da967 [file] [log] [blame]
Harald Welte2e4e6a12006-01-12 13:30:04 -08001#ifndef _X_TABLES_H
2#define _X_TABLES_H
3
Arnd Bergmann60c195c2009-02-26 00:51:43 +01004#include <linux/types.h>
5
Harald Welte2e4e6a12006-01-12 13:30:04 -08006#define XT_FUNCTION_MAXNAMELEN 30
7#define XT_TABLE_MAXNAMELEN 32
8
Dmitry Mishin1e30a012006-03-22 13:56:56 -08009struct xt_entry_match
10{
11 union {
12 struct {
Arnd Bergmann60c195c2009-02-26 00:51:43 +010013 __u16 match_size;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080014
15 /* Used by userspace */
16 char name[XT_FUNCTION_MAXNAMELEN-1];
17
Arnd Bergmann60c195c2009-02-26 00:51:43 +010018 __u8 revision;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080019 } user;
20 struct {
Arnd Bergmann60c195c2009-02-26 00:51:43 +010021 __u16 match_size;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080022
23 /* Used inside the kernel */
24 struct xt_match *match;
25 } kernel;
26
27 /* Total length */
Arnd Bergmann60c195c2009-02-26 00:51:43 +010028 __u16 match_size;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080029 } u;
30
31 unsigned char data[0];
32};
33
34struct xt_entry_target
35{
36 union {
37 struct {
Arnd Bergmann60c195c2009-02-26 00:51:43 +010038 __u16 target_size;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080039
40 /* Used by userspace */
41 char name[XT_FUNCTION_MAXNAMELEN-1];
42
Arnd Bergmann60c195c2009-02-26 00:51:43 +010043 __u8 revision;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080044 } user;
45 struct {
Arnd Bergmann60c195c2009-02-26 00:51:43 +010046 __u16 target_size;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080047
48 /* Used inside the kernel */
49 struct xt_target *target;
50 } kernel;
51
52 /* Total length */
Arnd Bergmann60c195c2009-02-26 00:51:43 +010053 __u16 target_size;
Dmitry Mishin1e30a012006-03-22 13:56:56 -080054 } u;
55
56 unsigned char data[0];
57};
58
Patrick McHardy3c2ad462007-05-10 14:14:16 -070059#define XT_TARGET_INIT(__name, __size) \
60{ \
61 .target.u.user = { \
62 .target_size = XT_ALIGN(__size), \
63 .name = __name, \
64 }, \
65}
66
Dmitry Mishin1e30a012006-03-22 13:56:56 -080067struct xt_standard_target
68{
69 struct xt_entry_target target;
70 int verdict;
71};
72
Harald Welte2e4e6a12006-01-12 13:30:04 -080073/* 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
Arnd Bergmann60c195c2009-02-26 00:51:43 +010079 __u8 revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -080080};
81
82/* CONTINUE verdict for targets */
83#define XT_CONTINUE 0xFFFFFFFF
84
85/* For standard target */
86#define XT_RETURN (-NF_REPEAT - 1)
87
David S. Miller6fbfc962006-01-20 11:57:07 -080088/* 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{
Arnd Bergmann60c195c2009-02-26 00:51:43 +010095 __u8 u8;
96 __u16 u16;
97 __u32 u32;
98 __u64 u64;
David S. Miller6fbfc962006-01-20 11:57:07 -080099};
100
101#define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \
102 & ~(__alignof__(struct _xt_align)-1))
Harald Welte2e4e6a12006-01-12 13:30:04 -0800103
104/* Standard return verdict, or do jump. */
105#define XT_STANDARD_TARGET ""
106/* Error verdict. */
107#define XT_ERROR_TARGET "ERROR"
108
Harald Welte2e4e6a12006-01-12 13:30:04 -0800109#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{
Arnd Bergmann60c195c2009-02-26 00:51:43 +0100114 __u64 pcnt, bcnt; /* Packet and byte counters */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800115};
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
Patrick McHardy89c002d2007-12-17 21:46:59 -0800131/* 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
Harald Welte2e4e6a12006-01-12 13:30:04 -0800174#ifdef __KERNEL__
175
176#include <linux/netdevice.h>
177
Jan Engelhardtf7108a22008-10-08 11:35:18 +0200178/**
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
Jan Engelhardt916a9172008-10-08 11:35:20 +0200188 * @family: Actual NFPROTO_* through which the function is invoked
189 * (helpful when match->family == NFPROTO_UNSPEC)
Jan Engelhardtf7108a22008-10-08 11:35:18 +0200190 */
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;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200198 u_int8_t family;
Jan Engelhardtf7108a22008-10-08 11:35:18 +0200199};
200
Jan Engelhardt9b4fce72008-10-08 11:35:18 +0200201/**
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;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200218 u_int8_t family;
Jan Engelhardt9b4fce72008-10-08 11:35:18 +0200219};
220
Jan Engelhardt6be3d852008-10-08 11:35:19 +0200221/* Match destructor parameters */
222struct xt_mtdtor_param {
223 const struct xt_match *match;
224 void *matchinfo;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200225 u_int8_t family;
Jan Engelhardt6be3d852008-10-08 11:35:19 +0200226};
227
Jan Engelhardt7eb35582008-10-08 11:35:19 +0200228/**
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;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200242 u_int8_t family;
Jan Engelhardt7eb35582008-10-08 11:35:19 +0200243};
244
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +0200245/**
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;
Jan Engelhardtf79fca52008-11-24 16:06:17 -0800256 const void *entryinfo;
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +0200257 const struct xt_target *target;
258 void *targinfo;
259 unsigned int hook_mask;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200260 u_int8_t family;
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +0200261};
262
Jan Engelhardta2df1642008-10-08 11:35:19 +0200263/* Target destructor parameters */
264struct xt_tgdtor_param {
265 const struct xt_target *target;
266 void *targinfo;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200267 u_int8_t family;
Jan Engelhardta2df1642008-10-08 11:35:19 +0200268};
269
Harald Welte2e4e6a12006-01-12 13:30:04 -0800270struct xt_match
271{
272 struct list_head list;
273
274 const char name[XT_FUNCTION_MAXNAMELEN-1];
Richard Kennedydaaf83d2009-01-12 00:06:11 +0000275 u_int8_t revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800276
Harald Welte2e4e6a12006-01-12 13:30:04 -0800277 /* 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. */
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -0700282 bool (*match)(const struct sk_buff *skb,
Jan Engelhardtf7108a22008-10-08 11:35:18 +0200283 const struct xt_match_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800284
285 /* Called when user tries to insert an entry of this type. */
Jan Engelhardt9b4fce72008-10-08 11:35:18 +0200286 bool (*checkentry)(const struct xt_mtchk_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800287
288 /* Called when entry of this type deleted. */
Jan Engelhardt6be3d852008-10-08 11:35:19 +0200289 void (*destroy)(const struct xt_mtdtor_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800290
Dmitry Mishin27229712006-04-01 02:25:19 -0800291 /* Called when userspace align differs from kernel space one */
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700292 void (*compat_from_user)(void *dst, void *src);
293 int (*compat_to_user)(void __user *dst, void *src);
Dmitry Mishin27229712006-04-01 02:25:19 -0800294
Harald Welte2e4e6a12006-01-12 13:30:04 -0800295 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
296 struct module *me;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800297
Patrick McHardy91270cf2006-08-22 00:43:38 -0700298 /* Free to use by each match */
299 unsigned long data;
300
Jan Engelhardtecb6f852008-01-31 03:54:47 -0800301 const char *table;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800302 unsigned int matchsize;
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700303 unsigned int compatsize;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800304 unsigned int hooks;
305 unsigned short proto;
Patrick McHardyc4b88512006-03-20 18:03:40 -0800306
307 unsigned short family;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800308};
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
Harald Welte2e4e6a12006-01-12 13:30:04 -0800317 /* 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. */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700320 unsigned int (*target)(struct sk_buff *skb,
Jan Engelhardt7eb35582008-10-08 11:35:19 +0200321 const struct xt_target_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800322
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. */
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +0200327 bool (*checkentry)(const struct xt_tgchk_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800328
329 /* Called when entry of this type deleted. */
Jan Engelhardta2df1642008-10-08 11:35:19 +0200330 void (*destroy)(const struct xt_tgdtor_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800331
Dmitry Mishin27229712006-04-01 02:25:19 -0800332 /* Called when userspace align differs from kernel space one */
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700333 void (*compat_from_user)(void *dst, void *src);
334 int (*compat_to_user)(void __user *dst, void *src);
Dmitry Mishin27229712006-04-01 02:25:19 -0800335
Harald Welte2e4e6a12006-01-12 13:30:04 -0800336 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
337 struct module *me;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800338
Jan Engelhardtecb6f852008-01-31 03:54:47 -0800339 const char *table;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800340 unsigned int targetsize;
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700341 unsigned int compatsize;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800342 unsigned int hooks;
343 unsigned short proto;
Patrick McHardyc4b88512006-03-20 18:03:40 -0800344
345 unsigned short family;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800346 u_int8_t revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800347};
348
349/* Furniture shopping... */
350struct xt_table
351{
352 struct list_head list;
353
Harald Welte2e4e6a12006-01-12 13:30:04 -0800354 /* What hooks you will enter on */
355 unsigned int valid_hooks;
356
Harald Welte2e4e6a12006-01-12 13:30:04 -0800357 /* Man behind the curtain... */
Stephen Hemminger4a2f9652009-02-18 16:29:44 +0100358 struct xt_table_info *private;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800359
360 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
361 struct module *me;
362
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200363 u_int8_t af; /* address/protocol family */
Stephen Hemminger4a2f9652009-02-18 16:29:44 +0100364
365 /* A unique name... */
366 const char name[XT_TABLE_MAXNAMELEN];
Harald Welte2e4e6a12006-01-12 13:30:04 -0800367};
368
369#include <linux/netfilter_ipv4.h>
370
371/* The table itself */
372struct xt_table_info
373{
374 /* Size per table */
375 unsigned int size;
376 /* Number of entries: FIXME. --RR */
377 unsigned int number;
378 /* Initial number of entries. Needed for module usage count */
379 unsigned int initial_entries;
380
381 /* Entry points and underflows */
Patrick McHardy6e23ae22007-11-19 18:53:30 -0800382 unsigned int hook_entry[NF_INET_NUMHOOKS];
383 unsigned int underflow[NF_INET_NUMHOOKS];
Harald Welte2e4e6a12006-01-12 13:30:04 -0800384
385 /* ipt_entry tables: one per CPU */
Eric Dumazet259d4e42007-12-04 23:24:56 -0800386 /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
Stephen Hemminger78454472009-02-20 10:35:32 +0100387 void *entries[1];
Harald Welte2e4e6a12006-01-12 13:30:04 -0800388};
389
Eric Dumazet259d4e42007-12-04 23:24:56 -0800390#define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \
391 + nr_cpu_ids * sizeof(char *))
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -0800392extern int xt_register_target(struct xt_target *target);
393extern void xt_unregister_target(struct xt_target *target);
Patrick McHardy52d9c422006-08-22 00:33:45 -0700394extern int xt_register_targets(struct xt_target *target, unsigned int n);
395extern void xt_unregister_targets(struct xt_target *target, unsigned int n);
396
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -0800397extern int xt_register_match(struct xt_match *target);
398extern void xt_unregister_match(struct xt_match *target);
Patrick McHardy52d9c422006-08-22 00:33:45 -0700399extern int xt_register_matches(struct xt_match *match, unsigned int n);
400extern void xt_unregister_matches(struct xt_match *match, unsigned int n);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800401
Jan Engelhardt916a9172008-10-08 11:35:20 +0200402extern int xt_check_match(struct xt_mtchk_param *,
Jan Engelhardt9b4fce72008-10-08 11:35:18 +0200403 unsigned int size, u_int8_t proto, bool inv_proto);
Jan Engelhardt916a9172008-10-08 11:35:20 +0200404extern int xt_check_target(struct xt_tgchk_param *,
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +0200405 unsigned int size, u_int8_t proto, bool inv_proto);
Patrick McHardy37f9f732006-03-20 17:59:06 -0800406
Alexey Dobriyan8d870052008-01-31 04:02:13 -0800407extern struct xt_table *xt_register_table(struct net *net,
408 struct xt_table *table,
Alexey Dobriyana98da112008-01-31 04:01:49 -0800409 struct xt_table_info *bootstrap,
410 struct xt_table_info *newinfo);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800411extern void *xt_unregister_table(struct xt_table *table);
412
413extern struct xt_table_info *xt_replace_table(struct xt_table *table,
414 unsigned int num_counters,
415 struct xt_table_info *newinfo,
416 int *error);
417
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200418extern struct xt_match *xt_find_match(u8 af, const char *name, u8 revision);
419extern struct xt_target *xt_find_target(u8 af, const char *name, u8 revision);
420extern struct xt_target *xt_request_find_target(u8 af, const char *name,
Harald Welte2e4e6a12006-01-12 13:30:04 -0800421 u8 revision);
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200422extern int xt_find_revision(u8 af, const char *name, u8 revision,
423 int target, int *err);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800424
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200425extern struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
Alexey Dobriyan8d870052008-01-31 04:02:13 -0800426 const char *name);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800427extern void xt_table_unlock(struct xt_table *t);
428
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200429extern int xt_proto_init(struct net *net, u_int8_t af);
430extern void xt_proto_fini(struct net *net, u_int8_t af);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800431
432extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
433extern void xt_free_table_info(struct xt_table_info *info);
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700434
435/*
436 * Per-CPU spinlock associated with per-cpu table entries, and
437 * with a counter for the "reading" side that allows a recursive
438 * reader to avoid taking the lock and deadlocking.
439 *
440 * "reading" is used by ip/arp/ip6 tables rule processing which runs per-cpu.
441 * It needs to ensure that the rules are not being changed while the packet
442 * is being processed. In some cases, the read lock will be acquired
443 * twice on the same CPU; this is okay because of the count.
444 *
445 * "writing" is used when reading counters.
446 * During replace any readers that are using the old tables have to complete
447 * before freeing the old table. This is handled by the write locking
448 * necessary for reading the counters.
449 */
450struct xt_info_lock {
451 spinlock_t lock;
452 unsigned char readers;
453};
454DECLARE_PER_CPU(struct xt_info_lock, xt_info_locks);
455
456/*
457 * Note: we need to ensure that preemption is disabled before acquiring
458 * the per-cpu-variable, so we do it as a two step process rather than
459 * using "spin_lock_bh()".
460 *
461 * We _also_ need to disable bottom half processing before updating our
462 * nesting count, to make sure that the only kind of re-entrancy is this
463 * code being called by itself: since the count+lock is not an atomic
464 * operation, we can allow no races.
465 *
466 * _Only_ that special combination of being per-cpu and never getting
467 * re-entered asynchronously means that the count is safe.
468 */
469static inline void xt_info_rdlock_bh(void)
470{
471 struct xt_info_lock *lock;
472
473 local_bh_disable();
474 lock = &__get_cpu_var(xt_info_locks);
475 if (!lock->readers++)
476 spin_lock(&lock->lock);
477}
478
479static inline void xt_info_rdunlock_bh(void)
480{
481 struct xt_info_lock *lock = &__get_cpu_var(xt_info_locks);
482
483 if (!--lock->readers)
484 spin_unlock(&lock->lock);
485 local_bh_enable();
486}
487
488/*
489 * The "writer" side needs to get exclusive access to the lock,
490 * regardless of readers. This must be called with bottom half
491 * processing (and thus also preemption) disabled.
492 */
493static inline void xt_info_wrlock(unsigned int cpu)
494{
495 spin_lock(&per_cpu(xt_info_locks, cpu).lock);
496}
497
498static inline void xt_info_wrunlock(unsigned int cpu)
499{
500 spin_unlock(&per_cpu(xt_info_locks, cpu).lock);
501}
Harald Welte2e4e6a12006-01-12 13:30:04 -0800502
Eric Dumazetb8dfe492009-03-25 17:31:52 +0100503/*
504 * This helper is performance critical and must be inlined
505 */
506static inline unsigned long ifname_compare_aligned(const char *_a,
507 const char *_b,
508 const char *_mask)
509{
510 const unsigned long *a = (const unsigned long *)_a;
511 const unsigned long *b = (const unsigned long *)_b;
512 const unsigned long *mask = (const unsigned long *)_mask;
513 unsigned long ret;
514
515 ret = (a[0] ^ b[0]) & mask[0];
516 if (IFNAMSIZ > sizeof(unsigned long))
517 ret |= (a[1] ^ b[1]) & mask[1];
518 if (IFNAMSIZ > 2 * sizeof(unsigned long))
519 ret |= (a[2] ^ b[2]) & mask[2];
520 if (IFNAMSIZ > 3 * sizeof(unsigned long))
521 ret |= (a[3] ^ b[3]) & mask[3];
522 BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
523 return ret;
524}
525
Dmitry Mishin27229712006-04-01 02:25:19 -0800526#ifdef CONFIG_COMPAT
527#include <net/compat.h>
528
529struct compat_xt_entry_match
530{
531 union {
532 struct {
533 u_int16_t match_size;
534 char name[XT_FUNCTION_MAXNAMELEN - 1];
535 u_int8_t revision;
536 } user;
Patrick McHardy46c5ea3c2006-05-02 05:12:22 +0200537 struct {
538 u_int16_t match_size;
539 compat_uptr_t match;
540 } kernel;
Dmitry Mishin27229712006-04-01 02:25:19 -0800541 u_int16_t match_size;
542 } u;
543 unsigned char data[0];
544};
545
546struct compat_xt_entry_target
547{
548 union {
549 struct {
550 u_int16_t target_size;
551 char name[XT_FUNCTION_MAXNAMELEN - 1];
552 u_int8_t revision;
553 } user;
Patrick McHardy46c5ea3c2006-05-02 05:12:22 +0200554 struct {
555 u_int16_t target_size;
556 compat_uptr_t target;
557 } kernel;
Dmitry Mishin27229712006-04-01 02:25:19 -0800558 u_int16_t target_size;
559 } u;
560 unsigned char data[0];
561};
562
563/* FIXME: this works only on 32 bit tasks
564 * need to change whole approach in order to calculate align as function of
565 * current task alignment */
566
567struct compat_xt_counters
568{
Patrick McHardy55fe5862006-04-24 17:16:28 -0700569#if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
Dmitry Mishin27229712006-04-01 02:25:19 -0800570 u_int32_t cnt[4];
Patrick McHardy55fe5862006-04-24 17:16:28 -0700571#else
572 u_int64_t cnt[2];
573#endif
Dmitry Mishin27229712006-04-01 02:25:19 -0800574};
575
576struct compat_xt_counters_info
577{
578 char name[XT_TABLE_MAXNAMELEN];
579 compat_uint_t num_counters;
580 struct compat_xt_counters counters[0];
581};
582
583#define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
584 & ~(__alignof__(struct compat_xt_counters)-1))
585
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200586extern void xt_compat_lock(u_int8_t af);
587extern void xt_compat_unlock(u_int8_t af);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700588
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200589extern int xt_compat_add_offset(u_int8_t af, unsigned int offset, short delta);
590extern void xt_compat_flush_offsets(u_int8_t af);
591extern short xt_compat_calc_jump(u_int8_t af, unsigned int offset);
Patrick McHardyb386d9f2007-12-17 21:47:48 -0800592
Jan Engelhardt5452e422008-04-14 11:15:35 +0200593extern int xt_compat_match_offset(const struct xt_match *match);
Patrick McHardy89566952007-12-17 21:46:40 -0800594extern int xt_compat_match_from_user(struct xt_entry_match *m,
Patrick McHardyb0a63632008-01-31 04:10:18 -0800595 void **dstptr, unsigned int *size);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700596extern int xt_compat_match_to_user(struct xt_entry_match *m,
Patrick McHardyb0a63632008-01-31 04:10:18 -0800597 void __user **dstptr, unsigned int *size);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700598
Jan Engelhardt5452e422008-04-14 11:15:35 +0200599extern int xt_compat_target_offset(const struct xt_target *target);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700600extern void xt_compat_target_from_user(struct xt_entry_target *t,
Patrick McHardyb0a63632008-01-31 04:10:18 -0800601 void **dstptr, unsigned int *size);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700602extern int xt_compat_target_to_user(struct xt_entry_target *t,
Patrick McHardyb0a63632008-01-31 04:10:18 -0800603 void __user **dstptr, unsigned int *size);
Dmitry Mishin27229712006-04-01 02:25:19 -0800604
605#endif /* CONFIG_COMPAT */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800606#endif /* __KERNEL__ */
607
608#endif /* _X_TABLES_H */