blob: a3e215bb0241d47379bce4ff6e81ba2b4995d3c3 [file] [log] [blame]
Harald Welte2e4e6a12006-01-12 13:30:04 -08001#ifndef _X_TABLES_H
2#define _X_TABLES_H
Arnd Bergmann60c195c2009-02-26 00:51:43 +01003
Harald Welte2e4e6a12006-01-12 13:30:04 -08004
5#include <linux/netdevice.h>
David Howells94d0ec52012-10-09 09:48:54 +01006#include <uapi/linux/netfilter/x_tables.h>
Harald Welte2e4e6a12006-01-12 13:30:04 -08007
Jan Engelhardtf7108a22008-10-08 11:35:18 +02008/**
Jan Engelhardtde74c162009-07-05 18:26:37 +02009 * struct xt_action_param - parameters for matches/targets
Jan Engelhardtf7108a22008-10-08 11:35:18 +020010 *
Jan Engelhardtde74c162009-07-05 18:26:37 +020011 * @match: the match extension
12 * @target: the target extension
13 * @matchinfo: per-match data
14 * @targetinfo: per-target data
Jan Engelhardtf7108a22008-10-08 11:35:18 +020015 * @in: input netdevice
16 * @out: output netdevice
Jan Engelhardtf7108a22008-10-08 11:35:18 +020017 * @fragoff: packet is a fragment, this is the data offset
18 * @thoff: position of transport header relative to skb->data
Evgeniy Polyakova5e78822009-06-04 16:54:42 +020019 * @hook: hook number given packet came from
Jan Engelhardt916a9172008-10-08 11:35:20 +020020 * @family: Actual NFPROTO_* through which the function is invoked
21 * (helpful when match->family == NFPROTO_UNSPEC)
Jan Engelhardtb4ba2612009-07-07 20:54:30 +020022 *
23 * Fields written to by extensions:
24 *
Evgeniy Polyakova5e78822009-06-04 16:54:42 +020025 * @hotdrop: drop packet if we had inspection problems
Jan Engelhardt16599782010-03-18 10:30:44 +010026 * Network namespace obtainable using dev_net(in/out)
Jan Engelhardtf7108a22008-10-08 11:35:18 +020027 */
Jan Engelhardtde74c162009-07-05 18:26:37 +020028struct xt_action_param {
29 union {
30 const struct xt_match *match;
31 const struct xt_target *target;
32 };
33 union {
34 const void *matchinfo, *targinfo;
35 };
Jan Engelhardtf7108a22008-10-08 11:35:18 +020036 const struct net_device *in, *out;
Jan Engelhardtf7108a22008-10-08 11:35:18 +020037 int fragoff;
38 unsigned int thoff;
Evgeniy Polyakova5e78822009-06-04 16:54:42 +020039 unsigned int hooknum;
Jan Engelhardt916a9172008-10-08 11:35:20 +020040 u_int8_t family;
Jan Engelhardtb4ba2612009-07-07 20:54:30 +020041 bool hotdrop;
Jan Engelhardtf7108a22008-10-08 11:35:18 +020042};
43
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020044/**
45 * struct xt_mtchk_param - parameters for match extensions'
46 * checkentry functions
47 *
Jan Engelhardt16599782010-03-18 10:30:44 +010048 * @net: network namespace through which the check was invoked
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020049 * @table: table the rule is tried to be inserted into
50 * @entryinfo: the family-specific rule data
Jan Engelhardt16599782010-03-18 10:30:44 +010051 * (struct ipt_ip, ip6t_ip, arpt_arp or (note) ebt_entry)
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020052 * @match: struct xt_match through which this function was invoked
53 * @matchinfo: per-match data
54 * @hook_mask: via which hooks the new rule is reachable
Jan Engelhardt16599782010-03-18 10:30:44 +010055 * Other fields as above.
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020056 */
57struct xt_mtchk_param {
Alexey Dobriyana83d8e82010-01-18 08:21:13 +010058 struct net *net;
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020059 const char *table;
60 const void *entryinfo;
61 const struct xt_match *match;
62 void *matchinfo;
63 unsigned int hook_mask;
Jan Engelhardt916a9172008-10-08 11:35:20 +020064 u_int8_t family;
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020065};
66
Jan Engelhardt16599782010-03-18 10:30:44 +010067/**
68 * struct xt_mdtor_param - match destructor parameters
69 * Fields as above.
70 */
Jan Engelhardt6be3d852008-10-08 11:35:19 +020071struct xt_mtdtor_param {
Alexey Dobriyanf54e9362010-01-18 08:25:47 +010072 struct net *net;
Jan Engelhardt6be3d852008-10-08 11:35:19 +020073 const struct xt_match *match;
74 void *matchinfo;
Jan Engelhardt916a9172008-10-08 11:35:20 +020075 u_int8_t family;
Jan Engelhardt6be3d852008-10-08 11:35:19 +020076};
77
Jan Engelhardt7eb35582008-10-08 11:35:19 +020078/**
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020079 * struct xt_tgchk_param - parameters for target extensions'
80 * checkentry functions
81 *
82 * @entryinfo: the family-specific rule data
83 * (struct ipt_entry, ip6t_entry, arpt_entry, ebt_entry)
84 *
85 * Other fields see above.
86 */
87struct xt_tgchk_param {
Patrick McHardyadd67462010-02-03 13:45:12 +010088 struct net *net;
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020089 const char *table;
Jan Engelhardtf79fca52008-11-24 16:06:17 -080090 const void *entryinfo;
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020091 const struct xt_target *target;
92 void *targinfo;
93 unsigned int hook_mask;
Jan Engelhardt916a9172008-10-08 11:35:20 +020094 u_int8_t family;
Jan Engelhardtaf5d6dc2008-10-08 11:35:19 +020095};
96
Jan Engelhardta2df1642008-10-08 11:35:19 +020097/* Target destructor parameters */
98struct xt_tgdtor_param {
Patrick McHardyadd67462010-02-03 13:45:12 +010099 struct net *net;
Jan Engelhardta2df1642008-10-08 11:35:19 +0200100 const struct xt_target *target;
101 void *targinfo;
Jan Engelhardt916a9172008-10-08 11:35:20 +0200102 u_int8_t family;
Jan Engelhardta2df1642008-10-08 11:35:19 +0200103};
104
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800105struct xt_match {
Harald Welte2e4e6a12006-01-12 13:30:04 -0800106 struct list_head list;
107
Jan Engelhardt4b2cbd42010-04-27 15:34:34 +0200108 const char name[XT_EXTENSION_MAXNAMELEN];
Richard Kennedydaaf83d2009-01-12 00:06:11 +0000109 u_int8_t revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800110
Harald Welte2e4e6a12006-01-12 13:30:04 -0800111 /* Return true or false: return FALSE and set *hotdrop = 1 to
112 force immediate packet drop. */
113 /* Arguments changed since 2.6.9, as this must now handle
114 non-linear skb, using skb_header_pointer and
115 skb_ip_make_writable. */
Jan Engelhardt1d93a9c2007-07-07 22:15:35 -0700116 bool (*match)(const struct sk_buff *skb,
Jan Engelhardt62fc8052009-07-07 20:42:08 +0200117 struct xt_action_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800118
119 /* Called when user tries to insert an entry of this type. */
Jan Engelhardtb0f38452010-03-19 17:16:42 +0100120 int (*checkentry)(const struct xt_mtchk_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800121
122 /* Called when entry of this type deleted. */
Jan Engelhardt6be3d852008-10-08 11:35:19 +0200123 void (*destroy)(const struct xt_mtdtor_param *);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100124#ifdef CONFIG_COMPAT
Dmitry Mishin27229712006-04-01 02:25:19 -0800125 /* Called when userspace align differs from kernel space one */
Jan Engelhardt739674f2009-06-26 08:23:19 +0200126 void (*compat_from_user)(void *dst, const void *src);
127 int (*compat_to_user)(void __user *dst, const void *src);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100128#endif
Harald Welte2e4e6a12006-01-12 13:30:04 -0800129 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
130 struct module *me;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800131
Jan Engelhardtecb6f852008-01-31 03:54:47 -0800132 const char *table;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800133 unsigned int matchsize;
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100134#ifdef CONFIG_COMPAT
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700135 unsigned int compatsize;
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100136#endif
Patrick McHardy37f9f732006-03-20 17:59:06 -0800137 unsigned int hooks;
138 unsigned short proto;
Patrick McHardyc4b88512006-03-20 18:03:40 -0800139
140 unsigned short family;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800141};
142
143/* Registration hooks for targets. */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800144struct xt_target {
Harald Welte2e4e6a12006-01-12 13:30:04 -0800145 struct list_head list;
146
Jan Engelhardt4b2cbd42010-04-27 15:34:34 +0200147 const char name[XT_EXTENSION_MAXNAMELEN];
Jan Engelhardtf5c511c2010-03-18 14:02:10 +0100148 u_int8_t revision;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800149
Harald Welte2e4e6a12006-01-12 13:30:04 -0800150 /* Returns verdict. Argument order changed since 2.6.9, as this
151 must now handle non-linear skbs, using skb_copy_bits and
152 skb_ip_make_writable. */
Herbert Xu3db05fe2007-10-15 00:53:15 -0700153 unsigned int (*target)(struct sk_buff *skb,
Jan Engelhardtde74c162009-07-05 18:26:37 +0200154 const struct xt_action_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800155
156 /* Called when user tries to insert an entry of this type:
157 hook_mask is a bitmask of hooks from which it can be
158 called. */
Luciano Coelho7ea7b852010-05-20 15:59:16 +0200159 /* Should return 0 on success or an error code otherwise (-Exxxx). */
Jan Engelhardt135367b2010-03-19 17:16:42 +0100160 int (*checkentry)(const struct xt_tgchk_param *);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800161
162 /* Called when entry of this type deleted. */
Jan Engelhardta2df1642008-10-08 11:35:19 +0200163 void (*destroy)(const struct xt_tgdtor_param *);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100164#ifdef CONFIG_COMPAT
Dmitry Mishin27229712006-04-01 02:25:19 -0800165 /* Called when userspace align differs from kernel space one */
Jan Engelhardt739674f2009-06-26 08:23:19 +0200166 void (*compat_from_user)(void *dst, const void *src);
167 int (*compat_to_user)(void __user *dst, const void *src);
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100168#endif
Harald Welte2e4e6a12006-01-12 13:30:04 -0800169 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
170 struct module *me;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800171
Jan Engelhardtecb6f852008-01-31 03:54:47 -0800172 const char *table;
Patrick McHardy37f9f732006-03-20 17:59:06 -0800173 unsigned int targetsize;
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100174#ifdef CONFIG_COMPAT
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700175 unsigned int compatsize;
Alexey Dobriyanc30f5402010-02-02 15:03:24 +0100176#endif
Patrick McHardy37f9f732006-03-20 17:59:06 -0800177 unsigned int hooks;
178 unsigned short proto;
Patrick McHardyc4b88512006-03-20 18:03:40 -0800179
180 unsigned short family;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800181};
182
183/* Furniture shopping... */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800184struct xt_table {
Harald Welte2e4e6a12006-01-12 13:30:04 -0800185 struct list_head list;
186
Harald Welte2e4e6a12006-01-12 13:30:04 -0800187 /* What hooks you will enter on */
188 unsigned int valid_hooks;
189
Harald Welte2e4e6a12006-01-12 13:30:04 -0800190 /* Man behind the curtain... */
Stephen Hemminger4a2f9652009-02-18 16:29:44 +0100191 struct xt_table_info *private;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800192
193 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
194 struct module *me;
195
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200196 u_int8_t af; /* address/protocol family */
Jan Engelhardt2b95efe2009-06-17 13:57:48 +0200197 int priority; /* hook order */
Stephen Hemminger4a2f9652009-02-18 16:29:44 +0100198
199 /* A unique name... */
200 const char name[XT_TABLE_MAXNAMELEN];
Harald Welte2e4e6a12006-01-12 13:30:04 -0800201};
202
203#include <linux/netfilter_ipv4.h>
204
205/* The table itself */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800206struct xt_table_info {
Harald Welte2e4e6a12006-01-12 13:30:04 -0800207 /* Size per table */
208 unsigned int size;
209 /* Number of entries: FIXME. --RR */
210 unsigned int number;
211 /* Initial number of entries. Needed for module usage count */
212 unsigned int initial_entries;
213
214 /* Entry points and underflows */
Patrick McHardy6e23ae22007-11-19 18:53:30 -0800215 unsigned int hook_entry[NF_INET_NUMHOOKS];
216 unsigned int underflow[NF_INET_NUMHOOKS];
Harald Welte2e4e6a12006-01-12 13:30:04 -0800217
Jan Engelhardtf3c5c1b2010-04-19 16:05:10 +0200218 /*
219 * Number of user chains. Since tables cannot have loops, at most
220 * @stacksize jumps (number of user chains) can possibly be made.
221 */
222 unsigned int stacksize;
Eric Dumazet7489aec2010-05-31 16:41:35 +0200223 unsigned int __percpu *stackptr;
Jan Engelhardtf3c5c1b2010-04-19 16:05:10 +0200224 void ***jumpstack;
Harald Welte2e4e6a12006-01-12 13:30:04 -0800225 /* ipt_entry tables: one per CPU */
Eric Dumazet259d4e42007-12-04 23:24:56 -0800226 /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
Stephen Hemminger78454472009-02-20 10:35:32 +0100227 void *entries[1];
Harald Welte2e4e6a12006-01-12 13:30:04 -0800228};
229
Eric Dumazet259d4e42007-12-04 23:24:56 -0800230#define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \
231 + nr_cpu_ids * sizeof(char *))
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700232int xt_register_target(struct xt_target *target);
233void xt_unregister_target(struct xt_target *target);
234int xt_register_targets(struct xt_target *target, unsigned int n);
235void xt_unregister_targets(struct xt_target *target, unsigned int n);
Patrick McHardy52d9c422006-08-22 00:33:45 -0700236
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700237int xt_register_match(struct xt_match *target);
238void xt_unregister_match(struct xt_match *target);
239int xt_register_matches(struct xt_match *match, unsigned int n);
240void xt_unregister_matches(struct xt_match *match, unsigned int n);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800241
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700242int xt_check_match(struct xt_mtchk_param *, unsigned int size, u_int8_t proto,
243 bool inv_proto);
244int xt_check_target(struct xt_tgchk_param *, unsigned int size, u_int8_t proto,
245 bool inv_proto);
Patrick McHardy37f9f732006-03-20 17:59:06 -0800246
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700247struct xt_table *xt_register_table(struct net *net,
248 const struct xt_table *table,
249 struct xt_table_info *bootstrap,
250 struct xt_table_info *newinfo);
251void *xt_unregister_table(struct xt_table *table);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800252
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700253struct xt_table_info *xt_replace_table(struct xt_table *table,
254 unsigned int num_counters,
255 struct xt_table_info *newinfo,
256 int *error);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800257
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700258struct xt_match *xt_find_match(u8 af, const char *name, u8 revision);
259struct xt_target *xt_find_target(u8 af, const char *name, u8 revision);
260struct xt_match *xt_request_find_match(u8 af, const char *name, u8 revision);
261struct xt_target *xt_request_find_target(u8 af, const char *name, u8 revision);
262int xt_find_revision(u8 af, const char *name, u8 revision, int target,
263 int *err);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800264
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700265struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
266 const char *name);
267void xt_table_unlock(struct xt_table *t);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800268
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700269int xt_proto_init(struct net *net, u_int8_t af);
270void xt_proto_fini(struct net *net, u_int8_t af);
Harald Welte2e4e6a12006-01-12 13:30:04 -0800271
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700272struct xt_table_info *xt_alloc_table_info(unsigned int size);
273void xt_free_table_info(struct xt_table_info *info);
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700274
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200275/**
276 * xt_recseq - recursive seqcount for netfilter use
277 *
278 * Packet processing changes the seqcount only if no recursion happened
279 * get_counters() can use read_seqcount_begin()/read_seqcount_retry(),
280 * because we use the normal seqcount convention :
281 * Low order bit set to 1 if a writer is active.
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700282 */
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200283DECLARE_PER_CPU(seqcount_t, xt_recseq);
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700284
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200285/**
286 * xt_write_recseq_begin - start of a write section
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700287 *
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200288 * Begin packet processing : all readers must wait the end
289 * 1) Must be called with preemption disabled
Christoph Lameter933393f2011-12-22 11:58:51 -0600290 * 2) softirqs must be disabled too (or we should use this_cpu_add())
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200291 * Returns :
292 * 1 if no recursion on this cpu
293 * 0 if recursion detected
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700294 */
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200295static inline unsigned int xt_write_recseq_begin(void)
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700296{
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200297 unsigned int addend;
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700298
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200299 /*
300 * Low order bit of sequence is set if we already
301 * called xt_write_recseq_begin().
302 */
303 addend = (__this_cpu_read(xt_recseq.sequence) + 1) & 1;
304
305 /*
306 * This is kind of a write_seqcount_begin(), but addend is 0 or 1
307 * We dont check addend value to avoid a test and conditional jump,
308 * since addend is most likely 1
309 */
310 __this_cpu_add(xt_recseq.sequence, addend);
311 smp_wmb();
312
313 return addend;
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700314}
315
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200316/**
317 * xt_write_recseq_end - end of a write section
318 * @addend: return value from previous xt_write_recseq_begin()
319 *
320 * End packet processing : all readers can proceed
321 * 1) Must be called with preemption disabled
Christoph Lameter933393f2011-12-22 11:58:51 -0600322 * 2) softirqs must be disabled too (or we should use this_cpu_add())
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700323 */
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200324static inline void xt_write_recseq_end(unsigned int addend)
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700325{
Eric Dumazet7f5c6d42011-04-04 17:04:03 +0200326 /* this is kind of a write_seqcount_end(), but addend is 0 or 1 */
327 smp_wmb();
328 __this_cpu_add(xt_recseq.sequence, addend);
Stephen Hemminger942e4a22009-04-28 22:36:33 -0700329}
Harald Welte2e4e6a12006-01-12 13:30:04 -0800330
Eric Dumazetb8dfe492009-03-25 17:31:52 +0100331/*
332 * This helper is performance critical and must be inlined
333 */
334static inline unsigned long ifname_compare_aligned(const char *_a,
335 const char *_b,
336 const char *_mask)
337{
338 const unsigned long *a = (const unsigned long *)_a;
339 const unsigned long *b = (const unsigned long *)_b;
340 const unsigned long *mask = (const unsigned long *)_mask;
341 unsigned long ret;
342
343 ret = (a[0] ^ b[0]) & mask[0];
344 if (IFNAMSIZ > sizeof(unsigned long))
345 ret |= (a[1] ^ b[1]) & mask[1];
346 if (IFNAMSIZ > 2 * sizeof(unsigned long))
347 ret |= (a[2] ^ b[2]) & mask[2];
348 if (IFNAMSIZ > 3 * sizeof(unsigned long))
349 ret |= (a[3] ^ b[3]) & mask[3];
350 BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
351 return ret;
352}
353
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700354struct nf_hook_ops *xt_hook_link(const struct xt_table *, nf_hookfn *);
355void xt_hook_unlink(const struct xt_table *, struct nf_hook_ops *);
Jan Engelhardt2b95efe2009-06-17 13:57:48 +0200356
Dmitry Mishin27229712006-04-01 02:25:19 -0800357#ifdef CONFIG_COMPAT
358#include <net/compat.h>
359
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800360struct compat_xt_entry_match {
Dmitry Mishin27229712006-04-01 02:25:19 -0800361 union {
362 struct {
363 u_int16_t match_size;
364 char name[XT_FUNCTION_MAXNAMELEN - 1];
365 u_int8_t revision;
366 } user;
Patrick McHardy46c5ea3c2006-05-02 05:12:22 +0200367 struct {
368 u_int16_t match_size;
369 compat_uptr_t match;
370 } kernel;
Dmitry Mishin27229712006-04-01 02:25:19 -0800371 u_int16_t match_size;
372 } u;
373 unsigned char data[0];
374};
375
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800376struct compat_xt_entry_target {
Dmitry Mishin27229712006-04-01 02:25:19 -0800377 union {
378 struct {
379 u_int16_t target_size;
380 char name[XT_FUNCTION_MAXNAMELEN - 1];
381 u_int8_t revision;
382 } user;
Patrick McHardy46c5ea3c2006-05-02 05:12:22 +0200383 struct {
384 u_int16_t target_size;
385 compat_uptr_t target;
386 } kernel;
Dmitry Mishin27229712006-04-01 02:25:19 -0800387 u_int16_t target_size;
388 } u;
389 unsigned char data[0];
390};
391
392/* FIXME: this works only on 32 bit tasks
393 * need to change whole approach in order to calculate align as function of
394 * current task alignment */
395
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800396struct compat_xt_counters {
Alexey Dobriyan0a026042010-02-10 15:00:32 +0100397 compat_u64 pcnt, bcnt; /* Packet and byte counters */
Dmitry Mishin27229712006-04-01 02:25:19 -0800398};
399
Eric Dumazetd94d9fe2009-11-04 09:50:58 -0800400struct compat_xt_counters_info {
Dmitry Mishin27229712006-04-01 02:25:19 -0800401 char name[XT_TABLE_MAXNAMELEN];
402 compat_uint_t num_counters;
403 struct compat_xt_counters counters[0];
404};
405
Alexey Dobriyan42107f52010-02-10 15:03:27 +0100406struct _compat_xt_align {
407 __u8 u8;
408 __u16 u16;
409 __u32 u32;
410 compat_u64 u64;
411};
412
Alexey Dobriyana79ff732010-04-13 11:21:46 +0200413#define COMPAT_XT_ALIGN(s) __ALIGN_KERNEL((s), __alignof__(struct _compat_xt_align))
Dmitry Mishin27229712006-04-01 02:25:19 -0800414
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700415void xt_compat_lock(u_int8_t af);
416void xt_compat_unlock(u_int8_t af);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700417
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700418int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta);
419void xt_compat_flush_offsets(u_int8_t af);
420void xt_compat_init_offsets(u_int8_t af, unsigned int number);
421int xt_compat_calc_jump(u_int8_t af, unsigned int offset);
Patrick McHardyb386d9f2007-12-17 21:47:48 -0800422
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700423int xt_compat_match_offset(const struct xt_match *match);
424int xt_compat_match_from_user(struct xt_entry_match *m, void **dstptr,
425 unsigned int *size);
426int xt_compat_match_to_user(const struct xt_entry_match *m,
427 void __user **dstptr, unsigned int *size);
Patrick McHardy9fa492c2006-09-20 12:05:37 -0700428
Joe Perchesa0f4ecf2013-09-26 14:48:15 -0700429int xt_compat_target_offset(const struct xt_target *target);
430void xt_compat_target_from_user(struct xt_entry_target *t, void **dstptr,
431 unsigned int *size);
432int xt_compat_target_to_user(const struct xt_entry_target *t,
433 void __user **dstptr, unsigned int *size);
Dmitry Mishin27229712006-04-01 02:25:19 -0800434
435#endif /* CONFIG_COMPAT */
Harald Welte2e4e6a12006-01-12 13:30:04 -0800436#endif /* _X_TABLES_H */