summaryrefslogtreecommitdiffstats
path: root/extensions/libxt_connmark.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-03-06 15:54:58 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-04-13 18:09:26 +0200
commit7299fa4b615d7f7ee12cde444266f6b31f667f9f (patch)
tree5dee6b071be8b1f4e71ef84ba8449ea72a1fa6cf /extensions/libxt_connmark.c
parent60756e7f8be9242b606f1b5fbcb38f45e4de29c5 (diff)
libxt_CONNMARK: use guided option parser
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'extensions/libxt_connmark.c')
-rw-r--r--extensions/libxt_connmark.c98
1 files changed, 26 insertions, 72 deletions
diff --git a/extensions/libxt_connmark.c b/extensions/libxt_connmark.c
index a0e89fe7..6f1d5323 100644
--- a/extensions/libxt_connmark.c
+++ b/extensions/libxt_connmark.c
@@ -20,12 +20,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
-#include <netdb.h>
-#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-
#include <xtables.h>
#include <linux/netfilter/xt_connmark.h>
@@ -35,7 +31,7 @@ struct xt_connmark_info {
};
enum {
- F_MARK = 1 << 0,
+ O_MARK = 0,
};
static void connmark_mt_help(void)
@@ -45,65 +41,32 @@ static void connmark_mt_help(void)
"[!] --mark value[/mask] Match ctmark value with optional mask\n");
}
-static const struct option connmark_mt_opts[] = {
- {.name = "mark", .has_arg = true, .val = '1'},
- XT_GETOPT_TABLEEND,
+static const struct xt_option_entry connmark_mt_opts[] = {
+ {.name = "mark", .id = O_MARK, .type = XTTYPE_MARKMASK32,
+ .flags = XTOPT_MAND | XTOPT_INVERT},
+ XTOPT_TABLEEND,
};
-static int
-connmark_mt_parse(int c, char **argv, int invert, unsigned int *flags,
- const void *entry, struct xt_entry_match **match)
+static void connmark_mt_parse(struct xt_option_call *cb)
{
- struct xt_connmark_mtinfo1 *info = (void *)(*match)->data;
- unsigned int mark, mask = UINT32_MAX;
- char *end;
-
- switch (c) {
- case '1': /* --mark */
- xtables_param_act(XTF_ONLY_ONCE, "connmark", "--mark", *flags & F_MARK);
- if (!xtables_strtoui(optarg, &end, &mark, 0, UINT32_MAX))
- xtables_param_act(XTF_BAD_VALUE, "connmark", "--mark", optarg);
- if (*end == '/')
- if (!xtables_strtoui(end + 1, &end, &mask, 0, UINT32_MAX))
- xtables_param_act(XTF_BAD_VALUE, "connmark", "--mark", optarg);
- if (*end != '\0')
- xtables_param_act(XTF_BAD_VALUE, "connmark", "--mark", optarg);
-
- if (invert)
- info->invert = true;
- info->mark = mark;
- info->mask = mask;
- *flags |= F_MARK;
- return true;
- }
- return false;
+ struct xt_connmark_mtinfo1 *info = cb->data;
+
+ xtables_option_parse(cb);
+ if (cb->invert)
+ info->invert = true;
+ info->mark = cb->val.mark;
+ info->mask = cb->val.mask;
}
-static int
-connmark_parse(int c, char **argv, int invert, unsigned int *flags,
- const void *entry, struct xt_entry_match **match)
+static void connmark_parse(struct xt_option_call *cb)
{
- struct xt_connmark_info *markinfo = (struct xt_connmark_info *)(*match)->data;
-
- switch (c) {
- char *end;
- case '1':
- xtables_check_inverse(optarg, &invert, &optind, 0, argv);
-
- markinfo->mark = strtoul(optarg, &end, 0);
- markinfo->mask = 0xffffffffUL;
-
- if (*end == '/')
- markinfo->mask = strtoul(end+1, &end, 0);
-
- if (*end != '\0' || end == optarg)
- xtables_error(PARAMETER_PROBLEM, "Bad MARK value \"%s\"", optarg);
- if (invert)
- markinfo->invert = 1;
- *flags = 1;
- break;
- }
- return 1;
+ struct xt_connmark_info *markinfo = cb->data;
+
+ xtables_option_parse(cb);
+ markinfo->mark = cb->val.mark;
+ markinfo->mask = cb->val.mask;
+ if (cb->invert)
+ markinfo->invert = 1;
}
static void print_mark(unsigned int mark, unsigned int mask)
@@ -114,13 +77,6 @@ static void print_mark(unsigned int mark, unsigned int mask)
printf(" 0x%x", mark);
}
-static void connmark_mt_check(unsigned int flags)
-{
- if (flags == 0)
- xtables_error(PARAMETER_PROBLEM,
- "connmark: The --mark option is required");
-}
-
static void
connmark_print(const void *ip, const struct xt_entry_match *match, int numeric)
{
@@ -175,11 +131,10 @@ static struct xtables_match connmark_mt_reg[] = {
.size = XT_ALIGN(sizeof(struct xt_connmark_info)),
.userspacesize = XT_ALIGN(sizeof(struct xt_connmark_info)),
.help = connmark_mt_help,
- .parse = connmark_parse,
- .final_check = connmark_mt_check,
.print = connmark_print,
.save = connmark_save,
- .extra_opts = connmark_mt_opts,
+ .x6_parse = connmark_parse,
+ .x6_options = connmark_mt_opts,
},
{
.version = XTABLES_VERSION,
@@ -189,11 +144,10 @@ static struct xtables_match connmark_mt_reg[] = {
.size = XT_ALIGN(sizeof(struct xt_connmark_mtinfo1)),
.userspacesize = XT_ALIGN(sizeof(struct xt_connmark_mtinfo1)),
.help = connmark_mt_help,
- .parse = connmark_mt_parse,
- .final_check = connmark_mt_check,
.print = connmark_mt_print,
.save = connmark_mt_save,
- .extra_opts = connmark_mt_opts,
+ .x6_parse = connmark_mt_parse,
+ .x6_options = connmark_mt_opts,
},
};