2 * 25-Jul-1998 Major changes to allow for ip chain table
4 * 3-Jan-2000 Named tables to allow packet selection for different uses.
8 * Format of an IP firewall descriptor
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.
18 #include <linux/types.h>
20 #include <linux/netfilter_ipv4.h>
22 #include <linux/netfilter/x_tables.h>
24 #define IPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
25 #define IPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
26 #define ipt_match xt_match
27 #define ipt_target xt_target
28 #define ipt_table xt_table
29 #define ipt_get_revision xt_get_revision
30 #define ipt_entry_match xt_entry_match
31 #define ipt_entry_target xt_entry_target
32 #define ipt_standard_target xt_standard_target
33 #define ipt_error_target xt_error_target
34 #define ipt_counters xt_counters
35 #define IPT_CONTINUE XT_CONTINUE
36 #define IPT_RETURN XT_RETURN
38 /* This group is older than old (iptables < v1.4.0-rc1~89) */
39 #include <linux/netfilter/xt_tcpudp.h>
40 #define ipt_udp xt_udp
41 #define ipt_tcp xt_tcp
42 #define IPT_TCP_INV_SRCPT XT_TCP_INV_SRCPT
43 #define IPT_TCP_INV_DSTPT XT_TCP_INV_DSTPT
44 #define IPT_TCP_INV_FLAGS XT_TCP_INV_FLAGS
45 #define IPT_TCP_INV_OPTION XT_TCP_INV_OPTION
46 #define IPT_TCP_INV_MASK XT_TCP_INV_MASK
47 #define IPT_UDP_INV_SRCPT XT_UDP_INV_SRCPT
48 #define IPT_UDP_INV_DSTPT XT_UDP_INV_DSTPT
49 #define IPT_UDP_INV_MASK XT_UDP_INV_MASK
51 /* The argument to IPT_SO_ADD_COUNTERS. */
52 #define ipt_counters_info xt_counters_info
53 /* Standard return verdict, or do jump. */
54 #define IPT_STANDARD_TARGET XT_STANDARD_TARGET
56 #define IPT_ERROR_TARGET XT_ERROR_TARGET
58 /* fn returns 0 to continue iteration */
59 #define IPT_MATCH_ITERATE(e, fn, args...) \
60 XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args)
62 /* fn returns 0 to continue iteration */
63 #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \
64 XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args)
66 /* Yes, Virginia, you have to zero the padding. */
68 /* Source and destination IP addr */
69 struct in_addr src, dst;
70 /* Mask for src and dest IP addr */
71 struct in_addr smsk, dmsk;
72 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
73 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
75 /* Protocol, 0 = ANY */
84 /* Values for "flag" field in struct ipt_ip (general ip structure). */
85 #define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */
86 #define IPT_F_GOTO 0x02 /* Set if jump is a goto */
87 #define IPT_F_MASK 0x03 /* All possible flag bits mask. */
89 /* Values for "inv" field in struct ipt_ip. */
90 #define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
91 #define IPT_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
92 #define IPT_INV_TOS 0x04 /* Invert the sense of TOS. */
93 #define IPT_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
94 #define IPT_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
95 #define IPT_INV_FRAG 0x20 /* Invert the sense of FRAG. */
96 #define IPT_INV_PROTO XT_INV_PROTO
97 #define IPT_INV_MASK 0x7F /* All possible flag bits mask. */
99 /* This structure defines each of the firewall rules. Consists of 3
100 parts which are 1) general IP header stuff 2) match specific
101 stuff 3) the target to perform if the rule matches */
105 /* Mark with fields that we care about. */
106 unsigned int nfcache;
108 /* Size of ipt_entry + matches */
110 /* Size of ipt_entry + matches + target */
114 unsigned int comefrom;
116 /* Packet and byte counters. */
117 struct xt_counters counters;
119 /* The matches (if any), then the target. */
120 unsigned char elems[0];
124 * New IP firewall options for [gs]etsockopt at the RAW IP level.
125 * Unlike BSD Linux inherits IP options so you don't have to use a raw
126 * socket for this. Instead we check rights in the calls.
128 * ATTENTION: check linux/in.h before adding new number here.
130 #define IPT_BASE_CTL 64
132 #define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
133 #define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1)
134 #define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS
136 #define IPT_SO_GET_INFO (IPT_BASE_CTL)
137 #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
138 #define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2)
139 #define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3)
140 #define IPT_SO_GET_MAX IPT_SO_GET_REVISION_TARGET
142 /* ICMP matching stuff */
144 __u8 type; /* type to match */
145 __u8 code[2]; /* range of code */
146 __u8 invflags; /* Inverse flags */
149 /* Values for "inv" field for struct ipt_icmp. */
150 #define IPT_ICMP_INV 0x01 /* Invert the sense of type/code test */
152 /* The argument to IPT_SO_GET_INFO */
154 /* Which table: caller fills this in. */
155 char name[XT_TABLE_MAXNAMELEN];
157 /* Kernel fills these in. */
158 /* Which hook entry points are valid: bitmask */
159 unsigned int valid_hooks;
161 /* Hook entry points: one per netfilter hook. */
162 unsigned int hook_entry[NF_INET_NUMHOOKS];
164 /* Underflow points. */
165 unsigned int underflow[NF_INET_NUMHOOKS];
167 /* Number of entries */
168 unsigned int num_entries;
170 /* Size of entries. */
174 /* The argument to IPT_SO_SET_REPLACE. */
177 char name[XT_TABLE_MAXNAMELEN];
179 /* Which hook entry points are valid: bitmask. You can't
181 unsigned int valid_hooks;
183 /* Number of entries */
184 unsigned int num_entries;
186 /* Total size of new entries */
189 /* Hook entry points. */
190 unsigned int hook_entry[NF_INET_NUMHOOKS];
192 /* Underflow points. */
193 unsigned int underflow[NF_INET_NUMHOOKS];
195 /* Information about old entries: */
196 /* Number of counters (must be equal to current number of entries). */
197 unsigned int num_counters;
198 /* The old entries' counters. */
199 struct xt_counters *counters;
201 /* The entries (hang off end: not really an array). */
202 struct ipt_entry entries[0];
205 /* The argument to IPT_SO_GET_ENTRIES. */
206 struct ipt_get_entries {
207 /* Which table: user fills this in. */
208 char name[XT_TABLE_MAXNAMELEN];
210 /* User fills this in: total entry size. */
214 struct ipt_entry entrytable[0];
217 /* Helper functions */
218 static __inline__ struct xt_entry_target *
219 ipt_get_target(struct ipt_entry *e)
221 return (void *)e + e->target_offset;
225 * Main firewall chains definitions and global var's definitions.
227 #endif /* _IPTABLES_H */