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];
65 /* Used inside the kernel */
66 struct ip6t_match *match;
73 unsigned char data[0];
76 struct ip6t_entry_target
80 u_int16_t target_size;
82 /* Used by userspace */
83 char name[IP6T_FUNCTION_MAXNAMELEN];
86 u_int16_t target_size;
88 /* Used inside the kernel */
89 struct ip6t_target *target;
93 u_int16_t target_size;
96 unsigned char data[0];
99 struct ip6t_standard_target
101 struct ip6t_entry_target target;
107 u_int64_t pcnt, bcnt; /* Packet and byte counters */
110 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
111 #define IP6T_F_PROTO 0x01 /* Set if rule cares about upper
113 #define IP6T_F_TOS 0x02 /* Match the TOS. */
114 #define IP6T_F_MASK 0x03 /* All possible flag bits mask. */
116 /* Values for "inv" field in struct ip6t_ip6. */
117 #define IP6T_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
118 #define IP6T_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
119 #define IP6T_INV_TOS 0x04 /* Invert the sense of TOS. */
120 #define IP6T_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
121 #define IP6T_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
122 #define IP6T_INV_FRAG 0x20 /* Invert the sense of FRAG. */
123 #define IP6T_INV_PROTO 0x40 /* Invert the sense of PROTO. */
124 #define IP6T_INV_MASK 0x7F /* All possible flag bits mask. */
126 /* This structure defines each of the firewall rules. Consists of 3
127 parts which are 1) general IP header stuff 2) match specific
128 stuff 3) the target to perform if the rule matches */
131 struct ip6t_ip6 ipv6;
133 /* Mark with fields that we care about. */
134 unsigned int nfcache;
136 /* Size of ipt_entry + matches */
137 u_int16_t target_offset;
138 /* Size of ipt_entry + matches + target */
139 u_int16_t next_offset;
142 unsigned int comefrom;
144 /* Packet and byte counters. */
145 struct ip6t_counters counters;
147 /* The matches (if any), then the target. */
148 unsigned char elems[0];
152 * New IP firewall options for [gs]etsockopt at the RAW IP level.
153 * Unlike BSD Linux inherits IP options so you don't have to use
154 * a raw socket for this. Instead we check rights in the calls. */
155 #define IP6T_BASE_CTL 64 /* base for firewall socket options */
157 #define IP6T_SO_SET_REPLACE (IP6T_BASE_CTL)
158 #define IP6T_SO_SET_ADD_COUNTERS (IP6T_BASE_CTL + 1)
159 #define IP6T_SO_SET_MAX IP6T_SO_SET_ADD_COUNTERS
161 #define IP6T_SO_GET_INFO (IP6T_BASE_CTL)
162 #define IP6T_SO_GET_ENTRIES (IP6T_BASE_CTL + 1)
163 #define IP6T_SO_GET_MAX IP6T_SO_GET_ENTRIES
165 /* CONTINUE verdict for targets */
166 #define IP6T_CONTINUE 0xFFFFFFFF
168 /* For standard target */
169 #define IP6T_RETURN (-NF_REPEAT - 1)
171 /* TCP matching stuff */
174 u_int16_t spts[2]; /* Source port range. */
175 u_int16_t dpts[2]; /* Destination port range. */
176 u_int8_t option; /* TCP Option iff non-zero*/
177 u_int8_t flg_mask; /* TCP flags mask byte */
178 u_int8_t flg_cmp; /* TCP flags compare byte */
179 u_int8_t invflags; /* Inverse flags */
182 /* Values for "inv" field in struct ipt_tcp. */
183 #define IP6T_TCP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
184 #define IP6T_TCP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
185 #define IP6T_TCP_INV_FLAGS 0x04 /* Invert the sense of TCP flags. */
186 #define IP6T_TCP_INV_OPTION 0x08 /* Invert the sense of option test. */
187 #define IP6T_TCP_INV_MASK 0x0F /* All possible flags. */
189 /* UDP matching stuff */
192 u_int16_t spts[2]; /* Source port range. */
193 u_int16_t dpts[2]; /* Destination port range. */
194 u_int8_t invflags; /* Inverse flags */
197 /* Values for "invflags" field in struct ipt_udp. */
198 #define IP6T_UDP_INV_SRCPT 0x01 /* Invert the sense of source ports. */
199 #define IP6T_UDP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */
200 #define IP6T_UDP_INV_MASK 0x03 /* All possible flags. */
202 /* ICMP matching stuff */
205 u_int8_t type; /* type to match */
206 u_int8_t code[2]; /* range of code */
207 u_int8_t invflags; /* Inverse flags */
210 /* Values for "inv" field for struct ipt_icmp. */
211 #define IP6T_ICMP_INV 0x01 /* Invert the sense of type/code test */
213 /* The argument to IP6T_SO_GET_INFO */
216 /* Which table: caller fills this in. */
217 char name[IP6T_TABLE_MAXNAMELEN];
219 /* Kernel fills these in. */
220 /* Which hook entry points are valid: bitmask */
221 unsigned int valid_hooks;
223 /* Hook entry points: one per netfilter hook. */
224 unsigned int hook_entry[NF_IP6_NUMHOOKS];
226 /* Underflow points. */
227 unsigned int underflow[NF_IP6_NUMHOOKS];
229 /* Number of entries */
230 unsigned int num_entries;
232 /* Size of entries. */
236 /* The argument to IP6T_SO_SET_REPLACE. */
240 char name[IP6T_TABLE_MAXNAMELEN];
242 /* Which hook entry points are valid: bitmask. You can't
244 unsigned int valid_hooks;
246 /* Number of entries */
247 unsigned int num_entries;
249 /* Total size of new entries */
252 /* Hook entry points. */
253 unsigned int hook_entry[NF_IP6_NUMHOOKS];
255 /* Underflow points. */
256 unsigned int underflow[NF_IP6_NUMHOOKS];
258 /* Information about old entries: */
259 /* Number of counters (must be equal to current number of entries). */
260 unsigned int num_counters;
261 /* The old entries' counters. */
262 struct ip6t_counters __user *counters;
264 /* The entries (hang off end: not really an array). */
265 struct ip6t_entry entries[0];
268 /* The argument to IP6T_SO_ADD_COUNTERS. */
269 struct ip6t_counters_info
272 char name[IP6T_TABLE_MAXNAMELEN];
274 unsigned int num_counters;
276 /* The counters (actually `number' of these). */
277 struct ip6t_counters counters[0];
280 /* The argument to IP6T_SO_GET_ENTRIES. */
281 struct ip6t_get_entries
283 /* Which table: user fills this in. */
284 char name[IP6T_TABLE_MAXNAMELEN];
286 /* User fills this in: total entry size. */
290 struct ip6t_entry entrytable[0];
293 /* Standard return verdict, or do jump. */
294 #define IP6T_STANDARD_TARGET ""
296 #define IP6T_ERROR_TARGET "ERROR"
298 /* Helper functions */
299 static __inline__ struct ip6t_entry_target *
300 ip6t_get_target(struct ip6t_entry *e)
302 return (void *)e + e->target_offset;
305 /* fn returns 0 to continue iteration */
306 #define IP6T_MATCH_ITERATE(e, fn, args...) \
310 struct ip6t_entry_match *__m; \
312 for (__i = sizeof(struct ip6t_entry); \
313 __i < (e)->target_offset; \
314 __i += __m->u.match_size) { \
315 __m = (void *)(e) + __i; \
317 __ret = fn(__m , ## args); \
324 /* fn returns 0 to continue iteration */
325 #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
329 struct ip6t_entry *__e; \
331 for (__i = 0; __i < (size); __i += __e->next_offset) { \
332 __e = (void *)(entries) + __i; \
334 __ret = fn(__e , ## args); \
342 * Main firewall chains definitions and global var's definitions.
347 #include <linux/init.h>
348 extern void ip6t_init(void) __init;
352 struct list_head list;
354 const char name[IP6T_FUNCTION_MAXNAMELEN];
356 /* Return true or false: return FALSE and set *hotdrop = 1 to
357 force immediate packet drop. */
358 /* Arguments changed since 2.6.9, as this must now handle
359 non-linear skb, using skb_header_pointer and
360 skb_ip_make_writable. */
361 int (*match)(const struct sk_buff *skb,
362 const struct net_device *in,
363 const struct net_device *out,
364 const void *matchinfo,
366 unsigned int protoff,
369 /* Called when user tries to insert an entry of this type. */
370 /* Should return true or false. */
371 int (*checkentry)(const char *tablename,
372 const struct ip6t_ip6 *ip,
374 unsigned int matchinfosize,
375 unsigned int hook_mask);
377 /* Called when entry of this type deleted. */
378 void (*destroy)(void *matchinfo, unsigned int matchinfosize);
380 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
384 /* Registration hooks for targets. */
387 struct list_head list;
389 const char name[IP6T_FUNCTION_MAXNAMELEN];
391 /* Returns verdict. Argument order changed since 2.6.9, as this
392 must now handle non-linear skbs, using skb_copy_bits and
393 skb_ip_make_writable. */
394 unsigned int (*target)(struct sk_buff **pskb,
395 const struct net_device *in,
396 const struct net_device *out,
397 unsigned int hooknum,
398 const void *targinfo,
401 /* Called when user tries to insert an entry of this type:
402 hook_mask is a bitmask of hooks from which it can be
404 /* Should return true or false. */
405 int (*checkentry)(const char *tablename,
406 const struct ip6t_entry *e,
408 unsigned int targinfosize,
409 unsigned int hook_mask);
411 /* Called when entry of this type deleted. */
412 void (*destroy)(void *targinfo, unsigned int targinfosize);
414 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
418 extern int ip6t_register_target(struct ip6t_target *target);
419 extern void ip6t_unregister_target(struct ip6t_target *target);
421 extern int ip6t_register_match(struct ip6t_match *match);
422 extern void ip6t_unregister_match(struct ip6t_match *match);
424 /* Furniture shopping... */
427 struct list_head list;
429 /* A unique name... */
430 char name[IP6T_TABLE_MAXNAMELEN];
432 /* What hooks you will enter on */
433 unsigned int valid_hooks;
435 /* Lock for the curtain */
438 /* Man behind the curtain... */
439 struct ip6t_table_info *private;
441 /* Set this to THIS_MODULE if you are a module, otherwise NULL */
445 extern int ip6t_register_table(struct ip6t_table *table,
446 const struct ip6t_replace *repl);
447 extern void ip6t_unregister_table(struct ip6t_table *table);
448 extern unsigned int ip6t_do_table(struct sk_buff **pskb,
450 const struct net_device *in,
451 const struct net_device *out,
452 struct ip6t_table *table,
455 /* Check for an extension */
456 extern int ip6t_ext_hdr(u8 nexthdr);
458 #define IP6T_ALIGN(s) (((s) + (__alignof__(struct ip6t_entry)-1)) & ~(__alignof__(struct ip6t_entry)-1))
460 #endif /*__KERNEL__*/
461 #endif /* _IP6_TABLES_H */