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 --- extensions/libxt_devgroup.c | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'extensions/libxt_devgroup.c') diff --git a/extensions/libxt_devgroup.c b/extensions/libxt_devgroup.c index f1352c47..99a4d502 100644 --- a/extensions/libxt_devgroup.c +++ b/extensions/libxt_devgroup.c @@ -35,49 +35,24 @@ static const char f_devgroups[] = "/etc/iproute2/group"; /* array of devgroups from f_devgroups[] */ static struct xtables_lmap *devgroups; -static void devgroup_parse_groupspec(const char *arg, unsigned int *group, - unsigned int *mask) -{ - char *end; - bool ok; - - ok = xtables_strtoui(arg, &end, group, 0, UINT32_MAX); - if (ok && (*end == '/' || *end == '\0')) { - if (*end == '/') - ok = xtables_strtoui(end + 1, NULL, mask, - 0, UINT32_MAX); - else - *mask = ~0U; - if (!ok) - xtables_error(PARAMETER_PROBLEM, - "Bad group value \"%s\"", arg); - } else { - *group = xtables_lmap_name2id(devgroups, arg); - if (*group == -1) - xtables_error(PARAMETER_PROBLEM, - "Device group \"%s\" not found", arg); - *mask = ~0U; - } -} - static void devgroup_parse(struct xt_option_call *cb) { struct xt_devgroup_info *info = cb->data; - unsigned int id, mask; + unsigned int group, mask; xtables_option_parse(cb); + xtables_parse_val_mask(cb, &group, &mask, devgroups); + switch (cb->entry->id) { case O_SRC_GROUP: - devgroup_parse_groupspec(cb->arg, &id, &mask); - info->src_group = id; + info->src_group = group; info->src_mask = mask; info->flags |= XT_DEVGROUP_MATCH_SRC; if (cb->invert) info->flags |= XT_DEVGROUP_INVERT_SRC; break; case O_DST_GROUP: - devgroup_parse_groupspec(cb->arg, &id, &mask); - info->dst_group = id; + info->dst_group = group; info->dst_mask = mask; info->flags |= XT_DEVGROUP_MATCH_DST; if (cb->invert) -- cgit v1.2.3