From 43a87268372a2d2da1ec0d95cee60da0a6f83bff Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 22 Jul 2019 12:16:19 +0200 Subject: ebtables-save: Fix counter formatting The initial problem was 'ebtables-save -c' printing iptables-style counters but at the same time not disabling ebtables-style counter output (which was even printed in wrong format for ebtables-save). The code around counter output was complicated enough to motivate a larger rework: * Make FMT_C_COUNTS indicate the appended counter style for ebtables. * Use FMT_EBT_SAVE to distinguish between '-c' style counters and the legacy pcnt/bcnt ones. Consequently, ebtables-save sets format to: FMT_NOCOUNTS - for no counters FMT_EBT_SAVE - for iptables-style counters FMT_EBT_SAVE | FMT_C_COUNTS - for '-c' style counters For regular ebtables, list_rules() always sets FMT_C_COUNTS (iptables-style counters are never used there) and FMT_NOCOUNTS if no counters are requested. The big plus is if neither FMT_NOCOUNTS nor FMT_C_COUNTS is set, iptables-style counters are to be printed - both in iptables and ebtables. This allows to drop the ebtables-specific 'save_counters' callback. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- .../shell/testcases/ebtables/0004-save-counters_0 | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 iptables/tests/shell/testcases/ebtables/0004-save-counters_0 (limited to 'iptables/tests') diff --git a/iptables/tests/shell/testcases/ebtables/0004-save-counters_0 b/iptables/tests/shell/testcases/ebtables/0004-save-counters_0 new file mode 100755 index 00000000..8348dc7e --- /dev/null +++ b/iptables/tests/shell/testcases/ebtables/0004-save-counters_0 @@ -0,0 +1,67 @@ +#!/bin/bash + +set -e + +# there is no legacy backend to test +[[ $XT_MULTI == */xtables-nft-multi ]] || { echo "skip $XT_MULTI"; exit 0; } + +$XT_MULTI ebtables --init-table +$XT_MULTI ebtables -A FORWARD -i nodev123 -o nodev432 -j ACCEPT +$XT_MULTI ebtables -A FORWARD -i nodev432 -o nodev123 -j ACCEPT + +EXPECT='Bridge table: filter + +Bridge chain: FORWARD, entries: 2, policy: ACCEPT +-i nodev123 -o nodev432 -j ACCEPT +-i nodev432 -o nodev123 -j ACCEPT' + +echo "ebtables -L FORWARD" +diff -u <(echo -e "$EXPECT") <($XT_MULTI ebtables -L FORWARD) + +EXPECT='Bridge table: filter + +Bridge chain: FORWARD, entries: 2, policy: ACCEPT +-i nodev123 -o nodev432 -j ACCEPT , pcnt = 0 -- bcnt = 0 +-i nodev432 -o nodev123 -j ACCEPT , pcnt = 0 -- bcnt = 0' + +echo "ebtables -L FORWARD --Lc" +diff -u <(echo -e "$EXPECT") <($XT_MULTI ebtables -L FORWARD --Lc) + +EXPECT='*filter +:INPUT ACCEPT +:FORWARD ACCEPT +:OUTPUT ACCEPT +-A FORWARD -i nodev123 -o nodev432 -j ACCEPT +-A FORWARD -i nodev432 -o nodev123 -j ACCEPT +' + +echo "ebtables-save" +diff -u <(echo -e "$EXPECT") <($XT_MULTI ebtables-save | grep -v '^#') + +EXPECT='*filter +:INPUT ACCEPT +:FORWARD ACCEPT +:OUTPUT ACCEPT +[0:0] -A FORWARD -i nodev123 -o nodev432 -j ACCEPT +[0:0] -A FORWARD -i nodev432 -o nodev123 -j ACCEPT +' + +echo "ebtables-save -c" +diff -u <(echo -e "$EXPECT") <($XT_MULTI ebtables-save -c | grep -v '^#') + +export EBTABLES_SAVE_COUNTER=yes + +# -c flag overrides EBTABLES_SAVE_COUNTER variable +echo "EBTABLES_SAVE_COUNTER=yes ebtables-save -c" +diff -u <(echo -e "$EXPECT") <($XT_MULTI ebtables-save -c | grep -v '^#') + +EXPECT='*filter +:INPUT ACCEPT +:FORWARD ACCEPT +:OUTPUT ACCEPT +-A FORWARD -i nodev123 -o nodev432 -j ACCEPT -c 0 0 +-A FORWARD -i nodev432 -o nodev123 -j ACCEPT -c 0 0 +' + +echo "EBTABLES_SAVE_COUNTER=yes ebtables-save" +diff -u <(echo -e "$EXPECT") <($XT_MULTI ebtables-save | grep -v '^#') -- cgit v1.2.3