1 /* Kernel module to match Hop-by-Hop and Destination parameters. */
3 /* (C) 2001-2002 Andras Kis-Szabo <kisza@sch.bme.hu>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ipv6.h>
13 #include <linux/types.h>
14 #include <net/checksum.h>
17 #include <asm/byteorder.h>
19 #include <linux/netfilter_ipv6/ip6_tables.h>
20 #include <linux/netfilter_ipv6/ip6t_opts.h>
24 MODULE_LICENSE("GPL");
26 MODULE_DESCRIPTION("IPv6 HbH match");
28 MODULE_DESCRIPTION("IPv6 DST match");
30 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
35 #define DEBUGP(format, args...)
41 * 1 -> must drop the packet
42 * 2 -> send ICMP PARM PROB regardless and drop packet
43 * 3 -> Send ICMP if not a multicast address and drop packet
46 * 1 -> can change the routing
48 * 0 -> Pad1 (only 1 byte!)
49 * 1 -> PadN LENGTH info (total length = length + 2)
50 * C0 | 2 -> JUMBO 4 x x x x ( xxxx > 64k )
55 match(const struct sk_buff *skb,
56 const struct net_device *in,
57 const struct net_device *out,
58 const void *matchinfo,
63 struct ipv6_opt_hdr _optsh, *oh;
64 const struct ip6t_opts *optinfo = matchinfo;
69 unsigned int hdrlen = 0;
71 u8 _opttype, *tp = NULL;
72 u8 _optlen, *lp = NULL;
75 /* type of the 1st exthdr */
76 nexthdr = skb->nh.ipv6h->nexthdr;
77 /* pointer to the 1st exthdr */
78 ptr = sizeof(struct ipv6hdr);
79 /* available length */
83 while (ip6t_ext_hdr(nexthdr)) {
84 struct ipv6_opt_hdr _hdr, *hp;
86 DEBUGP("ipv6_opts header iteration \n");
88 /* Is there enough space for the next ext header? */
89 if (len < (int)sizeof(struct ipv6_opt_hdr))
91 /* No more exthdr -> evaluate */
92 if (nexthdr == NEXTHDR_NONE) {
96 if (nexthdr == NEXTHDR_ESP) {
100 hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
103 /* Calculate the header length */
104 if (nexthdr == NEXTHDR_FRAGMENT) {
106 } else if (nexthdr == NEXTHDR_AUTH)
107 hdrlen = (hp->hdrlen+2)<<2;
109 hdrlen = ipv6_optlen(hp);
111 /* OPTS -> evaluate */
113 if (nexthdr == NEXTHDR_HOP) {
114 temp |= MASK_HOPOPTS;
116 if (nexthdr == NEXTHDR_DEST) {
117 temp |= MASK_DSTOPTS;
126 case NEXTHDR_ROUTING:
127 case NEXTHDR_FRAGMENT:
132 DEBUGP("ipv6_opts match: unknown nextheader %u\n",nexthdr);
137 nexthdr = hp->nexthdr;
140 if ( ptr > skb->len ) {
141 DEBUGP("ipv6_opts: new pointer is too large! \n");
146 /* OPTIONS header not found */
148 if ( temp != MASK_HOPOPTS ) return 0;
150 if ( temp != MASK_DSTOPTS ) return 0;
153 if (len < (int)sizeof(struct ipv6_opt_hdr)){
159 /* Packet smaller than it's length field */
163 oh = skb_header_pointer(skb, ptr, sizeof(_optsh), &_optsh);
166 DEBUGP("IPv6 OPTS LEN %u %u ", hdrlen, oh->hdrlen);
168 DEBUGP("len %02X %04X %02X ",
169 optinfo->hdrlen, hdrlen,
170 (!(optinfo->flags & IP6T_OPTS_LEN) ||
171 ((optinfo->hdrlen == hdrlen) ^
172 !!(optinfo->invflags & IP6T_OPTS_INV_LEN))));
176 (!(optinfo->flags & IP6T_OPTS_LEN) ||
177 ((optinfo->hdrlen == hdrlen) ^
178 !!(optinfo->invflags & IP6T_OPTS_INV_LEN)));
182 if ( !(optinfo->flags & IP6T_OPTS_OPTS) ){
184 } else if (optinfo->flags & IP6T_OPTS_NSTRICT) {
185 DEBUGP("Not strict - not implemented");
188 DEBUGP("#%d ",optinfo->optsnr);
189 for(temp=0; temp<optinfo->optsnr; temp++){
190 /* type field exists ? */
193 tp = skb_header_pointer(skb, ptr, sizeof(_opttype),
199 if (*tp != (optinfo->opts[temp] & 0xFF00)>>8){
200 DEBUGP("Tbad %02X %02X\n",
202 (optinfo->opts[temp] & 0xFF00)>>8);
211 /* length field exists ? */
214 lp = skb_header_pointer(skb, ptr + 1,
219 spec_len = optinfo->opts[temp] & 0x00FF;
221 if (spec_len != 0x00FF && spec_len != *lp) {
222 DEBUGP("Lbad %02X %04X\n", *lp,
233 /* Step to the next */
234 DEBUGP("len%04X \n", optlen);
236 if ((ptr > skb->len - optlen || hdrlen < optlen) &&
237 (temp < optinfo->optsnr - 1)) {
238 DEBUGP("new pointer is too large! \n");
244 if (temp == optinfo->optsnr)
252 /* Called when user tries to insert an entry of this type. */
254 checkentry(const char *tablename,
255 const struct ip6t_ip6 *ip,
257 unsigned int matchinfosize,
258 unsigned int hook_mask)
260 const struct ip6t_opts *optsinfo = matchinfo;
262 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_opts))) {
263 DEBUGP("ip6t_opts: matchsize %u != %u\n",
264 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_opts)));
267 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
268 DEBUGP("ip6t_opts: unknown flags %X\n",
276 static struct ip6t_match opts_match = {
283 .checkentry = &checkentry,
287 static int __init init(void)
289 return ip6t_register_match(&opts_match);
292 static void __exit cleanup(void)
294 ip6t_unregister_match(&opts_match);
298 module_exit(cleanup);