From: Phil Sutter <phil@nwl.cc>
To: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH 4/6] libxtables: Introduce struct xt_option_entry::base
Date: Wed, 22 Nov 2023 22:52:59 +0100 [thread overview]
Message-ID: <20231122215301.15725-5-phil@nwl.cc> (raw)
In-Reply-To: <20231122215301.15725-1-phil@nwl.cc>
Enable guided option parser users to parse integer values with a fixed
base.
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
include/xtables.h | 3 ++-
libxtables/xtoptions.c | 3 ++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/include/xtables.h b/include/xtables.h
index 1a9e08bb131ab..b3c45c981b1c7 100644
--- a/include/xtables.h
+++ b/include/xtables.h
@@ -122,6 +122,7 @@ enum xt_option_flags {
* @size: size of the item pointed to by @ptroff; this is a safeguard
* @min: lowest allowed value (for singular integral types)
* @max: highest allowed value (for singular integral types)
+ * @base: assumed base of parsed value for integer types (default 0)
*/
struct xt_option_entry {
const char *name;
@@ -129,7 +130,7 @@ struct xt_option_entry {
unsigned int id, excl, also, flags;
unsigned int ptroff;
size_t size;
- unsigned int min, max;
+ unsigned int min, max, base;
};
/**
diff --git a/libxtables/xtoptions.c b/libxtables/xtoptions.c
index 25540f8b88c6d..4fd0e70e6b555 100644
--- a/libxtables/xtoptions.c
+++ b/libxtables/xtoptions.c
@@ -161,7 +161,8 @@ static void xtopt_parse_int(struct xt_option_call *cb)
if (cb->entry->max != 0)
lmax = cb->entry->max;
- if (!xtables_strtoul(cb->arg, NULL, &value, lmin, lmax))
+ if (!xtables_strtoul_base(cb->arg, NULL, &value,
+ lmin, lmax, cb->entry->base))
xt_params->exit_err(PARAMETER_PROBLEM,
"%s: bad value for option \"--%s\", "
"or out of range (%ju-%ju).\n",
--
2.41.0
next prev parent reply other threads:[~2023-11-22 21:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-22 21:52 [iptables PATCH 0/6] Extend guided option parser for use by arptables Phil Sutter
2023-11-22 21:52 ` [iptables PATCH 1/6] libxtables: Combine the two extension option mergers Phil Sutter
2023-11-22 21:52 ` [iptables PATCH 2/6] libxtables: Fix guided option parser for use with arptables Phil Sutter
2023-11-22 21:52 ` [iptables PATCH 3/6] libxtables: Introduce xtables_strtoul_base() Phil Sutter
2023-11-22 21:52 ` Phil Sutter [this message]
2023-11-22 21:53 ` [iptables PATCH 5/6] extensions: libarpt_mangle: Use guided option parser Phil Sutter
2023-11-22 21:53 ` [iptables PATCH 6/6] extensions: MARK: arptables: " Phil Sutter
2023-11-23 16:55 ` [iptables PATCH 0/6] Extend guided option parser for use by arptables Phil Sutter
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=20231122215301.15725-5-phil@nwl.cc \
--to=phil@nwl.cc \
--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).