]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
main: Refer to nft_options in nft_options_check()
authorPhil Sutter <phil@nwl.cc>
Sat, 2 Dec 2023 10:10:34 +0000 (11:10 +0100)
committerFlorian Westphal <fw@strlen.de>
Sun, 3 Dec 2023 11:26:48 +0000 (12:26 +0100)
Consult the array when determining whether a given option is followed by
an argument or not instead of hard-coding those that do. The array holds
both short and long option name, so one extra pitfall removed.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
src/main.c

index c3c7fe23baa37fa0c94ba5ecbfeaaf82b9e1fe38..d3491cda7f8db164a31f1584caa5a4aad03d55b2 100644 (file)
@@ -325,6 +325,7 @@ static bool nft_options_check(int argc, char * const argv[])
 {
        bool skip = false, nonoption = false;
        int pos = 0, i;
+       size_t j;
 
        for (i = 1; i < argc; i++) {
                pos += strlen(argv[i - 1]) + 1;
@@ -341,16 +342,14 @@ static bool nft_options_check(int argc, char * const argv[])
                        nft_options_error(argc, argv, pos);
                        return false;
                }
-               if (argv[i][1] == 'd' ||
-                   argv[i][1] == 'I' ||
-                   argv[i][1] == 'f' ||
-                   argv[i][1] == 'D' ||
-                   !strcmp(argv[i], "--debug") ||
-                   !strcmp(argv[i], "--includepath") ||
-                   !strcmp(argv[i], "--define") ||
-                   !strcmp(argv[i], "--file")) {
-                       skip = true;
-                       continue;
+               for (j = 0; j < NR_NFT_OPTIONS; j++) {
+                       if (nft_options[j].arg &&
+                           (argv[i][1] == (char)nft_options[j].val ||
+                            (argv[i][1] == '-' &&
+                             !strcmp(argv[i] + 2, nft_options[j].name)))) {
+                               skip = true;
+                               break;
+                       }
                }
        }