Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Apr 2021 11:36:35 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 112f007e1281 - main - pf tests: Test clearing rules counters
Message-ID:  <202104141136.13EBaZxn098642@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=112f007e12818ba3d54869b331139090e69dbc74

commit 112f007e12818ba3d54869b331139090e69dbc74
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-04-12 15:29:19 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-04-14 11:33:02 +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
---
 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 86b85df8e18d..5cf11da76faf 100644
--- a/tests/sys/netpfil/pf/Makefile
+++ b/tests/sys/netpfil/pf/Makefile
@@ -19,6 +19,7 @@ ATF_TESTS_SH+=	altq \
 		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"
+}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104141136.13EBaZxn098642>