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;
67 unsigned int hdrlen = 0;
69 u8 _opttype, *tp = NULL;
70 u8 _optlen, *lp = NULL;
74 if (ipv6_find_hdr(skb, &ptr, NEXTHDR_HOP, NULL) < 0)
76 if (ipv6_find_hdr(skb, &ptr, NEXTHDR_DEST, NULL) < 0)
80 oh = skb_header_pointer(skb, ptr, sizeof(_optsh), &_optsh);
86 hdrlen = ipv6_optlen(oh);
87 if (skb->len - ptr < hdrlen) {
88 /* Packet smaller than it's length field */
92 DEBUGP("IPv6 OPTS LEN %u %u ", hdrlen, oh->hdrlen);
94 DEBUGP("len %02X %04X %02X ",
95 optinfo->hdrlen, hdrlen,
96 (!(optinfo->flags & IP6T_OPTS_LEN) ||
97 ((optinfo->hdrlen == hdrlen) ^
98 !!(optinfo->invflags & IP6T_OPTS_INV_LEN))));
100 ret = (oh != NULL) &&
101 (!(optinfo->flags & IP6T_OPTS_LEN) ||
102 ((optinfo->hdrlen == hdrlen) ^
103 !!(optinfo->invflags & IP6T_OPTS_INV_LEN)));
107 if (!(optinfo->flags & IP6T_OPTS_OPTS)) {
109 } else if (optinfo->flags & IP6T_OPTS_NSTRICT) {
110 DEBUGP("Not strict - not implemented");
113 DEBUGP("#%d ", optinfo->optsnr);
114 for (temp = 0; temp < optinfo->optsnr; temp++) {
115 /* type field exists ? */
118 tp = skb_header_pointer(skb, ptr, sizeof(_opttype),
124 if (*tp != (optinfo->opts[temp] & 0xFF00) >> 8) {
125 DEBUGP("Tbad %02X %02X\n",
127 (optinfo->opts[temp] & 0xFF00) >> 8);
136 /* length field exists ? */
139 lp = skb_header_pointer(skb, ptr + 1,
144 spec_len = optinfo->opts[temp] & 0x00FF;
146 if (spec_len != 0x00FF && spec_len != *lp) {
147 DEBUGP("Lbad %02X %04X\n", *lp,
158 /* Step to the next */
159 DEBUGP("len%04X \n", optlen);
161 if ((ptr > skb->len - optlen || hdrlen < optlen) &&
162 (temp < optinfo->optsnr - 1)) {
163 DEBUGP("new pointer is too large! \n");
169 if (temp == optinfo->optsnr)
178 /* Called when user tries to insert an entry of this type. */
180 checkentry(const char *tablename,
183 unsigned int matchinfosize,
184 unsigned int hook_mask)
186 const struct ip6t_opts *optsinfo = matchinfo;
188 if (matchinfosize != IP6T_ALIGN(sizeof(struct ip6t_opts))) {
189 DEBUGP("ip6t_opts: matchsize %u != %u\n",
190 matchinfosize, IP6T_ALIGN(sizeof(struct ip6t_opts)));
193 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
194 DEBUGP("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
201 static struct ip6t_match opts_match = {
208 .checkentry = &checkentry,
212 static int __init init(void)
214 return ip6t_register_match(&opts_match);
217 static void __exit cleanup(void)
219 ip6t_unregister_match(&opts_match);
223 module_exit(cleanup);