From 29b1d97764d1849651388d870565b3fa815a0bd8 Mon Sep 17 00:00:00 2001 From: Serhey Popovych Date: Thu, 1 Mar 2018 13:03:11 +0200 Subject: xtables: Introduce and use common function to parse val[/mask] arguments There are a couple of places in both core and extensions where arguments in the form of val[/mask] is parsed (see XTTYPE_MARKMASK32). In some cases symbolic name might be used which is mapped in code to numeric value. Introduce common function to handle both cases where value given is either val[/mask] or symbolic name. Signed-off-by: Serhey Popovych Signed-off-by: Florian Westphal --- libxtables/xtoptions.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) (limited to 'libxtables/xtoptions.c') diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c index d26d2f8b..ba3128bd 100644 --- a/libxtables/xtoptions.c +++ b/libxtables/xtoptions.c @@ -428,27 +428,7 @@ static void xtopt_parse_tosmask(struct xt_option_call *cb) */ static void xtopt_parse_markmask(struct xt_option_call *cb) { - unsigned int mark = 0, mask = ~0U; - char *end; - - if (!xtables_strtoui(cb->arg, &end, &mark, 0, UINT32_MAX)) - xt_params->exit_err(PARAMETER_PROBLEM, - "%s: bad mark value for option \"--%s\", " - "or out of range.\n", - cb->ext_name, cb->entry->name); - if (*end == '/' && - !xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX)) - xt_params->exit_err(PARAMETER_PROBLEM, - "%s: bad mask value for option \"--%s\", " - "or out of range.\n", - cb->ext_name, cb->entry->name); - if (*end != '\0') - xt_params->exit_err(PARAMETER_PROBLEM, - "%s: trailing garbage after value " - "for option \"--%s\".\n", - cb->ext_name, cb->entry->name); - cb->val.mark = mark; - cb->val.mask = mask; + xtables_parse_mark_mask(cb, &cb->val.mark, &cb->val.mask); } static int xtopt_sysloglvl_compare(const void *a, const void *b) -- cgit v1.2.3