8
9
#include <linux/netfilter/x_tables.h>
9
10
#include <linux/netfilter/xt_MARK.h>
11
16
/* Function which prints out usage message. */
12
17
static void MARK_help(void)
15
"MARK target v%s options:\n"
20
"MARK target options:\n"
16
21
" --set-mark value Set nfmark value\n"
17
22
" --and-mark value Binary AND the nfmark with value\n"
18
" --or-mark value Binary OR the nfmark with value\n"
23
" --or-mark value Binary OR the nfmark with value\n");
23
26
static const struct option MARK_opts[] = {
24
27
{ "set-mark", 1, NULL, '1' },
25
28
{ "and-mark", 1, NULL, '2' },
26
29
{ "or-mark", 1, NULL, '3' },
33
static const struct option mark_tg_opts[] = {
34
{.name = "set-xmark", .has_arg = true, .val = 'X'},
35
{.name = "set-mark", .has_arg = true, .val = '='},
36
{.name = "and-mark", .has_arg = true, .val = '&'},
37
{.name = "or-mark", .has_arg = true, .val = '|'},
38
{.name = "xor-mark", .has_arg = true, .val = '^'},
42
static void mark_tg_help(void)
45
"MARK target options:\n"
46
" --set-xmark value[/mask] Clear bits in mask and XOR value into nfmark\n"
47
" --set-mark value[/mask] Clear bits in mask and OR value into nfmark\n"
48
" --and-mark bits Binary AND the nfmark with bits\n"
49
" --or-mark bits Binary OR the nfmark with bits\n"
50
" --xor-mask bits Binary XOR the nfmark with bits\n"
30
54
/* Function which parses command options; returns true if it
128
static int mark_tg_parse(int c, char **argv, int invert, unsigned int *flags,
129
const void *entry, struct xt_entry_target **target)
131
struct xt_mark_tginfo2 *info = (void *)(*target)->data;
132
unsigned int value, mask = ~0U;
136
case 'X': /* --set-xmark */
137
case '=': /* --set-mark */
138
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
139
param_act(P_NO_INVERT, "MARK", "--set-xmark/--set-mark", invert);
140
if (!strtonum(optarg, &end, &value, 0, ~0U))
141
param_act(P_BAD_VALUE, "MARK", "--set-xmark/--set-mark", optarg);
143
if (!strtonum(end + 1, &end, &mask, 0, ~0U))
144
param_act(P_BAD_VALUE, "MARK", "--set-xmark/--set-mark", optarg);
146
param_act(P_BAD_VALUE, "MARK", "--set-xmark/--set-mark", optarg);
151
info->mask = value | mask;
154
case '&': /* --and-mark */
155
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
156
param_act(P_NO_INVERT, "MARK", "--and-mark", invert);
157
if (!strtonum(optarg, NULL, &mask, 0, ~0U))
158
param_act(P_BAD_VALUE, "MARK", "--and-mark", optarg);
163
case '|': /* --or-mark */
164
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
165
param_act(P_NO_INVERT, "MARK", "--or-mark", invert);
166
if (!strtonum(optarg, NULL, &value, 0, ~0U))
167
param_act(P_BAD_VALUE, "MARK", "--or-mark", optarg);
172
case '^': /* --xor-mark */
173
param_act(P_ONE_ACTION, "MARK", *flags & F_MARK);
174
param_act(P_NO_INVERT, "MARK", "--xor-mark", invert);
175
if (!strtonum(optarg, NULL, &value, 0, ~0U))
176
param_act(P_BAD_VALUE, "MARK", "--xor-mark", optarg);
189
static void mark_tg_check(unsigned int flags)
192
exit_error(PARAMETER_PROBLEM, "MARK: One of the --set-xmark, "
193
"--{and,or,xor,set}-mark options is required");
105
197
print_mark(unsigned long mark)
148
240
print_mark(markinfo->mark);
243
static void mark_tg_print(const void *ip, const struct xt_entry_target *target,
246
const struct xt_mark_tginfo2 *info = (const void *)target->data;
249
printf("MARK and 0x%x ", (unsigned int)(u_int32_t)~info->mask);
250
else if (info->mark == info->mask)
251
printf("MARK or 0x%x ", info->mark);
252
else if (info->mask == 0)
253
printf("MARK xor 0x%x ", info->mark);
255
printf("MARK xset 0x%x/0x%x ", info->mark, info->mask);
151
258
/* Saves the union ipt_targinfo in parsable form to stdout. */
152
259
static void MARK_save_v1(const void *ip, const struct xt_entry_target *target)
168
275
print_mark(markinfo->mark);
278
static void mark_tg_save(const void *ip, const struct xt_entry_target *target)
280
const struct xt_mark_tginfo2 *info = (const void *)target->data;
282
printf("--set-xmark 0x%x/0x%x ", info->mark, info->mask);
171
285
static struct xtables_target mark_target_v0 = {
172
286
.family = AF_INET,
174
.version = IPTABLES_VERSION,
288
.version = XTABLES_VERSION,
176
290
.size = XT_ALIGN(sizeof(struct xt_mark_target_info)),
177
291
.userspacesize = XT_ALIGN(sizeof(struct xt_mark_target_info)),
213
327
.extra_opts = MARK_opts,
330
static struct xtables_target mark_tg_reg_v2 = {
331
.version = XTABLES_VERSION,
335
.size = XT_ALIGN(sizeof(struct xt_mark_tginfo2)),
336
.userspacesize = XT_ALIGN(sizeof(struct xt_mark_tginfo2)),
337
.help = mark_tg_help,
338
.parse = mark_tg_parse,
339
.final_check = mark_tg_check,
340
.print = mark_tg_print,
341
.save = mark_tg_save,
342
.extra_opts = mark_tg_opts,
218
347
xtables_register_target(&mark_target_v0);
219
348
xtables_register_target(&mark_target_v1);
220
349
xtables_register_target(&mark_target6_v0);
350
xtables_register_target(&mark_tg_reg_v2);