]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: XTTYPE_MARKMASK32 support
authorJan Engelhardt <jengelh@medozas.de>
Sun, 6 Mar 2011 13:57:44 +0000 (14:57 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Wed, 13 Apr 2011 16:09:25 +0000 (18:09 +0200)
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
include/xtables.h.in
xtoptions.c

index c3c8da9c3234eefa3066641d198244e78502dbd6..2fa59771b2c6bc62caf50556b3edde5e3cd5f0e2 100644 (file)
@@ -50,6 +50,7 @@ struct in_addr;
  * %XTTYPE_UINT*:      standard integer
  * %XTTYPE_UINT*RC:    colon-separated range of standard integers
  * %XTTYPE_STRING:     arbitrary string
+ * %XTTYPE_MARKMASK32: 32-bit mark with optional mask
  */
 enum xt_option_type {
        XTTYPE_NONE,
@@ -57,6 +58,7 @@ enum xt_option_type {
        XTTYPE_UINT32,
        XTTYPE_UINT32RC,
        XTTYPE_STRING,
+       XTTYPE_MARKMASK32,
 };
 
 /**
@@ -113,6 +115,9 @@ struct xt_option_call {
        union {
                uint8_t u8;
                uint32_t u32, u32_range[2];
+               struct {
+                       uint32_t mark, mask;
+               };
        } val;
 };
 
index 631e7a3c35027e3de4ceeed7f36c68e7bb1a60d3..e9bcaa834cbc9d111a4913d8c1bc50a3232ef437 100644 (file)
@@ -186,11 +186,40 @@ static void xtopt_parse_string(struct xt_option_call *cb)
        p[z] = '\0';
 }
 
+/**
+ * Validate the input for being conformant to "mark[/mask]".
+ */
+static void xtopt_parse_markmask(struct xt_option_call *cb)
+{
+       unsigned int mark = 0, mask = ~0U;
+       char *end;
+
+       if (!xtables_strtoui(cb->arg, &end, &mark, 0, UINT32_MAX))
+               xt_params->exit_err(PARAMETER_PROBLEM,
+                       "%s: bad mark value for option \"--%s\", "
+                       "or out of range.\n",
+                       cb->ext_name, cb->entry->name);
+       if (*end == '/' &&
+           !xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
+               xt_params->exit_err(PARAMETER_PROBLEM,
+                       "%s: bad mask value for option \"--%s\", "
+                       "or out of range.\n",
+                       cb->ext_name, cb->entry->name);
+       if (*end != '\0')
+               xt_params->exit_err(PARAMETER_PROBLEM,
+                       "%s: trailing garbage after value "
+                       "for option \"--%s\".\n",
+                       cb->ext_name, cb->entry->name);
+       cb->val.mark = mark;
+       cb->val.mask = mask;
+}
+
 static void (*const xtopt_subparse[])(struct xt_option_call *) = {
        [XTTYPE_UINT8]       = xtopt_parse_int,
        [XTTYPE_UINT32]      = xtopt_parse_int,
        [XTTYPE_UINT32RC]    = xtopt_parse_mint,
        [XTTYPE_STRING]      = xtopt_parse_string,
+       [XTTYPE_MARKMASK32]  = xtopt_parse_markmask,
 };
 
 static const size_t xtopt_psize[] = {