It expects mark values in hex which is possible by setting the base field. The only adjustment needed to use the revision 2 parser is to fill the mask for --set-mark: With XTTYPE_MARKMASK32, an omitted mask sets all mask bits, XTTYPE_UINT32 leaves it uninitialized, though. Signed-off-by: Phil Sutter <phil@xxxxxx> --- extensions/libxt_MARK.c | 82 ++++++++--------------------------------- 1 file changed, 15 insertions(+), 67 deletions(-) diff --git a/extensions/libxt_MARK.c b/extensions/libxt_MARK.c index d6eacfcb33f69..703d894f233d9 100644 --- a/extensions/libxt_MARK.c +++ b/extensions/libxt_MARK.c @@ -1,4 +1,3 @@ -#include <getopt.h> #include <stdbool.h> #include <stdio.h> #include <xtables.h> @@ -69,6 +68,16 @@ static const struct xt_option_entry mark_tg_opts[] = { XTOPT_TABLEEND, }; +static const struct xt_option_entry mark_tg_arp_opts[] = { + {.name = "set-mark", .id = O_SET_MARK, .type = XTTYPE_UINT32, + .base = 16, .excl = F_ANY}, + {.name = "and-mark", .id = O_AND_MARK, .type = XTTYPE_UINT32, + .base = 16, .excl = F_ANY}, + {.name = "or-mark", .id = O_OR_MARK, .type = XTTYPE_UINT32, + .base = 16, .excl = F_ANY}, + XTOPT_TABLEEND, +}; + static void mark_tg_help(void) { printf( @@ -136,6 +145,8 @@ static void mark_tg_parse(struct xt_option_call *cb) case O_SET_MARK: info->mark = cb->val.mark; info->mask = cb->val.mark | cb->val.mask; + if (cb->entry->type == XTTYPE_UINT32) + info->mask = UINT32_MAX; break; case O_AND_MARK: info->mark = 0; @@ -263,70 +274,6 @@ static void mark_tg_arp_print(const void *ip, mark_tg_arp_save(ip, target); } -#define MARK_OPT 1 -#define AND_MARK_OPT 2 -#define OR_MARK_OPT 3 - -static struct option mark_tg_arp_opts[] = { - { .name = "set-mark", .has_arg = required_argument, .flag = 0, .val = MARK_OPT }, - { .name = "and-mark", .has_arg = required_argument, .flag = 0, .val = AND_MARK_OPT }, - { .name = "or-mark", .has_arg = required_argument, .flag = 0, .val = OR_MARK_OPT }, - { .name = NULL} -}; - -static int -mark_tg_arp_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_target **target) -{ - struct xt_mark_tginfo2 *info = - (struct xt_mark_tginfo2 *)(*target)->data; - int i; - - switch (c) { - case MARK_OPT: - if (sscanf(argv[optind-1], "%x", &i) != 1) { - xtables_error(PARAMETER_PROBLEM, - "Bad mark value `%s'", optarg); - return 0; - } - info->mark = i; - info->mask = 0xffffffffU; - if (*flags) - xtables_error(PARAMETER_PROBLEM, - "MARK: Can't specify --set-mark twice"); - *flags = 1; - break; - case AND_MARK_OPT: - if (sscanf(argv[optind-1], "%x", &i) != 1) { - xtables_error(PARAMETER_PROBLEM, - "Bad mark value `%s'", optarg); - return 0; - } - info->mark = 0; - info->mask = ~i; - if (*flags) - xtables_error(PARAMETER_PROBLEM, - "MARK: Can't specify --and-mark twice"); - *flags = 1; - break; - case OR_MARK_OPT: - if (sscanf(argv[optind-1], "%x", &i) != 1) { - xtables_error(PARAMETER_PROBLEM, - "Bad mark value `%s'", optarg); - return 0; - } - info->mark = info->mask = i; - if (*flags) - xtables_error(PARAMETER_PROBLEM, - "MARK: Can't specify --or-mark twice"); - *flags = 1; - break; - default: - return 0; - } - return 1; -} - static int mark_tg_xlate(struct xt_xlate *xl, const struct xt_xlate_tg_params *params) { @@ -429,8 +376,9 @@ static struct xtables_target mark_tg_reg[] = { .help = mark_tg_help, .print = mark_tg_arp_print, .save = mark_tg_arp_save, - .parse = mark_tg_arp_parse, - .extra_opts = mark_tg_arp_opts, + .x6_parse = mark_tg_parse, + .x6_fcheck = mark_tg_check, + .x6_options = mark_tg_arp_opts, .xlate = mark_tg_xlate, }, }; -- 2.41.0