From 4d6ede0b324e5e9dcbb1d7cc2a7aebed9e56821a Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Wed, 16 Feb 2011 01:59:18 +0100 Subject: libip[6]t_ah: use guided option parser Signed-off-by: Jan Engelhardt --- extensions/libipt_ah.c | 89 +++++++++----------------------------------------- 1 file changed, 16 insertions(+), 73 deletions(-) (limited to 'extensions/libipt_ah.c') diff --git a/extensions/libipt_ah.c b/extensions/libipt_ah.c index c50eecc4..53adfd87 100644 --- a/extensions/libipt_ah.c +++ b/extensions/libipt_ah.c @@ -1,14 +1,11 @@ -/* Shared library add-on to iptables to add AH support. */ -#include #include -#include -#include -#include -#include -#include #include #include +enum { + O_AHSPI = 0, +}; + static void ah_help(void) { printf( @@ -17,53 +14,13 @@ static void ah_help(void) " match spi (range)\n"); } -static const struct option ah_opts[] = { - {.name = "ahspi", .has_arg = true, .val = '1'}, - XT_GETOPT_TABLEEND, +static const struct xt_option_entry ah_opts[] = { + {.name = "ahspi", .id = O_AHSPI, .type = XTTYPE_UINT32RC, + .flags = XTOPT_INVERT | XTOPT_PUT, + XTOPT_POINTER(struct ipt_ah, spis)}, + XTOPT_TABLEEND, }; -static uint32_t -parse_ah_spi(const char *spistr) -{ - unsigned long int spi; - char* ep; - - spi = strtoul(spistr,&ep,0) ; - - if ( spistr == ep ) { - xtables_error(PARAMETER_PROBLEM, - "AH no valid digits in spi `%s'", spistr); - } - if ( spi == ULONG_MAX && errno == ERANGE ) { - xtables_error(PARAMETER_PROBLEM, - "spi `%s' specified too big: would overflow", spistr); - } - if ( *spistr != '\0' && *ep != '\0' ) { - xtables_error(PARAMETER_PROBLEM, - "AH error parsing spi `%s'", spistr); - } - return spi; -} - -static void -parse_ah_spis(const char *spistring, uint32_t *spis) -{ - char *buffer; - char *cp; - - buffer = strdup(spistring); - if ((cp = strchr(buffer, ':')) == NULL) - spis[0] = spis[1] = parse_ah_spi(buffer); - else { - *cp = '\0'; - cp++; - - spis[0] = buffer[0] ? parse_ah_spi(buffer) : 0; - spis[1] = cp[0] ? parse_ah_spi(cp) : 0xFFFFFFFF; - } - free(buffer); -} - static void ah_init(struct xt_entry_match *m) { struct ipt_ah *ahinfo = (struct ipt_ah *)m->data; @@ -71,27 +28,13 @@ static void ah_init(struct xt_entry_match *m) ahinfo->spis[1] = 0xFFFFFFFF; } -#define AH_SPI 0x01 - -static int ah_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_match **match) +static void ah_parse(struct xt_option_call *cb) { - struct ipt_ah *ahinfo = (struct ipt_ah *)(*match)->data; - - switch (c) { - case '1': - if (*flags & AH_SPI) - xtables_error(PARAMETER_PROBLEM, - "Only one `--ahspi' allowed"); - xtables_check_inverse(optarg, &invert, &optind, 0, argv); - parse_ah_spis(optarg, ahinfo->spis); - if (invert) - ahinfo->invflags |= IPT_AH_INV_SPI; - *flags |= AH_SPI; - break; - } + struct ipt_ah *ahinfo = cb->data; - return 1; + xtables_option_parse(cb); + if (cb->invert) + ahinfo->invflags |= IPT_AH_INV_SPI; } static void @@ -155,10 +98,10 @@ static struct xtables_match ah_mt_reg = { .userspacesize = XT_ALIGN(sizeof(struct ipt_ah)), .help = ah_help, .init = ah_init, - .parse = ah_parse, .print = ah_print, .save = ah_save, - .extra_opts = ah_opts, + .x6_parse = ah_parse, + .x6_options = ah_opts, }; void -- cgit v1.2.3