From owner-dev-commits-src-branches@freebsd.org Tue May 11 15:06:47 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0362463AC9A; Tue, 11 May 2021 15:06:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Ffh8k5LDDz4Sg0; Tue, 11 May 2021 15:06:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9D37D1A2B5; Tue, 11 May 2021 15:06:46 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14BF6klf049460; Tue, 11 May 2021 15:06:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14BF6kem049455; Tue, 11 May 2021 15:06:46 GMT (envelope-from git) Date: Tue, 11 May 2021 15:06:46 GMT Message-Id: <202105111506.14BF6kem049455@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Kristof Provost Subject: git: 6790b1257b63 - stable/12 - pf tests: Test set keepcounters MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/stable/12 X-Git-Reftype: branch X-Git-Commit: 6790b1257b634ba212142d3c8968e1f2fbe08fa5 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 11 May 2021 15:06:47 -0000 The branch stable/12 has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=6790b1257b634ba212142d3c8968e1f2fbe08fa5 commit 6790b1257b634ba212142d3c8968e1f2fbe08fa5 Author: Kristof Provost AuthorDate: 2021-04-15 14:53:16 +0000 Commit: Kristof Provost CommitDate: 2021-05-11 08:28:33 +0000 pf tests: Test set keepcounters MFC after: 4 weeks Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D29781 (cherry picked from commit e14d56f370184fdf7ef33ec57883a45f4a220cff) --- tests/sys/netpfil/pf/rules_counter.sh | 82 +++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/sys/netpfil/pf/rules_counter.sh b/tests/sys/netpfil/pf/rules_counter.sh index 56dc159f49c8..567bf439b0ef 100644 --- a/tests/sys/netpfil/pf/rules_counter.sh +++ b/tests/sys/netpfil/pf/rules_counter.sh @@ -73,7 +73,89 @@ get_clear_cleanup() pft_cleanup } +atf_test_case "keepcounters" "cleanup" +keepcounters_head() +{ + atf_set descr 'Test keepcounter functionality' + atf_set require.user root +} + +keepcounters_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" + + # 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 + + # 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 + + # As we set the (same) rules again we'd expect the counters to return + # to zero + pft_set_rules noflush alcatraz \ + "pass all" + + atf_check -s exit:0 -e ignore \ + -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \ + jexec alcatraz pfctl -s r -v + + # Increment rule counters + atf_check -s exit:0 -o ignore ping -c 3 192.0.2.2 + + # Now set new rules with 'keepcounters' set, so we'd expect nonzero + # counters + pft_set_rules noflush alcatraz \ + "set keepcounters" \ + "pass all" + + 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 + + # However, if we set a different rule it should return to zero + pft_set_rules noflush alcatraz \ + "set keepcounters" \ + "pass inet all" + + atf_check -s exit:0 -e ignore \ + -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \ + jexec alcatraz pfctl -s r -v + + # If we generate traffic and don't set keepcounters we also see zero + # counts when setting new rules + atf_check -s exit:0 -o ignore ping -c 3 192.0.2.2 + pft_set_rules noflush alcatraz \ + "pass inet all" + + atf_check -s exit:0 -e ignore \ + -o match:'Evaluations: 0[[:space:]]*Packets: 0*[[:space:]]*Bytes: 0*[[:space:]]*' \ + jexec alcatraz pfctl -s r -v +} + +keepcounters_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "get_clear" + atf_add_test_case "keepcounters" }