From 528cbf99ff6062420270e637df4d40a77514fe56 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 7 Aug 2018 12:29:35 +0200 Subject: xtables: Fix for wrong counter format in -S output Legacy iptables uses '-c PCNT BCNT' format in listed rules, nft-variant used '[PCNT BCNT]' prefix like with iptables-save. In order to pass the counter format preference along, FMT_C_COUNTS is introduced and related 'format' checks adjusted. Since legacy iptables prints the counters between matches and target, this change affects save_matches_and_target() function. In order to get access to the rule counters, it's declaration is adjusted to receive iptables_command_state pointer instead of match, target and jumpto pointers from the same object. While being at it, integrate jump to user-defined chain into it as well since the related code in both callers was almost identical. Though since different rule flags are used between iptables and ip6tables, pass a 'goto_flag' boolean instead of the actual 'flags' bitfield. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- .../shell/testcases/iptables/0003-list-rules_0 | 48 ++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 iptables/tests/shell/testcases/iptables/0003-list-rules_0 (limited to 'iptables/tests') diff --git a/iptables/tests/shell/testcases/iptables/0003-list-rules_0 b/iptables/tests/shell/testcases/iptables/0003-list-rules_0 new file mode 100755 index 00000000..2e87ce5a --- /dev/null +++ b/iptables/tests/shell/testcases/iptables/0003-list-rules_0 @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +$XT_MULTI iptables -N foo +$XT_MULTI iptables -A FORWARD -i eth23 -o eth42 -j ACCEPT +$XT_MULTI iptables -A FORWARD -i eth42 -o eth23 -g foo +$XT_MULTI iptables -t nat -A OUTPUT -o eth123 -m mark --mark 0x42 -j ACCEPT + +EXPECT='-P INPUT ACCEPT +-P FORWARD ACCEPT +-P OUTPUT ACCEPT +-N foo +-A FORWARD -i eth23 -o eth42 -j ACCEPT +-A FORWARD -i eth42 -o eth23 -g foo' + +diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -S) + +EXPECT='-P INPUT ACCEPT -c 0 0 +-P FORWARD ACCEPT -c 0 0 +-P OUTPUT ACCEPT -c 0 0 +-N foo +-A FORWARD -i eth23 -o eth42 -c 0 0 -j ACCEPT +-A FORWARD -i eth42 -o eth23 -c 0 0 -g foo' + +diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -v -S) + +EXPECT='-P FORWARD ACCEPT +-A FORWARD -i eth23 -o eth42 -j ACCEPT +-A FORWARD -i eth42 -o eth23 -g foo' + +diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -S FORWARD) + +EXPECT='-P FORWARD ACCEPT -c 0 0 +-A FORWARD -i eth23 -o eth42 -c 0 0 -j ACCEPT +-A FORWARD -i eth42 -o eth23 -c 0 0 -g foo' + +diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -v -S FORWARD) + +EXPECT='-P OUTPUT ACCEPT +-A OUTPUT -o eth123 -m mark --mark 0x42 -j ACCEPT' + +diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -t nat -S OUTPUT) + +EXPECT='-P OUTPUT ACCEPT -c 0 0 +-A OUTPUT -o eth123 -m mark --mark 0x42 -c 0 0 -j ACCEPT' + +diff -u -Z <(echo -e "$EXPECT") <($XT_MULTI iptables -v -t nat -S OUTPUT) -- cgit v1.2.3