1
/* Shared library add-on to iptables to add MARK target support. */
8
#include <linux/netfilter/x_tables.h>
9
#include <linux/netfilter/xt_MARK.h>
11
/* Function which prints out usage message. */
12
static void MARK_help(void)
15
"MARK target v%s options:\n"
16
" --set-mark value Set nfmark value\n"
17
" --and-mark value Binary AND the nfmark with value\n"
18
" --or-mark value Binary OR the nfmark with value\n"
23
static const struct option MARK_opts[] = {
24
{ "set-mark", 1, NULL, '1' },
25
{ "and-mark", 1, NULL, '2' },
26
{ "or-mark", 1, NULL, '3' },
30
/* Function which parses command options; returns true if it
33
MARK_parse_v0(int c, char **argv, int invert, unsigned int *flags,
34
const void *entry, struct xt_entry_target **target)
36
struct xt_mark_target_info *markinfo
37
= (struct xt_mark_target_info *)(*target)->data;
41
if (string_to_number_l(optarg, 0, 0,
43
exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
45
exit_error(PARAMETER_PROBLEM,
46
"MARK target: Can't specify --set-mark twice");
50
exit_error(PARAMETER_PROBLEM,
51
"MARK target: kernel too old for --and-mark");
53
exit_error(PARAMETER_PROBLEM,
54
"MARK target: kernel too old for --or-mark");
62
static void MARK_check(unsigned int flags)
65
exit_error(PARAMETER_PROBLEM,
66
"MARK target: Parameter --set/and/or-mark"
70
/* Function which parses command options; returns true if it
73
MARK_parse_v1(int c, char **argv, int invert, unsigned int *flags,
74
const void *entry, struct xt_entry_target **target)
76
struct xt_mark_target_info_v1 *markinfo
77
= (struct xt_mark_target_info_v1 *)(*target)->data;
81
markinfo->mode = XT_MARK_SET;
84
markinfo->mode = XT_MARK_AND;
87
markinfo->mode = XT_MARK_OR;
93
if (string_to_number_l(optarg, 0, 0, &markinfo->mark))
94
exit_error(PARAMETER_PROBLEM, "Bad MARK value `%s'", optarg);
97
exit_error(PARAMETER_PROBLEM,
98
"MARK target: Can't specify --set-mark twice");
105
print_mark(unsigned long mark)
107
printf("0x%lx ", mark);
110
/* Prints out the targinfo. */
111
static void MARK_print_v0(const void *ip,
112
const struct xt_entry_target *target, int numeric)
114
const struct xt_mark_target_info *markinfo =
115
(const struct xt_mark_target_info *)target->data;
117
print_mark(markinfo->mark);
120
/* Saves the union ipt_targinfo in parsable form to stdout. */
121
static void MARK_save_v0(const void *ip, const struct xt_entry_target *target)
123
const struct xt_mark_target_info *markinfo =
124
(const struct xt_mark_target_info *)target->data;
126
printf("--set-mark ");
127
print_mark(markinfo->mark);
130
/* Prints out the targinfo. */
131
static void MARK_print_v1(const void *ip, const struct xt_entry_target *target,
134
const struct xt_mark_target_info_v1 *markinfo =
135
(const struct xt_mark_target_info_v1 *)target->data;
137
switch (markinfo->mode) {
148
print_mark(markinfo->mark);
151
/* Saves the union ipt_targinfo in parsable form to stdout. */
152
static void MARK_save_v1(const void *ip, const struct xt_entry_target *target)
154
const struct xt_mark_target_info_v1 *markinfo =
155
(const struct xt_mark_target_info_v1 *)target->data;
157
switch (markinfo->mode) {
159
printf("--set-mark ");
162
printf("--and-mark ");
165
printf("--or-mark ");
168
print_mark(markinfo->mark);
171
static struct xtables_target mark_target_v0 = {
174
.version = IPTABLES_VERSION,
176
.size = XT_ALIGN(sizeof(struct xt_mark_target_info)),
177
.userspacesize = XT_ALIGN(sizeof(struct xt_mark_target_info)),
179
.parse = MARK_parse_v0,
180
.final_check = MARK_check,
181
.print = MARK_print_v0,
182
.save = MARK_save_v0,
183
.extra_opts = MARK_opts,
186
static struct xtables_target mark_target_v1 = {
189
.version = IPTABLES_VERSION,
191
.size = XT_ALIGN(sizeof(struct xt_mark_target_info_v1)),
192
.userspacesize = XT_ALIGN(sizeof(struct xt_mark_target_info_v1)),
194
.parse = MARK_parse_v1,
195
.final_check = MARK_check,
196
.print = MARK_print_v1,
197
.save = MARK_save_v1,
198
.extra_opts = MARK_opts,
201
static struct xtables_target mark_target6_v0 = {
204
.version = IPTABLES_VERSION,
206
.size = XT_ALIGN(sizeof(struct xt_mark_target_info)),
207
.userspacesize = XT_ALIGN(sizeof(struct xt_mark_target_info)),
209
.parse = MARK_parse_v0,
210
.final_check = MARK_check,
211
.print = MARK_print_v0,
212
.save = MARK_save_v0,
213
.extra_opts = MARK_opts,
218
xtables_register_target(&mark_target_v0);
219
xtables_register_target(&mark_target_v1);
220
xtables_register_target(&mark_target6_v0);