Path: blob/main/tests/sys/netpfil/common/pass_block.sh
39507 views
#-1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2019 Ahsan Barkati4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24# SUCH DAMAGE.25#26#2728. $(atf_get_srcdir)/utils.subr29. $(atf_get_srcdir)/runner.subr3031v4_head()32{33atf_set require.user root34}3536v4_body()37{38firewall=$139firewall_init $firewall4041epair=$(vnet_mkepair)42ifconfig ${epair}a 192.0.2.1/24 up43vnet_mkjail iron ${epair}b44jexec iron ifconfig ${epair}b 192.0.2.2/24 up4546# Block All47firewall_config "iron" ${firewall} \48"pf" \49"block in" \50"ipfw" \51"ipfw -q add 100 deny all from any to any" \52"ipf" \53"block in all"5455atf_check -s exit:2 -o ignore ping -c 1 -t 1 192.0.2.25657# Pass All58firewall_config "iron" ${firewall} \59"pf" \60"pass in" \61"ipfw" \62"ipfw -q add 100 allow all from any to any" \63"ipf" \64"pass in all"6566atf_check -s exit:0 -o ignore ping -c 1 -t 1 192.0.2.267}6869v4_cleanup()70{71firewall=$172firewall_cleanup $firewall73}7475v6_head()76{77atf_set require.user root78}7980v6_body()81{82firewall=$183firewall_init $firewall8485epair=$(vnet_mkepair)86ifconfig ${epair}a inet6 fd7a:803f:cc4b::1/64 up no_dad8788vnet_mkjail iron ${epair}b89jexec iron ifconfig ${epair}b inet6 fd7a:803f:cc4b::2/64 up no_dad9091# Block All92firewall_config "iron" ${firewall} \93"pf" \94"block in" \95"ipfw" \96"ipfw -q add 100 deny all from any to any" \97"ipf" \98"block in all"99100atf_check -s exit:2 -o ignore ping -6 -c 1 -W 1 fd7a:803f:cc4b::2101102# Pass All103firewall_config "iron" ${firewall} \104"pf" \105"pass in" \106"ipfw" \107"ipfw -q add 100 allow all from any to any" \108"ipf" \109"pass in all"110111atf_check -s exit:0 -o ignore ping -6 -c 1 -W 1 fd7a:803f:cc4b::2112}113114v6_cleanup()115{116firewall=$1117firewall_cleanup $firewall118}119120setup_tests "v4" \121"pf" \122"ipfw" \123"ipf" \124"v6" \125"pf" \126"ipfw" \127"ipf"128129130