git: 07baf5f27e52 - stable/13 - pf tests: Test clearing rules counters

Kristof Provost kp at FreeBSD.org
Fri May 7 15:25:57 UTC 2021


The branch stable/13 has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=07baf5f27e527e4e74b106cb966a61cf63a895ef

commit 07baf5f27e527e4e74b106cb966a61cf63a895ef
Author:     Kristof Provost <kp at FreeBSD.org>
AuthorDate: 2021-04-12 15:29:19 +0000
Commit:     Kristof Provost <kp at FreeBSD.org>
CommitDate: 2021-05-07 08:15:43 +0000

    pf tests: Test clearing rules counters
    
    This was briefly broken, so ensure that we can read and clear rules
    counters.
    
    MFC after:      4 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
    Differential Revision:  https://reviews.freebsd.org/D29728
    
    (cherry picked from commit 112f007e12818ba3d54869b331139090e69dbc74)
---
 tests/sys/netpfil/pf/Makefile         |  1 +
 tests/sys/netpfil/pf/rules_counter.sh | 79 +++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+)

diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile
index ea9d71610c77..e422da3b9e3d 100644
--- a/tests/sys/netpfil/pf/Makefile
+++ b/tests/sys/netpfil/pf/Makefile
@@ -18,6 +18,7 @@ ATF_TESTS_SH+=	anchor \
 		pfsync	\
 		rdr \
 		route_to \
+		rules_counter \
 		set_skip \
 		set_tos \
 		src_track \
diff --git a/tests/sys/netpfil/pf/rules_counter.sh b/tests/sys/netpfil/pf/rules_counter.sh
new file mode 100644
index 000000000000..56dc159f49c8
--- /dev/null
+++ b/tests/sys/netpfil/pf/rules_counter.sh
@@ -0,0 +1,79 @@
+# $FreeBSD$
+#
+# SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+#
+# Copyright (c) 2021 Rubicon Communications, LLC (Netgate)
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+. $(atf_get_srcdir)/utils.subr
+
+atf_test_case "get_clear" "cleanup"
+get_clear_head()
+{
+	atf_set descr 'Test clearing rules counters on get rules'
+	atf_set require.user root
+}
+
+get_clear_body()
+{
+	pft_init
+
+	epair_send=$(vnet_mkepair)
+	ifconfig ${epair_send}a 192.0.2.1/24 up
+
+	vnet_mkjail alcatraz ${epair_send}b
+	jexec alcatraz ifconfig ${epair_send}b 192.0.2.2/24 up
+	jexec alcatraz pfctl -e
+
+	pft_set_rules alcatraz \
+		"pass all"
+
+	# Ensure the rule matched packets, so we can verify non-zero counters
+	atf_check -s exit:0 -o ignore ping -c 3 192.0.2.2
+
+	# Expect non-zero counters
+	atf_check -s exit:0 -e ignore \
+	    -o match:'Evaluations: [1-9][0-9]*[[:space:]]*Packets: [1-9][0-9]*[[:space:]]*Bytes: [1-9][0-9]*[[:space:]]*' \
+	    jexec alcatraz pfctl -s r -v
+
+	# We should still see non-zero because we didn't clear on the last
+	# pfctl, but are going to clear now
+	atf_check -s exit:0 -e ignore \
+	    -o match:'Evaluations: [1-9][0-9]*[[:space:]]*Packets: [1-9][0-9]*[[:space:]]*Bytes: [1-9][0-9]*[[:space:]]*' \
+	    jexec alcatraz pfctl -s r -v -z
+
+	# Expect zero counters
+	atf_check -s exit:0 -e ignore \
+	    -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \
+	    jexec alcatraz pfctl -s r -v
+}
+
+get_clear_cleanup()
+{
+	pft_cleanup
+}
+
+atf_init_test_cases()
+{
+	atf_add_test_case "get_clear"
+}


More information about the dev-commits-src-all mailing list