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("Xtables: IPv6 Hop-By-Hop and Destination Header 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 hbh_mt6(const struct sk_buff *skb, const struct xt_match_param *par)
47 struct ipv6_opt_hdr _optsh;
48 const struct ipv6_opt_hdr *oh;
49 const struct ip6t_opts *optinfo = par->matchinfo;
52 unsigned int hdrlen = 0;
56 const u_int8_t *tp = NULL;
57 const u_int8_t *lp = NULL;
61 err = ipv6_find_hdr(skb, &ptr, par->match->data, NULL);
68 oh = skb_header_pointer(skb, ptr, sizeof(_optsh), &_optsh);
74 hdrlen = ipv6_optlen(oh);
75 if (skb->len - ptr < hdrlen) {
76 /* Packet smaller than it's length field */
80 pr_debug("IPv6 OPTS LEN %u %u ", hdrlen, oh->hdrlen);
82 pr_debug("len %02X %04X %02X ",
83 optinfo->hdrlen, hdrlen,
84 (!(optinfo->flags & IP6T_OPTS_LEN) ||
85 ((optinfo->hdrlen == hdrlen) ^
86 !!(optinfo->invflags & IP6T_OPTS_INV_LEN))));
89 (!(optinfo->flags & IP6T_OPTS_LEN) ||
90 ((optinfo->hdrlen == hdrlen) ^
91 !!(optinfo->invflags & IP6T_OPTS_INV_LEN)));
95 if (!(optinfo->flags & IP6T_OPTS_OPTS)) {
99 pr_debug("#%d ", optinfo->optsnr);
100 for (temp = 0; temp < optinfo->optsnr; temp++) {
101 /* type field exists ? */
104 tp = skb_header_pointer(skb, ptr, sizeof(_opttype),
110 if (*tp != (optinfo->opts[temp] & 0xFF00) >> 8) {
111 pr_debug("Tbad %02X %02X\n", *tp,
112 (optinfo->opts[temp] & 0xFF00) >> 8);
121 /* length field exists ? */
124 lp = skb_header_pointer(skb, ptr + 1,
129 spec_len = optinfo->opts[temp] & 0x00FF;
131 if (spec_len != 0x00FF && spec_len != *lp) {
132 pr_debug("Lbad %02X %04X\n", *lp,
143 /* Step to the next */
144 pr_debug("len%04X \n", optlen);
146 if ((ptr > skb->len - optlen || hdrlen < optlen) &&
147 temp < optinfo->optsnr - 1) {
148 pr_debug("new pointer is too large! \n");
154 if (temp == optinfo->optsnr)
163 static bool hbh_mt6_check(const struct xt_mtchk_param *par)
165 const struct ip6t_opts *optsinfo = par->matchinfo;
167 if (optsinfo->invflags & ~IP6T_OPTS_INV_MASK) {
168 pr_debug("ip6t_opts: unknown flags %X\n", optsinfo->invflags);
172 if (optsinfo->flags & IP6T_OPTS_NSTRICT) {
173 pr_debug("ip6t_opts: Not strict - not implemented");
180 static struct xt_match hbh_mt6_reg[] __read_mostly = {
183 .family = NFPROTO_IPV6,
185 .matchsize = sizeof(struct ip6t_opts),
186 .checkentry = hbh_mt6_check,
192 .family = NFPROTO_IPV6,
194 .matchsize = sizeof(struct ip6t_opts),
195 .checkentry = hbh_mt6_check,
197 .data = NEXTHDR_DEST,
201 static int __init hbh_mt6_init(void)
203 return xt_register_matches(hbh_mt6_reg, ARRAY_SIZE(hbh_mt6_reg));
206 static void __exit hbh_mt6_exit(void)
208 xt_unregister_matches(hbh_mt6_reg, ARRAY_SIZE(hbh_mt6_reg));
211 module_init(hbh_mt6_init);
212 module_exit(hbh_mt6_exit);