]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
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 | */ | |
14 | ||
15 | #ifndef _IPTABLES_H | |
16 | #define _IPTABLES_H | |
17 | ||
18 | #ifdef __KERNEL__ | |
19 | #include <linux/if.h> | |
1da177e4 LT |
20 | #include <linux/in.h> |
21 | #include <linux/ip.h> | |
22 | #include <linux/skbuff.h> | |
23 | #endif | |
c8942f1f | 24 | #include <linux/types.h> |
1da177e4 LT |
25 | #include <linux/compiler.h> |
26 | #include <linux/netfilter_ipv4.h> | |
27 | ||
2e4e6a17 HW |
28 | #include <linux/netfilter/x_tables.h> |
29 | ||
30 | #define IPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN | |
2748e5de | 31 | #define IPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN |
2e4e6a17 HW |
32 | #define ipt_match xt_match |
33 | #define ipt_target xt_target | |
34 | #define ipt_table xt_table | |
35 | #define ipt_get_revision xt_get_revision | |
1da177e4 LT |
36 | |
37 | /* Yes, Virginia, you have to zero the padding. */ | |
38 | struct ipt_ip { | |
39 | /* Source and destination IP addr */ | |
40 | struct in_addr src, dst; | |
41 | /* Mask for src and dest IP addr */ | |
42 | struct in_addr smsk, dmsk; | |
43 | char iniface[IFNAMSIZ], outiface[IFNAMSIZ]; | |
44 | unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ]; | |
45 | ||
46 | /* Protocol, 0 = ANY */ | |
47 | u_int16_t proto; | |
48 | ||
49 | /* Flags word */ | |
50 | u_int8_t flags; | |
51 | /* Inverse flags */ | |
52 | u_int8_t invflags; | |
53 | }; | |
54 | ||
1e30a014 DM |
55 | #define ipt_entry_match xt_entry_match |
56 | #define ipt_entry_target xt_entry_target | |
57 | #define ipt_standard_target xt_standard_target | |
1da177e4 | 58 | |
2e4e6a17 | 59 | #define ipt_counters xt_counters |
1da177e4 LT |
60 | |
61 | /* Values for "flag" field in struct ipt_ip (general ip structure). */ | |
62 | #define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */ | |
05465343 PM |
63 | #define IPT_F_GOTO 0x02 /* Set if jump is a goto */ |
64 | #define IPT_F_MASK 0x03 /* All possible flag bits mask. */ | |
1da177e4 LT |
65 | |
66 | /* Values for "inv" field in struct ipt_ip. */ | |
67 | #define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */ | |
68 | #define IPT_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */ | |
69 | #define IPT_INV_TOS 0x04 /* Invert the sense of TOS. */ | |
70 | #define IPT_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */ | |
71 | #define IPT_INV_DSTIP 0x10 /* Invert the sense of DST OP. */ | |
72 | #define IPT_INV_FRAG 0x20 /* Invert the sense of FRAG. */ | |
2e4e6a17 | 73 | #define IPT_INV_PROTO XT_INV_PROTO |
1da177e4 LT |
74 | #define IPT_INV_MASK 0x7F /* All possible flag bits mask. */ |
75 | ||
76 | /* This structure defines each of the firewall rules. Consists of 3 | |
77 | parts which are 1) general IP header stuff 2) match specific | |
78 | stuff 3) the target to perform if the rule matches */ | |
d94d9fee | 79 | struct ipt_entry { |
1da177e4 LT |
80 | struct ipt_ip ip; |
81 | ||
82 | /* Mark with fields that we care about. */ | |
83 | unsigned int nfcache; | |
84 | ||
85 | /* Size of ipt_entry + matches */ | |
86 | u_int16_t target_offset; | |
87 | /* Size of ipt_entry + matches + target */ | |
88 | u_int16_t next_offset; | |
89 | ||
90 | /* Back pointer */ | |
91 | unsigned int comefrom; | |
92 | ||
93 | /* Packet and byte counters. */ | |
2e4e6a17 | 94 | struct xt_counters counters; |
1da177e4 LT |
95 | |
96 | /* The matches (if any), then the target. */ | |
97 | unsigned char elems[0]; | |
98 | }; | |
99 | ||
100 | /* | |
101 | * New IP firewall options for [gs]etsockopt at the RAW IP level. | |
102 | * Unlike BSD Linux inherits IP options so you don't have to use a raw | |
b96e7ecb YK |
103 | * socket for this. Instead we check rights in the calls. |
104 | * | |
105 | * ATTENTION: check linux/in.h before adding new number here. | |
106 | */ | |
107 | #define IPT_BASE_CTL 64 | |
108 | ||
109 | #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) | |
110 | #define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1) | |
111 | #define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS | |
112 | ||
113 | #define IPT_SO_GET_INFO (IPT_BASE_CTL) | |
114 | #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) | |
115 | #define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2) | |
116 | #define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3) | |
117 | #define IPT_SO_GET_MAX IPT_SO_GET_REVISION_TARGET | |
1da177e4 | 118 | |
2e4e6a17 HW |
119 | #define IPT_CONTINUE XT_CONTINUE |
120 | #define IPT_RETURN XT_RETURN | |
1da177e4 | 121 | |
2e4e6a17 HW |
122 | #include <linux/netfilter/xt_tcpudp.h> |
123 | #define ipt_udp xt_udp | |
124 | #define ipt_tcp xt_tcp | |
1da177e4 | 125 | |
2e4e6a17 HW |
126 | #define IPT_TCP_INV_SRCPT XT_TCP_INV_SRCPT |
127 | #define IPT_TCP_INV_DSTPT XT_TCP_INV_DSTPT | |
128 | #define IPT_TCP_INV_FLAGS XT_TCP_INV_FLAGS | |
129 | #define IPT_TCP_INV_OPTION XT_TCP_INV_OPTION | |
130 | #define IPT_TCP_INV_MASK XT_TCP_INV_MASK | |
1da177e4 | 131 | |
2e4e6a17 HW |
132 | #define IPT_UDP_INV_SRCPT XT_UDP_INV_SRCPT |
133 | #define IPT_UDP_INV_DSTPT XT_UDP_INV_DSTPT | |
134 | #define IPT_UDP_INV_MASK XT_UDP_INV_MASK | |
1da177e4 LT |
135 | |
136 | /* ICMP matching stuff */ | |
d94d9fee | 137 | struct ipt_icmp { |
1da177e4 LT |
138 | u_int8_t type; /* type to match */ |
139 | u_int8_t code[2]; /* range of code */ | |
140 | u_int8_t invflags; /* Inverse flags */ | |
141 | }; | |
142 | ||
143 | /* Values for "inv" field for struct ipt_icmp. */ | |
144 | #define IPT_ICMP_INV 0x01 /* Invert the sense of type/code test */ | |
145 | ||
146 | /* The argument to IPT_SO_GET_INFO */ | |
d94d9fee | 147 | struct ipt_getinfo { |
1da177e4 LT |
148 | /* Which table: caller fills this in. */ |
149 | char name[IPT_TABLE_MAXNAMELEN]; | |
150 | ||
151 | /* Kernel fills these in. */ | |
152 | /* Which hook entry points are valid: bitmask */ | |
153 | unsigned int valid_hooks; | |
154 | ||
155 | /* Hook entry points: one per netfilter hook. */ | |
6e23ae2a | 156 | unsigned int hook_entry[NF_INET_NUMHOOKS]; |
1da177e4 LT |
157 | |
158 | /* Underflow points. */ | |
6e23ae2a | 159 | unsigned int underflow[NF_INET_NUMHOOKS]; |
1da177e4 LT |
160 | |
161 | /* Number of entries */ | |
162 | unsigned int num_entries; | |
163 | ||
164 | /* Size of entries. */ | |
165 | unsigned int size; | |
166 | }; | |
167 | ||
168 | /* The argument to IPT_SO_SET_REPLACE. */ | |
d94d9fee | 169 | struct ipt_replace { |
1da177e4 LT |
170 | /* Which table. */ |
171 | char name[IPT_TABLE_MAXNAMELEN]; | |
172 | ||
173 | /* Which hook entry points are valid: bitmask. You can't | |
174 | change this. */ | |
175 | unsigned int valid_hooks; | |
176 | ||
177 | /* Number of entries */ | |
178 | unsigned int num_entries; | |
179 | ||
180 | /* Total size of new entries */ | |
181 | unsigned int size; | |
182 | ||
183 | /* Hook entry points. */ | |
6e23ae2a | 184 | unsigned int hook_entry[NF_INET_NUMHOOKS]; |
1da177e4 LT |
185 | |
186 | /* Underflow points. */ | |
6e23ae2a | 187 | unsigned int underflow[NF_INET_NUMHOOKS]; |
1da177e4 LT |
188 | |
189 | /* Information about old entries: */ | |
190 | /* Number of counters (must be equal to current number of entries). */ | |
191 | unsigned int num_counters; | |
192 | /* The old entries' counters. */ | |
2e4e6a17 | 193 | struct xt_counters __user *counters; |
1da177e4 LT |
194 | |
195 | /* The entries (hang off end: not really an array). */ | |
196 | struct ipt_entry entries[0]; | |
197 | }; | |
198 | ||
199 | /* The argument to IPT_SO_ADD_COUNTERS. */ | |
2e4e6a17 | 200 | #define ipt_counters_info xt_counters_info |
1da177e4 LT |
201 | |
202 | /* The argument to IPT_SO_GET_ENTRIES. */ | |
d94d9fee | 203 | struct ipt_get_entries { |
1da177e4 LT |
204 | /* Which table: user fills this in. */ |
205 | char name[IPT_TABLE_MAXNAMELEN]; | |
206 | ||
207 | /* User fills this in: total entry size. */ | |
208 | unsigned int size; | |
209 | ||
210 | /* The entries. */ | |
211 | struct ipt_entry entrytable[0]; | |
212 | }; | |
213 | ||
1da177e4 | 214 | /* Standard return verdict, or do jump. */ |
2e4e6a17 | 215 | #define IPT_STANDARD_TARGET XT_STANDARD_TARGET |
1da177e4 | 216 | /* Error verdict. */ |
2e4e6a17 | 217 | #define IPT_ERROR_TARGET XT_ERROR_TARGET |
1da177e4 LT |
218 | |
219 | /* Helper functions */ | |
220 | static __inline__ struct ipt_entry_target * | |
221 | ipt_get_target(struct ipt_entry *e) | |
222 | { | |
223 | return (void *)e + e->target_offset; | |
224 | } | |
225 | ||
dcea992a | 226 | #ifndef __KERNEL__ |
1da177e4 | 227 | /* fn returns 0 to continue iteration */ |
89c002d6 PM |
228 | #define IPT_MATCH_ITERATE(e, fn, args...) \ |
229 | XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args) | |
1da177e4 LT |
230 | |
231 | /* fn returns 0 to continue iteration */ | |
89c002d6 PM |
232 | #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \ |
233 | XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args) | |
72b2b1dd | 234 | #endif |
1da177e4 LT |
235 | |
236 | /* | |
237 | * Main firewall chains definitions and global var's definitions. | |
238 | */ | |
239 | #ifdef __KERNEL__ | |
240 | ||
241 | #include <linux/init.h> | |
242 | extern void ipt_init(void) __init; | |
243 | ||
44d34e72 | 244 | extern struct xt_table *ipt_register_table(struct net *net, |
35aad0ff | 245 | const struct xt_table *table, |
44d34e72 | 246 | const struct ipt_replace *repl); |
f54e9367 | 247 | extern void ipt_unregister_table(struct net *net, struct xt_table *table); |
1da177e4 | 248 | |
1da177e4 | 249 | /* Standard entry. */ |
d94d9fee | 250 | struct ipt_standard { |
1da177e4 LT |
251 | struct ipt_entry entry; |
252 | struct ipt_standard_target target; | |
253 | }; | |
254 | ||
d94d9fee | 255 | struct ipt_error_target { |
1da177e4 LT |
256 | struct ipt_entry_target target; |
257 | char errorname[IPT_FUNCTION_MAXNAMELEN]; | |
258 | }; | |
259 | ||
d94d9fee | 260 | struct ipt_error { |
1da177e4 LT |
261 | struct ipt_entry entry; |
262 | struct ipt_error_target target; | |
263 | }; | |
264 | ||
3c2ad469 PM |
265 | #define IPT_ENTRY_INIT(__size) \ |
266 | { \ | |
267 | .target_offset = sizeof(struct ipt_entry), \ | |
268 | .next_offset = (__size), \ | |
269 | } | |
270 | ||
271 | #define IPT_STANDARD_INIT(__verdict) \ | |
272 | { \ | |
273 | .entry = IPT_ENTRY_INIT(sizeof(struct ipt_standard)), \ | |
274 | .target = XT_TARGET_INIT(IPT_STANDARD_TARGET, \ | |
275 | sizeof(struct xt_standard_target)), \ | |
276 | .target.verdict = -(__verdict) - 1, \ | |
277 | } | |
278 | ||
279 | #define IPT_ERROR_INIT \ | |
280 | { \ | |
281 | .entry = IPT_ENTRY_INIT(sizeof(struct ipt_error)), \ | |
282 | .target = XT_TARGET_INIT(IPT_ERROR_TARGET, \ | |
283 | sizeof(struct ipt_error_target)), \ | |
284 | .target.errorname = "ERROR", \ | |
285 | } | |
286 | ||
e3eaa991 | 287 | extern void *ipt_alloc_initial_table(const struct xt_table *); |
3db05fea | 288 | extern unsigned int ipt_do_table(struct sk_buff *skb, |
1da177e4 LT |
289 | unsigned int hook, |
290 | const struct net_device *in, | |
291 | const struct net_device *out, | |
e60a13e0 | 292 | struct xt_table *table); |
1da177e4 | 293 | |
2e4e6a17 | 294 | #define IPT_ALIGN(s) XT_ALIGN(s) |
2722971c DM |
295 | |
296 | #ifdef CONFIG_COMPAT | |
297 | #include <net/compat.h> | |
298 | ||
d94d9fee | 299 | struct compat_ipt_entry { |
2722971c DM |
300 | struct ipt_ip ip; |
301 | compat_uint_t nfcache; | |
302 | u_int16_t target_offset; | |
303 | u_int16_t next_offset; | |
304 | compat_uint_t comefrom; | |
305 | struct compat_xt_counters counters; | |
306 | unsigned char elems[0]; | |
307 | }; | |
308 | ||
73cd598d PM |
309 | /* Helper functions */ |
310 | static inline struct ipt_entry_target * | |
311 | compat_ipt_get_target(struct compat_ipt_entry *e) | |
312 | { | |
313 | return (void *)e + e->target_offset; | |
314 | } | |
315 | ||
2722971c DM |
316 | #define COMPAT_IPT_ALIGN(s) COMPAT_XT_ALIGN(s) |
317 | ||
318 | #endif /* CONFIG_COMPAT */ | |
1da177e4 LT |
319 | #endif /*__KERNEL__*/ |
320 | #endif /* _IPTABLES_H */ |