1 /* This kernel module matches connection mark values set by the
4 * Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
5 * by Henrik Nordstrom <hno@marasystems.com>
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.
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.
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
22 #include <linux/module.h>
23 #include <linux/skbuff.h>
25 MODULE_AUTHOR("Henrik Nordstrom <hno@marasytems.com>");
26 MODULE_DESCRIPTION("IP tables connmark match module");
27 MODULE_LICENSE("GPL");
28 MODULE_ALIAS("ipt_connmark");
30 #include <linux/netfilter/x_tables.h>
31 #include <linux/netfilter/xt_connmark.h>
32 #include <net/netfilter/nf_conntrack_compat.h>
35 match(const struct sk_buff
*skb
,
36 const struct net_device
*in
,
37 const struct net_device
*out
,
38 const struct xt_match
*match
,
39 const void *matchinfo
,
44 const struct xt_connmark_info
*info
= matchinfo
;
46 const u_int32_t
*ctmark
= nf_ct_get_mark(skb
, &ctinfo
);
50 return (((*ctmark
) & info
->mask
) == info
->mark
) ^ info
->invert
;
54 checkentry(const char *tablename
,
56 const struct xt_match
*match
,
58 unsigned int hook_mask
)
60 struct xt_connmark_info
*cm
= matchinfo
;
62 if (cm
->mark
> 0xffffffff || cm
->mask
> 0xffffffff) {
63 printk(KERN_WARNING
"connmark: only support 32bit mark\n");
66 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
67 if (nf_ct_l3proto_try_module_get(match
->family
) < 0) {
68 printk(KERN_WARNING
"can't load nf_conntrack support for "
69 "proto=%d\n", match
->family
);
77 destroy(const struct xt_match
*match
, void *matchinfo
)
79 #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
80 nf_ct_l3proto_module_put(match
->family
);
85 struct compat_xt_connmark_info
{
86 compat_ulong_t mark
, mask
;
92 static void compat_from_user(void *dst
, void *src
)
94 struct compat_xt_connmark_info
*cm
= src
;
95 struct xt_connmark_info m
= {
100 memcpy(dst
, &m
, sizeof(m
));
103 static int compat_to_user(void __user
*dst
, void *src
)
105 struct xt_connmark_info
*m
= src
;
106 struct compat_xt_connmark_info cm
= {
111 return copy_to_user(dst
, &cm
, sizeof(cm
)) ? -EFAULT
: 0;
113 #endif /* CONFIG_COMPAT */
115 static struct xt_match xt_connmark_match
[] = {
119 .checkentry
= checkentry
,
122 .matchsize
= sizeof(struct xt_connmark_info
),
124 .compatsize
= sizeof(struct compat_xt_connmark_info
),
125 .compat_from_user
= compat_from_user
,
126 .compat_to_user
= compat_to_user
,
133 .checkentry
= checkentry
,
136 .matchsize
= sizeof(struct xt_connmark_info
),
141 static int __init
xt_connmark_init(void)
144 return xt_register_matches(xt_connmark_match
,
145 ARRAY_SIZE(xt_connmark_match
));
148 static void __exit
xt_connmark_fini(void)
150 xt_unregister_matches(xt_connmark_match
, ARRAY_SIZE(xt_connmark_match
));
153 module_init(xt_connmark_init
);
154 module_exit(xt_connmark_fini
);