1 /* Kernel module to match NFMARK values. */
3 /* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
13 #include <linux/netfilter/xt_mark.h>
14 #include <linux/netfilter/x_tables.h>
16 MODULE_LICENSE("GPL");
17 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
18 MODULE_DESCRIPTION("iptables mark matching module");
19 MODULE_ALIAS("ipt_mark");
20 MODULE_ALIAS("ip6t_mark");
23 match(const struct sk_buff
*skb
,
24 const struct net_device
*in
,
25 const struct net_device
*out
,
26 const struct xt_match
*match
,
27 const void *matchinfo
,
32 const struct xt_mark_info
*info
= matchinfo
;
34 return ((skb
->mark
& info
->mask
) == info
->mark
) ^ info
->invert
;
38 checkentry(const char *tablename
,
40 const struct xt_match
*match
,
42 unsigned int hook_mask
)
44 const struct xt_mark_info
*minfo
= matchinfo
;
46 if (minfo
->mark
> 0xffffffff || minfo
->mask
> 0xffffffff) {
47 printk(KERN_WARNING
"mark: only supports 32bit mark\n");
54 struct compat_xt_mark_info
{
55 compat_ulong_t mark
, mask
;
61 static void compat_from_user(void *dst
, void *src
)
63 const struct compat_xt_mark_info
*cm
= src
;
64 struct xt_mark_info m
= {
69 memcpy(dst
, &m
, sizeof(m
));
72 static int compat_to_user(void __user
*dst
, void *src
)
74 const struct xt_mark_info
*m
= src
;
75 struct compat_xt_mark_info cm
= {
80 return copy_to_user(dst
, &cm
, sizeof(cm
)) ? -EFAULT
: 0;
82 #endif /* CONFIG_COMPAT */
84 static struct xt_match xt_mark_match
[] __read_mostly
= {
88 .checkentry
= checkentry
,
90 .matchsize
= sizeof(struct xt_mark_info
),
92 .compatsize
= sizeof(struct compat_xt_mark_info
),
93 .compat_from_user
= compat_from_user
,
94 .compat_to_user
= compat_to_user
,
101 .checkentry
= checkentry
,
103 .matchsize
= sizeof(struct xt_mark_info
),
108 static int __init
xt_mark_init(void)
110 return xt_register_matches(xt_mark_match
, ARRAY_SIZE(xt_mark_match
));
113 static void __exit
xt_mark_fini(void)
115 xt_unregister_matches(xt_mark_match
, ARRAY_SIZE(xt_mark_match
));
118 module_init(xt_mark_init
);
119 module_exit(xt_mark_fini
);