Merge branch 'parisc' from /home/kyle/repos/parisc-2.6.git
[deliverable/linux.git] / net / netfilter / xt_connmark.c
CommitLineData
1da177e4
LT
1/* This kernel module matches connection mark values set by the
2 * CONNMARK target
3 *
4 * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
5 * by Henrik Nordstrom <hno@marasystems.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#include <linux/module.h>
23#include <linux/skbuff.h>
24
25MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
26MODULE_DESCRIPTION("IP tables connmark match module");
27MODULE_LICENSE("GPL");
2e4e6a17 28MODULE_ALIAS("ipt_connmark");
1da177e4 29
2e4e6a17
HW
30#include <linux/netfilter/x_tables.h>
31#include <linux/netfilter/xt_connmark.h>
9fb9cbb1 32#include <net/netfilter/nf_conntrack_compat.h>
1da177e4
LT
33
34static int
35match(const struct sk_buff *skb,
36 const struct net_device *in,
37 const struct net_device *out,
c4986734 38 const struct xt_match *match,
1da177e4
LT
39 const void *matchinfo,
40 int offset,
2e4e6a17 41 unsigned int protoff,
1da177e4
LT
42 int *hotdrop)
43{
2e4e6a17 44 const struct xt_connmark_info *info = matchinfo;
9fb9cbb1
YK
45 u_int32_t ctinfo;
46 const u_int32_t *ctmark = nf_ct_get_mark(skb, &ctinfo);
47 if (!ctmark)
1da177e4
LT
48 return 0;
49
9fb9cbb1 50 return (((*ctmark) & info->mask) == info->mark) ^ info->invert;
1da177e4
LT
51}
52
53static int
54checkentry(const char *tablename,
2e4e6a17 55 const void *ip,
c4986734 56 const struct xt_match *match,
1da177e4 57 void *matchinfo,
1da177e4
LT
58 unsigned int hook_mask)
59{
3e72b2fe 60 struct xt_connmark_info *cm = matchinfo;
1da177e4 61
bf3a46aa
HW
62 if (cm->mark > 0xffffffff || cm->mask > 0xffffffff) {
63 printk(KERN_WARNING "connmark: only support 32bit mark\n");
64 return 0;
65 }
b9f78f9f 66 if (nf_ct_l3proto_try_module_get(match->family) < 0) {
fe0b9294 67 printk(KERN_WARNING "can't load conntrack support for "
b9f78f9f
PNA
68 "proto=%d\n", match->family);
69 return 0;
70 }
1da177e4
LT
71 return 1;
72}
73
b9f78f9f 74static void
efa74165 75destroy(const struct xt_match *match, void *matchinfo)
b9f78f9f 76{
b9f78f9f 77 nf_ct_l3proto_module_put(match->family);
b9f78f9f
PNA
78}
79
f1eda053
PM
80#ifdef CONFIG_COMPAT
81struct compat_xt_connmark_info {
82 compat_ulong_t mark, mask;
83 u_int8_t invert;
84 u_int8_t __pad1;
85 u_int16_t __pad2;
86};
87
88static void compat_from_user(void *dst, void *src)
89{
90 struct compat_xt_connmark_info *cm = src;
91 struct xt_connmark_info m = {
92 .mark = cm->mark,
93 .mask = cm->mask,
94 .invert = cm->invert,
95 };
96 memcpy(dst, &m, sizeof(m));
97}
98
99static int compat_to_user(void __user *dst, void *src)
100{
101 struct xt_connmark_info *m = src;
102 struct compat_xt_connmark_info cm = {
103 .mark = m->mark,
104 .mask = m->mask,
105 .invert = m->invert,
106 };
107 return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
108}
109#endif /* CONFIG_COMPAT */
110
4470bbc7
PM
111static struct xt_match xt_connmark_match[] = {
112 {
113 .name = "connmark",
114 .family = AF_INET,
115 .checkentry = checkentry,
116 .match = match,
117 .destroy = destroy,
118 .matchsize = sizeof(struct xt_connmark_info),
f1eda053
PM
119#ifdef CONFIG_COMPAT
120 .compatsize = sizeof(struct compat_xt_connmark_info),
121 .compat_from_user = compat_from_user,
122 .compat_to_user = compat_to_user,
123#endif
4470bbc7
PM
124 .me = THIS_MODULE
125 },
126 {
127 .name = "connmark",
128 .family = AF_INET6,
129 .checkentry = checkentry,
130 .match = match,
131 .destroy = destroy,
132 .matchsize = sizeof(struct xt_connmark_info),
133 .me = THIS_MODULE
134 },
1da177e4
LT
135};
136
65b4b4e8 137static int __init xt_connmark_init(void)
1da177e4 138{
4470bbc7
PM
139 return xt_register_matches(xt_connmark_match,
140 ARRAY_SIZE(xt_connmark_match));
1da177e4
LT
141}
142
65b4b4e8 143static void __exit xt_connmark_fini(void)
1da177e4 144{
f64ad5bb 145 xt_unregister_matches(xt_connmark_match, ARRAY_SIZE(xt_connmark_match));
1da177e4
LT
146}
147
65b4b4e8
AM
148module_init(xt_connmark_init);
149module_exit(xt_connmark_fini);
This page took 0.210759 seconds and 5 git commands to generate.