]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
xt: Fix fallback printing for extensions matching keywords
authorPhil Sutter <phil@nwl.cc>
Thu, 9 Mar 2023 13:31:31 +0000 (14:31 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 2 Nov 2023 10:56:19 +0000 (11:56 +0100)
commit aef5330fe7827f760b70d5d27010445c3adb3d3c upstream.

Yet another Bison workaround: Instead of the fancy error message, an
incomprehensible syntax error is emitted:

| # iptables-nft -A FORWARD -p tcp -m osf --genre linux
| # nft list ruleset | nft -f -
| # Warning: table ip filter is managed by iptables-nft, do not touch!
| /dev/stdin:4:29-31: Error: syntax error, unexpected osf, expecting string
|  meta l4proto tcp xt match osf counter packets 0 bytes 0
|                            ^^^

Avoid this by quoting the extension name when printing:

| # nft list ruleset | sudo ./src/nft -f -
| # Warning: table ip filter is managed by iptables-nft, do not touch!
| /dev/stdin:4:20-33: Error: unsupported xtables compat expression, use iptables-nft with this ruleset
|  meta l4proto tcp xt match "osf" counter packets 0 bytes 0
|                   ^^^^^^^^^^^^^^

Fixes: 79195a8cc9e9d ("xt: Rewrite unsupported compat expression dumping")
Fixes: e41c53ca5b043 ("xt: Fall back to generic printing from translation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
src/parser_bison.y
src/xt.c

index 47a9ccf3c94a44d5958710a27789a45b8f37bdda..eaebaa50191bc1b3c5234cea80c8bfb971ea007c 100644 (file)
@@ -2888,7 +2888,7 @@ stmt                      :       verdict_stmt
                        |       xt_stmt         close_scope_xt
                        ;
 
-xt_stmt                        :       XT      STRING  STRING
+xt_stmt                        :       XT      STRING  string
                        {
                                $$ = NULL;
                                xfree($2);
index b75c94e856ca74ea38b67e47f18b3b1c525d9777..31cf40e0a20d3503a22396ddef5f2c52e838486f 100644 (file)
--- a/src/xt.c
+++ b/src/xt.c
@@ -116,7 +116,7 @@ void xt_stmt_xlate(const struct stmt *stmt, struct output_ctx *octx)
        xfree(entry);
 #endif
        if (!rc)
-               nft_print(octx, "xt %s %s",
+               nft_print(octx, "xt %s \"%s\"",
                          typename[stmt->xt.type], stmt->xt.name);
 }