]>
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 IP6 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 _IP6_TABLES_H | |
16 | #define _IP6_TABLES_H | |
17 | ||
18 | #ifdef __KERNEL__ | |
19 | #include <linux/if.h> | |
1da177e4 LT |
20 | #include <linux/in6.h> |
21 | #include <linux/ipv6.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_ipv6.h> | |
27 | ||
2e4e6a17 HW |
28 | #include <linux/netfilter/x_tables.h> |
29 | ||
12b00c2c | 30 | #ifndef __KERNEL__ |
2e4e6a17 HW |
31 | #define IP6T_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN |
32 | #define IP6T_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN | |
2e4e6a17 HW |
33 | #define ip6t_match xt_match |
34 | #define ip6t_target xt_target | |
35 | #define ip6t_table xt_table | |
36 | #define ip6t_get_revision xt_get_revision | |
87a2e70d JE |
37 | #define ip6t_entry_match xt_entry_match |
38 | #define ip6t_entry_target xt_entry_target | |
39 | #define ip6t_standard_target xt_standard_target | |
40 | #define ip6t_counters xt_counters | |
12b00c2c | 41 | #endif |
1da177e4 LT |
42 | |
43 | /* Yes, Virginia, you have to zero the padding. */ | |
44 | struct ip6t_ip6 { | |
45 | /* Source and destination IP6 addr */ | |
46 | struct in6_addr src, dst; | |
47 | /* Mask for src and dest IP6 addr */ | |
48 | struct in6_addr smsk, dmsk; | |
49 | char iniface[IFNAMSIZ], outiface[IFNAMSIZ]; | |
50 | unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ]; | |
51 | ||
7bfe2461 YK |
52 | /* Upper protocol number |
53 | * - The allowed value is 0 (any) or protocol number of last parsable | |
54 | * header, which is 50 (ESP), 59 (No Next Header), 135 (MH), or | |
55 | * the non IPv6 extension headers. | |
56 | * - The protocol numbers of IPv6 extension headers except of ESP and | |
57 | * MH do not match any packets. | |
58 | * - You also need to set IP6T_FLAGS_PROTO to "flags" to check protocol. | |
59 | */ | |
1da177e4 LT |
60 | u_int16_t proto; |
61 | /* TOS to match iff flags & IP6T_F_TOS */ | |
62 | u_int8_t tos; | |
63 | ||
64 | /* Flags word */ | |
65 | u_int8_t flags; | |
66 | /* Inverse flags */ | |
67 | u_int8_t invflags; | |
68 | }; | |
69 | ||
1da177e4 LT |
70 | /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */ |
71 | #define IP6T_F_PROTO 0x01 /* Set if rule cares about upper | |
72 | protocols */ | |
73 | #define IP6T_F_TOS 0x02 /* Match the TOS. */ | |
05465343 PM |
74 | #define IP6T_F_GOTO 0x04 /* Set if jump is a goto */ |
75 | #define IP6T_F_MASK 0x07 /* All possible flag bits mask. */ | |
1da177e4 LT |
76 | |
77 | /* Values for "inv" field in struct ip6t_ip6. */ | |
78 | #define IP6T_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */ | |
79 | #define IP6T_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */ | |
80 | #define IP6T_INV_TOS 0x04 /* Invert the sense of TOS. */ | |
81 | #define IP6T_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */ | |
82 | #define IP6T_INV_DSTIP 0x10 /* Invert the sense of DST OP. */ | |
83 | #define IP6T_INV_FRAG 0x20 /* Invert the sense of FRAG. */ | |
2e4e6a17 | 84 | #define IP6T_INV_PROTO XT_INV_PROTO |
1da177e4 LT |
85 | #define IP6T_INV_MASK 0x7F /* All possible flag bits mask. */ |
86 | ||
87 | /* This structure defines each of the firewall rules. Consists of 3 | |
88 | parts which are 1) general IP header stuff 2) match specific | |
89 | stuff 3) the target to perform if the rule matches */ | |
d94d9fee | 90 | struct ip6t_entry { |
1da177e4 LT |
91 | struct ip6t_ip6 ipv6; |
92 | ||
93 | /* Mark with fields that we care about. */ | |
94 | unsigned int nfcache; | |
95 | ||
96 | /* Size of ipt_entry + matches */ | |
97 | u_int16_t target_offset; | |
98 | /* Size of ipt_entry + matches + target */ | |
99 | u_int16_t next_offset; | |
100 | ||
101 | /* Back pointer */ | |
102 | unsigned int comefrom; | |
103 | ||
104 | /* Packet and byte counters. */ | |
2e4e6a17 | 105 | struct xt_counters counters; |
1da177e4 LT |
106 | |
107 | /* The matches (if any), then the target. */ | |
108 | unsigned char elems[0]; | |
109 | }; | |
110 | ||
9934e81c | 111 | /* Standard entry */ |
d94d9fee | 112 | struct ip6t_standard { |
9934e81c | 113 | struct ip6t_entry entry; |
87a2e70d | 114 | struct xt_standard_target target; |
9934e81c PM |
115 | }; |
116 | ||
d94d9fee | 117 | struct ip6t_error_target { |
87a2e70d | 118 | struct xt_entry_target target; |
12b00c2c | 119 | char errorname[XT_FUNCTION_MAXNAMELEN]; |
9934e81c PM |
120 | }; |
121 | ||
d94d9fee | 122 | struct ip6t_error { |
9934e81c PM |
123 | struct ip6t_entry entry; |
124 | struct ip6t_error_target target; | |
125 | }; | |
126 | ||
3c2ad469 PM |
127 | #define IP6T_ENTRY_INIT(__size) \ |
128 | { \ | |
129 | .target_offset = sizeof(struct ip6t_entry), \ | |
130 | .next_offset = (__size), \ | |
131 | } | |
132 | ||
133 | #define IP6T_STANDARD_INIT(__verdict) \ | |
134 | { \ | |
135 | .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_standard)), \ | |
136 | .target = XT_TARGET_INIT(IP6T_STANDARD_TARGET, \ | |
87a2e70d | 137 | sizeof(struct xt_standard_target)), \ |
3c2ad469 PM |
138 | .target.verdict = -(__verdict) - 1, \ |
139 | } | |
140 | ||
141 | #define IP6T_ERROR_INIT \ | |
142 | { \ | |
143 | .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_error)), \ | |
144 | .target = XT_TARGET_INIT(IP6T_ERROR_TARGET, \ | |
145 | sizeof(struct ip6t_error_target)), \ | |
146 | .target.errorname = "ERROR", \ | |
147 | } | |
148 | ||
1da177e4 LT |
149 | /* |
150 | * New IP firewall options for [gs]etsockopt at the RAW IP level. | |
151 | * Unlike BSD Linux inherits IP options so you don't have to use | |
b96e7ecb YK |
152 | * a raw socket for this. Instead we check rights in the calls. |
153 | * | |
154 | * ATTENTION: check linux/in6.h before adding new number here. | |
155 | */ | |
156 | #define IP6T_BASE_CTL 64 | |
157 | ||
158 | #define IP6T_SO_SET_REPLACE (IP6T_BASE_CTL) | |
159 | #define IP6T_SO_SET_ADD_COUNTERS (IP6T_BASE_CTL + 1) | |
160 | #define IP6T_SO_SET_MAX IP6T_SO_SET_ADD_COUNTERS | |
161 | ||
162 | #define IP6T_SO_GET_INFO (IP6T_BASE_CTL) | |
163 | #define IP6T_SO_GET_ENTRIES (IP6T_BASE_CTL + 1) | |
164 | #define IP6T_SO_GET_REVISION_MATCH (IP6T_BASE_CTL + 4) | |
165 | #define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 5) | |
166 | #define IP6T_SO_GET_MAX IP6T_SO_GET_REVISION_TARGET | |
1da177e4 LT |
167 | |
168 | /* CONTINUE verdict for targets */ | |
2e4e6a17 | 169 | #define IP6T_CONTINUE XT_CONTINUE |
1da177e4 LT |
170 | |
171 | /* For standard target */ | |
2e4e6a17 | 172 | #define IP6T_RETURN XT_RETURN |
1da177e4 | 173 | |
2e4e6a17 HW |
174 | /* TCP/UDP matching stuff */ |
175 | #include <linux/netfilter/xt_tcpudp.h> | |
176 | ||
177 | #define ip6t_tcp xt_tcp | |
178 | #define ip6t_udp xt_udp | |
1da177e4 LT |
179 | |
180 | /* Values for "inv" field in struct ipt_tcp. */ | |
2e4e6a17 HW |
181 | #define IP6T_TCP_INV_SRCPT XT_TCP_INV_SRCPT |
182 | #define IP6T_TCP_INV_DSTPT XT_TCP_INV_DSTPT | |
183 | #define IP6T_TCP_INV_FLAGS XT_TCP_INV_FLAGS | |
184 | #define IP6T_TCP_INV_OPTION XT_TCP_INV_OPTION | |
185 | #define IP6T_TCP_INV_MASK XT_TCP_INV_MASK | |
1da177e4 LT |
186 | |
187 | /* Values for "invflags" field in struct ipt_udp. */ | |
2e4e6a17 HW |
188 | #define IP6T_UDP_INV_SRCPT XT_UDP_INV_SRCPT |
189 | #define IP6T_UDP_INV_DSTPT XT_UDP_INV_DSTPT | |
190 | #define IP6T_UDP_INV_MASK XT_UDP_INV_MASK | |
1da177e4 LT |
191 | |
192 | /* ICMP matching stuff */ | |
d94d9fee | 193 | struct ip6t_icmp { |
1da177e4 LT |
194 | u_int8_t type; /* type to match */ |
195 | u_int8_t code[2]; /* range of code */ | |
196 | u_int8_t invflags; /* Inverse flags */ | |
197 | }; | |
198 | ||
199 | /* Values for "inv" field for struct ipt_icmp. */ | |
200 | #define IP6T_ICMP_INV 0x01 /* Invert the sense of type/code test */ | |
201 | ||
202 | /* The argument to IP6T_SO_GET_INFO */ | |
d94d9fee | 203 | struct ip6t_getinfo { |
1da177e4 | 204 | /* Which table: caller fills this in. */ |
12b00c2c | 205 | char name[XT_TABLE_MAXNAMELEN]; |
1da177e4 LT |
206 | |
207 | /* Kernel fills these in. */ | |
208 | /* Which hook entry points are valid: bitmask */ | |
209 | unsigned int valid_hooks; | |
210 | ||
211 | /* Hook entry points: one per netfilter hook. */ | |
6e23ae2a | 212 | unsigned int hook_entry[NF_INET_NUMHOOKS]; |
1da177e4 LT |
213 | |
214 | /* Underflow points. */ | |
6e23ae2a | 215 | unsigned int underflow[NF_INET_NUMHOOKS]; |
1da177e4 LT |
216 | |
217 | /* Number of entries */ | |
218 | unsigned int num_entries; | |
219 | ||
220 | /* Size of entries. */ | |
221 | unsigned int size; | |
222 | }; | |
223 | ||
224 | /* The argument to IP6T_SO_SET_REPLACE. */ | |
d94d9fee | 225 | struct ip6t_replace { |
1da177e4 | 226 | /* Which table. */ |
12b00c2c | 227 | char name[XT_TABLE_MAXNAMELEN]; |
1da177e4 LT |
228 | |
229 | /* Which hook entry points are valid: bitmask. You can't | |
230 | change this. */ | |
231 | unsigned int valid_hooks; | |
232 | ||
233 | /* Number of entries */ | |
234 | unsigned int num_entries; | |
235 | ||
236 | /* Total size of new entries */ | |
237 | unsigned int size; | |
238 | ||
239 | /* Hook entry points. */ | |
6e23ae2a | 240 | unsigned int hook_entry[NF_INET_NUMHOOKS]; |
1da177e4 LT |
241 | |
242 | /* Underflow points. */ | |
6e23ae2a | 243 | unsigned int underflow[NF_INET_NUMHOOKS]; |
1da177e4 LT |
244 | |
245 | /* Information about old entries: */ | |
246 | /* Number of counters (must be equal to current number of entries). */ | |
247 | unsigned int num_counters; | |
248 | /* The old entries' counters. */ | |
2e4e6a17 | 249 | struct xt_counters __user *counters; |
1da177e4 LT |
250 | |
251 | /* The entries (hang off end: not really an array). */ | |
252 | struct ip6t_entry entries[0]; | |
253 | }; | |
254 | ||
255 | /* The argument to IP6T_SO_ADD_COUNTERS. */ | |
2e4e6a17 | 256 | #define ip6t_counters_info xt_counters_info |
1da177e4 LT |
257 | |
258 | /* The argument to IP6T_SO_GET_ENTRIES. */ | |
d94d9fee | 259 | struct ip6t_get_entries { |
1da177e4 | 260 | /* Which table: user fills this in. */ |
12b00c2c | 261 | char name[XT_TABLE_MAXNAMELEN]; |
1da177e4 LT |
262 | |
263 | /* User fills this in: total entry size. */ | |
264 | unsigned int size; | |
265 | ||
266 | /* The entries. */ | |
267 | struct ip6t_entry entrytable[0]; | |
268 | }; | |
269 | ||
270 | /* Standard return verdict, or do jump. */ | |
2e4e6a17 | 271 | #define IP6T_STANDARD_TARGET XT_STANDARD_TARGET |
1da177e4 | 272 | /* Error verdict. */ |
2e4e6a17 | 273 | #define IP6T_ERROR_TARGET XT_ERROR_TARGET |
1da177e4 LT |
274 | |
275 | /* Helper functions */ | |
87a2e70d | 276 | static __inline__ struct xt_entry_target * |
1da177e4 LT |
277 | ip6t_get_target(struct ip6t_entry *e) |
278 | { | |
279 | return (void *)e + e->target_offset; | |
280 | } | |
281 | ||
dcea992a | 282 | #ifndef __KERNEL__ |
1da177e4 | 283 | /* fn returns 0 to continue iteration */ |
89c002d6 PM |
284 | #define IP6T_MATCH_ITERATE(e, fn, args...) \ |
285 | XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args) | |
1da177e4 LT |
286 | |
287 | /* fn returns 0 to continue iteration */ | |
89c002d6 PM |
288 | #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \ |
289 | XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args) | |
72b2b1dd | 290 | #endif |
1da177e4 LT |
291 | |
292 | /* | |
293 | * Main firewall chains definitions and global var's definitions. | |
294 | */ | |
295 | ||
296 | #ifdef __KERNEL__ | |
297 | ||
298 | #include <linux/init.h> | |
299 | extern void ip6t_init(void) __init; | |
300 | ||
e3eaa991 | 301 | extern void *ip6t_alloc_initial_table(const struct xt_table *); |
336b517f | 302 | extern struct xt_table *ip6t_register_table(struct net *net, |
35aad0ff | 303 | const struct xt_table *table, |
44d34e72 | 304 | const struct ip6t_replace *repl); |
f54e9367 | 305 | extern void ip6t_unregister_table(struct net *net, struct xt_table *table); |
3db05fea | 306 | extern unsigned int ip6t_do_table(struct sk_buff *skb, |
1da177e4 LT |
307 | unsigned int hook, |
308 | const struct net_device *in, | |
309 | const struct net_device *out, | |
e60a13e0 | 310 | struct xt_table *table); |
1da177e4 LT |
311 | |
312 | /* Check for an extension */ | |
313 | extern int ip6t_ext_hdr(u8 nexthdr); | |
e674d0f3 YK |
314 | /* find specified header and get offset to it */ |
315 | extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset, | |
b777e0ce | 316 | int target, unsigned short *fragoff); |
1da177e4 | 317 | |
06e1374a | 318 | #define IP6T_ALIGN(s) XT_ALIGN(s) |
1da177e4 | 319 | |
3bc3fe5e PM |
320 | #ifdef CONFIG_COMPAT |
321 | #include <net/compat.h> | |
322 | ||
d94d9fee | 323 | struct compat_ip6t_entry { |
3bc3fe5e PM |
324 | struct ip6t_ip6 ipv6; |
325 | compat_uint_t nfcache; | |
326 | u_int16_t target_offset; | |
327 | u_int16_t next_offset; | |
328 | compat_uint_t comefrom; | |
329 | struct compat_xt_counters counters; | |
330 | unsigned char elems[0]; | |
331 | }; | |
332 | ||
87a2e70d | 333 | static inline struct xt_entry_target * |
3bc3fe5e PM |
334 | compat_ip6t_get_target(struct compat_ip6t_entry *e) |
335 | { | |
336 | return (void *)e + e->target_offset; | |
337 | } | |
338 | ||
339 | #define COMPAT_IP6T_ALIGN(s) COMPAT_XT_ALIGN(s) | |
340 | ||
3bc3fe5e | 341 | #endif /* CONFIG_COMPAT */ |
1da177e4 LT |
342 | #endif /*__KERNEL__*/ |
343 | #endif /* _IP6_TABLES_H */ |