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 IP6 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.
20 #include <linux/types.h>
21 #include <linux/in6.h>
22 #include <linux/ipv6.h>
23 #include <linux/skbuff.h>
25 #include <linux/compiler.h>
26 #include <linux/netfilter_ipv6.h>
28 #define IP6T_FUNCTION_MAXNAMELEN 30
29 #define IP6T_TABLE_MAXNAMELEN 32
31 /* Yes, Virginia, you have to zero the padding. */
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];
40 /* ARGH, HopByHop uses 0, so can't do 0 = ANY,
41 instead IP6T_F_NOPROTO must be set */
43 /* TOS to match iff flags & IP6T_F_TOS */
52 /* FIXME: If alignment in kernel different from userspace? --RR */
53 struct ip6t_entry_match
59 /* Used by userspace */
60 char name[IP6T_FUNCTION_MAXNAMELEN-1];
66 /* Used inside the kernel */
67 struct ip6t_match *match;
74 unsigned char data[0];
77 struct ip6t_entry_target
81 u_int16_t target_size;
83 /* Used by userspace */
84 char name[IP6T_FUNCTION_MAXNAMELEN-1];
88 u_int16_t target_size;
90 /* Used inside the kernel */
91 struct ip6t_target *target;
95 u_int16_t target_size;
98 unsigned char data[0];
101 struct ip6t_standard_target
103 struct ip6t_entry_target target;
109 u_int64_t pcnt, bcnt; /* Packet and byte counters */
112 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
113 #define IP6T_F_PROTO 0x01 /* Set if rule cares about upper
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. */
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. */
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 */
134 struct ip6t_ip6 ipv6;
136 /* Mark with fields that we care about. */
137 unsigned int nfcache;
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;
145 unsigned int comefrom;
147 /* Packet and byte counters. */
148 struct ip6t_counters counters;
150 /* The matches (if any), then the target. */
151 unsigned char elems[0];
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 */
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
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
170 /* CONTINUE verdict for targets */
171 #define IP6T_CONTINUE 0xFFFFFFFF
173 /* For standard target */
174 #define IP6T_RETURN (-NF_REPEAT - 1)
176 /* TCP matching stuff */
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 */
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. */
194 /* UDP matching stuff */
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 */
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. */
207 /* ICMP matching stuff */
210 u_int8_t type; /* type to match */
211 u_int8_t code[2]; /* range of code */
212 u_int8_t invflags; /* Inverse flags */
215 /* Values for "inv" field for struct ipt_icmp. */
216 #define IP6T_ICMP_INV 0x01 /* Invert the sense of type/code test */
218 /* The argument to IP6T_SO_GET_INFO */
221 /* Which table: caller fills this in. */
222 char name[IP6T_TABLE_MAXNAMELEN];
224 /* Kernel fills these in. */
225 /* Which hook entry points are valid: bitmask */
226 unsigned int valid_hooks;
228 /* Hook entry points: one per netfilter hook. */
229 unsigned int hook_entry[NF_IP6_NUMHOOKS];
231 /* Underflow points. */
232 unsigned int underflow[NF_IP6_NUMHOOKS];
234 /* Number of entries */
235 unsigned int num_entries;
237 /* Size of entries. */
241 /* The argument to IP6T_SO_SET_REPLACE. */
245 char name[IP6T_TABLE_MAXNAMELEN];
247 /* Which hook entry points are valid: bitmask. You can't
249 unsigned int valid_hooks;
251 /* Number of entries */
252 unsigned int num_entries;
254 /* Total size of new entries */
257 /* Hook entry points. */
258 unsigned int hook_entry[NF_IP6_NUMHOOKS];
260 /* Underflow points. */
261 unsigned int underflow[NF_IP6_NUMHOOKS];
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;
269 /* The entries (hang off end: not really an array). */
270 struct ip6t_entry entries[0];
273 /* The argument to IP6T_SO_ADD_COUNTERS. */
274 struct ip6t_counters_info
277 char name[IP6T_TABLE_MAXNAMELEN];
279 unsigned int num_counters;
281 /* The counters (actually `number' of these). */
282 struct ip6t_counters counters[0];
285 /* The argument to IP6T_SO_GET_ENTRIES. */
286 struct ip6t_get_entries
288 /* Which table: user fills this in. */
289 char name[IP6T_TABLE_MAXNAMELEN];
291 /* User fills this in: total entry size. */
295 struct ip6t_entry entrytable[0];
298 /* The argument to IP6T_SO_GET_REVISION_*. Returns highest revision
299 * kernel supports, if >= revision. */
300 struct ip6t_get_revision
302 char name[IP6T_FUNCTION_MAXNAMELEN-1];
307 /* Standard return verdict, or do jump. */
308 #define IP6T_STANDARD_TARGET ""
310 #define IP6T_ERROR_TARGET "ERROR"
312 /* Helper functions */
313 static __inline__ struct ip6t_entry_target *
314 ip6t_get_target(struct ip6t_entry *e)
316 return (void *)e + e->target_offset;
319 /* fn returns 0 to continue iteration */
320 #define IP6T_MATCH_ITERATE(e, fn, args...) \
324 struct ip6t_entry_match *__m; \
326 for (__i = sizeof(struct ip6t_entry); \
327 __i < (e)->target_offset; \
328 __i += __m->u.match_size) { \
329 __m = (void *)(e) + __i; \
331 __ret = fn(__m , ## args); \
338 /* fn returns 0 to continue iteration */
339 #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
343 struct ip6t_entry *__e; \
345 for (__i = 0; __i < (size); __i += __e->next_offset) { \
346 __e = (void *)(entries) + __i; \
348 __ret = fn(__e , ## args); \
356 * Main firewall chains definitions and global var's definitions.
361 #include <linux/init.h>
362 extern void ip6t_init(void) __init;
366 struct list_head list;
368 const char name[IP6T_FUNCTION_MAXNAMELEN-1];
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,
382 unsigned int protoff,
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,
390 unsigned int matchinfosize,
391 unsigned int hook_mask);
393 /* Called when entry of this type deleted. */
394 void (*destroy)(void *matchinfo, unsigned int matchinfosize);
396 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
400 /* Registration hooks for targets. */
403 struct list_head list;
405 const char name[IP6T_FUNCTION_MAXNAMELEN-1];
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,
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
422 /* Should return true or false. */
423 int (*checkentry)(const char *tablename,
424 const struct ip6t_entry *e,
426 unsigned int targinfosize,
427 unsigned int hook_mask);
429 /* Called when entry of this type deleted. */
430 void (*destroy)(void *targinfo, unsigned int targinfosize);
432 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
436 extern int ip6t_register_target(struct ip6t_target *target);
437 extern void ip6t_unregister_target(struct ip6t_target *target);
439 extern int ip6t_register_match(struct ip6t_match *match);
440 extern void ip6t_unregister_match(struct ip6t_match *match);
442 /* Furniture shopping... */
445 struct list_head list;
447 /* A unique name... */
448 char name[IP6T_TABLE_MAXNAMELEN];
450 /* What hooks you will enter on */
451 unsigned int valid_hooks;
453 /* Lock for the curtain */
456 /* Man behind the curtain... */
457 struct ip6t_table_info *private;
459 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
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,
468 const struct net_device *in,
469 const struct net_device *out,
470 struct ip6t_table *table,
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,
479 #define IP6T_ALIGN(s) (((s) + (__alignof__(struct ip6t_entry)-1)) & ~(__alignof__(struct ip6t_entry)-1))
481 #endif /*__KERNEL__*/
482 #endif /* _IP6_TABLES_H */