4 #include <linux/types.h>
6 #define XT_FUNCTION_MAXNAMELEN 30
7 #define XT_TABLE_MAXNAMELEN 32
15 /* Used by userspace */
16 char name[XT_FUNCTION_MAXNAMELEN-1];
23 /* Used inside the kernel */
24 struct xt_match *match;
31 unsigned char data[0];
34 struct xt_entry_target
40 /* Used by userspace */
41 char name[XT_FUNCTION_MAXNAMELEN-1];
48 /* Used inside the kernel */
49 struct xt_target *target;
56 unsigned char data[0];
59 #define XT_TARGET_INIT(__name, __size) \
62 .target_size = XT_ALIGN(__size), \
67 struct xt_standard_target
69 struct xt_entry_target target;
73 /* The argument to IPT_SO_GET_REVISION_*. Returns highest revision
74 * kernel supports, if >= revision. */
75 struct xt_get_revision
77 char name[XT_FUNCTION_MAXNAMELEN-1];
82 /* CONTINUE verdict for targets */
83 #define XT_CONTINUE 0xFFFFFFFF
85 /* For standard target */
86 #define XT_RETURN (-NF_REPEAT - 1)
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
101 #define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \
102 & ~(__alignof__(struct _xt_align)-1))
104 /* Standard return verdict, or do jump. */
105 #define XT_STANDARD_TARGET ""
107 #define XT_ERROR_TARGET "ERROR"
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)
114 __u64 pcnt, bcnt; /* Packet and byte counters */
117 /* The argument to IPT_SO_ADD_COUNTERS. */
118 struct xt_counters_info
121 char name[XT_TABLE_MAXNAMELEN];
123 unsigned int num_counters;
125 /* The counters (actually `number' of these). */
126 struct xt_counters counters[0];
129 #define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
131 /* fn returns 0 to continue iteration */
132 #define XT_MATCH_ITERATE(type, e, fn, args...) \
136 struct xt_entry_match *__m; \
138 for (__i = sizeof(type); \
139 __i < (e)->target_offset; \
140 __i += __m->u.match_size) { \
141 __m = (void *)e + __i; \
143 __ret = fn(__m , ## args); \
150 /* fn returns 0 to continue iteration */
151 #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \
153 unsigned int __i, __n; \
157 for (__i = 0, __n = 0; __i < (size); \
158 __i += __entry->next_offset, __n++) { \
159 __entry = (void *)(entries) + __i; \
163 __ret = fn(__entry , ## args); \
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)
176 #include <linux/netdevice.h>
179 * struct xt_match_param - parameters for match extensions' match functions
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
188 * @family: Actual NFPROTO_* through which the function is invoked
189 * (helpful when match->family == NFPROTO_UNSPEC)
191 struct xt_match_param {
192 const struct net_device *in, *out;
193 const struct xt_match *match;
194 const void *matchinfo;
202 * struct xt_mtchk_param - parameters for match extensions'
203 * checkentry functions
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
212 struct xt_mtchk_param {
214 const void *entryinfo;
215 const struct xt_match *match;
217 unsigned int hook_mask;
221 /* Match destructor parameters */
222 struct xt_mtdtor_param {
223 const struct xt_match *match;
229 * struct xt_target_param - parameters for target extensions' target functions
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
235 * Other fields see above.
237 struct xt_target_param {
238 const struct net_device *in, *out;
239 unsigned int hooknum;
240 const struct xt_target *target;
241 const void *targinfo;
246 * struct xt_tgchk_param - parameters for target extensions'
247 * checkentry functions
249 * @entryinfo: the family-specific rule data
250 * (struct ipt_entry, ip6t_entry, arpt_entry, ebt_entry)
252 * Other fields see above.
254 struct xt_tgchk_param {
256 const void *entryinfo;
257 const struct xt_target *target;
259 unsigned int hook_mask;
263 /* Target destructor parameters */
264 struct xt_tgdtor_param {
265 const struct xt_target *target;
272 struct list_head list;
274 const char name[XT_FUNCTION_MAXNAMELEN-1];
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. */
282 bool (*match)(const struct sk_buff *skb,
283 const struct xt_match_param *);
285 /* Called when user tries to insert an entry of this type. */
286 bool (*checkentry)(const struct xt_mtchk_param *);
288 /* Called when entry of this type deleted. */
289 void (*destroy)(const struct xt_mtdtor_param *);
291 /* Called when userspace align differs from kernel space one */
292 void (*compat_from_user)(void *dst, void *src);
293 int (*compat_to_user)(void __user *dst, void *src);
295 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
298 /* Free to use by each match */
302 unsigned int matchsize;
303 unsigned int compatsize;
305 unsigned short proto;
307 unsigned short family;
310 /* Registration hooks for targets. */
313 struct list_head list;
315 const char name[XT_FUNCTION_MAXNAMELEN-1];
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. */
320 unsigned int (*target)(struct sk_buff *skb,
321 const struct xt_target_param *);
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
326 /* Should return true or false. */
327 bool (*checkentry)(const struct xt_tgchk_param *);
329 /* Called when entry of this type deleted. */
330 void (*destroy)(const struct xt_tgdtor_param *);
332 /* Called when userspace align differs from kernel space one */
333 void (*compat_from_user)(void *dst, void *src);
334 int (*compat_to_user)(void __user *dst, void *src);
336 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
340 unsigned int targetsize;
341 unsigned int compatsize;
343 unsigned short proto;
345 unsigned short family;
349 /* Furniture shopping... */
352 struct list_head list;
354 /* What hooks you will enter on */
355 unsigned int valid_hooks;
357 /* Lock for the curtain */
360 /* Man behind the curtain... */
361 struct xt_table_info *private;
363 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
366 u_int8_t af; /* address/protocol family */
368 /* A unique name... */
369 const char name[XT_TABLE_MAXNAMELEN];
372 #include <linux/netfilter_ipv4.h>
374 /* The table itself */
379 /* Number of entries: FIXME. --RR */
381 /* Initial number of entries. Needed for module usage count */
382 unsigned int initial_entries;
384 /* Entry points and underflows */
385 unsigned int hook_entry[NF_INET_NUMHOOKS];
386 unsigned int underflow[NF_INET_NUMHOOKS];
388 /* ipt_entry tables: one per CPU */
389 /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */
393 #define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \
394 + nr_cpu_ids * sizeof(char *))
395 extern int xt_register_target(struct xt_target *target);
396 extern void xt_unregister_target(struct xt_target *target);
397 extern int xt_register_targets(struct xt_target *target, unsigned int n);
398 extern void xt_unregister_targets(struct xt_target *target, unsigned int n);
400 extern int xt_register_match(struct xt_match *target);
401 extern void xt_unregister_match(struct xt_match *target);
402 extern int xt_register_matches(struct xt_match *match, unsigned int n);
403 extern void xt_unregister_matches(struct xt_match *match, unsigned int n);
405 extern int xt_check_match(struct xt_mtchk_param *,
406 unsigned int size, u_int8_t proto, bool inv_proto);
407 extern int xt_check_target(struct xt_tgchk_param *,
408 unsigned int size, u_int8_t proto, bool inv_proto);
410 extern struct xt_table *xt_register_table(struct net *net,
411 struct xt_table *table,
412 struct xt_table_info *bootstrap,
413 struct xt_table_info *newinfo);
414 extern void *xt_unregister_table(struct xt_table *table);
416 extern struct xt_table_info *xt_replace_table(struct xt_table *table,
417 unsigned int num_counters,
418 struct xt_table_info *newinfo,
421 extern struct xt_match *xt_find_match(u8 af, const char *name, u8 revision);
422 extern struct xt_target *xt_find_target(u8 af, const char *name, u8 revision);
423 extern struct xt_target *xt_request_find_target(u8 af, const char *name,
425 extern int xt_find_revision(u8 af, const char *name, u8 revision,
426 int target, int *err);
428 extern struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af,
430 extern void xt_table_unlock(struct xt_table *t);
432 extern int xt_proto_init(struct net *net, u_int8_t af);
433 extern void xt_proto_fini(struct net *net, u_int8_t af);
435 extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
436 extern void xt_free_table_info(struct xt_table_info *info);
437 extern void xt_table_entry_swap_rcu(struct xt_table_info *old,
438 struct xt_table_info *new);
441 * This helper is performance critical and must be inlined
443 static inline unsigned long ifname_compare_aligned(const char *_a,
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;
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));
464 #include <net/compat.h>
466 struct compat_xt_entry_match
470 u_int16_t match_size;
471 char name[XT_FUNCTION_MAXNAMELEN - 1];
475 u_int16_t match_size;
478 u_int16_t match_size;
480 unsigned char data[0];
483 struct compat_xt_entry_target
487 u_int16_t target_size;
488 char name[XT_FUNCTION_MAXNAMELEN - 1];
492 u_int16_t target_size;
493 compat_uptr_t target;
495 u_int16_t target_size;
497 unsigned char data[0];
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 */
504 struct compat_xt_counters
506 #if defined(CONFIG_X86_64) || defined(CONFIG_IA64)
513 struct compat_xt_counters_info
515 char name[XT_TABLE_MAXNAMELEN];
516 compat_uint_t num_counters;
517 struct compat_xt_counters counters[0];
520 #define COMPAT_XT_ALIGN(s) (((s) + (__alignof__(struct compat_xt_counters)-1)) \
521 & ~(__alignof__(struct compat_xt_counters)-1))
523 extern void xt_compat_lock(u_int8_t af);
524 extern void xt_compat_unlock(u_int8_t af);
526 extern int xt_compat_add_offset(u_int8_t af, unsigned int offset, short delta);
527 extern void xt_compat_flush_offsets(u_int8_t af);
528 extern short xt_compat_calc_jump(u_int8_t af, unsigned int offset);
530 extern int xt_compat_match_offset(const struct xt_match *match);
531 extern int xt_compat_match_from_user(struct xt_entry_match *m,
532 void **dstptr, unsigned int *size);
533 extern int xt_compat_match_to_user(struct xt_entry_match *m,
534 void __user **dstptr, unsigned int *size);
536 extern int xt_compat_target_offset(const struct xt_target *target);
537 extern void xt_compat_target_from_user(struct xt_entry_target *t,
538 void **dstptr, unsigned int *size);
539 extern int xt_compat_target_to_user(struct xt_entry_target *t,
540 void __user **dstptr, unsigned int *size);
542 #endif /* CONFIG_COMPAT */
543 #endif /* __KERNEL__ */
545 #endif /* _X_TABLES_H */