[NETFILTER]: make ipv6_find_hdr() find transport protocol header
[deliverable/linux.git] / include / linux / netfilter_ipv6 / ip6_tables.h
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>
20 #include <linux/types.h>
21 #include <linux/in6.h>
22 #include <linux/ipv6.h>
23 #include <linux/skbuff.h>
24 #endif
25 #include <linux/compiler.h>
26 #include <linux/netfilter_ipv6.h>
27
28 #define IP6T_FUNCTION_MAXNAMELEN 30
29 #define IP6T_TABLE_MAXNAMELEN 32
30
31 /* Yes, Virginia, you have to zero the padding. */
32 struct ip6t_ip6 {
33 /* Source and destination IP6 addr */
34 struct in6_addr src, dst;
35 /* Mask for src and dest IP6 addr */
36 struct in6_addr smsk, dmsk;
37 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
38 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
39
40 /* ARGH, HopByHop uses 0, so can't do 0 = ANY,
41 instead IP6T_F_NOPROTO must be set */
42 u_int16_t proto;
43 /* TOS to match iff flags & IP6T_F_TOS */
44 u_int8_t tos;
45
46 /* Flags word */
47 u_int8_t flags;
48 /* Inverse flags */
49 u_int8_t invflags;
50 };
51
52 /* FIXME: If alignment in kernel different from userspace? --RR */
53 struct ip6t_entry_match
54 {
55 union {
56 struct {
57 u_int16_t match_size;
58
59 /* Used by userspace */
60 char name[IP6T_FUNCTION_MAXNAMELEN-1];
61 u_int8_t revision;
62 } user;
63 struct {
64 u_int16_t match_size;
65
66 /* Used inside the kernel */
67 struct ip6t_match *match;
68 } kernel;
69
70 /* Total length */
71 u_int16_t match_size;
72 } u;
73
74 unsigned char data[0];
75 };
76
77 struct ip6t_entry_target
78 {
79 union {
80 struct {
81 u_int16_t target_size;
82
83 /* Used by userspace */
84 char name[IP6T_FUNCTION_MAXNAMELEN-1];
85 u_int8_t revision;
86 } user;
87 struct {
88 u_int16_t target_size;
89
90 /* Used inside the kernel */
91 struct ip6t_target *target;
92 } kernel;
93
94 /* Total length */
95 u_int16_t target_size;
96 } u;
97
98 unsigned char data[0];
99 };
100
101 struct ip6t_standard_target
102 {
103 struct ip6t_entry_target target;
104 int verdict;
105 };
106
107 struct ip6t_counters
108 {
109 u_int64_t pcnt, bcnt; /* Packet and byte counters */
110 };
111
112 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
113 #define IP6T_F_PROTO 0x01 /* Set if rule cares about upper
114 protocols */
115 #define IP6T_F_TOS 0x02 /* Match the TOS. */
116 #define IP6T_F_GOTO 0x04 /* Set if jump is a goto */
117 #define IP6T_F_MASK 0x07 /* All possible flag bits mask. */
118
119 /* Values for "inv" field in struct ip6t_ip6. */
120 #define IP6T_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
121 #define IP6T_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
122 #define IP6T_INV_TOS 0x04 /* Invert the sense of TOS. */
123 #define IP6T_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
124 #define IP6T_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
125 #define IP6T_INV_FRAG 0x20 /* Invert the sense of FRAG. */
126 #define IP6T_INV_PROTO 0x40 /* Invert the sense of PROTO. */
127 #define IP6T_INV_MASK 0x7F /* All possible flag bits mask. */
128
129 /* This structure defines each of the firewall rules. Consists of 3
130 parts which are 1) general IP header stuff 2) match specific
131 stuff 3) the target to perform if the rule matches */
132 struct ip6t_entry
133 {
134 struct ip6t_ip6 ipv6;
135
136 /* Mark with fields that we care about. */
137 unsigned int nfcache;
138
139 /* Size of ipt_entry + matches */
140 u_int16_t target_offset;
141 /* Size of ipt_entry + matches + target */
142 u_int16_t next_offset;
143
144 /* Back pointer */
145 unsigned int comefrom;
146
147 /* Packet and byte counters. */
148 struct ip6t_counters counters;
149
150 /* The matches (if any), then the target. */
151 unsigned char elems[0];
152 };
153
154 /*
155 * New IP firewall options for [gs]etsockopt at the RAW IP level.
156 * Unlike BSD Linux inherits IP options so you don't have to use
157 * a raw socket for this. Instead we check rights in the calls. */
158 #define IP6T_BASE_CTL 64 /* base for firewall socket options */
159
160 #define IP6T_SO_SET_REPLACE (IP6T_BASE_CTL)
161 #define IP6T_SO_SET_ADD_COUNTERS (IP6T_BASE_CTL + 1)
162 #define IP6T_SO_SET_MAX IP6T_SO_SET_ADD_COUNTERS
163
164 #define IP6T_SO_GET_INFO (IP6T_BASE_CTL)
165 #define IP6T_SO_GET_ENTRIES (IP6T_BASE_CTL + 1)
166 #define IP6T_SO_GET_REVISION_MATCH (IP6T_BASE_CTL + 2)
167 #define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 3)
168 #define IP6T_SO_GET_MAX IP6T_SO_GET_REVISION_TARGET
169
170 /* CONTINUE verdict for targets */
171 #define IP6T_CONTINUE 0xFFFFFFFF
172
173 /* For standard target */
174 #define IP6T_RETURN (-NF_REPEAT - 1)
175
176 /* TCP matching stuff */
177 struct ip6t_tcp
178 {
179 u_int16_t spts[2]; /* Source port range. */
180 u_int16_t dpts[2]; /* Destination port range. */
181 u_int8_t option; /* TCP Option iff non-zero*/
182 u_int8_t flg_mask; /* TCP flags mask byte */
183 u_int8_t flg_cmp; /* TCP flags compare byte */
184 u_int8_t invflags; /* Inverse flags */
185 };
186
187 /* Values for "inv" field in struct ipt_tcp. */
188 #define IP6T_TCP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
189 #define IP6T_TCP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
190 #define IP6T_TCP_INV_FLAGS 0x04 /* Invert the sense of TCP flags. */
191 #define IP6T_TCP_INV_OPTION 0x08 /* Invert the sense of option test. */
192 #define IP6T_TCP_INV_MASK 0x0F /* All possible flags. */
193
194 /* UDP matching stuff */
195 struct ip6t_udp
196 {
197 u_int16_t spts[2]; /* Source port range. */
198 u_int16_t dpts[2]; /* Destination port range. */
199 u_int8_t invflags; /* Inverse flags */
200 };
201
202 /* Values for "invflags" field in struct ipt_udp. */
203 #define IP6T_UDP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
204 #define IP6T_UDP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
205 #define IP6T_UDP_INV_MASK 0x03 /* All possible flags. */
206
207 /* ICMP matching stuff */
208 struct ip6t_icmp
209 {
210 u_int8_t type; /* type to match */
211 u_int8_t code[2]; /* range of code */
212 u_int8_t invflags; /* Inverse flags */
213 };
214
215 /* Values for "inv" field for struct ipt_icmp. */
216 #define IP6T_ICMP_INV 0x01 /* Invert the sense of type/code test */
217
218 /* The argument to IP6T_SO_GET_INFO */
219 struct ip6t_getinfo
220 {
221 /* Which table: caller fills this in. */
222 char name[IP6T_TABLE_MAXNAMELEN];
223
224 /* Kernel fills these in. */
225 /* Which hook entry points are valid: bitmask */
226 unsigned int valid_hooks;
227
228 /* Hook entry points: one per netfilter hook. */
229 unsigned int hook_entry[NF_IP6_NUMHOOKS];
230
231 /* Underflow points. */
232 unsigned int underflow[NF_IP6_NUMHOOKS];
233
234 /* Number of entries */
235 unsigned int num_entries;
236
237 /* Size of entries. */
238 unsigned int size;
239 };
240
241 /* The argument to IP6T_SO_SET_REPLACE. */
242 struct ip6t_replace
243 {
244 /* Which table. */
245 char name[IP6T_TABLE_MAXNAMELEN];
246
247 /* Which hook entry points are valid: bitmask. You can't
248 change this. */
249 unsigned int valid_hooks;
250
251 /* Number of entries */
252 unsigned int num_entries;
253
254 /* Total size of new entries */
255 unsigned int size;
256
257 /* Hook entry points. */
258 unsigned int hook_entry[NF_IP6_NUMHOOKS];
259
260 /* Underflow points. */
261 unsigned int underflow[NF_IP6_NUMHOOKS];
262
263 /* Information about old entries: */
264 /* Number of counters (must be equal to current number of entries). */
265 unsigned int num_counters;
266 /* The old entries' counters. */
267 struct ip6t_counters __user *counters;
268
269 /* The entries (hang off end: not really an array). */
270 struct ip6t_entry entries[0];
271 };
272
273 /* The argument to IP6T_SO_ADD_COUNTERS. */
274 struct ip6t_counters_info
275 {
276 /* Which table. */
277 char name[IP6T_TABLE_MAXNAMELEN];
278
279 unsigned int num_counters;
280
281 /* The counters (actually `number' of these). */
282 struct ip6t_counters counters[0];
283 };
284
285 /* The argument to IP6T_SO_GET_ENTRIES. */
286 struct ip6t_get_entries
287 {
288 /* Which table: user fills this in. */
289 char name[IP6T_TABLE_MAXNAMELEN];
290
291 /* User fills this in: total entry size. */
292 unsigned int size;
293
294 /* The entries. */
295 struct ip6t_entry entrytable[0];
296 };
297
298 /* The argument to IP6T_SO_GET_REVISION_*. Returns highest revision
299 * kernel supports, if >= revision. */
300 struct ip6t_get_revision
301 {
302 char name[IP6T_FUNCTION_MAXNAMELEN-1];
303
304 u_int8_t revision;
305 };
306
307 /* Standard return verdict, or do jump. */
308 #define IP6T_STANDARD_TARGET ""
309 /* Error verdict. */
310 #define IP6T_ERROR_TARGET "ERROR"
311
312 /* Helper functions */
313 static __inline__ struct ip6t_entry_target *
314 ip6t_get_target(struct ip6t_entry *e)
315 {
316 return (void *)e + e->target_offset;
317 }
318
319 /* fn returns 0 to continue iteration */
320 #define IP6T_MATCH_ITERATE(e, fn, args...) \
321 ({ \
322 unsigned int __i; \
323 int __ret = 0; \
324 struct ip6t_entry_match *__m; \
325 \
326 for (__i = sizeof(struct ip6t_entry); \
327 __i < (e)->target_offset; \
328 __i += __m->u.match_size) { \
329 __m = (void *)(e) + __i; \
330 \
331 __ret = fn(__m , ## args); \
332 if (__ret != 0) \
333 break; \
334 } \
335 __ret; \
336 })
337
338 /* fn returns 0 to continue iteration */
339 #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
340 ({ \
341 unsigned int __i; \
342 int __ret = 0; \
343 struct ip6t_entry *__e; \
344 \
345 for (__i = 0; __i < (size); __i += __e->next_offset) { \
346 __e = (void *)(entries) + __i; \
347 \
348 __ret = fn(__e , ## args); \
349 if (__ret != 0) \
350 break; \
351 } \
352 __ret; \
353 })
354
355 /*
356 * Main firewall chains definitions and global var's definitions.
357 */
358
359 #ifdef __KERNEL__
360
361 #include <linux/init.h>
362 extern void ip6t_init(void) __init;
363
364 struct ip6t_match
365 {
366 struct list_head list;
367
368 const char name[IP6T_FUNCTION_MAXNAMELEN-1];
369
370 u_int8_t revision;
371
372 /* Return true or false: return FALSE and set *hotdrop = 1 to
373 force immediate packet drop. */
374 /* Arguments changed since 2.6.9, as this must now handle
375 non-linear skb, using skb_header_pointer and
376 skb_ip_make_writable. */
377 int (*match)(const struct sk_buff *skb,
378 const struct net_device *in,
379 const struct net_device *out,
380 const void *matchinfo,
381 int offset,
382 unsigned int protoff,
383 int *hotdrop);
384
385 /* Called when user tries to insert an entry of this type. */
386 /* Should return true or false. */
387 int (*checkentry)(const char *tablename,
388 const struct ip6t_ip6 *ip,
389 void *matchinfo,
390 unsigned int matchinfosize,
391 unsigned int hook_mask);
392
393 /* Called when entry of this type deleted. */
394 void (*destroy)(void *matchinfo, unsigned int matchinfosize);
395
396 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
397 struct module *me;
398 };
399
400 /* Registration hooks for targets. */
401 struct ip6t_target
402 {
403 struct list_head list;
404
405 const char name[IP6T_FUNCTION_MAXNAMELEN-1];
406
407 u_int8_t revision;
408
409 /* Returns verdict. Argument order changed since 2.6.9, as this
410 must now handle non-linear skbs, using skb_copy_bits and
411 skb_ip_make_writable. */
412 unsigned int (*target)(struct sk_buff **pskb,
413 const struct net_device *in,
414 const struct net_device *out,
415 unsigned int hooknum,
416 const void *targinfo,
417 void *userdata);
418
419 /* Called when user tries to insert an entry of this type:
420 hook_mask is a bitmask of hooks from which it can be
421 called. */
422 /* Should return true or false. */
423 int (*checkentry)(const char *tablename,
424 const struct ip6t_entry *e,
425 void *targinfo,
426 unsigned int targinfosize,
427 unsigned int hook_mask);
428
429 /* Called when entry of this type deleted. */
430 void (*destroy)(void *targinfo, unsigned int targinfosize);
431
432 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
433 struct module *me;
434 };
435
436 extern int ip6t_register_target(struct ip6t_target *target);
437 extern void ip6t_unregister_target(struct ip6t_target *target);
438
439 extern int ip6t_register_match(struct ip6t_match *match);
440 extern void ip6t_unregister_match(struct ip6t_match *match);
441
442 /* Furniture shopping... */
443 struct ip6t_table
444 {
445 struct list_head list;
446
447 /* A unique name... */
448 char name[IP6T_TABLE_MAXNAMELEN];
449
450 /* What hooks you will enter on */
451 unsigned int valid_hooks;
452
453 /* Lock for the curtain */
454 rwlock_t lock;
455
456 /* Man behind the curtain... */
457 struct ip6t_table_info *private;
458
459 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
460 struct module *me;
461 };
462
463 extern int ip6t_register_table(struct ip6t_table *table,
464 const struct ip6t_replace *repl);
465 extern void ip6t_unregister_table(struct ip6t_table *table);
466 extern unsigned int ip6t_do_table(struct sk_buff **pskb,
467 unsigned int hook,
468 const struct net_device *in,
469 const struct net_device *out,
470 struct ip6t_table *table,
471 void *userdata);
472
473 /* Check for an extension */
474 extern int ip6t_ext_hdr(u8 nexthdr);
475 /* find specified header and get offset to it */
476 extern int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
477 int target, unsigned short *fragoff);
478
479 #define IP6T_ALIGN(s) (((s) + (__alignof__(struct ip6t_entry)-1)) & ~(__alignof__(struct ip6t_entry)-1))
480
481 #endif /*__KERNEL__*/
482 #endif /* _IP6_TABLES_H */
This page took 0.057819 seconds and 5 git commands to generate.