From b26d08b56eb81779589eb43fb0f636ac9eb51cb2 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 1 Mar 2011 19:51:16 +0100 Subject: libip6t_ipv6header: use guided option parser Signed-off-by: Jan Engelhardt --- extensions/libip6t_ipv6header.c | 88 +++++++++++++---------------------------- 1 file changed, 27 insertions(+), 61 deletions(-) (limited to 'extensions') diff --git a/extensions/libip6t_ipv6header.c b/extensions/libip6t_ipv6header.c index c05cedbb..fca6f323 100644 --- a/extensions/libip6t_ipv6header.c +++ b/extensions/libip6t_ipv6header.c @@ -3,24 +3,18 @@ on whether they contain certain headers */ /* Original idea: Brad Chapman * Rewritten by: Andras Kis-Szabo */ - -#include -#include -#include -#include +#include #include #include #include #include -#include - +#include #include -/* This maybe required -#include -#include -*/ - +enum { + O_HEADER = 0, + O_SOFT, +}; /* A few hardcoded protocols for 'all' and in case the user has no * /etc/protocols */ @@ -140,10 +134,11 @@ static void ipv6header_help(void) "--soft The header CONTAINS the specified extensions\n"); } -static const struct option ipv6header_opts[] = { - {.name = "header", .has_arg = true, .val = '1'}, - {.name = "soft", .has_arg = false, .val = '2'}, - XT_GETOPT_TABLEEND, +static const struct xt_option_entry ipv6header_opts[] = { + {.name = "header", .id = O_HEADER, .type = XTTYPE_STRING, + .flags = XTOPT_MAND | XTOPT_INVERT}, + {.name = "soft", .id = O_SOFT, .type = XTTYPE_NONE}, + XTOPT_TABLEEND, }; static unsigned int @@ -161,50 +156,22 @@ parse_header(const char *flags) { return ret; } -#define IPV6_HDR_HEADER 0x01 -#define IPV6_HDR_SOFT 0x02 - -static int -ipv6header_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_match **match) +static void ipv6header_parse(struct xt_option_call *cb) { - struct ip6t_ipv6header_info *info = (struct ip6t_ipv6header_info *)(*match)->data; - - switch (c) { - case '1' : - /* Parse the provided header names */ - if (*flags & IPV6_HDR_HEADER) - xtables_error(PARAMETER_PROBLEM, - "Only one `--header' allowed"); - - xtables_check_inverse(optarg, &invert, &optind, 0, argv); - - if (! (info->matchflags = parse_header(optarg)) ) - xtables_error(PARAMETER_PROBLEM, "ip6t_ipv6header: cannot parse header names"); - - if (invert) - info->invflags |= 0xFF; - *flags |= IPV6_HDR_HEADER; - break; - case '2' : - /* Soft-mode requested? */ - if (*flags & IPV6_HDR_SOFT) - xtables_error(PARAMETER_PROBLEM, - "Only one `--soft' allowed"); - - info->modeflag |= 0xFF; - *flags |= IPV6_HDR_SOFT; - break; + struct ip6t_ipv6header_info *info = cb->data; + + xtables_option_parse(cb); + switch (cb->entry->id) { + case O_HEADER: + if (!(info->matchflags = parse_header(cb->arg))) + xtables_error(PARAMETER_PROBLEM, "ip6t_ipv6header: cannot parse header names"); + if (cb->invert) + info->invflags |= 0xFF; + break; + case O_SOFT: + info->modeflag |= 0xFF; + break; } - - return 1; -} - -static void ipv6header_check(unsigned int flags) -{ - if (!(flags & IPV6_HDR_HEADER)) - xtables_error(PARAMETER_PROBLEM, - "ip6t_ipv6header: no options specified"); } static void @@ -266,11 +233,10 @@ static struct xtables_match ipv6header_mt6_reg = { .size = XT_ALIGN(sizeof(struct ip6t_ipv6header_info)), .userspacesize = XT_ALIGN(sizeof(struct ip6t_ipv6header_info)), .help = ipv6header_help, - .parse = ipv6header_parse, - .final_check = ipv6header_check, .print = ipv6header_print, .save = ipv6header_save, - .extra_opts = ipv6header_opts, + .x6_parse = ipv6header_parse, + .x6_options = ipv6header_opts, }; void _init(void) -- cgit v1.2.3