]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: XTTYPE_UINT32 support
authorJan Engelhardt <jengelh@medozas.de>
Wed, 16 Feb 2011 00:22:25 +0000 (01:22 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Wed, 6 Apr 2011 10:54:23 +0000 (12:54 +0200)
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
include/xtables.h.in
xtoptions.c

index c281fed743233de7e9a4b8c275100573d962211b..91a6eaaa9d43153f667181e7632fb314047b4e4d 100644 (file)
@@ -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;
 };
 
index df917b670d13862b3649f64a57bad86e64fee29c..843395be2c0cb7c9747443b7785a326bda0092aa 100644 (file)
@@ -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),
 };
 
 /**