Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* This is a module which is used for setting the NFMARK field of an skb. */ |
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 | #include <linux/ip.h> | |
13 | #include <net/checksum.h> | |
14 | ||
2e4e6a17 HW |
15 | #include <linux/netfilter/x_tables.h> |
16 | #include <linux/netfilter/xt_MARK.h> | |
1da177e4 LT |
17 | |
18 | MODULE_LICENSE("GPL"); | |
19 | MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); | |
2e4e6a17 HW |
20 | MODULE_DESCRIPTION("ip[6]tables MARK modification module"); |
21 | MODULE_ALIAS("ipt_MARK"); | |
22 | MODULE_ALIAS("ip6t_MARK"); | |
1da177e4 LT |
23 | |
24 | static unsigned int | |
25 | target_v0(struct sk_buff **pskb, | |
26 | const struct net_device *in, | |
27 | const struct net_device *out, | |
28 | unsigned int hooknum, | |
c4986734 | 29 | const struct xt_target *target, |
fe1cb108 | 30 | const void *targinfo) |
1da177e4 | 31 | { |
2e4e6a17 | 32 | const struct xt_mark_target_info *markinfo = targinfo; |
1da177e4 | 33 | |
6869c4d8 | 34 | if((*pskb)->nfmark != markinfo->mark) |
1da177e4 | 35 | (*pskb)->nfmark = markinfo->mark; |
6869c4d8 | 36 | |
2e4e6a17 | 37 | return XT_CONTINUE; |
1da177e4 LT |
38 | } |
39 | ||
40 | static unsigned int | |
41 | target_v1(struct sk_buff **pskb, | |
42 | const struct net_device *in, | |
43 | const struct net_device *out, | |
44 | unsigned int hooknum, | |
c4986734 | 45 | const struct xt_target *target, |
fe1cb108 | 46 | const void *targinfo) |
1da177e4 | 47 | { |
2e4e6a17 | 48 | const struct xt_mark_target_info_v1 *markinfo = targinfo; |
1da177e4 LT |
49 | int mark = 0; |
50 | ||
51 | switch (markinfo->mode) { | |
2e4e6a17 | 52 | case XT_MARK_SET: |
1da177e4 LT |
53 | mark = markinfo->mark; |
54 | break; | |
55 | ||
2e4e6a17 | 56 | case XT_MARK_AND: |
1da177e4 LT |
57 | mark = (*pskb)->nfmark & markinfo->mark; |
58 | break; | |
59 | ||
2e4e6a17 | 60 | case XT_MARK_OR: |
1da177e4 LT |
61 | mark = (*pskb)->nfmark | markinfo->mark; |
62 | break; | |
63 | } | |
64 | ||
6869c4d8 | 65 | if((*pskb)->nfmark != mark) |
1da177e4 | 66 | (*pskb)->nfmark = mark; |
6869c4d8 | 67 | |
2e4e6a17 | 68 | return XT_CONTINUE; |
1da177e4 LT |
69 | } |
70 | ||
71 | ||
72 | static int | |
73 | checkentry_v0(const char *tablename, | |
2e4e6a17 | 74 | const void *entry, |
c4986734 | 75 | const struct xt_target *target, |
1da177e4 LT |
76 | void *targinfo, |
77 | unsigned int targinfosize, | |
78 | unsigned int hook_mask) | |
79 | { | |
2e4e6a17 | 80 | struct xt_mark_target_info *markinfo = targinfo; |
bf3a46aa | 81 | |
bf3a46aa HW |
82 | if (markinfo->mark > 0xffffffff) { |
83 | printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n"); | |
84 | return 0; | |
85 | } | |
1da177e4 LT |
86 | return 1; |
87 | } | |
88 | ||
89 | static int | |
90 | checkentry_v1(const char *tablename, | |
2e4e6a17 | 91 | const void *entry, |
c4986734 | 92 | const struct xt_target *target, |
1da177e4 LT |
93 | void *targinfo, |
94 | unsigned int targinfosize, | |
95 | unsigned int hook_mask) | |
96 | { | |
2e4e6a17 | 97 | struct xt_mark_target_info_v1 *markinfo = targinfo; |
1da177e4 | 98 | |
2e4e6a17 HW |
99 | if (markinfo->mode != XT_MARK_SET |
100 | && markinfo->mode != XT_MARK_AND | |
101 | && markinfo->mode != XT_MARK_OR) { | |
1da177e4 LT |
102 | printk(KERN_WARNING "MARK: unknown mode %u\n", |
103 | markinfo->mode); | |
104 | return 0; | |
105 | } | |
bf3a46aa HW |
106 | if (markinfo->mark > 0xffffffff) { |
107 | printk(KERN_WARNING "MARK: Only supports 32bit wide mark\n"); | |
108 | return 0; | |
109 | } | |
1da177e4 LT |
110 | return 1; |
111 | } | |
112 | ||
4470bbc7 PM |
113 | static struct xt_target xt_mark_target[] = { |
114 | { | |
115 | .name = "MARK", | |
116 | .family = AF_INET, | |
117 | .revision = 0, | |
118 | .checkentry = checkentry_v0, | |
119 | .target = target_v0, | |
120 | .targetsize = sizeof(struct xt_mark_target_info), | |
121 | .table = "mangle", | |
122 | .me = THIS_MODULE, | |
123 | }, | |
124 | { | |
125 | .name = "MARK", | |
126 | .family = AF_INET, | |
127 | .revision = 1, | |
128 | .checkentry = checkentry_v1, | |
129 | .target = target_v1, | |
130 | .targetsize = sizeof(struct xt_mark_target_info_v1), | |
131 | .table = "mangle", | |
132 | .me = THIS_MODULE, | |
133 | }, | |
134 | { | |
135 | .name = "MARK", | |
136 | .family = AF_INET6, | |
137 | .revision = 0, | |
138 | .checkentry = checkentry_v0, | |
139 | .target = target_v0, | |
140 | .targetsize = sizeof(struct xt_mark_target_info), | |
141 | .table = "mangle", | |
142 | .me = THIS_MODULE, | |
143 | }, | |
2e4e6a17 HW |
144 | }; |
145 | ||
65b4b4e8 | 146 | static int __init xt_mark_init(void) |
1da177e4 | 147 | { |
4470bbc7 | 148 | return xt_register_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target)); |
1da177e4 LT |
149 | } |
150 | ||
65b4b4e8 | 151 | static void __exit xt_mark_fini(void) |
1da177e4 | 152 | { |
4470bbc7 | 153 | xt_unregister_targets(xt_mark_target, ARRAY_SIZE(xt_mark_target)); |
1da177e4 LT |
154 | } |
155 | ||
65b4b4e8 AM |
156 | module_init(xt_mark_init); |
157 | module_exit(xt_mark_fini); |