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/x_tables.h>
20 #include <linux/netfilter_ipv6/ip6_tables.h>
21 #include <linux/netfilter_ipv6/ip6t_opts.h>
23 MODULE_LICENSE("GPL");
24 MODULE_DESCRIPTION("IPv6 opts match");
25 MODULE_AUTHOR("Andras Kis-Szabo <kisza@sch.bme.hu>");
26 MODULE_ALIAS("ip6t_dst");
31 * 1 -> must drop the packet
32 * 2 -> send ICMP PARM PROB regardless and drop packet
33 * 3 -> Send ICMP if not a multicast address and drop packet
36 * 1 -> can change the routing
38 * 0 -> Pad1 (only 1 byte!)
39 * 1 -> PadN LENGTH info (total length = length + 2)
40 * C0 | 2 -> JUMBO 4 x x x x ( xxxx > 64k )
45 match(const struct sk_buff *skb,
46 const struct net_device *in,
47 const struct net_device *out,
48 const struct xt_match *match,
49 const void *matchinfo,
54 struct ipv6_opt_hdr _optsh;
55 const struct ipv6_opt_hdr *oh;
56 const struct ip6t_opts *optinfo = matchinfo;
59 unsigned int hdrlen = 0;
63 const u_int8_t *tp = NULL;
64 const u_int8_t *lp = NULL;
68 err = ipv6_find_hdr(skb, &ptr, match->data, NULL);
75 oh = skb_header_pointer(skb, ptr, sizeof(_optsh), &_optsh);
81 hdrlen = ipv6_optlen(oh);
82 if (skb->len - ptr < hdrlen) {
83 /* Packet smaller than it's length field */
87 pr_debug("IPv6 OPTS LEN %u %u ", hdrlen, oh->hdrlen);
89 pr_debug("len %02X %04X %02X ",
90 optinfo->hdrlen, hdrlen,
91 (!(optinfo->flags & IP6T_OPTS_LEN) ||
92 ((optinfo->hdrlen == hdrlen) ^
93 !!(optinfo->invflags & IP6T_OPTS_INV_LEN))));
96 (!(optinfo->flags & IP6T_OPTS_LEN) ||
97 ((optinfo->hdrlen == hdrlen) ^
98 !!(optinfo->invflags & IP6T_OPTS_INV_LEN)));
102 if (!(optinfo->flags & IP6T_OPTS_OPTS)) {
104 } else if (optinfo->flags & IP6T_OPTS_NSTRICT) {
105 pr_debug("Not strict - not implemented");
108 pr_debug("#%d ", optinfo->optsnr);
109 for (temp = 0; temp < optinfo->optsnr; temp++) {
110 /* type field exists ? */
113 tp = skb_header_pointer(skb, ptr, sizeof(_opttype),
119 if (*tp != (optinfo->opts[temp] & 0xFF00) >> 8) {
120 pr_debug("Tbad %02X %02X\n", *tp,
121 (optinfo->opts[temp] & 0xFF00) >> 8);
130 /* length field exists ? */
133 lp = skb_header_pointer(skb, ptr + 1,
138 spec_len = optinfo->opts[temp] & 0x00FF;
140 if (spec_len != 0x00FF && spec_len != *lp) {
141 pr_debug("Lbad %02X %04X\n", *lp,
152 /* Step to the next */
153 pr_debug("len%04X \n", optlen);
155 if ((ptr > skb->len - optlen || hdrlen < optlen) &&
156 temp < optinfo->optsnr - 1) {
157 pr_debug("new pointer is too large! \n");
163 if (temp == optinfo->optsnr)
172 /* Called when user tries to insert an entry of this type. */
174 checkentry(const char *tablename,
176 const struct xt_match *match,
178 unsigned int hook_mask)
180 const struct ip6t_opts *optsinfo = matchinfo;
182 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
183 pr_debug("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
189 static struct xt_match opts_match[] __read_mostly = {
194 .matchsize = sizeof(struct ip6t_opts),
195 .checkentry = checkentry,
203 .matchsize = sizeof(struct ip6t_opts),
204 .checkentry = checkentry,
206 .data = NEXTHDR_DEST,
210 static int __init ip6t_hbh_init(void)
212 return xt_register_matches(opts_match, ARRAY_SIZE(opts_match));
215 static void __exit ip6t_hbh_fini(void)
217 xt_unregister_matches(opts_match, ARRAY_SIZE(opts_match));
220 module_init(ip6t_hbh_init);
221 module_exit(ip6t_hbh_fini);