]>
Commit | Line | Data |
---|---|---|
a0ca215a MN |
1 | /* |
2 | * Copyright (C)2006 USAGI/WIDE Project | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License version 2 as | |
6 | * published by the Free Software Foundation. | |
7 | * | |
8 | * Author: | |
9 | * Masahide NAKAMURA @USAGI <masahide.nakamura.cz@hitachi.com> | |
10 | * | |
11 | * Based on net/netfilter/xt_tcpudp.c | |
12 | * | |
13 | */ | |
be91fd5e | 14 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
a0ca215a MN |
15 | #include <linux/types.h> |
16 | #include <linux/module.h> | |
17 | #include <net/ip.h> | |
18 | #include <linux/ipv6.h> | |
19 | #include <net/ipv6.h> | |
20 | #include <net/mip6.h> | |
21 | ||
22 | #include <linux/netfilter/x_tables.h> | |
23 | #include <linux/netfilter_ipv6/ip6t_mh.h> | |
24 | ||
2ae15b64 | 25 | MODULE_DESCRIPTION("Xtables: IPv6 Mobility Header match"); |
a0ca215a MN |
26 | MODULE_LICENSE("GPL"); |
27 | ||
a0ca215a | 28 | /* Returns 1 if the type is matched by the range, 0 otherwise */ |
1d93a9cb JE |
29 | static inline bool |
30 | type_match(u_int8_t min, u_int8_t max, u_int8_t type, bool invert) | |
a0ca215a | 31 | { |
1d93a9cb | 32 | return (type >= min && type <= max) ^ invert; |
a0ca215a MN |
33 | } |
34 | ||
4b560b44 JE |
35 | static bool mh_mt6(const struct sk_buff *skb, |
36 | const struct xt_action_param *par) | |
a0ca215a | 37 | { |
a47362a2 JE |
38 | struct ip6_mh _mh; |
39 | const struct ip6_mh *mh; | |
f7108a20 | 40 | const struct ip6t_mh *mhinfo = par->matchinfo; |
a0ca215a MN |
41 | |
42 | /* Must not be a fragment. */ | |
f7108a20 | 43 | if (par->fragoff != 0) |
1d93a9cb | 44 | return false; |
a0ca215a | 45 | |
f7108a20 | 46 | mh = skb_header_pointer(skb, par->thoff, sizeof(_mh), &_mh); |
a0ca215a MN |
47 | if (mh == NULL) { |
48 | /* We've been asked to examine this packet, and we | |
49 | can't. Hence, no choice but to drop. */ | |
be91fd5e | 50 | pr_debug("Dropping evil MH tinygram.\n"); |
f7108a20 | 51 | *par->hotdrop = true; |
1d93a9cb | 52 | return false; |
a0ca215a MN |
53 | } |
54 | ||
138939e0 | 55 | if (mh->ip6mh_proto != IPPROTO_NONE) { |
be91fd5e | 56 | pr_debug("Dropping invalid MH Payload Proto: %u\n", |
138939e0 | 57 | mh->ip6mh_proto); |
f7108a20 | 58 | *par->hotdrop = true; |
1d93a9cb | 59 | return false; |
138939e0 MN |
60 | } |
61 | ||
a0ca215a MN |
62 | return type_match(mhinfo->types[0], mhinfo->types[1], mh->ip6mh_type, |
63 | !!(mhinfo->invflags & IP6T_MH_INV_TYPE)); | |
64 | } | |
65 | ||
b0f38452 | 66 | static int mh_mt6_check(const struct xt_mtchk_param *par) |
a0ca215a | 67 | { |
9b4fce7a | 68 | const struct ip6t_mh *mhinfo = par->matchinfo; |
a0ca215a MN |
69 | |
70 | /* Must specify no unknown invflags */ | |
bd414ee6 | 71 | return (mhinfo->invflags & ~IP6T_MH_INV_MASK) ? -EINVAL : 0; |
a0ca215a MN |
72 | } |
73 | ||
d3c5ee6d | 74 | static struct xt_match mh_mt6_reg __read_mostly = { |
a0ca215a | 75 | .name = "mh", |
ee999d8b | 76 | .family = NFPROTO_IPV6, |
d3c5ee6d JE |
77 | .checkentry = mh_mt6_check, |
78 | .match = mh_mt6, | |
a0ca215a MN |
79 | .matchsize = sizeof(struct ip6t_mh), |
80 | .proto = IPPROTO_MH, | |
81 | .me = THIS_MODULE, | |
82 | }; | |
83 | ||
d3c5ee6d | 84 | static int __init mh_mt6_init(void) |
a0ca215a | 85 | { |
d3c5ee6d | 86 | return xt_register_match(&mh_mt6_reg); |
a0ca215a MN |
87 | } |
88 | ||
d3c5ee6d | 89 | static void __exit mh_mt6_exit(void) |
a0ca215a | 90 | { |
d3c5ee6d | 91 | xt_unregister_match(&mh_mt6_reg); |
a0ca215a MN |
92 | } |
93 | ||
d3c5ee6d JE |
94 | module_init(mh_mt6_init); |
95 | module_exit(mh_mt6_exit); |