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/x_tables.h>
22 #include <linux/netfilter_ipv6/ip6_tables.h>
23 #include <linux/netfilter_ipv6/ip6t_ipv6header.h>
25 MODULE_LICENSE("GPL");
26 MODULE_DESCRIPTION("Xtables: IPv6 header types match");
27 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
30 ipv6header_mt6(const struct sk_buff
*skb
, const struct net_device
*in
,
31 const struct net_device
*out
, const struct xt_match
*match
,
32 const void *matchinfo
, int offset
, unsigned int protoff
,
35 const struct ip6t_ipv6header_info
*info
= matchinfo
;
41 /* Make sure this isn't an evil packet */
43 /* type of the 1st exthdr */
44 nexthdr
= ipv6_hdr(skb
)->nexthdr
;
45 /* pointer to the 1st exthdr */
46 ptr
= sizeof(struct ipv6hdr
);
47 /* available length */
51 while (ip6t_ext_hdr(nexthdr
)) {
52 struct ipv6_opt_hdr _hdr
, *hp
;
55 /* Is there enough space for the next ext header? */
56 if (len
< (int)sizeof(struct ipv6_opt_hdr
))
58 /* No more exthdr -> evaluate */
59 if (nexthdr
== NEXTHDR_NONE
) {
64 if (nexthdr
== NEXTHDR_ESP
) {
69 hp
= skb_header_pointer(skb
, ptr
, sizeof(_hdr
), &_hdr
);
72 /* Calculate the header length */
73 if (nexthdr
== NEXTHDR_FRAGMENT
)
75 else if (nexthdr
== NEXTHDR_AUTH
)
76 hdrlen
= (hp
->hdrlen
+ 2) << 2;
78 hdrlen
= ipv6_optlen(hp
);
88 case NEXTHDR_FRAGMENT
:
89 temp
|= MASK_FRAGMENT
;
102 nexthdr
= hp
->nexthdr
;
109 if (nexthdr
!= NEXTHDR_NONE
&& nexthdr
!= NEXTHDR_ESP
)
113 return !((temp
^ info
->matchflags
^ info
->invflags
)
117 return temp
!= info
->matchflags
;
119 return temp
== info
->matchflags
;
124 ipv6header_mt6_check(const char *tablename
, const void *ip
,
125 const struct xt_match
*match
, void *matchinfo
,
126 unsigned int hook_mask
)
128 const struct ip6t_ipv6header_info
*info
= matchinfo
;
130 /* invflags is 0 or 0xff in hard mode */
131 if ((!info
->modeflag
) && info
->invflags
!= 0x00 &&
132 info
->invflags
!= 0xFF)
138 static struct xt_match ipv6header_mt6_reg __read_mostly
= {
139 .name
= "ipv6header",
141 .match
= ipv6header_mt6
,
142 .matchsize
= sizeof(struct ip6t_ipv6header_info
),
143 .checkentry
= ipv6header_mt6_check
,
148 static int __init
ipv6header_mt6_init(void)
150 return xt_register_match(&ipv6header_mt6_reg
);
153 static void __exit
ipv6header_mt6_exit(void)
155 xt_unregister_match(&ipv6header_mt6_reg
);
158 module_init(ipv6header_mt6_init
);
159 module_exit(ipv6header_mt6_exit
);