]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables: Pull table validity check out of do_parse()
authorPhil Sutter <phil@nwl.cc>
Fri, 26 Nov 2021 14:53:14 +0000 (15:53 +0100)
committerPhil Sutter <phil@nwl.cc>
Wed, 12 Jan 2022 13:04:52 +0000 (14:04 +0100)
Makes do_parse() more generic, error codes don't change so this should
be safe.

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

index 5c48bd94644f32c07c24f9535a632ff1e18eae7b..ac864eb24a35ea39545bb08e8fa6c5604193b2e4 100644 (file)
@@ -514,10 +514,6 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
                                xtables_error(PARAMETER_PROBLEM,
                                              "The -t option cannot be used in %s.\n",
                                              xt_params->program_name);
-                       if (!nft_table_builtin_find(h, optarg))
-                               xtables_error(VERSION_PROBLEM,
-                                             "table '%s' does not exist",
-                                             optarg);
                        p->table = optarg;
                        table_set = true;
                        break;
@@ -720,6 +716,10 @@ int do_commandx(struct nft_handle *h, int argc, char *argv[], char **table,
 
        do_parse(h, argc, argv, &p, &cs, &args);
 
+       if (!nft_table_builtin_find(h, p.table))
+               xtables_error(VERSION_PROBLEM,
+                             "table '%s' does not exist",
+                             p.table);
        switch (p.command) {
        case CMD_APPEND:
                ret = h->ops->add_entry(h, p.chain, p.table, &cs, &args,