]>
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> | |
20 | #include <linux/types.h> | |
21 | #include <linux/in.h> | |
22 | #include <linux/ip.h> | |
23 | #include <linux/skbuff.h> | |
24 | #endif | |
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 */ | |
79 | struct ipt_entry | |
80 | { | |
81 | struct ipt_ip ip; | |
82 | ||
83 | /* Mark with fields that we care about. */ | |
84 | unsigned int nfcache; | |
85 | ||
86 | /* Size of ipt_entry + matches */ | |
87 | u_int16_t target_offset; | |
88 | /* Size of ipt_entry + matches + target */ | |
89 | u_int16_t next_offset; | |
90 | ||
91 | /* Back pointer */ | |
92 | unsigned int comefrom; | |
93 | ||
94 | /* Packet and byte counters. */ | |
2e4e6a17 | 95 | struct xt_counters counters; |
1da177e4 LT |
96 | |
97 | /* The matches (if any), then the target. */ | |
98 | unsigned char elems[0]; | |
99 | }; | |
100 | ||
101 | /* | |
102 | * New IP firewall options for [gs]etsockopt at the RAW IP level. | |
103 | * Unlike BSD Linux inherits IP options so you don't have to use a raw | |
b96e7ecb YK |
104 | * socket for this. Instead we check rights in the calls. |
105 | * | |
106 | * ATTENTION: check linux/in.h before adding new number here. | |
107 | */ | |
108 | #define IPT_BASE_CTL 64 | |
109 | ||
110 | #define IPT_SO_SET_REPLACE (IPT_BASE_CTL) | |
111 | #define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1) | |
112 | #define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS | |
113 | ||
114 | #define IPT_SO_GET_INFO (IPT_BASE_CTL) | |
115 | #define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1) | |
116 | #define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2) | |
117 | #define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3) | |
118 | #define IPT_SO_GET_MAX IPT_SO_GET_REVISION_TARGET | |
1da177e4 | 119 | |
2e4e6a17 HW |
120 | #define IPT_CONTINUE XT_CONTINUE |
121 | #define IPT_RETURN XT_RETURN | |
1da177e4 | 122 | |
2e4e6a17 HW |
123 | #include <linux/netfilter/xt_tcpudp.h> |
124 | #define ipt_udp xt_udp | |
125 | #define ipt_tcp xt_tcp | |
1da177e4 | 126 | |
2e4e6a17 HW |
127 | #define IPT_TCP_INV_SRCPT XT_TCP_INV_SRCPT |
128 | #define IPT_TCP_INV_DSTPT XT_TCP_INV_DSTPT | |
129 | #define IPT_TCP_INV_FLAGS XT_TCP_INV_FLAGS | |
130 | #define IPT_TCP_INV_OPTION XT_TCP_INV_OPTION | |
131 | #define IPT_TCP_INV_MASK XT_TCP_INV_MASK | |
1da177e4 | 132 | |
2e4e6a17 HW |
133 | #define IPT_UDP_INV_SRCPT XT_UDP_INV_SRCPT |
134 | #define IPT_UDP_INV_DSTPT XT_UDP_INV_DSTPT | |
135 | #define IPT_UDP_INV_MASK XT_UDP_INV_MASK | |
1da177e4 LT |
136 | |
137 | /* ICMP matching stuff */ | |
138 | struct ipt_icmp | |
139 | { | |
140 | u_int8_t type; /* type to match */ | |
141 | u_int8_t code[2]; /* range of code */ | |
142 | u_int8_t invflags; /* Inverse flags */ | |
143 | }; | |
144 | ||
145 | /* Values for "inv" field for struct ipt_icmp. */ | |
146 | #define IPT_ICMP_INV 0x01 /* Invert the sense of type/code test */ | |
147 | ||
148 | /* The argument to IPT_SO_GET_INFO */ | |
149 | struct ipt_getinfo | |
150 | { | |
151 | /* Which table: caller fills this in. */ | |
152 | char name[IPT_TABLE_MAXNAMELEN]; | |
153 | ||
154 | /* Kernel fills these in. */ | |
155 | /* Which hook entry points are valid: bitmask */ | |
156 | unsigned int valid_hooks; | |
157 | ||
158 | /* Hook entry points: one per netfilter hook. */ | |
159 | unsigned int hook_entry[NF_IP_NUMHOOKS]; | |
160 | ||
161 | /* Underflow points. */ | |
162 | unsigned int underflow[NF_IP_NUMHOOKS]; | |
163 | ||
164 | /* Number of entries */ | |
165 | unsigned int num_entries; | |
166 | ||
167 | /* Size of entries. */ | |
168 | unsigned int size; | |
169 | }; | |
170 | ||
171 | /* The argument to IPT_SO_SET_REPLACE. */ | |
172 | struct ipt_replace | |
173 | { | |
174 | /* Which table. */ | |
175 | char name[IPT_TABLE_MAXNAMELEN]; | |
176 | ||
177 | /* Which hook entry points are valid: bitmask. You can't | |
178 | change this. */ | |
179 | unsigned int valid_hooks; | |
180 | ||
181 | /* Number of entries */ | |
182 | unsigned int num_entries; | |
183 | ||
184 | /* Total size of new entries */ | |
185 | unsigned int size; | |
186 | ||
187 | /* Hook entry points. */ | |
188 | unsigned int hook_entry[NF_IP_NUMHOOKS]; | |
189 | ||
190 | /* Underflow points. */ | |
191 | unsigned int underflow[NF_IP_NUMHOOKS]; | |
192 | ||
193 | /* Information about old entries: */ | |
194 | /* Number of counters (must be equal to current number of entries). */ | |
195 | unsigned int num_counters; | |
196 | /* The old entries' counters. */ | |
2e4e6a17 | 197 | struct xt_counters __user *counters; |
1da177e4 LT |
198 | |
199 | /* The entries (hang off end: not really an array). */ | |
200 | struct ipt_entry entries[0]; | |
201 | }; | |
202 | ||
203 | /* The argument to IPT_SO_ADD_COUNTERS. */ | |
2e4e6a17 | 204 | #define ipt_counters_info xt_counters_info |
1da177e4 LT |
205 | |
206 | /* The argument to IPT_SO_GET_ENTRIES. */ | |
207 | struct ipt_get_entries | |
208 | { | |
209 | /* Which table: user fills this in. */ | |
210 | char name[IPT_TABLE_MAXNAMELEN]; | |
211 | ||
212 | /* User fills this in: total entry size. */ | |
213 | unsigned int size; | |
214 | ||
215 | /* The entries. */ | |
216 | struct ipt_entry entrytable[0]; | |
217 | }; | |
218 | ||
1da177e4 | 219 | /* Standard return verdict, or do jump. */ |
2e4e6a17 | 220 | #define IPT_STANDARD_TARGET XT_STANDARD_TARGET |
1da177e4 | 221 | /* Error verdict. */ |
2e4e6a17 | 222 | #define IPT_ERROR_TARGET XT_ERROR_TARGET |
1da177e4 LT |
223 | |
224 | /* Helper functions */ | |
225 | static __inline__ struct ipt_entry_target * | |
226 | ipt_get_target(struct ipt_entry *e) | |
227 | { | |
228 | return (void *)e + e->target_offset; | |
229 | } | |
230 | ||
231 | /* fn returns 0 to continue iteration */ | |
232 | #define IPT_MATCH_ITERATE(e, fn, args...) \ | |
233 | ({ \ | |
234 | unsigned int __i; \ | |
235 | int __ret = 0; \ | |
236 | struct ipt_entry_match *__match; \ | |
237 | \ | |
238 | for (__i = sizeof(struct ipt_entry); \ | |
239 | __i < (e)->target_offset; \ | |
240 | __i += __match->u.match_size) { \ | |
241 | __match = (void *)(e) + __i; \ | |
242 | \ | |
243 | __ret = fn(__match , ## args); \ | |
244 | if (__ret != 0) \ | |
245 | break; \ | |
246 | } \ | |
247 | __ret; \ | |
248 | }) | |
249 | ||
250 | /* fn returns 0 to continue iteration */ | |
251 | #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \ | |
252 | ({ \ | |
253 | unsigned int __i; \ | |
254 | int __ret = 0; \ | |
255 | struct ipt_entry *__entry; \ | |
256 | \ | |
257 | for (__i = 0; __i < (size); __i += __entry->next_offset) { \ | |
258 | __entry = (void *)(entries) + __i; \ | |
259 | \ | |
260 | __ret = fn(__entry , ## args); \ | |
261 | if (__ret != 0) \ | |
262 | break; \ | |
263 | } \ | |
264 | __ret; \ | |
265 | }) | |
266 | ||
267 | /* | |
268 | * Main firewall chains definitions and global var's definitions. | |
269 | */ | |
270 | #ifdef __KERNEL__ | |
271 | ||
272 | #include <linux/init.h> | |
273 | extern void ipt_init(void) __init; | |
274 | ||
e60a13e0 | 275 | extern int ipt_register_table(struct xt_table *table, |
2e4e6a17 | 276 | const struct ipt_replace *repl); |
e60a13e0 | 277 | extern void ipt_unregister_table(struct xt_table *table); |
1da177e4 | 278 | |
1da177e4 LT |
279 | /* Standard entry. */ |
280 | struct ipt_standard | |
281 | { | |
282 | struct ipt_entry entry; | |
283 | struct ipt_standard_target target; | |
284 | }; | |
285 | ||
286 | struct ipt_error_target | |
287 | { | |
288 | struct ipt_entry_target target; | |
289 | char errorname[IPT_FUNCTION_MAXNAMELEN]; | |
290 | }; | |
291 | ||
292 | struct ipt_error | |
293 | { | |
294 | struct ipt_entry entry; | |
295 | struct ipt_error_target target; | |
296 | }; | |
297 | ||
3c2ad469 PM |
298 | #define IPT_ENTRY_INIT(__size) \ |
299 | { \ | |
300 | .target_offset = sizeof(struct ipt_entry), \ | |
301 | .next_offset = (__size), \ | |
302 | } | |
303 | ||
304 | #define IPT_STANDARD_INIT(__verdict) \ | |
305 | { \ | |
306 | .entry = IPT_ENTRY_INIT(sizeof(struct ipt_standard)), \ | |
307 | .target = XT_TARGET_INIT(IPT_STANDARD_TARGET, \ | |
308 | sizeof(struct xt_standard_target)), \ | |
309 | .target.verdict = -(__verdict) - 1, \ | |
310 | } | |
311 | ||
312 | #define IPT_ERROR_INIT \ | |
313 | { \ | |
314 | .entry = IPT_ENTRY_INIT(sizeof(struct ipt_error)), \ | |
315 | .target = XT_TARGET_INIT(IPT_ERROR_TARGET, \ | |
316 | sizeof(struct ipt_error_target)), \ | |
317 | .target.errorname = "ERROR", \ | |
318 | } | |
319 | ||
1da177e4 LT |
320 | extern unsigned int ipt_do_table(struct sk_buff **pskb, |
321 | unsigned int hook, | |
322 | const struct net_device *in, | |
323 | const struct net_device *out, | |
e60a13e0 | 324 | struct xt_table *table); |
1da177e4 | 325 | |
2e4e6a17 | 326 | #define IPT_ALIGN(s) XT_ALIGN(s) |
2722971c DM |
327 | |
328 | #ifdef CONFIG_COMPAT | |
329 | #include <net/compat.h> | |
330 | ||
331 | struct compat_ipt_entry | |
332 | { | |
333 | struct ipt_ip ip; | |
334 | compat_uint_t nfcache; | |
335 | u_int16_t target_offset; | |
336 | u_int16_t next_offset; | |
337 | compat_uint_t comefrom; | |
338 | struct compat_xt_counters counters; | |
339 | unsigned char elems[0]; | |
340 | }; | |
341 | ||
342 | #define COMPAT_IPT_ALIGN(s) COMPAT_XT_ALIGN(s) | |
343 | ||
344 | #endif /* CONFIG_COMPAT */ | |
1da177e4 LT |
345 | #endif /*__KERNEL__*/ |
346 | #endif /* _IPTABLES_H */ |