1 /* This is a module which is used for setting the NFMARK field of an skb. */
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 <net/checksum.h>
15 #include <linux/netfilter/x_tables.h>
16 #include <linux/netfilter/xt_MARK.h>
18 MODULE_LICENSE("GPL");
19 MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
20 MODULE_DESCRIPTION("ip[6]tables MARK modification module");
21 MODULE_ALIAS("ipt_MARK");
22 MODULE_ALIAS("ip6t_MARK");
25 target_v0(struct sk_buff
**pskb
,
26 const struct net_device
*in
,
27 const struct net_device
*out
,
29 const struct xt_target
*target
,
32 const struct xt_mark_target_info
*markinfo
= targinfo
;
34 if((*pskb
)->nfmark
!= markinfo
->mark
)
35 (*pskb
)->nfmark
= markinfo
->mark
;
41 target_v1(struct sk_buff
**pskb
,
42 const struct net_device
*in
,
43 const struct net_device
*out
,
45 const struct xt_target
*target
,
48 const struct xt_mark_target_info_v1
*markinfo
= targinfo
;
51 switch (markinfo
->mode
) {
53 mark
= markinfo
->mark
;
57 mark
= (*pskb
)->nfmark
& markinfo
->mark
;
61 mark
= (*pskb
)->nfmark
| markinfo
->mark
;
65 if((*pskb
)->nfmark
!= mark
)
66 (*pskb
)->nfmark
= mark
;
73 checkentry_v0(const char *tablename
,
75 const struct xt_target
*target
,
77 unsigned int targinfosize
,
78 unsigned int hook_mask
)
80 struct xt_mark_target_info
*markinfo
= targinfo
;
82 if (markinfo
->mark
> 0xffffffff) {
83 printk(KERN_WARNING
"MARK: Only supports 32bit wide mark\n");
90 checkentry_v1(const char *tablename
,
92 const struct xt_target
*target
,
94 unsigned int targinfosize
,
95 unsigned int hook_mask
)
97 struct xt_mark_target_info_v1
*markinfo
= targinfo
;
99 if (markinfo
->mode
!= XT_MARK_SET
100 && markinfo
->mode
!= XT_MARK_AND
101 && markinfo
->mode
!= XT_MARK_OR
) {
102 printk(KERN_WARNING
"MARK: unknown mode %u\n",
106 if (markinfo
->mark
> 0xffffffff) {
107 printk(KERN_WARNING
"MARK: Only supports 32bit wide mark\n");
113 static struct xt_target xt_mark_target
[] = {
118 .checkentry
= checkentry_v0
,
120 .targetsize
= sizeof(struct xt_mark_target_info
),
128 .checkentry
= checkentry_v1
,
130 .targetsize
= sizeof(struct xt_mark_target_info_v1
),
138 .checkentry
= checkentry_v0
,
140 .targetsize
= sizeof(struct xt_mark_target_info
),
146 static int __init
xt_mark_init(void)
148 return xt_register_targets(xt_mark_target
, ARRAY_SIZE(xt_mark_target
));
151 static void __exit
xt_mark_fini(void)
153 xt_unregister_targets(xt_mark_target
, ARRAY_SIZE(xt_mark_target
));
156 module_init(xt_mark_init
);
157 module_exit(xt_mark_fini
);