Skip to content

Commit 17b0d7e

Browse files
Jan Engelhardtdavem330
authored andcommitted
[NETFILTER]: xt_mark match, revision 1
Introduces the xt_mark match revision 1. It uses fixed types, eventually obsoleting revision 0 some day (uses nonfixed types). Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de> Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 64eb12f commit 17b0d7e

2 files changed

Lines changed: 57 additions & 20 deletions

File tree

‎include/linux/netfilter/xt_mark.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ struct xt_mark_info {
66
u_int8_t invert;
77
};
88

9+
struct xt_mark_mtinfo1 {
10+
u_int32_t mark, mask;
11+
u_int8_t invert;
12+
};
13+
914
#endif /*_XT_MARK_H*/

‎net/netfilter/xt_mark.c‎

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
/* Kernel module to match NFMARK values. */
2-
3-
/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
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>
47
*
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+
* 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.
811
*/
912

1013
#include <linux/module.h>
@@ -19,20 +22,31 @@ MODULE_DESCRIPTION("iptables mark matching module");
1922
MODULE_ALIAS("ipt_mark");
2023
MODULE_ALIAS("ip6t_mark");
2124

25+
static bool
26+
mark_mt_v0(const struct sk_buff *skb, const struct net_device *in,
27+
const struct net_device *out, const struct xt_match *match,
28+
const void *matchinfo, int offset, unsigned int protoff,
29+
bool *hotdrop)
30+
{
31+
const struct xt_mark_info *info = matchinfo;
32+
33+
return ((skb->mark & info->mask) == info->mark) ^ info->invert;
34+
}
35+
2236
static bool
2337
mark_mt(const struct sk_buff *skb, const struct net_device *in,
2438
const struct net_device *out, const struct xt_match *match,
2539
const void *matchinfo, int offset, unsigned int protoff, bool *hotdrop)
2640
{
27-
const struct xt_mark_info *info = matchinfo;
41+
const struct xt_mark_mtinfo1 *info = matchinfo;
2842

2943
return ((skb->mark & info->mask) == info->mark) ^ info->invert;
3044
}
3145

3246
static bool
33-
mark_mt_check(const char *tablename, const void *entry,
34-
const struct xt_match *match, void *matchinfo,
35-
unsigned int hook_mask)
47+
mark_mt_check_v0(const char *tablename, const void *entry,
48+
const struct xt_match *match, void *matchinfo,
49+
unsigned int hook_mask)
3650
{
3751
const struct xt_mark_info *minfo = matchinfo;
3852

@@ -51,7 +65,7 @@ struct compat_xt_mark_info {
5165
u_int16_t __pad2;
5266
};
5367

54-
static void mark_mt_compat_from_user(void *dst, void *src)
68+
static void mark_mt_compat_from_user_v0(void *dst, void *src)
5569
{
5670
const struct compat_xt_mark_info *cm = src;
5771
struct xt_mark_info m = {
@@ -62,7 +76,7 @@ static void mark_mt_compat_from_user(void *dst, void *src)
6276
memcpy(dst, &m, sizeof(m));
6377
}
6478

65-
static int mark_mt_compat_to_user(void __user *dst, void *src)
79+
static int mark_mt_compat_to_user_v0(void __user *dst, void *src)
6680
{
6781
const struct xt_mark_info *m = src;
6882
struct compat_xt_mark_info cm = {
@@ -77,30 +91,48 @@ static int mark_mt_compat_to_user(void __user *dst, void *src)
7791
static struct xt_match mark_mt_reg[] __read_mostly = {
7892
{
7993
.name = "mark",
94+
.revision = 0,
8095
.family = AF_INET,
81-
.checkentry = mark_mt_check,
82-
.match = mark_mt,
96+
.checkentry = mark_mt_check_v0,
97+
.match = mark_mt_v0,
8398
.matchsize = sizeof(struct xt_mark_info),
8499
#ifdef CONFIG_COMPAT
85100
.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,
101+
.compat_from_user = mark_mt_compat_from_user_v0,
102+
.compat_to_user = mark_mt_compat_to_user_v0,
88103
#endif
89104
.me = THIS_MODULE,
90105
},
91106
{
92107
.name = "mark",
108+
.revision = 0,
93109
.family = AF_INET6,
94-
.checkentry = mark_mt_check,
95-
.match = mark_mt,
110+
.checkentry = mark_mt_check_v0,
111+
.match = mark_mt_v0,
96112
.matchsize = sizeof(struct xt_mark_info),
97113
#ifdef CONFIG_COMPAT
98114
.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,
115+
.compat_from_user = mark_mt_compat_from_user_v0,
116+
.compat_to_user = mark_mt_compat_to_user_v0,
101117
#endif
102118
.me = THIS_MODULE,
103119
},
120+
{
121+
.name = "mark",
122+
.revision = 1,
123+
.family = AF_INET,
124+
.match = mark_mt,
125+
.matchsize = sizeof(struct xt_mark_mtinfo1),
126+
.me = THIS_MODULE,
127+
},
128+
{
129+
.name = "mark",
130+
.revision = 1,
131+
.family = AF_INET6,
132+
.match = mark_mt,
133+
.matchsize = sizeof(struct xt_mark_mtinfo1),
134+
.me = THIS_MODULE,
135+
},
104136
};
105137

106138
static int __init mark_mt_init(void)

0 commit comments

Comments
 (0)