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 mark_mt(const struct sk_buff *skb, const struct net_device *in,
24 const struct net_device *out, const struct xt_match *match,
25 const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop)
27 const struct xt_mark_info *info = matchinfo;
29 return ((skb->mark & info->mask) == info->mark) ^ info->invert;
33 mark_mt_check(const char *tablename, const void *entry,
34 const struct xt_match *match, void *matchinfo,
35 unsigned int hook_mask)
37 const struct xt_mark_info *minfo = matchinfo;
39 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
40 printk(KERN_WARNING "mark: only supports 32bit mark\n");
47 struct compat_xt_mark_info {
48 compat_ulong_t mark, mask;
54 static void mark_mt_compat_from_user(void *dst, void *src)
56 const struct compat_xt_mark_info *cm = src;
57 struct xt_mark_info m = {
62 memcpy(dst, &m, sizeof(m));
65 static int mark_mt_compat_to_user(void __user *dst, void *src)
67 const struct xt_mark_info *m = src;
68 struct compat_xt_mark_info cm = {
73 return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
75 #endif /* CONFIG_COMPAT */
77 static struct xt_match mark_mt_reg[] __read_mostly = {
81 .checkentry = mark_mt_check,
83 .matchsize = sizeof(struct xt_mark_info),
85 .compatsize = sizeof(struct compat_xt_mark_info),
86 .compat_from_user = mark_mt_compat_from_user,
87 .compat_to_user = mark_mt_compat_to_user,
94 .checkentry = mark_mt_check,
96 .matchsize = sizeof(struct xt_mark_info),
98 .compatsize = sizeof(struct compat_xt_mark_info),
99 .compat_from_user = mark_mt_compat_from_user,
100 .compat_to_user = mark_mt_compat_to_user,
106 static int __init mark_mt_init(void)
108 return xt_register_matches(mark_mt_reg, ARRAY_SIZE(mark_mt_reg));
111 static void __exit mark_mt_exit(void)
113 xt_unregister_matches(mark_mt_reg, ARRAY_SIZE(mark_mt_reg));
116 module_init(mark_mt_init);
117 module_exit(mark_mt_exit);