1 /* ipv6header match - matches IPv6 packets based
2 on whether they contain certain headers */
4 /* Original idea: Brad Chapman
5 * Rewritten by: Andras Kis-Szabo <kisza@sch.bme.hu> */
7 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/skbuff.h>
16 #include <linux/ipv6.h>
17 #include <linux/types.h>
18 #include <net/checksum.h>
21 #include <linux/netfilter_ipv6/ip6_tables.h>
22 #include <linux/netfilter_ipv6/ip6t_ipv6header.h>
24 MODULE_LICENSE("GPL");
25 MODULE_DESCRIPTION("IPv6 headers match");
26 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
29 ipv6header_match(const struct sk_buff *skb,
30 const struct net_device *in,
31 const struct net_device *out,
32 const void *matchinfo,
38 const struct ip6t_ipv6header_info *info = matchinfo;
44 /* Make sure this isn't an evil packet */
46 /* type of the 1st exthdr */
47 nexthdr = skb->nh.ipv6h->nexthdr;
48 /* pointer to the 1st exthdr */
49 ptr = sizeof(struct ipv6hdr);
50 /* available length */
54 while (ip6t_ext_hdr(nexthdr)) {
55 struct ipv6_opt_hdr *hdr;
58 /* Is there enough space for the next ext header? */
59 if (len < (int)sizeof(struct ipv6_opt_hdr))
61 /* No more exthdr -> evaluate */
62 if (nexthdr == NEXTHDR_NONE) {
67 if (nexthdr == NEXTHDR_ESP) {
72 hdr=(struct ipv6_opt_hdr *)skb->data+ptr;
74 /* Calculate the header length */
75 if (nexthdr == NEXTHDR_FRAGMENT) {
77 } else if (nexthdr == NEXTHDR_AUTH)
78 hdrlen = (hdr->hdrlen+2)<<2;
80 hdrlen = ipv6_optlen(hdr);
90 case NEXTHDR_FRAGMENT:
91 temp |= MASK_FRAGMENT;
104 nexthdr = hdr->nexthdr;
111 if ( (nexthdr != NEXTHDR_NONE ) && (nexthdr != NEXTHDR_ESP) )
115 return (!( (temp & info->matchflags)
116 ^ info->matchflags) ^ info->invflags);
118 return (!( temp ^ info->matchflags) ^ info->invflags);
122 ipv6header_checkentry(const char *tablename,
123 const struct ip6t_ip6 *ip,
125 unsigned int matchsize,
126 unsigned int hook_mask)
128 /* Check for obvious errors */
129 /* This match is valid in all hooks! */
130 if (matchsize != IP6T_ALIGN(sizeof(struct ip6t_ipv6header_info)))
136 static struct ip6t_match ip6t_ipv6header_match = {
137 .name = "ipv6header",
138 .match = &ipv6header_match,
139 .checkentry = &ipv6header_checkentry,
144 static int __init ipv6header_init(void)
146 return ip6t_register_match(&ip6t_ipv6header_match);
149 static void __exit ipv6header_exit(void)
151 ip6t_unregister_match(&ip6t_ipv6header_match);
154 module_init(ipv6header_init);
155 module_exit(ipv6header_exit);