[PATCH 07/10] libxtables: XTTYPE_UINT32 support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Jan Engelhardt <jengelh@xxxxxxxxxx>
---
 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 c281fed..91a6eaa 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 df917b6..843395b 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),
 };
 
 /**
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux