blob: 7bfc5893ec314e247693374131a31f0144da20d3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * 25-Jul-1998 Major changes to allow for ip chain table
3 *
4 * 3-Jan-2000 Named tables to allow packet selection for different uses.
5 */
6
7/*
8 * Format of an IP firewall descriptor
9 *
10 * src, dst, src_mask, dst_mask are always stored in network byte order.
11 * flags are stored in host byte order (of course).
12 * Port numbers are stored in HOST byte order.
13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#ifndef _IPTABLES_H
15#define _IPTABLES_H
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/if.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/in.h>
19#include <linux/ip.h>
20#include <linux/skbuff.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <linux/init.h>
David Howells17c07592012-10-09 09:48:59 +010023#include <uapi/linux/netfilter_ipv4/ip_tables.h>
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025extern void ipt_init(void) __init;
26
Florian Westphala67dd262016-02-25 10:08:35 +010027int ipt_register_table(struct net *net, const struct xt_table *table,
28 const struct ipt_replace *repl,
29 const struct nf_hook_ops *ops, struct xt_table **res);
30void ipt_unregister_table(struct net *net, struct xt_table *table,
31 const struct nf_hook_ops *ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033/* Standard entry. */
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080034struct ipt_standard {
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 struct ipt_entry entry;
Jan Engelhardt87a2e70d2010-10-13 16:11:22 +020036 struct xt_standard_target target;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037};
38
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080039struct ipt_error {
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 struct ipt_entry entry;
Jan Engelhardt75f0a0f2010-10-13 16:37:45 +020041 struct xt_error_target target;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042};
43
Patrick McHardy3c2ad462007-05-10 14:14:16 -070044#define IPT_ENTRY_INIT(__size) \
45{ \
46 .target_offset = sizeof(struct ipt_entry), \
47 .next_offset = (__size), \
48}
49
50#define IPT_STANDARD_INIT(__verdict) \
51{ \
52 .entry = IPT_ENTRY_INIT(sizeof(struct ipt_standard)), \
Jan Engelhardt243bf6e2010-10-13 16:28:00 +020053 .target = XT_TARGET_INIT(XT_STANDARD_TARGET, \
Patrick McHardy3c2ad462007-05-10 14:14:16 -070054 sizeof(struct xt_standard_target)), \
55 .target.verdict = -(__verdict) - 1, \
56}
57
58#define IPT_ERROR_INIT \
59{ \
60 .entry = IPT_ENTRY_INIT(sizeof(struct ipt_error)), \
Jan Engelhardt243bf6e2010-10-13 16:28:00 +020061 .target = XT_TARGET_INIT(XT_ERROR_TARGET, \
Jan Engelhardt75f0a0f2010-10-13 16:37:45 +020062 sizeof(struct xt_error_target)), \
Patrick McHardy3c2ad462007-05-10 14:14:16 -070063 .target.errorname = "ERROR", \
64}
65
Jan Engelhardte3eaa992009-06-17 22:14:54 +020066extern void *ipt_alloc_initial_table(const struct xt_table *);
Herbert Xu3db05fe2007-10-15 00:53:15 -070067extern unsigned int ipt_do_table(struct sk_buff *skb,
David S. Miller1c491ba2015-04-03 20:56:08 -040068 const struct nf_hook_state *state,
Jan Engelhardte60a13e2007-02-07 15:12:33 -080069 struct xt_table *table);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Dmitry Mishin27229712006-04-01 02:25:19 -080071#ifdef CONFIG_COMPAT
72#include <net/compat.h>
73
Eric Dumazetd94d9fe2009-11-04 09:50:58 -080074struct compat_ipt_entry {
Dmitry Mishin27229712006-04-01 02:25:19 -080075 struct ipt_ip ip;
76 compat_uint_t nfcache;
Ben Hutchings7ff30c42011-08-24 18:44:57 +000077 __u16 target_offset;
78 __u16 next_offset;
Dmitry Mishin27229712006-04-01 02:25:19 -080079 compat_uint_t comefrom;
80 struct compat_xt_counters counters;
81 unsigned char elems[0];
82};
83
Patrick McHardy73cd5982007-12-17 21:47:32 -080084/* Helper functions */
Jan Engelhardt87a2e70d2010-10-13 16:11:22 +020085static inline struct xt_entry_target *
Patrick McHardy73cd5982007-12-17 21:47:32 -080086compat_ipt_get_target(struct compat_ipt_entry *e)
87{
88 return (void *)e + e->target_offset;
89}
90
Dmitry Mishin27229712006-04-01 02:25:19 -080091#endif /* CONFIG_COMPAT */
Linus Torvalds1da177e2005-04-16 15:20:36 -070092#endif /* _IPTABLES_H */