From: Jan Engelhardt <jengelh@medozas.de>
To: kaber@trash.net
Cc: netfilter-devel@vger.kernel.org
Subject: [PATCH 12/13] libxt_IDLETIMER: use guided option parser
Date: Mon, 9 May 2011 11:37:10 +0200 [thread overview]
Message-ID: <1304933832-16412-13-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_IDLETIMER.c | 70 +++++++----------------------------------
1 files changed, 12 insertions(+), 58 deletions(-)
diff --git a/extensions/libxt_IDLETIMER.c b/extensions/libxt_IDLETIMER.c
index 847ab18..21004a4 100644
--- a/extensions/libxt_IDLETIMER.c
+++ b/extensions/libxt_IDLETIMER.c
@@ -20,26 +20,24 @@
* 02110-1301 USA
*
*/
-#include <stdbool.h>
#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <getopt.h>
-#include <stddef.h>
-
#include <xtables.h>
#include <linux/netfilter/xt_IDLETIMER.h>
enum {
- IDLETIMER_TG_OPT_TIMEOUT = 1 << 0,
- IDLETIMER_TG_OPT_LABEL = 1 << 1,
+ O_TIMEOUT = 0,
+ O_LABEL,
};
-static const struct option idletimer_tg_opts[] = {
- {.name = "timeout", .has_arg = true, .val = 't'},
- {.name = "label", .has_arg = true, .val = 'l'},
- XT_GETOPT_TABLEEND,
+#define s struct idletimer_tg_info
+static const struct xt_option_entry idletimer_tg_opts[] = {
+ {.name = "timeout", .id = O_TIMEOUT, .type = XTTYPE_UINT32,
+ .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)},
+ {.name = "label", .id = O_LABEL, .type = XTTYPE_STRING,
+ .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)},
+ XTOPT_TABLEEND,
};
+#undef s
static void idletimer_tg_help(void)
{
@@ -50,49 +48,6 @@ static void idletimer_tg_help(void)
"\n");
}
-static int idletimer_tg_parse(int c, char **argv, int invert,
- unsigned int *flags,
- const void *entry,
- struct xt_entry_target **target)
-{
- struct idletimer_tg_info *info =
- (struct idletimer_tg_info *)(*target)->data;
-
- switch (c) {
- case 't':
- xtables_param_act(XTF_ONLY_ONCE, "IDLETIMER", "--timeout",
- *flags & IDLETIMER_TG_OPT_TIMEOUT);
-
- info->timeout = atoi(optarg);
- *flags |= IDLETIMER_TG_OPT_TIMEOUT;
- break;
-
- case 'l':
- xtables_param_act(XTF_ONLY_ONCE, "IDLETIMER", "--label",
- *flags & IDLETIMER_TG_OPT_TIMEOUT);
-
- if (strlen(optarg) > MAX_IDLETIMER_LABEL_SIZE - 1)
- xtables_param_act(XTF_BAD_VALUE, "IDLETIMER", "--label",
- optarg);
-
- strcpy(info->label, optarg);
- *flags |= IDLETIMER_TG_OPT_LABEL;
- break;
- }
-
- return true;
-}
-
-static void idletimer_tg_final_check(unsigned int flags)
-{
- if (!(flags & IDLETIMER_TG_OPT_TIMEOUT))
- xtables_error(PARAMETER_PROBLEM, "IDLETIMER target: "
- "--timeout parameter required");
- if (!(flags & IDLETIMER_TG_OPT_LABEL))
- xtables_error(PARAMETER_PROBLEM, "IDLETIMER target: "
- "--label parameter required");
-}
-
static void idletimer_tg_print(const void *ip,
const struct xt_entry_target *target,
int numeric)
@@ -122,11 +77,10 @@ static struct xtables_target idletimer_tg_reg = {
.size = XT_ALIGN(sizeof(struct idletimer_tg_info)),
.userspacesize = offsetof(struct idletimer_tg_info, timer),
.help = idletimer_tg_help,
- .parse = idletimer_tg_parse,
- .final_check = idletimer_tg_final_check,
+ .x6_parse = xtables_option_parse,
.print = idletimer_tg_print,
.save = idletimer_tg_save,
- .extra_opts = idletimer_tg_opts,
+ .x6_options = idletimer_tg_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 ` Jan Engelhardt [this message]
2011-05-09 9:37 ` [PATCH 13/13] libxt_NFLOG: " Jan Engelhardt
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-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).