]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cmd: incorrect error reporting when table declaration exists
authorPablo Neira Ayuso <pablo@netfilter.org>
Tue, 29 Jun 2021 12:36:18 +0000 (14:36 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Tue, 29 Jun 2021 12:44:01 +0000 (14:44 +0200)
This example ruleset is missing the chain declaration:

 add table x
 add set x y { typeof ip saddr ; }
 add rule x y counter

After this patch, error reporting provides suggestions for the missing
chain:

 # nft -f ruleset.nft
 ruleset.nft:3:12-12: Error: No such file or directory; did you mean chain ‘INPUT’ in table ip ‘filter’?
 add rule x y counter
            ^

Before this patch, it incorrectly refers to the table:

 ruleset.nft:3:10-10: Error: No such file or directory; did you mean table ‘filter’ in family ip?
 add rule x y counter
          ^

This patch invalidates the table that is found via fuzzy lookup if it
exists in the cache.

Fixes: 0276c2fee939 ("cmd: check for table mismatch first in error reporting")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/cmd.c

index 8d4bf8bc13aa95fe4d690f9d9bd628f5000f4f57..d956919b6b5e55f7f1421f40ce3f407b791b3fec 100644 (file)
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -30,6 +30,10 @@ static int nft_cmd_enoent_table(struct netlink_ctx *ctx, const struct cmd *cmd,
 static int table_fuzzy_check(struct netlink_ctx *ctx, const struct cmd *cmd,
                             const struct table *table)
 {
+       if (table_cache_find(&ctx->nft->cache.table_cache,
+                            cmd->handle.table.name, cmd->handle.family))
+               return 0;
+
        if (strcmp(cmd->handle.table.name, table->handle.table.name) ||
            cmd->handle.family != table->handle.family) {
                netlink_io_error(ctx, &cmd->handle.table.location,