From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 12/28] libip[6]t_icmp: use guided option parser
Date: Tue, 12 Apr 2011 16:23:27 +0200 [thread overview]
Message-ID: <1302618224-9449-13-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_icmp6.c | 53 ++++++++++++++-----------------------------
extensions/libipt_icmp.c | 47 +++++++++++++++------------------------
2 files changed, 35 insertions(+), 65 deletions(-)
diff --git a/extensions/libip6t_icmp6.c b/extensions/libip6t_icmp6.c
index fa87b69..68b940b 100644
--- a/extensions/libip6t_icmp6.c
+++ b/extensions/libip6t_icmp6.c
@@ -1,14 +1,14 @@
-/* Shared library add-on to ip6tables to add ICMP support. */
-#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
-#include <netdb.h>
#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
#include <xtables.h>
#include <limits.h> /* INT_MAX in ip6_tables.h */
#include <linux/netfilter_ipv6/ip6_tables.h>
+enum {
+ O_ICMPV6_TYPE = 0,
+};
+
struct icmpv6_names {
const char *name;
uint8_t type;
@@ -84,9 +84,10 @@ static void icmp6_help(void)
print_icmpv6types();
}
-static const struct option icmp6_opts[] = {
- {.name = "icmpv6-type", .has_arg = true, .val = '1'},
- XT_GETOPT_TABLEEND,
+static const struct xt_option_entry icmp6_opts[] = {
+ {.name = "icmpv6-type", .id = O_ICMPV6_TYPE, .type = XTTYPE_STRING,
+ .flags = XTOPT_MAND | XTOPT_INVERT},
+ XTOPT_TABLEEND,
};
static void
@@ -149,26 +150,14 @@ static void icmp6_init(struct xt_entry_match *m)
icmpv6info->code[1] = 0xFF;
}
-static int icmp6_parse(int c, char **argv, int invert, unsigned int *flags,
- const void *entry, struct xt_entry_match **match)
+static void icmp6_parse(struct xt_option_call *cb)
{
- struct ip6t_icmp *icmpv6info = (struct ip6t_icmp *)(*match)->data;
-
- switch (c) {
- case '1':
- if (*flags == 1)
- xtables_error(PARAMETER_PROBLEM,
- "icmpv6 match: only use --icmpv6-type once!");
- xtables_check_inverse(optarg, &invert, &optind, 0, argv);
- parse_icmpv6(optarg, &icmpv6info->type,
- icmpv6info->code);
- if (invert)
- icmpv6info->invflags |= IP6T_ICMP_INV;
- *flags = 1;
- break;
- }
+ struct ip6t_icmp *icmpv6info = cb->data;
- return 1;
+ xtables_option_parse(cb);
+ parse_icmpv6(cb->arg, &icmpv6info->type, icmpv6info->code);
+ if (cb->invert)
+ icmpv6info->invflags |= IP6T_ICMP_INV;
}
static void print_icmpv6type(uint8_t type,
@@ -230,13 +219,6 @@ static void icmp6_save(const void *ip, const struct xt_entry_match *match)
printf("/%u", icmpv6->code[0]);
}
-static void icmp6_check(unsigned int flags)
-{
- if (!flags)
- xtables_error(PARAMETER_PROBLEM,
- "icmpv6 match: You must specify `--icmpv6-type'");
-}
-
static struct xtables_match icmp6_mt6_reg = {
.name = "icmp6",
.version = XTABLES_VERSION,
@@ -245,11 +227,10 @@ static struct xtables_match icmp6_mt6_reg = {
.userspacesize = XT_ALIGN(sizeof(struct ip6t_icmp)),
.help = icmp6_help,
.init = icmp6_init,
- .parse = icmp6_parse,
- .final_check = icmp6_check,
.print = icmp6_print,
.save = icmp6_save,
- .extra_opts = icmp6_opts,
+ .x6_parse = icmp6_parse,
+ .x6_options = icmp6_opts,
};
void _init(void)
diff --git a/extensions/libipt_icmp.c b/extensions/libipt_icmp.c
index c75713d..666e7da 100644
--- a/extensions/libipt_icmp.c
+++ b/extensions/libipt_icmp.c
@@ -1,12 +1,8 @@
-/* Shared library add-on to iptables to add ICMP support. */
-#include <stdbool.h>
+#include <stdint.h>
#include <stdio.h>
-#include <netdb.h>
#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
#include <xtables.h>
-#include <limits.h> /* INT_MAX in ip_tables.h */
+#include <limits.h> /* INT_MAX in ip6_tables.h */
#include <linux/netfilter_ipv4/ip_tables.h>
/* special hack for icmp-type 'any':
@@ -17,6 +13,10 @@
* See: https://bugzilla.netfilter.org/cgi-bin/bugzilla/show_bug.cgi?id=37
*/
+enum {
+ O_ICMP_TYPE = 0,
+};
+
struct icmp_names {
const char *name;
uint8_t type;
@@ -108,9 +108,10 @@ static void icmp_help(void)
print_icmptypes();
}
-static const struct option icmp_opts[] = {
- {.name = "icmp-type", .has_arg = true, .val = '1'},
- XT_GETOPT_TABLEEND,
+static const struct xt_option_entry icmp_opts[] = {
+ {.name = "icmp-type", .id = O_ICMP_TYPE, .type = XTTYPE_STRING,
+ .flags = XTOPT_MAND | XTOPT_INVERT},
+ XTOPT_TABLEEND,
};
static void
@@ -174,26 +175,14 @@ static void icmp_init(struct xt_entry_match *m)
icmpinfo->code[1] = 0xFF;
}
-static int icmp_parse(int c, char **argv, int invert, unsigned int *flags,
- const void *entry, struct xt_entry_match **match)
+static void icmp_parse(struct xt_option_call *cb)
{
- struct ipt_icmp *icmpinfo = (struct ipt_icmp *)(*match)->data;
-
- switch (c) {
- case '1':
- if (*flags == 1)
- xtables_error(PARAMETER_PROBLEM,
- "icmp match: only use --icmp-type once!");
- xtables_check_inverse(optarg, &invert, &optind, 0, argv);
- parse_icmp(optarg, &icmpinfo->type,
- icmpinfo->code);
- if (invert)
- icmpinfo->invflags |= IPT_ICMP_INV;
- *flags = 1;
- break;
- }
+ struct ipt_icmp *icmpinfo = cb->data;
- return 1;
+ xtables_option_parse(cb);
+ parse_icmp(cb->arg, &icmpinfo->type, icmpinfo->code);
+ if (cb->invert)
+ icmpinfo->invflags |= IPT_ICMP_INV;
}
static void print_icmptype(uint8_t type,
@@ -268,10 +257,10 @@ static struct xtables_match icmp_mt_reg = {
.userspacesize = XT_ALIGN(sizeof(struct ipt_icmp)),
.help = icmp_help,
.init = icmp_init,
- .parse = icmp_parse,
.print = icmp_print,
.save = icmp_save,
- .extra_opts = icmp_opts,
+ .x6_parse = icmp_parse,
+ .x6_options = icmp_opts,
};
void _init(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 ` [PATCH 10/28] libip6t_dst: " Jan Engelhardt
2011-04-12 14:23 ` [PATCH 11/28] libip6t_hbh: " Jan Engelhardt
2011-04-12 14:23 ` Jan Engelhardt [this message]
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-13-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).