]>
Commit | Line | Data |
---|---|---|
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 | ||
25 | MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>"); | |
26 | MODULE_DESCRIPTION("IP tables connmark match module"); | |
27 | MODULE_LICENSE("GPL"); | |
2e4e6a17 | 28 | MODULE_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 | |
34 | static int | |
35 | match(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 | ||
53 | static int | |
54 | checkentry(const char *tablename, | |
2e4e6a17 | 55 | const void *ip, |
c4986734 | 56 | const struct xt_match *match, |
1da177e4 LT |
57 | void *matchinfo, |
58 | unsigned int matchsize, | |
59 | unsigned int hook_mask) | |
60 | { | |
5d04bff0 | 61 | struct xt_connmark_info *cm = (struct xt_connmark_info *)matchinfo; |
1da177e4 | 62 | |
bf3a46aa HW |
63 | if (cm->mark > 0xffffffff || cm->mask > 0xffffffff) { |
64 | printk(KERN_WARNING "connmark: only support 32bit mark\n"); | |
65 | return 0; | |
66 | } | |
1da177e4 LT |
67 | return 1; |
68 | } | |
69 | ||
2e4e6a17 | 70 | static struct xt_match connmark_match = { |
5d04bff0 PM |
71 | .name = "connmark", |
72 | .match = match, | |
73 | .matchsize = sizeof(struct xt_connmark_info), | |
74 | .checkentry = checkentry, | |
a45049c5 | 75 | .family = AF_INET, |
5d04bff0 | 76 | .me = THIS_MODULE |
2e4e6a17 | 77 | }; |
5d04bff0 | 78 | |
2e4e6a17 | 79 | static struct xt_match connmark6_match = { |
5d04bff0 PM |
80 | .name = "connmark", |
81 | .match = match, | |
82 | .matchsize = sizeof(struct xt_connmark_info), | |
83 | .checkentry = checkentry, | |
a45049c5 | 84 | .family = AF_INET6, |
5d04bff0 | 85 | .me = THIS_MODULE |
1da177e4 LT |
86 | }; |
87 | ||
88 | static int __init init(void) | |
89 | { | |
2e4e6a17 HW |
90 | int ret; |
91 | ||
92 | need_conntrack(); | |
93 | ||
a45049c5 | 94 | ret = xt_register_match(&connmark_match); |
2e4e6a17 HW |
95 | if (ret) |
96 | return ret; | |
97 | ||
a45049c5 | 98 | ret = xt_register_match(&connmark6_match); |
2e4e6a17 | 99 | if (ret) |
a45049c5 | 100 | xt_unregister_match(&connmark_match); |
2e4e6a17 | 101 | return ret; |
1da177e4 LT |
102 | } |
103 | ||
104 | static void __exit fini(void) | |
105 | { | |
a45049c5 PNA |
106 | xt_unregister_match(&connmark6_match); |
107 | xt_unregister_match(&connmark_match); | |
1da177e4 LT |
108 | } |
109 | ||
110 | module_init(init); | |
111 | module_exit(fini); |