diff options
Diffstat (limited to 'libxtables')
-rw-r--r-- | libxtables/xtables.c | 52 | ||||
-rw-r--r-- | libxtables/xtoptions.c | 22 |
2 files changed, 53 insertions, 21 deletions
diff --git a/libxtables/xtables.c b/libxtables/xtables.c index 57a11022..f93e88dd 100644 --- a/libxtables/xtables.c +++ b/libxtables/xtables.c @@ -1960,6 +1960,58 @@ void xtables_print_num(uint64_t number, unsigned int format) printf(FMT("%4lluT ","%lluT "), (unsigned long long)number); } +void xtables_parse_val_mask(struct xt_option_call *cb, + unsigned int *val, unsigned int *mask, + const struct xtables_lmap *lmap) +{ + char *end; + + *mask = ~0U; + + if (!xtables_strtoui(cb->arg, &end, val, 0, UINT32_MAX)) { + if (lmap) + goto name2val; + else + goto bad_val; + } + + if (*end == '\0') + return; + + if (*end != '/') { + if (lmap) + goto name2val; + else + goto garbage; + } + + if (!xtables_strtoui(end + 1, &end, mask, 0, UINT32_MAX)) + goto bad_val; + + if (*end == '\0') + return; + +garbage: + xt_params->exit_err(PARAMETER_PROBLEM, + "%s: trailing garbage after value " + "for option \"--%s\".\n", + cb->ext_name, cb->entry->name); + +bad_val: + xt_params->exit_err(PARAMETER_PROBLEM, + "%s: bad integer value for option \"--%s\", " + "or out of range.\n", + cb->ext_name, cb->entry->name); + +name2val: + *val = xtables_lmap_name2id(lmap, cb->arg); + if ((int)*val == -1) + xt_params->exit_err(PARAMETER_PROBLEM, + "%s: could not map name %s to an integer value " + "for option \"--%s\".\n", + cb->ext_name, cb->arg, cb->entry->name); +} + int kernel_version; void get_kernel_version(void) 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) |