]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - net/ipv6/netfilter/ip6t_mh.c
[NETFILTER]: Update modules' descriptions
[mirror_ubuntu-hirsute-kernel.git] / net / ipv6 / netfilter / ip6t_mh.c
CommitLineData
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 */
14#include <linux/types.h>
15#include <linux/module.h>
16#include <net/ip.h>
17#include <linux/ipv6.h>
18#include <net/ipv6.h>
19#include <net/mip6.h>
20
21#include <linux/netfilter/x_tables.h>
22#include <linux/netfilter_ipv6/ip6t_mh.h>
23
2ae15b64 24MODULE_DESCRIPTION("Xtables: IPv6 Mobility Header match");
a0ca215a
MN
25MODULE_LICENSE("GPL");
26
27#ifdef DEBUG_IP_FIREWALL_USER
28#define duprintf(format, args...) printk(format , ## args)
29#else
30#define duprintf(format, args...)
31#endif
32
33/* Returns 1 if the type is matched by the range, 0 otherwise */
1d93a9cb
JE
34static inline bool
35type_match(u_int8_t min, u_int8_t max, u_int8_t type, bool invert)
a0ca215a 36{
1d93a9cb 37 return (type >= min && type <= max) ^ invert;
a0ca215a
MN
38}
39
1d93a9cb 40static bool
d3c5ee6d
JE
41mh_mt6(const struct sk_buff *skb, const struct net_device *in,
42 const struct net_device *out, const struct xt_match *match,
43 const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop)
a0ca215a 44{
a47362a2
JE
45 struct ip6_mh _mh;
46 const struct ip6_mh *mh;
a0ca215a
MN
47 const struct ip6t_mh *mhinfo = matchinfo;
48
49 /* Must not be a fragment. */
50 if (offset)
1d93a9cb 51 return false;
a0ca215a
MN
52
53 mh = skb_header_pointer(skb, protoff, sizeof(_mh), &_mh);
54 if (mh == NULL) {
55 /* We've been asked to examine this packet, and we
56 can't. Hence, no choice but to drop. */
57 duprintf("Dropping evil MH tinygram.\n");
cff533ac 58 *hotdrop = true;
1d93a9cb 59 return false;
a0ca215a
MN
60 }
61
138939e0
MN
62 if (mh->ip6mh_proto != IPPROTO_NONE) {
63 duprintf("Dropping invalid MH Payload Proto: %u\n",
64 mh->ip6mh_proto);
cff533ac 65 *hotdrop = true;
1d93a9cb 66 return false;
138939e0
MN
67 }
68
a0ca215a
MN
69 return type_match(mhinfo->types[0], mhinfo->types[1], mh->ip6mh_type,
70 !!(mhinfo->invflags & IP6T_MH_INV_TYPE));
71}
72
73/* Called when user tries to insert an entry of this type. */
ccb79bdc 74static bool
d3c5ee6d
JE
75mh_mt6_check(const char *tablename, const void *entry,
76 const struct xt_match *match, void *matchinfo,
77 unsigned int hook_mask)
a0ca215a
MN
78{
79 const struct ip6t_mh *mhinfo = matchinfo;
80
81 /* Must specify no unknown invflags */
82 return !(mhinfo->invflags & ~IP6T_MH_INV_MASK);
83}
84
d3c5ee6d 85static struct xt_match mh_mt6_reg __read_mostly = {
a0ca215a
MN
86 .name = "mh",
87 .family = AF_INET6,
d3c5ee6d
JE
88 .checkentry = mh_mt6_check,
89 .match = mh_mt6,
a0ca215a
MN
90 .matchsize = sizeof(struct ip6t_mh),
91 .proto = IPPROTO_MH,
92 .me = THIS_MODULE,
93};
94
d3c5ee6d 95static int __init mh_mt6_init(void)
a0ca215a 96{
d3c5ee6d 97 return xt_register_match(&mh_mt6_reg);
a0ca215a
MN
98}
99
d3c5ee6d 100static void __exit mh_mt6_exit(void)
a0ca215a 101{
d3c5ee6d 102 xt_unregister_match(&mh_mt6_reg);
a0ca215a
MN
103}
104
d3c5ee6d
JE
105module_init(mh_mt6_init);
106module_exit(mh_mt6_exit);