From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 13/13] libxt_NFLOG: use guided option parser
Date: Mon, 9 May 2011 11:37:11 +0200 [thread overview]
Message-ID: <1304933832-16412-14-git-send-email-jengelh@medozas.de> (raw)
In-Reply-To: <1304933832-16412-1-git-send-email-jengelh@medozas.de>
Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
---
extensions/libxt_NFLOG.c | 98 +++++++++++----------------------------------
1 files changed, 24 insertions(+), 74 deletions(-)
diff --git a/extensions/libxt_NFLOG.c b/extensions/libxt_NFLOG.c
index 61c9741..448576a 100644
--- a/extensions/libxt_NFLOG.c
+++ b/extensions/libxt_NFLOG.c
@@ -9,19 +9,25 @@
#include <linux/netfilter/xt_NFLOG.h>
enum {
- NFLOG_GROUP = 0x1,
- NFLOG_PREFIX = 0x2,
- NFLOG_RANGE = 0x4,
- NFLOG_THRESHOLD = 0x8,
+ O_GROUP = 0,
+ O_PREFIX,
+ O_RANGE,
+ O_THRESHOLD,
};
-static const struct option NFLOG_opts[] = {
- {.name = "nflog-group", .has_arg = true, .val = NFLOG_GROUP},
- {.name = "nflog-prefix", .has_arg = true, .val = NFLOG_PREFIX},
- {.name = "nflog-range", .has_arg = true, .val = NFLOG_RANGE},
- {.name = "nflog-threshold", .has_arg = true, .val = NFLOG_THRESHOLD},
- XT_GETOPT_TABLEEND,
+#define s struct xt_nflog_info
+static const struct xt_option_entry NFLOG_opts[] = {
+ {.name = "nflog-group", .id = O_GROUP, .type = XTTYPE_UINT16,
+ .flags = XTOPT_PUT, XTOPT_POINTER(s, group)},
+ {.name = "nflog-prefix", .id = O_PREFIX, .type = XTTYPE_STRING,
+ .min = 1, .flags = XTOPT_PUT, XTOPT_POINTER(s, prefix)},
+ {.name = "nflog-range", .id = O_RANGE, .type = XTTYPE_UINT32,
+ .flags = XTOPT_PUT, XTOPT_POINTER(s, len)},
+ {.name = "nflog-threshold", .id = O_THRESHOLD, .type = XTTYPE_UINT16,
+ .flags = XTOPT_PUT, XTOPT_POINTER(s, threshold)},
+ XTOPT_TABLEEND,
};
+#undef s
static void NFLOG_help(void)
{
@@ -39,72 +45,16 @@ static void NFLOG_init(struct xt_entry_target *t)
info->threshold = XT_NFLOG_DEFAULT_THRESHOLD;
}
-static int NFLOG_parse(int c, char **argv, int invert, unsigned int *flags,
- const void *entry, struct xt_entry_target **target)
+static void NFLOG_parse(struct xt_option_call *cb)
{
- struct xt_nflog_info *info = (struct xt_nflog_info *)(*target)->data;
- int n;
- size_t length;
-
- switch (c) {
- case NFLOG_GROUP:
- if (*flags & NFLOG_GROUP)
- xtables_error(PARAMETER_PROBLEM,
- "Can't specify --nflog-group twice");
- if (xtables_check_inverse(optarg, &invert, NULL, 0, argv))
- xtables_error(PARAMETER_PROBLEM,
- "Unexpected `!' after --nflog-group");
-
- n = atoi(optarg);
- if (n < 0)
- xtables_error(PARAMETER_PROBLEM,
- "--nflog-group can not be negative");
- info->group = n;
- break;
- case NFLOG_PREFIX:
- if (*flags & NFLOG_PREFIX)
- xtables_error(PARAMETER_PROBLEM,
- "Can't specify --nflog-prefix twice");
- if (xtables_check_inverse(optarg, &invert, NULL, 0, argv))
- xtables_error(PARAMETER_PROBLEM,
- "Unexpected `!' after --nflog-prefix");
-
- length = strlen(optarg);
- if (length == 0)
- xtables_error(PARAMETER_PROBLEM,
- "No prefix specified for --nflog-prefix");
- if (length >= sizeof(info->prefix))
- xtables_error(PARAMETER_PROBLEM,
- "--nflog-prefix too long, max %Zu characters",
- sizeof(info->prefix) - 1);
- if (length != strlen(strtok(optarg, "\n")))
- xtables_error(PARAMETER_PROBLEM,
- "Newlines are not allowed in --nflog-prefix");
- strcpy(info->prefix, optarg);
- break;
- case NFLOG_RANGE:
- if (*flags & NFLOG_RANGE)
- xtables_error(PARAMETER_PROBLEM,
- "Can't specify --nflog-range twice");
- n = atoi(optarg);
- if (n < 0)
- xtables_error(PARAMETER_PROBLEM,
- "Invalid --nflog-range, must be >= 0");
- info->len = n;
- break;
- case NFLOG_THRESHOLD:
- if (*flags & NFLOG_THRESHOLD)
- xtables_error(PARAMETER_PROBLEM,
- "Can't specify --nflog-threshold twice");
- n = atoi(optarg);
- if (n < 1)
+ xtables_option_parse(cb);
+ switch (cb->entry->id) {
+ case O_PREFIX:
+ if (strchr(cb->arg, '\n') != NULL)
xtables_error(PARAMETER_PROBLEM,
- "Invalid --nflog-threshold, must be >= 1");
- info->threshold = n;
+ "Newlines not allowed in --log-prefix");
break;
}
- *flags |= c;
- return 1;
}
static void nflog_print(const struct xt_nflog_info *info, char *prefix)
@@ -144,10 +94,10 @@ static struct xtables_target nflog_target = {
.userspacesize = XT_ALIGN(sizeof(struct xt_nflog_info)),
.help = NFLOG_help,
.init = NFLOG_init,
- .parse = NFLOG_parse,
+ .x6_parse = NFLOG_parse,
.print = NFLOG_print,
.save = NFLOG_save,
- .extra_opts = NFLOG_opts,
+ .x6_options = NFLOG_opts,
};
void _init(void)
--
1.7.1
next prev parent reply other threads:[~2011-05-09 9:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-09 9:36 guided option parser, run 5 Jan Engelhardt
2011-05-09 9:36 ` [PATCH 01/13] libxt_tos: add inversion support back again Jan Engelhardt
2011-05-09 9:37 ` [PATCH 02/13] libxtables: fix assignment in wrong offset (XTTYPE_UINT*RC) Jan Engelhardt
2011-05-09 9:37 ` [PATCH 03/13] libxt_u32: add missing call to xtables_option_parse Jan Engelhardt
2011-05-09 9:37 ` [PATCH 04/13] extensions: remove bogus use of XT_GETOPT_TABLEEND Jan Engelhardt
2011-05-09 9:37 ` [PATCH 05/13] libxt_owner: remove ifdef IPT_COMM_OWNER Jan Engelhardt
2011-05-09 9:37 ` [PATCH 06/13] libxtables: output name of extension on rev detect failure Jan Engelhardt
2011-05-09 9:37 ` [PATCH 07/13] extensions: const annotations Jan Engelhardt
2011-05-09 9:37 ` [PATCH 08/13] libxt_statistic: streamline and document possible placement of negation Jan Engelhardt
2011-05-09 9:37 ` [PATCH 09/13] libxt_statistic: increase precision on create and dump Jan Engelhardt
2011-05-09 9:37 ` [PATCH 10/13] libxtables: XTTYPE_DOUBLE support Jan Engelhardt
2011-05-09 9:37 ` [PATCH 11/13] libxt_statistic: use guided option parser Jan Engelhardt
2011-05-09 9:37 ` [PATCH 12/13] libxt_IDLETIMER: " Jan Engelhardt
2011-05-09 9:37 ` Jan Engelhardt [this message]
2011-05-09 18:24 ` guided option parser, run 5 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=1304933832-16412-14-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).