Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy...
[deliverable/linux.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
24MODULE_DESCRIPTION("ip6t_tables match for MH");
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 */
34static inline int
35type_match(u_int8_t min, u_int8_t max, u_int8_t type, int invert)
36{
37 int ret;
38
39 ret = (type >= min && type <= max) ^ invert;
40 return ret;
41}
42
43static int
44match(const struct sk_buff *skb,
45 const struct net_device *in,
46 const struct net_device *out,
47 const struct xt_match *match,
48 const void *matchinfo,
49 int offset,
50 unsigned int protoff,
51 int *hotdrop)
52{
53 struct ip6_mh _mh, *mh;
54 const struct ip6t_mh *mhinfo = matchinfo;
55
56 /* Must not be a fragment. */
57 if (offset)
58 return 0;
59
60 mh = skb_header_pointer(skb, protoff, sizeof(_mh), &_mh);
61 if (mh == NULL) {
62 /* We've been asked to examine this packet, and we
63 can't. Hence, no choice but to drop. */
64 duprintf("Dropping evil MH tinygram.\n");
65 *hotdrop = 1;
66 return 0;
67 }
68
138939e0
MN
69 if (mh->ip6mh_proto != IPPROTO_NONE) {
70 duprintf("Dropping invalid MH Payload Proto: %u\n",
71 mh->ip6mh_proto);
72 *hotdrop = 1;
73 return 0;
74 }
75
a0ca215a
MN
76 return type_match(mhinfo->types[0], mhinfo->types[1], mh->ip6mh_type,
77 !!(mhinfo->invflags & IP6T_MH_INV_TYPE));
78}
79
80/* Called when user tries to insert an entry of this type. */
81static int
82mh_checkentry(const char *tablename,
83 const void *entry,
84 const struct xt_match *match,
85 void *matchinfo,
86 unsigned int hook_mask)
87{
88 const struct ip6t_mh *mhinfo = matchinfo;
89
90 /* Must specify no unknown invflags */
91 return !(mhinfo->invflags & ~IP6T_MH_INV_MASK);
92}
93
94static struct xt_match mh_match = {
95 .name = "mh",
96 .family = AF_INET6,
97 .checkentry = mh_checkentry,
98 .match = match,
99 .matchsize = sizeof(struct ip6t_mh),
100 .proto = IPPROTO_MH,
101 .me = THIS_MODULE,
102};
103
104static int __init ip6t_mh_init(void)
105{
106 return xt_register_match(&mh_match);
107}
108
109static void __exit ip6t_mh_fini(void)
110{
111 xt_unregister_match(&mh_match);
112}
113
114module_init(ip6t_mh_init);
115module_exit(ip6t_mh_fini);
This page took 0.098202 seconds and 5 git commands to generate.