From 1e6c1ee1bf2822d5fdf61725148700a410fb8b86 Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Sun, 6 Mar 2011 16:58:24 +0100 Subject: libxt_quota: use guided option parser Signed-off-by: Jan Engelhardt --- extensions/libxt_quota.c | 67 +++++++++++------------------------------------- 1 file changed, 15 insertions(+), 52 deletions(-) (limited to 'extensions/libxt_quota.c') diff --git a/extensions/libxt_quota.c b/extensions/libxt_quota.c index e3699ad7..988f404f 100644 --- a/extensions/libxt_quota.c +++ b/extensions/libxt_quota.c @@ -3,18 +3,18 @@ * * Sam Johnston */ -#include -#include #include -#include -#include #include - #include -static const struct option quota_opts[] = { - {.name = "quota", .has_arg = true, .val = '1'}, - XT_GETOPT_TABLEEND, +enum { + O_QUOTA = 0, +}; + +static const struct xt_option_entry quota_opts[] = { + {.name = "quota", .id = O_QUOTA, .type = XTTYPE_UINT64, + .flags = XTOPT_MAND | XTOPT_INVERT}, + XTOPT_TABLEEND, }; static void quota_help(void) @@ -40,49 +40,13 @@ quota_save(const void *ip, const struct xt_entry_match *match) printf(" --quota %llu", (unsigned long long) q->quota); } -/* parse quota option */ -static int -parse_quota(const char *s, uint64_t * quota) -{ - *quota = strtoull(s, NULL, 10); - -#ifdef DEBUG_XT_QUOTA - printf("Quota: %llu\n", *quota); -#endif - - if (*quota == UINT64_MAX) - xtables_error(PARAMETER_PROBLEM, "quota invalid: '%s'\n", s); - else - return 1; -} - -static int -quota_parse(int c, char **argv, int invert, unsigned int *flags, - const void *entry, struct xt_entry_match **match) +static void quota_parse(struct xt_option_call *cb) { - struct xt_quota_info *info = (struct xt_quota_info *) (*match)->data; - - switch (c) { - case '1': - if (xtables_check_inverse(optarg, &invert, NULL, 0, argv)) - xtables_error(PARAMETER_PROBLEM, "quota: unexpected '!'"); - if (!parse_quota(optarg, &info->quota)) - xtables_error(PARAMETER_PROBLEM, - "bad quota: '%s'", optarg); + struct xt_quota_info *info = cb->data; - if (invert) - info->flags |= XT_QUOTA_INVERT; - *flags |= 1; - break; - } - return 1; -} - -static void quota_check(unsigned int flags) -{ - if (flags == 0) - xtables_error(PARAMETER_PROBLEM, - "quota: the --quota argument must be specified\n"); + xtables_option_parse(cb); + if (cb->invert) + info->flags |= XT_QUOTA_INVERT; } static struct xtables_match quota_match = { @@ -92,11 +56,10 @@ static struct xtables_match quota_match = { .size = XT_ALIGN(sizeof (struct xt_quota_info)), .userspacesize = offsetof(struct xt_quota_info, master), .help = quota_help, - .parse = quota_parse, - .final_check = quota_check, .print = quota_print, .save = quota_save, - .extra_opts = quota_opts, + .x6_parse = quota_parse, + .x6_options = quota_opts, }; void -- cgit v1.2.3