]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
ebtables: Make 'h' case just a call to print_help()
authorPhil Sutter <phil@nwl.cc>
Fri, 24 Nov 2023 19:22:44 +0000 (20:22 +0100)
committerPhil Sutter <phil@nwl.cc>
Tue, 5 Dec 2023 15:35:37 +0000 (16:35 +0100)
Move the special ebtables help parameter handling into its print_help()
function to prepare for it turning into a callback. Add new field 'argc'
to struct iptables_command_state to make this possible. It is actually
kind of consistent as it holds 'argv' already.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/xshared.h
iptables/xtables-eb.c

index 68acfb4b406fba2023a2b29b73f584d608490705..de32198fa0b67b33e5ec3e93a2c877803ca118b3 100644 (file)
@@ -137,6 +137,7 @@ struct iptables_command_state {
        char *protocol;
        int proto_used;
        const char *jumpto;
+       int argc;
        char **argv;
        bool restore;
 };
index 017e1ad3648402cff166743811ea01f4f0b27bac..8ab479237faa85664fe1eff81650e6142d6dcafe 100644 (file)
@@ -308,6 +308,33 @@ static void print_help(struct iptables_command_state *cs)
        const struct xtables_rule_match *m = cs->matches;
        struct xtables_target *t = cs->target;
 
+       while (optind < cs->argc) {
+               /*struct ebt_u_match *m;
+               struct ebt_u_watcher *w;*/
+
+               if (!strcasecmp("list_extensions", cs->argv[optind])) {
+                       ebt_list_extensions(xtables_targets, cs->matches);
+                       exit(0);
+               }
+               /*if ((m = ebt_find_match(cs->argv[optind])))
+                       ebt_add_match(new_entry, m);
+               else if ((w = ebt_find_watcher(cs->argv[optind])))
+                       ebt_add_watcher(new_entry, w);
+               else {*/
+                       if (!(t = xtables_find_target(cs->argv[optind],
+                                                     XTF_TRY_LOAD)))
+                               xtables_error(PARAMETER_PROBLEM,
+                                             "Extension '%s' not found",
+                                             cs->argv[optind]);
+                       if (cs->options & OPT_JUMP)
+                               xtables_error(PARAMETER_PROBLEM,
+                                             "Sorry, you can only see help for one target extension at a time");
+                       cs->options |= OPT_JUMP;
+                       cs->target = t;
+               //}
+               optind++;
+       }
+
        printf("%s %s\n", prog_name, prog_vers);
        printf(
 "Usage:\n"
@@ -735,6 +762,7 @@ int do_commandeb(struct nft_handle *h, int argc, char *argv[], char **table,
        unsigned int flags = 0;
        struct xtables_target *t;
        struct iptables_command_state cs = {
+               .argc = argc,
                .argv = argv,
                .jumpto = "",
                .eb.bitmask = EBT_NOPROTO,
@@ -897,32 +925,8 @@ print_zero:
                        if (OPT_COMMANDS)
                                xtables_error(PARAMETER_PROBLEM,
                                              "Multiple commands are not allowed");
-                       command = 'h';
-
-                       /* All other arguments should be extension names */
-                       while (optind < argc) {
-                               /*struct ebt_u_match *m;
-                               struct ebt_u_watcher *w;*/
-
-                               if (!strcasecmp("list_extensions", argv[optind])) {
-                                       ebt_list_extensions(xtables_targets, cs.matches);
-                                       exit(0);
-                               }
-                               /*if ((m = ebt_find_match(argv[optind])))
-                                       ebt_add_match(new_entry, m);
-                               else if ((w = ebt_find_watcher(argv[optind])))
-                                       ebt_add_watcher(new_entry, w);
-                               else {*/
-                                       if (!(t = xtables_find_target(argv[optind], XTF_TRY_LOAD)))
-                                               xtables_error(PARAMETER_PROBLEM,"Extension '%s' not found", argv[optind]);
-                                       if (flags & OPT_JUMP)
-                                               xtables_error(PARAMETER_PROBLEM,"Sorry, you can only see help for one target extension at a time");
-                                       flags |= OPT_JUMP;
-                                       cs.target = t;
-                               //}
-                               optind++;
-                       }
-                       break;
+                       print_help(&cs);
+                       exit(0);
                case 't': /* Table */
                        if (restore && table_set)
                                xtables_error(PARAMETER_PROBLEM,
@@ -1142,11 +1146,6 @@ print_zero:
        if (!(table = ebt_find_table(replace->name)))
                ebt_print_error2("Bad table name");*/
 
-       if (command == 'h' && !(flags & OPT_ZERO)) {
-               print_help(&cs);
-               ret = 1;
-       }
-
        /* Do the final checks */
        if (command == 'A' || command == 'I' ||
            command == 'D' || command == 'C' || command == 14) {