netfilter: xtables: move extension arguments into compound structure (1/6)
[deliverable/linux.git] / net / netfilter / xt_mark.c
CommitLineData
17b0d7ef
JE
1/*
2 * xt_mark - Netfilter module to match NFMARK value
3 *
4 * (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
5 * Copyright © CC Computer Consultants GmbH, 2007 - 2008
6 * Jan Engelhardt <jengelh@computergmbh.de>
1da177e4 7 *
17b0d7ef
JE
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
1da177e4
LT
11 */
12
13#include <linux/module.h>
14#include <linux/skbuff.h>
15
2e4e6a17
HW
16#include <linux/netfilter/xt_mark.h>
17#include <linux/netfilter/x_tables.h>
1da177e4
LT
18
19MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
2ae15b64 21MODULE_DESCRIPTION("Xtables: packet mark match");
2e4e6a17
HW
22MODULE_ALIAS("ipt_mark");
23MODULE_ALIAS("ip6t_mark");
1da177e4 24
17b0d7ef 25static bool
f7108a20 26mark_mt_v0(const struct sk_buff *skb, const struct xt_match_param *par)
17b0d7ef 27{
f7108a20 28 const struct xt_mark_info *info = par->matchinfo;
17b0d7ef
JE
29
30 return ((skb->mark & info->mask) == info->mark) ^ info->invert;
31}
32
1d93a9cb 33static bool
f7108a20 34mark_mt(const struct sk_buff *skb, const struct xt_match_param *par)
1da177e4 35{
f7108a20 36 const struct xt_mark_mtinfo1 *info = par->matchinfo;
1da177e4 37
82e91ffe 38 return ((skb->mark & info->mask) == info->mark) ^ info->invert;
1da177e4
LT
39}
40
ccb79bdc 41static bool
17b0d7ef
JE
42mark_mt_check_v0(const char *tablename, const void *entry,
43 const struct xt_match *match, void *matchinfo,
44 unsigned int hook_mask)
1da177e4 45{
3e72b2fe 46 const struct xt_mark_info *minfo = matchinfo;
bf3a46aa 47
bf3a46aa
HW
48 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
49 printk(KERN_WARNING "mark: only supports 32bit mark\n");
ccb79bdc 50 return false;
bf3a46aa 51 }
ccb79bdc 52 return true;
1da177e4
LT
53}
54
bc80b656
PM
55#ifdef CONFIG_COMPAT
56struct compat_xt_mark_info {
57 compat_ulong_t mark, mask;
58 u_int8_t invert;
59 u_int8_t __pad1;
60 u_int16_t __pad2;
61};
62
17b0d7ef 63static void mark_mt_compat_from_user_v0(void *dst, void *src)
bc80b656 64{
a47362a2 65 const struct compat_xt_mark_info *cm = src;
bc80b656
PM
66 struct xt_mark_info m = {
67 .mark = cm->mark,
68 .mask = cm->mask,
69 .invert = cm->invert,
70 };
71 memcpy(dst, &m, sizeof(m));
72}
73
17b0d7ef 74static int mark_mt_compat_to_user_v0(void __user *dst, void *src)
bc80b656 75{
a47362a2 76 const struct xt_mark_info *m = src;
bc80b656
PM
77 struct compat_xt_mark_info cm = {
78 .mark = m->mark,
79 .mask = m->mask,
80 .invert = m->invert,
81 };
82 return copy_to_user(dst, &cm, sizeof(cm)) ? -EFAULT : 0;
83}
84#endif /* CONFIG_COMPAT */
85
d3c5ee6d 86static struct xt_match mark_mt_reg[] __read_mostly = {
4470bbc7
PM
87 {
88 .name = "mark",
17b0d7ef 89 .revision = 0,
55b69e91 90 .family = NFPROTO_UNSPEC,
17b0d7ef
JE
91 .checkentry = mark_mt_check_v0,
92 .match = mark_mt_v0,
4470bbc7 93 .matchsize = sizeof(struct xt_mark_info),
bc80b656
PM
94#ifdef CONFIG_COMPAT
95 .compatsize = sizeof(struct compat_xt_mark_info),
17b0d7ef
JE
96 .compat_from_user = mark_mt_compat_from_user_v0,
97 .compat_to_user = mark_mt_compat_to_user_v0,
bc80b656 98#endif
4470bbc7
PM
99 .me = THIS_MODULE,
100 },
17b0d7ef
JE
101 {
102 .name = "mark",
103 .revision = 1,
55b69e91 104 .family = NFPROTO_UNSPEC,
17b0d7ef
JE
105 .match = mark_mt,
106 .matchsize = sizeof(struct xt_mark_mtinfo1),
107 .me = THIS_MODULE,
108 },
1da177e4
LT
109};
110
d3c5ee6d 111static int __init mark_mt_init(void)
1da177e4 112{
d3c5ee6d 113 return xt_register_matches(mark_mt_reg, ARRAY_SIZE(mark_mt_reg));
1da177e4
LT
114}
115
d3c5ee6d 116static void __exit mark_mt_exit(void)
1da177e4 117{
d3c5ee6d 118 xt_unregister_matches(mark_mt_reg, ARRAY_SIZE(mark_mt_reg));
1da177e4
LT
119}
120
d3c5ee6d
JE
121module_init(mark_mt_init);
122module_exit(mark_mt_exit);
This page took 0.45027 seconds and 5 git commands to generate.