2 * xt_MARK - Netfilter module to modify the NFMARK field of an skb
4 * (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
5 * Copyright © CC Computer Consultants GmbH, 2007 - 2008
6 * Jan Engelhardt <jengelh@computergmbh.de>
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.
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
16 #include <net/checksum.h>
18 #include <linux/netfilter/x_tables.h>
19 #include <linux/netfilter/xt_MARK.h>
21 MODULE_LICENSE("GPL");
22 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
23 MODULE_DESCRIPTION("Xtables: packet mark modification");
24 MODULE_ALIAS("ipt_MARK");
25 MODULE_ALIAS("ip6t_MARK");
28 mark_tg_v0(struct sk_buff
*skb
, const struct net_device
*in
,
29 const struct net_device
*out
, unsigned int hooknum
,
30 const struct xt_target
*target
, const void *targinfo
)
32 const struct xt_mark_target_info
*markinfo
= targinfo
;
34 skb
->mark
= markinfo
->mark
;
39 mark_tg_v1(struct sk_buff
*skb
, const struct net_device
*in
,
40 const struct net_device
*out
, unsigned int hooknum
,
41 const struct xt_target
*target
, const void *targinfo
)
43 const struct xt_mark_target_info_v1
*markinfo
= targinfo
;
46 switch (markinfo
->mode
) {
48 mark
= markinfo
->mark
;
52 mark
= skb
->mark
& markinfo
->mark
;
56 mark
= skb
->mark
| markinfo
->mark
;
65 mark_tg(struct sk_buff
*skb
, const struct net_device
*in
,
66 const struct net_device
*out
, unsigned int hooknum
,
67 const struct xt_target
*target
, const void *targinfo
)
69 const struct xt_mark_tginfo2
*info
= targinfo
;
71 skb
->mark
= (skb
->mark
& ~info
->mask
) ^ info
->mark
;
76 mark_tg_check_v0(const char *tablename
, const void *entry
,
77 const struct xt_target
*target
, void *targinfo
,
78 unsigned int hook_mask
)
80 const struct xt_mark_target_info
*markinfo
= targinfo
;
82 if (markinfo
->mark
> 0xffffffff) {
83 printk(KERN_WARNING
"MARK: Only supports 32bit wide mark\n");
90 mark_tg_check_v1(const char *tablename
, const void *entry
,
91 const struct xt_target
*target
, void *targinfo
,
92 unsigned int hook_mask
)
94 const struct xt_mark_target_info_v1
*markinfo
= targinfo
;
96 if (markinfo
->mode
!= XT_MARK_SET
97 && markinfo
->mode
!= XT_MARK_AND
98 && markinfo
->mode
!= XT_MARK_OR
) {
99 printk(KERN_WARNING
"MARK: unknown mode %u\n",
103 if (markinfo
->mark
> 0xffffffff) {
104 printk(KERN_WARNING
"MARK: Only supports 32bit wide mark\n");
111 struct compat_xt_mark_target_info
{
115 static void mark_tg_compat_from_user_v0(void *dst
, void *src
)
117 const struct compat_xt_mark_target_info
*cm
= src
;
118 struct xt_mark_target_info m
= {
121 memcpy(dst
, &m
, sizeof(m
));
124 static int mark_tg_compat_to_user_v0(void __user
*dst
, void *src
)
126 const struct xt_mark_target_info
*m
= src
;
127 struct compat_xt_mark_target_info cm
= {
130 return copy_to_user(dst
, &cm
, sizeof(cm
)) ? -EFAULT
: 0;
133 struct compat_xt_mark_target_info_v1
{
140 static void mark_tg_compat_from_user_v1(void *dst
, void *src
)
142 const struct compat_xt_mark_target_info_v1
*cm
= src
;
143 struct xt_mark_target_info_v1 m
= {
147 memcpy(dst
, &m
, sizeof(m
));
150 static int mark_tg_compat_to_user_v1(void __user
*dst
, void *src
)
152 const struct xt_mark_target_info_v1
*m
= src
;
153 struct compat_xt_mark_target_info_v1 cm
= {
157 return copy_to_user(dst
, &cm
, sizeof(cm
)) ? -EFAULT
: 0;
159 #endif /* CONFIG_COMPAT */
161 static struct xt_target mark_tg_reg
[] __read_mostly
= {
166 .checkentry
= mark_tg_check_v0
,
167 .target
= mark_tg_v0
,
168 .targetsize
= sizeof(struct xt_mark_target_info
),
170 .compatsize
= sizeof(struct compat_xt_mark_target_info
),
171 .compat_from_user
= mark_tg_compat_from_user_v0
,
172 .compat_to_user
= mark_tg_compat_to_user_v0
,
181 .checkentry
= mark_tg_check_v1
,
182 .target
= mark_tg_v1
,
183 .targetsize
= sizeof(struct xt_mark_target_info_v1
),
185 .compatsize
= sizeof(struct compat_xt_mark_target_info_v1
),
186 .compat_from_user
= mark_tg_compat_from_user_v1
,
187 .compat_to_user
= mark_tg_compat_to_user_v1
,
196 .checkentry
= mark_tg_check_v0
,
197 .target
= mark_tg_v0
,
198 .targetsize
= sizeof(struct xt_mark_target_info
),
200 .compatsize
= sizeof(struct compat_xt_mark_target_info
),
201 .compat_from_user
= mark_tg_compat_from_user_v0
,
202 .compat_to_user
= mark_tg_compat_to_user_v0
,
211 .checkentry
= mark_tg_check_v1
,
212 .target
= mark_tg_v1
,
213 .targetsize
= sizeof(struct xt_mark_target_info_v1
),
215 .compatsize
= sizeof(struct compat_xt_mark_target_info_v1
),
216 .compat_from_user
= mark_tg_compat_from_user_v1
,
217 .compat_to_user
= mark_tg_compat_to_user_v1
,
227 .targetsize
= sizeof(struct xt_mark_tginfo2
),
235 .targetsize
= sizeof(struct xt_mark_tginfo2
),
240 static int __init
mark_tg_init(void)
242 return xt_register_targets(mark_tg_reg
, ARRAY_SIZE(mark_tg_reg
));
245 static void __exit
mark_tg_exit(void)
247 xt_unregister_targets(mark_tg_reg
, ARRAY_SIZE(mark_tg_reg
));
250 module_init(mark_tg_init
);
251 module_exit(mark_tg_exit
);