From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 04/28] libxtables: XTTYPE_UINT32RC support
Date: Tue, 12 Apr 2011 16:23:19 +0200 [thread overview]
Message-ID: <1302618224-9449-5-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1302618224-9449-1-git-send-email-jengelh@medozas.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
include/xtables.h.in | 6 ++++-
xtoptions.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/include/xtables.h.in b/include/xtables.h.in
index dc074bc..3e596e0 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -48,11 +48,13 @@ struct in_addr;
/**
* %XTTYPE_NONE: option takes no argument
* %XTTYPE_UINT*: standard integer
+ * %XTTYPE_UINT*RC: colon-separated range of standard integers
*/
enum xt_option_type {
XTTYPE_NONE,
XTTYPE_UINT8,
XTTYPE_UINT32,
+ XTTYPE_UINT32RC,
};
/**
@@ -96,6 +98,7 @@ struct xt_option_entry {
* @data: per-extension data block
* @xflags: options of the extension that have been used
* @invert: whether option was used with !
+ * @nvals: number of results in uXX_multi
* @val: parsed result
*/
struct xt_option_call {
@@ -104,9 +107,10 @@ struct xt_option_call {
void *data;
unsigned int xflags;
bool invert;
+ uint8_t nvals;
union {
uint8_t u8;
- uint32_t u32;
+ uint32_t u32, u32_range[2];
} val;
};
diff --git a/xtoptions.c b/xtoptions.c
index 693c06d..03c629e 100644
--- a/xtoptions.c
+++ b/xtoptions.c
@@ -113,14 +113,66 @@ static void xtopt_parse_int(struct xt_option_call *cb)
}
}
+/**
+ * Multiple integer parse routine.
+ *
+ * This function is capable of parsing any number of fields. Only the first
+ * two values from the string will be put into @cb however (and as such,
+ * @cb->val.uXX_range is just that large) to cater for the few extensions that
+ * do not have a range[2] field, but {min, max}, and which cannot use
+ * XTOPT_POINTER.
+ */
+static void xtopt_parse_mint(struct xt_option_call *cb)
+{
+ const struct xt_option_entry *entry = cb->entry;
+ const char *arg = cb->arg;
+ uint32_t *put = XTOPT_MKPTR(cb);
+ unsigned int maxiter, value;
+ char *end = "";
+ char sep = ':';
+
+ maxiter = entry->size / sizeof(uint32_t);
+ if (maxiter == 0)
+ maxiter = 2; /* ARRAY_SIZE(cb->val.uXX_range) */
+ if (entry->size % sizeof(uint32_t) != 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) {
+ 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_strtoui(arg, &end, &value, 0, UINT32_MAX))
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "%s: bad value for option \"--%s\", "
+ "or out of range (0-%u).\n",
+ cb->ext_name, entry->name, UINT32_MAX);
+ if (*end != '\0' && *end != sep)
+ xt_params->exit_err(PARAMETER_PROBLEM,
+ "%s: Argument to \"--%s\" has unexpected "
+ "characters.\n", cb->ext_name, entry->name);
+ ++cb->nvals;
+ if (cb->nvals < ARRAY_SIZE(cb->val.u32_range))
+ cb->val.u32_range[cb->nvals] = value;
+ if (entry->flags & XTOPT_PUT)
+ *put++ = value;
+ if (*end == '\0')
+ break;
+ }
+}
+
static void (*const xtopt_subparse[])(struct xt_option_call *) = {
[XTTYPE_UINT8] = xtopt_parse_int,
[XTTYPE_UINT32] = xtopt_parse_int,
+ [XTTYPE_UINT32RC] = xtopt_parse_mint,
};
static const size_t xtopt_psize[] = {
[XTTYPE_UINT8] = sizeof(uint8_t),
[XTTYPE_UINT32] = sizeof(uint32_t),
+ [XTTYPE_UINT32RC] = sizeof(uint32_t[2]),
};
/**
@@ -180,7 +232,8 @@ void xtables_option_metavalidate(const char *name,
"%s: entry type of option \"--%s\" cannot be "
"combined with XTOPT_PUT\n",
name, entry->name);
- if (xtopt_psize[entry->type] != entry->size)
+ if (xtopt_psize[entry->type] != -1 &&
+ xtopt_psize[entry->type] != entry->size)
xt_params->exit_err(OTHER_PROBLEM,
"%s: option \"--%s\" points to a memory block "
"of wrong size (expected %zu, got %zu)\n",
--
1.7.1
next prev parent reply other threads:[~2011-04-12 14:23 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-12 14:23 guided option parser, run 2 Jan Engelhardt
2011-04-12 14:23 ` [PATCH 01/28] libxtables: XTTYPE_UINT8 support Jan Engelhardt
2011-04-12 14:23 ` [PATCH 02/28] libip[6]t_HL: use guided option parser Jan Engelhardt
2011-04-12 14:23 ` [PATCH 03/28] libip[6]t_hl: " Jan Engelhardt
2011-04-12 14:23 ` Jan Engelhardt [this message]
2011-04-12 14:23 ` [PATCH 05/28] libip[6]t_ah: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 06/28] libip6t_frag: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 07/28] libxt_esp: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 08/28] libxtables: XTTYPE_STRING support Jan Engelhardt
2011-04-12 14:23 ` [PATCH 09/28] libip[6]t_REJECT: use guided option parser Jan Engelhardt
2011-04-12 14:23 ` [PATCH 10/28] libip6t_dst: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 11/28] libip6t_hbh: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 12/28] libip[6]t_icmp: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 13/28] libip6t_ipv6header: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 14/28] libipt_ECN: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 15/28] libipt_addrtype: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 16/28] libxt_AUDIT: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 17/28] libxt_CLASSIFY: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 18/28] libxt_DSCP: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 19/28] libxt_LED: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 20/28] libxt_SECMARK: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 21/28] libxt_TCPOPTSTRIP: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 22/28] libxt_comment: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 23/28] libxt_helper: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 24/28] libxt_physdev: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 25/28] libxt_pkttype: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 26/28] libxt_state: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 27/28] libxt_time: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 28/28] libxt_u32: " Jan Engelhardt
2011-04-13 11:41 ` guided option parser, run 2 Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302618224-9449-5-git-send-email-jengelh@medozas.de \
--to=jengelh@medozas.de \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).