git: 025df3e6a0c3 - main - pf tests: test keepcounters when we exceed 32 bits

From: Kristof Provost <kp_at_FreeBSD.org>
Date: Fri, 21 Jun 2024 11:49:33 UTC
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=025df3e6a0c3a4477dd55153543f395bc018dd37

commit 025df3e6a0c3a4477dd55153543f395bc018dd37
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2024-06-10 10:11:02 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2024-06-21 11:49:17 +0000

    pf tests: test keepcounters when we exceed 32 bits
    
    Ensure that we correctly transfer byte counts if the value exceeds what can be
    stored in a single 32-bit counter.
    
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 tests/sys/netpfil/pf/rules_counter.sh | 49 +++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/tests/sys/netpfil/pf/rules_counter.sh b/tests/sys/netpfil/pf/rules_counter.sh
index 962e7c93ba93..98f96a7adca1 100644
--- a/tests/sys/netpfil/pf/rules_counter.sh
+++ b/tests/sys/netpfil/pf/rules_counter.sh
@@ -148,6 +148,54 @@ keepcounters_body()
 	    jexec alcatraz pfctl -s r -v
 }
 
+atf_test_case "4G" "cleanup"
+4G_head()
+{
+	atf_set descr 'Test keepcounter for values above 32 bits'
+	atf_set require.user root
+}
+
+4G_body()
+{
+	pft_init
+
+	epair=$(vnet_mkepair)
+	ifconfig ${epair}a 192.0.2.1/24 up
+
+	vnet_mkjail alcatraz ${epair}b
+	jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up
+	jexec alcatraz nc -l 1234 >/dev/null &
+
+	jexec alcatraz pfctl -e
+	pft_set_rules alcatraz \
+		"pass all"
+
+	# Now pass more than 4GB of data
+	dd if=/dev/zero bs=1k count=4M | nc -N 192.0.2.2 1234
+
+	bytes=$(jexec alcatraz pfctl -s r -v | awk '/Bytes:/ { print $7; }')
+	if [ $bytes -lt 4000000000 ];
+	then
+		atf_fail "Expected to see > 4GB"
+	fi
+
+	# Set new rules, keeping counters
+	pft_set_rules noflush alcatraz \
+		"set keepcounters" \
+		"pass all"
+
+	bytes=$(jexec alcatraz pfctl -s r -v | awk '/Bytes:/ { print $7; }')
+	if [ $bytes -lt 4000000000 ];
+	then
+		atf_fail "Expected to see > 4GB after rule reload"
+	fi
+}
+
+4G_cleanup()
+{
+	pft_cleanup
+}
+
 keepcounters_cleanup()
 {
 	pft_cleanup
@@ -157,4 +205,5 @@ atf_init_test_cases()
 {
 	atf_add_test_case "get_clear"
 	atf_add_test_case "keepcounters"
+	atf_add_test_case "4G"
 }