summaryrefslogtreecommitdiffstats
path: root/extensions/libip6t_ipv6header.c
diff options
context:
space:
mode:
authorJan Engelhardt <jengelh@medozas.de>2011-03-01 19:51:16 +0100
committerJan Engelhardt <jengelh@medozas.de>2011-04-06 13:12:55 +0200
commitb26d08b56eb81779589eb43fb0f636ac9eb51cb2 (patch)
treefac302604d2835e33b94023de8885aff97d794be /extensions/libip6t_ipv6header.c
parent1b8db4f4ca250f13a0e7edddb31cfc1f82d42806 (diff)
libip6t_ipv6header: use guided option parser
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
Diffstat (limited to 'extensions/libip6t_ipv6header.c')
-rw-r--r--extensions/libip6t_ipv6header.c88
1 files changed, 27 insertions, 61 deletions
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 <kisza@sch.bme.hu> */
-
-#include <getopt.h>
-#include <xtables.h>
-#include <stdbool.h>
-#include <stddef.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <netdb.h>
-#include <sys/types.h>
-
+#include <xtables.h>
#include <linux/netfilter_ipv6/ip6t_ipv6header.h>
-/* This maybe required
-#include <linux/in.h>
-#include <linux/in6.h>
-*/
-
+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)