From 5f1fcacebf9b4529950b6e3f88327049a0ea7cd2 Mon Sep 17 00:00:00 2001 From: Florian Westphal Date: Wed, 24 Feb 2021 11:08:02 +0100 Subject: iptables-nft: fix -Z option it zeroes the rule counters, so it needs fully populated cache. Add a test case to cover this. Fixes: 9d07514ac5c7a ("nft: calculate cache requirements from list of commands") Signed-off-by: Florian Westphal Acked-by: Phil Sutter --- iptables/nft-cmd.c | 2 +- .../shell/testcases/iptables/0007-zero-counters_0 | 64 ++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100755 iptables/tests/shell/testcases/iptables/0007-zero-counters_0 (limited to 'iptables') diff --git a/iptables/nft-cmd.c b/iptables/nft-cmd.c index 5d33f1f0..f2b935c5 100644 --- a/iptables/nft-cmd.c +++ b/iptables/nft-cmd.c @@ -185,7 +185,7 @@ int nft_cmd_chain_zero_counters(struct nft_handle *h, const char *chain, if (!cmd) return 0; - nft_cache_level_set(h, NFT_CL_CHAINS, cmd); + nft_cache_level_set(h, NFT_CL_RULES, cmd); return 1; } diff --git a/iptables/tests/shell/testcases/iptables/0007-zero-counters_0 b/iptables/tests/shell/testcases/iptables/0007-zero-counters_0 new file mode 100755 index 00000000..36da1907 --- /dev/null +++ b/iptables/tests/shell/testcases/iptables/0007-zero-counters_0 @@ -0,0 +1,64 @@ +#!/bin/bash + +RC=0 +COUNTR=$RANDOM$RANDOM + +$XT_MULTI iptables-restore -c <