From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 10/28] libip6t_dst: use guided option parser
Date: Tue, 12 Apr 2011 16:23:25 +0200 [thread overview]
Message-ID: <1302618224-9449-11-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1302618224-9449-1-git-send-email-jengelh@medozas.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
extensions/libip6t_dst.c | 61 +++++++++++++++-------------------------------
1 files changed, 20 insertions(+), 41 deletions(-)
diff --git a/extensions/libip6t_dst.c b/extensions/libip6t_dst.c
index 74f6029..4125bd3 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 <stdbool.h>
#include <stdio.h>
-#include <netdb.h>
#include <string.h>
#include <stdlib.h>
-#include <getopt.h>
#include <errno.h>
#include <xtables.h>
#include <linux/netfilter_ipv6/ip6t_opts.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
+
+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
--
1.7.1
next prev parent reply other threads:[~2011-04-12 14:23 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-12 14:23 guided option parser, run 2 Jan Engelhardt
2011-04-12 14:23 ` [PATCH 01/28] libxtables: XTTYPE_UINT8 support Jan Engelhardt
2011-04-12 14:23 ` [PATCH 02/28] libip[6]t_HL: use guided option parser Jan Engelhardt
2011-04-12 14:23 ` [PATCH 03/28] libip[6]t_hl: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 04/28] libxtables: XTTYPE_UINT32RC support Jan Engelhardt
2011-04-12 14:23 ` [PATCH 05/28] libip[6]t_ah: use guided option parser Jan Engelhardt
2011-04-12 14:23 ` [PATCH 06/28] libip6t_frag: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 07/28] libxt_esp: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 08/28] libxtables: XTTYPE_STRING support Jan Engelhardt
2011-04-12 14:23 ` [PATCH 09/28] libip[6]t_REJECT: use guided option parser Jan Engelhardt
2011-04-12 14:23 ` Jan Engelhardt [this message]
2011-04-12 14:23 ` [PATCH 11/28] libip6t_hbh: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 12/28] libip[6]t_icmp: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 13/28] libip6t_ipv6header: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 14/28] libipt_ECN: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 15/28] libipt_addrtype: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 16/28] libxt_AUDIT: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 17/28] libxt_CLASSIFY: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 18/28] libxt_DSCP: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 19/28] libxt_LED: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 20/28] libxt_SECMARK: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 21/28] libxt_TCPOPTSTRIP: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 22/28] libxt_comment: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 23/28] libxt_helper: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 24/28] libxt_physdev: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 25/28] libxt_pkttype: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 26/28] libxt_state: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 27/28] libxt_time: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 28/28] libxt_u32: " Jan Engelhardt
2011-04-13 11:41 ` guided option parser, run 2 Patrick McHardy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302618224-9449-11-git-send-email-jengelh@medozas.de \
--to=jengelh@medozas.de \
--cc=kaber@trash.net \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).