Skip to contentSkip to conversation

cache: fix --echo with index/position

PATCH Applied Eric Garver 2 participants 4 messages Sep 6, 2019 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 cache: fix --echo with index/position

Always call evaluate_cache_add() so it can set special flags - in this case NFT_CACHE_UPDATE.

Fixes 01e5c6f0ed03 ("src: add cache level flags")
---
 src/cache.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
src/cache.c +2 -4
index cffcbb623ced..a778650ac133 100644
@@ -104,11 +104,9 @@ unsigned int cache_evaluate(struct nft_ctx *nft, struct list_head *cmds)
 		case CMD_ADD:
 		case CMD_INSERT:
 		case CMD_CREATE:
-			if (nft_output_echo(&nft->output)) {
-				flags = NFT_CACHE_FULL;
-				break;
-			}
 			flags = evaluate_cache_add(cmd, flags);
+			if (nft_output_echo(&nft->output))
+				flags |= NFT_CACHE_FULL;
 			break;
 		case CMD_REPLACE:
 			flags = NFT_CACHE_FULL;
Signature · 1 line
2.20.1
#1 lore raw

PATCH 2/2 tests: shell: check that rule add with index works with echo

---
 tests/shell/testcases/cache/0007_echo_cache_init_0 | 14 ++++++++++++++
 .../cache/dumps/0007_echo_cache_init_0.nft         |  7 +++++++
 2 files changed, 21 insertions(+)
 create mode 100755 tests/shell/testcases/cache/0007_echo_cache_init_0
 create mode 100644 tests/shell/testcases/cache/dumps/0007_echo_cache_init_0.nft
tests/shell/testcases/cache/0007_echo_cache_init_0 new file +14 -0
new file mode 100755
index 000000000000..280a0d06bdc3
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+set -e
+
+$NFT -i >/dev/null <<EOF
+add table inet t
+add chain inet t c
+add rule inet t c accept comment "first"
+add rule inet t c accept comment "third"
+EOF
+
+# make sure the rule cache gets initialized when using echo option
+#
+$NFT --echo add rule inet t c index 0 accept comment '"second"' >/dev/null
tests/shell/testcases/cache/dumps/0007_echo_cache_init_0.nft new file +7 -0
new file mode 100644
index 000000000000..c774ee72a683
@@ -0,0 +1,7 @@
+table inet t {
+	chain c {
+		accept comment "first"
+		accept comment "second"
+		accept comment "third"
+	}
+}
Signature · 1 line
2.20.1
#2 lore raw

Re: [PATCH 2/2] tests: shell: check that rule add with index works with echo

Also applied, thanks.