1c849f533SKristof Provost# 2c849f533SKristof Provost# SPDX-License-Identifier: BSD-2-Clause 3c849f533SKristof Provost# 4c849f533SKristof Provost# Copyright (c) 2025 Kristof Provost <kp@FreeBSD.org> 5c849f533SKristof Provost# 6c849f533SKristof Provost# Redistribution and use in source and binary forms, with or without 7c849f533SKristof Provost# modification, are permitted provided that the following conditions 8c849f533SKristof Provost# are met: 9c849f533SKristof Provost# 1. Redistributions of source code must retain the above copyright 10c849f533SKristof Provost# notice, this list of conditions and the following disclaimer. 11c849f533SKristof Provost# 2. Redistributions in binary form must reproduce the above copyright 12c849f533SKristof Provost# notice, this list of conditions and the following disclaimer in the 13c849f533SKristof Provost# documentation and/or other materials provided with the distribution. 14c849f533SKristof Provost# 15c849f533SKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16c849f533SKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17c849f533SKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18c849f533SKristof Provost# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19c849f533SKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20c849f533SKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21c849f533SKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22c849f533SKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23c849f533SKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24c849f533SKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25c849f533SKristof Provost# SUCH DAMAGE. 26c849f533SKristof Provost 27c849f533SKristof Provost. $(atf_get_srcdir)/utils.subr 28c849f533SKristof Provost 29c849f533SKristof Provostatf_test_case "basic" "cleanup" 30c849f533SKristof Provostbasic_head() 31c849f533SKristof Provost{ 32c849f533SKristof Provost atf_set descr 'Basic pf_snmp test' 33c849f533SKristof Provost atf_set require.user root 34c849f533SKristof Provost} 35c849f533SKristof Provost 36c849f533SKristof Provostbasic_body() 37c849f533SKristof Provost{ 38c849f533SKristof Provost pft_init 39c849f533SKristof Provost 40c849f533SKristof Provost epair=$(vnet_mkepair) 41c849f533SKristof Provost 42c849f533SKristof Provost ifconfig ${epair}b 192.0.2.2/24 up 43c849f533SKristof Provost 44c849f533SKristof Provost vnet_mkjail alcatraz ${epair}a 45c849f533SKristof Provost jexec alcatraz ifconfig ${epair}a 192.0.2.1/24 up 46c849f533SKristof Provost 47c849f533SKristof Provost # Start bsnmpd 48c849f533SKristof Provost jexec alcatraz bsnmpd -c $(atf_get_srcdir)/bsnmpd.conf 49c849f533SKristof Provost 50c849f533SKristof Provost jexec alcatraz pfctl -e 51c849f533SKristof Provost pft_set_rules alcatraz \ 52c849f533SKristof Provost "pass" 53c849f533SKristof Provost 54c849f533SKristof Provost # Sanity check, and create state 55c849f533SKristof Provost atf_check -s exit:0 -o ignore \ 56c849f533SKristof Provost ping -c 1 192.0.2.1 57c849f533SKristof Provost 58c849f533SKristof Provost # pf should be enabled 59c849f533SKristof Provost atf_check -s exit:0 -o match:'pfStatusRunning.0 = true' \ 60c849f533SKristof Provost bsnmpwalk -s public@192.0.2.1 -i pf_tree.def begemot 61c849f533SKristof Provost} 62c849f533SKristof Provost 63c849f533SKristof Provostbasic_cleanup() 64c849f533SKristof Provost{ 65c849f533SKristof Provost pft_cleanup 66c849f533SKristof Provost} 67c849f533SKristof Provost 68*36586800SKristof Provostatf_test_case "table" "cleanup" 69*36586800SKristof Provosttable_head() 70*36586800SKristof Provost{ 71*36586800SKristof Provost atf_set descr 'Test tables and pf_snmp' 72*36586800SKristof Provost atf_set require.user root 73*36586800SKristof Provost} 74*36586800SKristof Provost 75*36586800SKristof Provosttable_body() 76*36586800SKristof Provost{ 77*36586800SKristof Provost pft_init 78*36586800SKristof Provost 79*36586800SKristof Provost epair=$(vnet_mkepair) 80*36586800SKristof Provost 81*36586800SKristof Provost ifconfig ${epair}b 192.0.2.2/24 up 82*36586800SKristof Provost 83*36586800SKristof Provost vnet_mkjail alcatraz ${epair}a 84*36586800SKristof Provost jexec alcatraz ifconfig ${epair}a 192.0.2.1/24 up 85*36586800SKristof Provost 86*36586800SKristof Provost jexec alcatraz pfctl -e 87*36586800SKristof Provost pft_set_rules alcatraz \ 88*36586800SKristof Provost "table <foo> counters { 192.0.2.0/24 }" \ 89*36586800SKristof Provost "pass in from <foo>" 90*36586800SKristof Provost 91*36586800SKristof Provost # Start bsnmpd after creating the table so we don't have to wait for 92*36586800SKristof Provost # a refresh timeout 93*36586800SKristof Provost jexec alcatraz bsnmpd -c $(atf_get_srcdir)/bsnmpd.conf 94*36586800SKristof Provost 95*36586800SKristof Provost # Sanity check, and create state 96*36586800SKristof Provost atf_check -s exit:0 -o ignore \ 97*36586800SKristof Provost ping -c 1 192.0.2.1 98*36586800SKristof Provost 99*36586800SKristof Provost # We should have one table 100*36586800SKristof Provost atf_check -s exit:0 -o match:'pfTablesTblNumber.0 = 1' \ 101*36586800SKristof Provost bsnmpwalk -s public@192.0.2.1 -i pf_tree.def begemot 102*36586800SKristof Provost 103*36586800SKristof Provost # We have the 'foo' table 104*36586800SKristof Provost atf_check -s exit:0 -o match:'pfTablesTblDescr.* = foo' \ 105*36586800SKristof Provost bsnmpwalk -s public@192.0.2.1 -i pf_tree.def pfTables 106*36586800SKristof Provost 107*36586800SKristof Provost # Which contains address 192.0.2.0/24 108*36586800SKristof Provost atf_check -s exit:0 -o match:'pfTablesAddrNet.* = 192.0.2.0' \ 109*36586800SKristof Provost bsnmpwalk -s public@192.0.2.1 -i pf_tree.def pfTables 110*36586800SKristof Provost atf_check -s exit:0 -o match:'pfTablesAddrPrefix.* = 24' \ 111*36586800SKristof Provost bsnmpwalk -s public@192.0.2.1 -i pf_tree.def pfTables 112*36586800SKristof Provost} 113*36586800SKristof Provost 114*36586800SKristof Provosttable_cleanup() 115*36586800SKristof Provost{ 116*36586800SKristof Provost pft_cleanup 117*36586800SKristof Provost} 118*36586800SKristof Provost 119c849f533SKristof Provostatf_init_test_cases() 120c849f533SKristof Provost{ 121c849f533SKristof Provost atf_add_test_case "basic" 122*36586800SKristof Provost atf_add_test_case "table" 123c849f533SKristof Provost} 124