diff options
author | Serhey Popovych <serhe.popovych@gmail.com> | 2018-03-01 13:03:11 +0200 |
---|---|---|
committer | Florian Westphal <fw@strlen.de> | 2018-04-27 18:56:20 +0200 |
commit | 29b1d97764d1849651388d870565b3fa815a0bd8 (patch) | |
tree | 1e9c5e71eaf91ca360949b020602390280df90d9 /extensions/libipt_realm.c | |
parent | 56aadc01b258ef7849463723ab5ddc4885db22f6 (diff) |
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 <serhe.popovych@gmail.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
Diffstat (limited to 'extensions/libipt_realm.c')
-rw-r--r-- | extensions/libipt_realm.c | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/extensions/libipt_realm.c b/extensions/libipt_realm.c index 75009105..545b2580 100644 --- a/extensions/libipt_realm.c +++ b/extensions/libipt_realm.c @@ -34,30 +34,17 @@ static struct xtables_lmap *realms; static void realm_parse(struct xt_option_call *cb) { - struct xt_realm_info *realminfo = cb->data; - int id; - char *end; + struct xt_realm_info *ri = cb->data; + unsigned int id, mask; xtables_option_parse(cb); - realminfo->id = strtoul(cb->arg, &end, 0); - if (end != cb->arg && (*end == '/' || *end == '\0')) { - if (*end == '/') - realminfo->mask = strtoul(end+1, &end, 0); - else - realminfo->mask = 0xffffffff; - if (*end != '\0' || end == cb->arg) - xtables_error(PARAMETER_PROBLEM, - "Bad realm value \"%s\"", cb->arg); - } else { - id = xtables_lmap_name2id(realms, cb->arg); - if (id == -1) - xtables_error(PARAMETER_PROBLEM, - "Realm \"%s\" not found", cb->arg); - realminfo->id = id; - realminfo->mask = 0xffffffff; - } + xtables_parse_val_mask(cb, &id, &mask, realms); + + ri->id = id; + ri->mask = mask; + if (cb->invert) - realminfo->invert = 1; + ri->invert = 1; } static void |