]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
extensions: libxt_limit: Use guided option parser for NFPROTO_BRIDGE, too
authorPhil Sutter <phil@nwl.cc>
Tue, 28 Nov 2023 13:27:27 +0000 (14:27 +0100)
committerPhil Sutter <phil@nwl.cc>
Wed, 10 Jan 2024 15:07:31 +0000 (16:07 +0100)
extensions/libxt_limit.c

index e6ec67f30268871e78046d6e95d114e90a2ff835..63f3289d82c22a9b55d901f3f07be1e1cf08b4c5 100644 (file)
@@ -7,7 +7,6 @@
 #define _DEFAULT_SOURCE 1
 #define _ISOC99_SOURCE 1
 #include <errno.h>
-#include <getopt.h>
 #include <math.h>
 #include <stdio.h>
 #include <string.h>
@@ -202,44 +201,6 @@ static int limit_xlate_eb(struct xt_xlate *xl,
        return 1;
 }
 
-#define FLAG_LIMIT             0x01
-#define FLAG_LIMIT_BURST       0x02
-#define ARG_LIMIT              '1'
-#define ARG_LIMIT_BURST                '2'
-
-static int brlimit_parse(int c, char **argv, int invert, unsigned int *flags,
-                        const void *entry, struct xt_entry_match **match)
-{
-       struct xt_rateinfo *r = (struct xt_rateinfo *)(*match)->data;
-       uintmax_t num;
-
-       switch (c) {
-       case ARG_LIMIT:
-               EBT_CHECK_OPTION(flags, FLAG_LIMIT);
-               if (invert)
-                       xtables_error(PARAMETER_PROBLEM,
-                                     "Unexpected `!' after --limit");
-               if (!parse_rate(optarg, &r->avg))
-                       xtables_error(PARAMETER_PROBLEM,
-                                     "bad rate `%s'", optarg);
-               break;
-       case ARG_LIMIT_BURST:
-               EBT_CHECK_OPTION(flags, FLAG_LIMIT_BURST);
-               if (invert)
-                       xtables_error(PARAMETER_PROBLEM,
-                                     "Unexpected `!' after --limit-burst");
-               if (!xtables_strtoul(optarg, NULL, &num, 0, 10000))
-                       xtables_error(PARAMETER_PROBLEM,
-                                     "bad --limit-burst `%s'", optarg);
-               r->burst = num;
-               break;
-       default:
-               return 0;
-       }
-
-       return 1;
-}
-
 static void brlimit_print(const void *ip, const struct xt_entry_match *match,
                          int numeric)
 {
@@ -250,13 +211,6 @@ static void brlimit_print(const void *ip, const struct xt_entry_match *match,
        printf(" --limit-burst %u ", r->burst);
 }
 
-static const struct option brlimit_opts[] =
-{
-       { .name = "limit",      .has_arg = true,        .val = ARG_LIMIT },
-       { .name = "limit-burst",.has_arg = true,        .val = ARG_LIMIT_BURST },
-       XT_GETOPT_TABLEEND,
-};
-
 static struct xtables_match limit_match[] = {
        {
                .family         = NFPROTO_UNSPEC,
@@ -280,9 +234,9 @@ static struct xtables_match limit_match[] = {
                .userspacesize  = offsetof(struct xt_rateinfo, prev),
                .help           = limit_help,
                .init           = limit_init,
-               .parse          = brlimit_parse,
+               .x6_parse       = limit_parse,
                .print          = brlimit_print,
-               .extra_opts     = brlimit_opts,
+               .x6_options     = limit_opts,
                .xlate          = limit_xlate_eb,
        },
 };