summaryrefslogtreecommitdiffstats
path: root/xtoptions.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-05-24 23:50:29 +0200
committerJan Engelhardt <jengelh@medozas.de>2011-05-25 00:38:50 +0200
commit6944f2c8190f1c4319aeac748470c71b0ba45025 (patch)
treebadf3e40fe0b47be98d0f24ef078cc7e6831da0d /xtoptions.c
parent1b6c7632e5e35ecce91f87a4ae36eca3103cfee2 (diff)
libxtables: have xtopt_parse_mint interpret partially-spec'd ranges
When ":n" or "n:" is specified, it will now be interpreted as "0:n" and "n:<max>", respecitvely. nvals will always reflect the number of (expanded) components. This restores the functionality of options that take such partially-unspecified ranges. This makes it possible to nuke the per-matchdata init functions of some extensions and simply the extensions postparsing to the point where it only needs to check for nvals==1 or ==2. Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'xtoptions.c')
-rw-r--r--xtoptions.c32
1 files changed, 19 insertions, 13 deletions
diff --git a/xtoptions.c b/xtoptions.c
index 30d70b0c..ac0601f2 100644
--- a/xtoptions.c
+++ b/xtoptions.c
@@ -284,7 +284,7 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
const struct xt_option_entry *entry = cb->entry;
const char *arg = cb->arg;
size_t esize = xtopt_esize_by_type(entry->type);
- uintmax_t lmax = xtopt_max_by_type(entry->type);
+ const uintmax_t lmax = xtopt_max_by_type(entry->type);
void *put = XTOPT_MKPTR(cb);
unsigned int maxiter;
uintmax_t value;
@@ -293,27 +293,33 @@ static void xtopt_parse_mint(struct xt_option_call *cb)
maxiter = entry->size / esize;
if (maxiter == 0)
- maxiter = 2; /* ARRAY_SIZE(cb->val.uXX_range) */
+ maxiter = ARRAY_SIZE(cb->val.u32_range);
if (entry->size % esize != 0)
xt_params->exit_err(OTHER_PROBLEM, "%s: memory block does "
"not have proper size\n", __func__);
cb->nvals = 0;
- for (arg = cb->arg; ; arg = end + 1) {
+ for (arg = cb->arg, end = (char *)arg; ; arg = end + 1) {
if (cb->nvals == maxiter)
xt_params->exit_err(PARAMETER_PROBLEM, "%s: Too many "
"components for option \"--%s\" (max: %u)\n",
cb->ext_name, entry->name, maxiter);
- if (!xtables_strtoul(arg, &end, &value, 0, lmax))
- xt_params->exit_err(PARAMETER_PROBLEM,
- "%s: bad value for option \"--%s\" near "
- "\"%s\", or out of range (0-%ju).\n",
- cb->ext_name, entry->name, arg, lmax);
- if (*end != '\0' && *end != sep)
- xt_params->exit_err(PARAMETER_PROBLEM,
- "%s: Argument to \"--%s\" has unexpected "
- "characters near \"%s\".\n",
- cb->ext_name, entry->name, end);
+ if (*arg == '\0' || *arg == sep) {
+ /* Default range components when field not spec'd. */
+ end = (char *)arg;
+ value = (cb->nvals == 1) ? lmax : 0;
+ } else {
+ if (!xtables_strtoul(arg, &end, &value, 0, lmax))
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "%s: bad value for option \"--%s\" near "
+ "\"%s\", or out of range (0-%ju).\n",
+ cb->ext_name, entry->name, arg, lmax);
+ if (*end != '\0' && *end != sep)
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "%s: Argument to \"--%s\" has "
+ "unexpected characters near \"%s\".\n",
+ cb->ext_name, entry->name, end);
+ }
xtopt_mint_value_to_cb(cb, value);
++cb->nvals;
xtopt_mint_value_to_ptr(cb, &put, value);