From 082e9e11ed345572e2bf4790a5f8ba5245164fc6 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Fri, 18 Feb 2011 02:11:31 +0100 Subject: libip6t_dst: use guided option parser Signed-off-by: Jan Engelhardt --- extensions/libip6t_dst.c | 61 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 41 deletions(-) (limited to 'extensions') diff --git a/extensions/libip6t_dst.c b/extensions/libip6t_dst.c index 74f6029f..4125bd3d 100644 --- a/extensions/libip6t_dst.c +++ b/extensions/libip6t_dst.c @@ -1,16 +1,14 @@ -/* Shared library add-on to ip6tables to add Dst header support. */ -#include #include -#include #include #include -#include #include #include #include -#include -#include -#include + +enum { + O_DSTLEN = 0, + O_DSTOPTS, +}; static void dst_help(void) { @@ -22,10 +20,12 @@ static void dst_help(void) IP6T_OPTS_OPTSNR); } -static const struct option dst_opts[] = { - {.name = "dst-len", .has_arg = true, .val = '1'}, - {.name = "dst-opts", .has_arg = true, .val = '2'}, - XT_GETOPT_TABLEEND, +static const struct xt_option_entry dst_opts[] = { + {.name = "dst-len", .id = O_DSTLEN, .type = XTTYPE_UINT32, + .flags = XTOPT_INVERT | XTOPT_PUT, + XTOPT_POINTER(struct ip6t_opts, hdrlen)}, + {.name = "dst-opts", .id = O_DSTOPTS, .type = XTTYPE_STRING}, + XTOPT_TABLEEND, }; static uint32_t @@ -105,38 +105,17 @@ parse_options(const char *optsstr, uint16_t *opts) return i; } -static int dst_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_match **match) +static void dst_parse(struct xt_option_call *cb) { - struct ip6t_opts *optinfo = (struct ip6t_opts *)(*match)->data; - - switch (c) { - case '1': - if (*flags & IP6T_OPTS_LEN) - xtables_error(PARAMETER_PROBLEM, - "Only one `--dst-len' allowed"); - xtables_check_inverse(optarg, &invert, &optind, 0, argv); - optinfo->hdrlen = parse_opts_num(optarg, "length"); - if (invert) - optinfo->invflags |= IP6T_OPTS_INV_LEN; - optinfo->flags |= IP6T_OPTS_LEN; - *flags |= IP6T_OPTS_LEN; - break; - case '2': - if (*flags & IP6T_OPTS_OPTS) - xtables_error(PARAMETER_PROBLEM, - "Only one `--dst-opts' allowed"); - xtables_check_inverse(optarg, &invert, &optind, 0, argv); - if (invert) - xtables_error(PARAMETER_PROBLEM, - " '!' not allowed with `--dst-opts'"); - optinfo->optsnr = parse_options(optarg, optinfo->opts); + struct ip6t_opts *optinfo = cb->data; + + xtables_option_parse(cb); + switch (cb->entry->id) { + case O_DSTOPTS: + optinfo->optsnr = parse_options(cb->arg, optinfo->opts); optinfo->flags |= IP6T_OPTS_OPTS; - *flags |= IP6T_OPTS_OPTS; break; } - - return 1; } static void @@ -199,10 +178,10 @@ static struct xtables_match dst_mt6_reg = { .size = XT_ALIGN(sizeof(struct ip6t_opts)), .userspacesize = XT_ALIGN(sizeof(struct ip6t_opts)), .help = dst_help, - .parse = dst_parse, .print = dst_print, .save = dst_save, - .extra_opts = dst_opts, + .x6_parse = dst_parse, + .x6_options = dst_opts, }; void -- cgit v1.2.3