From a93142d5f55db74ebd7d49be9bd88f7a499ded40 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 16 Feb 2011 01:22:25 +0100 Subject: libxtables: XTTYPE_UINT32 support Signed-off-by: Jan Engelhardt --- include/xtables.h.in | 4 +++- xtoptions.c | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/include/xtables.h.in b/include/xtables.h.in index c281fed7..91a6eaaa 100644 --- a/include/xtables.h.in +++ b/include/xtables.h.in @@ -47,9 +47,11 @@ struct in_addr; /** * %XTTYPE_NONE: option takes no argument + * %XTTYPE_UINT*: standard integer */ enum xt_option_type { XTTYPE_NONE, + XTTYPE_UINT32, }; /** @@ -99,7 +101,7 @@ struct xt_option_call { unsigned int xflags; bool invert; union { - /* to be filled */ + uint32_t u32; } val; }; diff --git a/xtoptions.c b/xtoptions.c index df917b67..843395be 100644 --- a/xtoptions.c +++ b/xtoptions.c @@ -80,12 +80,34 @@ xtables_options_xfrm(struct option *orig_opts, struct option *oldopts, return merge; } +/** + * Require a simple integer. + */ +static void xtopt_parse_int(struct xt_option_call *cb) +{ + const struct xt_option_entry *entry = cb->entry; + unsigned int lmin = 0, lmax = UINT32_MAX; + unsigned int value; + + if (!xtables_strtoui(cb->arg, NULL, &value, lmin, lmax)) + xt_params->exit_err(PARAMETER_PROBLEM, + "%s: bad value for option \"--%s\", " + "or out of range (%u-%u).\n", + cb->ext_name, entry->name, lmin, lmax); + + if (entry->type == XTTYPE_UINT32) { + cb->val.u32 = value; + if (entry->flags & XTOPT_PUT) + *(uint32_t *)XTOPT_MKPTR(cb) = cb->val.u32; + } +} + static void (*const xtopt_subparse[])(struct xt_option_call *) = { - [XTTYPE_NONE] = NULL, + [XTTYPE_UINT32] = xtopt_parse_int, }; static const size_t xtopt_psize[] = { - [XTTYPE_NONE] = 0, + [XTTYPE_UINT32] = sizeof(uint32_t), }; /** -- cgit v1.2.3