[NETFILTER]: nf_conntrack: use hashtable for expectations
[deliverable/linux.git] / net / netfilter / xt_mark.c
CommitLineData
1da177e4
LT
1/* Kernel module to match NFMARK values. */
2
3/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
4 *
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.
8 */
9
10#include <linux/module.h>
11#include <linux/skbuff.h>
12
2e4e6a17
HW
13#include <linux/netfilter/xt_mark.h>
14#include <linux/netfilter/x_tables.h>
1da177e4
LT
15
16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
18MODULE_DESCRIPTION("iptables mark matching module");
2e4e6a17
HW
19MODULE_ALIAS("ipt_mark");
20MODULE_ALIAS("ip6t_mark");
1da177e4 21
1d93a9cb 22static bool
1da177e4
LT
23match(const struct sk_buff *skb,
24 const struct net_device *in,
25 const struct net_device *out,
c4986734 26 const struct xt_match *match,
1da177e4
LT
27 const void *matchinfo,
28 int offset,
2e4e6a17 29 unsigned int protoff,
cff533ac 30 bool *hotdrop)
1da177e4 31{
2e4e6a17 32 const struct xt_mark_info *info = matchinfo;
1da177e4 33
82e91ffe 34 return ((skb->mark & info->mask) == info->mark) ^ info->invert;
1da177e4
LT
35}
36
ccb79bdc 37static bool
1da177e4 38checkentry(const char *tablename,
601e68e1 39 const void *entry,
c4986734 40 const struct xt_match *match,
601e68e1
YH
41 void *matchinfo,
42 unsigned int hook_mask)
1da177e4 43{
3e72b2fe 44 const struct xt_mark_info *minfo = matchinfo;
bf3a46aa 45
bf3a46aa
HW
46 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
47 printk(KERN_WARNING "mark: only supports 32bit mark\n");
ccb79bdc 48 return false;
bf3a46aa 49 }
ccb79bdc 50 return true;
1da177e4
LT
51}
52
bc80b656
PM
53#ifdef CONFIG_COMPAT
54struct compat_xt_mark_info {
55 compat_ulong_t mark, mask;
56 u_int8_t invert;
57 u_int8_t __pad1;
58 u_int16_t __pad2;
59};
60
61static void compat_from_user(void *dst, void *src)
62{
a47362a2 63 const struct compat_xt_mark_info *cm = src;
bc80b656
PM
64 struct xt_mark_info m = {
65 .mark = cm->mark,
66 .mask = cm->mask,
67 .invert = cm->invert,
68 };
69 memcpy(dst, &m, sizeof(m));
70}
71
72static int compat_to_user(void __user *dst, void *src)
73{
a47362a2 74 const struct xt_mark_info *m = src;
bc80b656
PM
75 struct compat_xt_mark_info cm = {
76 .mark = m->mark,
77 .mask = m->mask,
78 .invert = m->invert,
79 };
80 return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
81}
82#endif /* CONFIG_COMPAT */
83
9f15c530 84static struct xt_match xt_mark_match[] __read_mostly = {
4470bbc7
PM
85 {
86 .name = "mark",
87 .family = AF_INET,
88 .checkentry = checkentry,
89 .match = match,
90 .matchsize = sizeof(struct xt_mark_info),
bc80b656
PM
91#ifdef CONFIG_COMPAT
92 .compatsize = sizeof(struct compat_xt_mark_info),
93 .compat_from_user = compat_from_user,
94 .compat_to_user = compat_to_user,
95#endif
4470bbc7
PM
96 .me = THIS_MODULE,
97 },
98 {
99 .name = "mark",
100 .family = AF_INET6,
101 .checkentry = checkentry,
102 .match = match,
103 .matchsize = sizeof(struct xt_mark_info),
104 .me = THIS_MODULE,
105 },
1da177e4
LT
106};
107
65b4b4e8 108static int __init xt_mark_init(void)
1da177e4 109{
4470bbc7 110 return xt_register_matches(xt_mark_match, ARRAY_SIZE(xt_mark_match));
1da177e4
LT
111}
112
65b4b4e8 113static void __exit xt_mark_fini(void)
1da177e4 114{
4470bbc7 115 xt_unregister_matches(xt_mark_match, ARRAY_SIZE(xt_mark_match));
1da177e4
LT
116}
117
65b4b4e8
AM
118module_init(xt_mark_init);
119module_exit(xt_mark_fini);
This page took 0.250793 seconds and 5 git commands to generate.