diff --git a/tests/sys/common/vnet.subr b/tests/sys/common/vnet.subr index 590e8dea992e..cdd3d3f69709 100644 --- a/tests/sys/common/vnet.subr +++ b/tests/sys/common/vnet.subr @@ -1,73 +1,95 @@ -# $FreeBSD$ -# VNAT/jail utility functions +# VNET/jail utility functions ## +list_interface() +{ + echo $1 >> created_interfaces.lst +} + +unlist_interface() +{ + sed -i "" /^$1\$/d created_interfaces.lst +} + vnet_init() { if [ "`sysctl -i -n kern.features.vimage`" != 1 ]; then atf_skip "This test requires VIMAGE" fi } vnet_mkepair() { ifname=$(ifconfig epair create) - echo $ifname >> created_interfaces.lst - echo ${ifname%a}b >> created_interfaces.lst + list_interface $ifname + list_interface ${ifname%a}b echo ${ifname%a} } vnet_mkbridge() { ifname=$(ifconfig bridge create) - echo $ifname >> created_interfaces.lst + list_interface $ifname echo ${ifname} } vnet_mkvlan() { ifname=$(ifconfig vlan create) - echo ${ifname} >> created_interfaces.lst + list_interface $ifname echo ${ifname} } vnet_mkloopback() { ifname=$(ifconfig lo create) - echo $ifname >> created_interfaces.lst + list_interface $ifname echo ${ifname} } vnet_mkjail() { jailname=$1 shift vnet_interfaces= for ifname in $@ do vnet_interfaces="${vnet_interfaces} vnet.interface=${ifname}" + unlist_interface $ifname done jail -c name=${jailname} persist vnet ${vnet_interfaces} - echo $jailname >> created_jails.lst + echo $jailname $@ >> created_jails.lst +} + +vnet_ifmove() +{ + ifname=$1 + jailname=$2 + + ifconfig ${ifname} vnet ${jailname} + unlist_interface $ifname + sed -i "" "/^${jailname}/s/\$/ ${ifname}/" created_jails.lst } vnet_cleanup() { if [ -f created_jails.lst ]; then - for jailname in `cat created_jails.lst` - do + while read jailname ifnames; do + for ifname in ${ifnames}; do + jexec ${jailname} ifconfig ${ifname} destroy + done jail -r ${jailname} - done + done < created_jails.lst rm created_jails.lst fi if [ -f created_interfaces.lst ]; then for ifname in `cat created_interfaces.lst` do ifconfig ${ifname} destroy done rm created_interfaces.lst fi } diff --git a/tests/sys/netpfil/pf/set_skip.sh b/tests/sys/netpfil/pf/set_skip.sh index ce7b1900ae00..3f4cfc3fda2c 100644 --- a/tests/sys/netpfil/pf/set_skip.sh +++ b/tests/sys/netpfil/pf/set_skip.sh @@ -1,171 +1,171 @@ # $FreeBSD$ # # SPDX-License-Identifier: BSD-2-Clause-FreeBSD # # Copyright (c) 2018 Kristof Provost # # 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 "set_skip_group" "cleanup" set_skip_group_head() { atf_set descr 'Basic set skip test' atf_set require.user root } set_skip_group_body() { # See PR 229241 pft_init vnet_mkjail alcatraz jexec alcatraz ifconfig lo0 127.0.0.1/8 up jexec alcatraz ifconfig lo0 group foo jexec alcatraz pfctl -e pft_set_rules alcatraz "set skip on foo" \ "block in proto icmp" jexec alcatraz ifconfig atf_check -s exit:0 -o ignore jexec alcatraz ping -c 1 127.0.0.1 } set_skip_group_cleanup() { pft_cleanup } atf_test_case "set_skip_group_lo" "cleanup" set_skip_group_lo_head() { atf_set descr 'Basic set skip test, lo' atf_set require.user root } set_skip_group_lo_body() { # See PR 229241 pft_init vnet_mkjail alcatraz jexec alcatraz ifconfig lo0 127.0.0.1/8 up jexec alcatraz pfctl -e pft_set_rules alcatraz "set skip on lo" \ "block on lo0" atf_check -s exit:0 -o ignore jexec alcatraz ping -c 1 127.0.0.1 pft_set_rules noflush alcatraz "set skip on lo" \ "block on lo0" atf_check -s exit:0 -o ignore jexec alcatraz ping -c 1 127.0.0.1 jexec alcatraz pfctl -s rules } set_skip_group_lo_cleanup() { pft_cleanup } atf_test_case "set_skip_dynamic" "cleanup" set_skip_dynamic_head() { atf_set descr "Cope with group changes" atf_set require.user root } set_skip_dynamic_body() { pft_init set -x vnet_mkjail alcatraz jexec alcatraz pfctl -e pft_set_rules alcatraz "set skip on epair" \ "block" epair=$(vnet_mkepair) ifconfig ${epair}a 192.0.2.2/24 up - ifconfig ${epair}b vnet alcatraz + vnet_ifmove ${epair}b alcatraz jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up atf_check -s exit:0 -o ignore jexec alcatraz ping -c 1 192.0.2.2 } set_skip_dynamic_cleanup() { pft_cleanup } atf_test_case "pr255852" "cleanup" pr255852_head() { atf_set descr "PR 255852" atf_set require.user root } pr255852_body() { pft_init epair=$(vnet_mkepair) ifconfig ${epair}a 192.0.2.1/24 up vnet_mkjail alcatraz ${epair}b jexec alcatraz ifconfig lo0 127.0.0.1/8 up jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up # Sanity check atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 jexec alcatraz pfctl -e pft_set_rules alcatraz "set skip on { lo0, epair }" \ "block" jexec alcatraz pfctl -vsI # We're skipping on epair, so this should work atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 # Note: flushing avoid the issue pft_set_rules noflush alcatraz "set skip on { lo0 }" \ "block" jexec alcatraz pfctl -vsI # No longer skipping, so this should fail atf_check -s exit:2 -o ignore ping -c 1 -t 1 192.0.2.2 } pr255852_cleanup() { pft_cleanup } atf_init_test_cases() { atf_add_test_case "set_skip_group" atf_add_test_case "set_skip_group_lo" atf_add_test_case "set_skip_dynamic" atf_add_test_case "pr255852" }