All of lore.kernel.org
 help / color / mirror / Atom feed
* [nft PATCH v2] parser_bison: Fix for broken compatibility with older dumps
@ 2023-10-19 16:41 Phil Sutter
  2023-10-19 23:38 ` Phil Sutter
  0 siblings, 1 reply; 2+ messages in thread
From: Phil Sutter @ 2023-10-19 16:41 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

Commit e6d1d0d611958 ("src: add set element multi-statement
support") changed the order of expressions and other state attached to set
elements are expected in input. This broke parsing of ruleset dumps
created by nft commands prior to that commit.

Restore compatibility by also accepting the old ordering.

Fixes: e6d1d0d611958 ("src: add set element multi-statement support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Changes since v1:
- Fix author email address to match SoB.
---
 src/parser_bison.y                            |  6 ++++
 tests/shell/testcases/sets/elem_opts_compat_0 | 29 +++++++++++++++++++
 2 files changed, 35 insertions(+)
 create mode 100755 tests/shell/testcases/sets/elem_opts_compat_0

diff --git a/src/parser_bison.y b/src/parser_bison.y
index c517dc38b37d6..f0652ba651c68 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -4523,6 +4523,12 @@ meter_key_expr_alloc	:	concat_expr
 
 set_elem_expr		:	set_elem_expr_alloc
 			|	set_elem_expr_alloc		set_elem_expr_options
+			|	set_elem_expr_alloc		set_elem_expr_options	set_elem_stmt_list
+			{
+				$$ = $1;
+				list_splice_tail($3, &$$->stmt_list);
+				xfree($3);
+			}
 			;
 
 set_elem_key_expr	:	set_lhs_expr		{ $$ = $1; }
diff --git a/tests/shell/testcases/sets/elem_opts_compat_0 b/tests/shell/testcases/sets/elem_opts_compat_0
new file mode 100755
index 0000000000000..e0129536fcb7a
--- /dev/null
+++ b/tests/shell/testcases/sets/elem_opts_compat_0
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# ordering of element options and expressions has changed, make sure parser
+# accepts both ways
+
+set -e
+
+$NFT -f - <<EOF
+table t {
+	set s {
+		type inet_service
+		counter;
+		timeout 30s;
+	}
+}
+EOF
+
+check() {
+	out=$($NFT list ruleset)
+	secs=$(sed -n 's/.*expires \([0-9]\+\)s.*/\1/p' <<< "$out")
+	[[ $secs -lt 11 ]]
+	grep -q 'counter packets 10 bytes 20' <<< "$out"
+}
+
+$NFT add element t s '{ 23 counter packets 10 bytes 20 expires 10s }'
+check
+$NFT flush set t s
+$NFT add element t s '{ 42 expires 10s counter packets 10 bytes 20 }'
+check
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [nft PATCH v2] parser_bison: Fix for broken compatibility with older dumps
  2023-10-19 16:41 [nft PATCH v2] parser_bison: Fix for broken compatibility with older dumps Phil Sutter
@ 2023-10-19 23:38 ` Phil Sutter
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Sutter @ 2023-10-19 23:38 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Thu, Oct 19, 2023 at 06:41:34PM +0200, Phil Sutter wrote:
> Commit e6d1d0d611958 ("src: add set element multi-statement
> support") changed the order of expressions and other state attached to set
> elements are expected in input. This broke parsing of ruleset dumps
> created by nft commands prior to that commit.
> 
> Restore compatibility by also accepting the old ordering.
> 
> Fixes: e6d1d0d611958 ("src: add set element multi-statement support")
> Signed-off-by: Phil Sutter <phil@nwl.cc>

Patch applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-10-19 23:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-19 16:41 [nft PATCH v2] parser_bison: Fix for broken compatibility with older dumps Phil Sutter
2023-10-19 23:38 ` Phil Sutter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.