Path: blob/main/tests/sys/netpfil/common/forward.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 descr 'Basic forwarding test'34atf_set require.user root35atf_set require.progs python3 scapy36}3738v4_body()39{40firewall=$141firewall_init $firewall4243epair_send=$(vnet_mkepair)44ifconfig ${epair_send}a 192.0.2.1/24 up4546epair_recv=$(vnet_mkepair)47ifconfig ${epair_recv}a up4849vnet_mkjail iron ${epair_send}b ${epair_recv}b50jexec iron ifconfig ${epair_send}b 192.0.2.2/24 up51jexec iron ifconfig ${epair_recv}b 198.51.100.2/24 up52jexec iron sysctl net.inet.ip.forwarding=153jexec iron arp -s 198.51.100.3 00:01:02:03:04:0554route add -net 198.51.100.0/24 192.0.2.2555657atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \58--sendif ${epair_send}a \59--to 198.51.100.3 \60--recvif ${epair_recv}a6162firewall_config "iron" ${firewall} \63"pf" \64"block in" \65"ipfw" \66"ipfw -q add 100 deny all from any to any in" \67"ipf" \68"block in all" \6970atf_check -s exit:1 $(atf_get_srcdir)/pft_ping.py \71--sendif ${epair_send}a \72--to 198.51.100.3 \73--recvif ${epair_recv}a7475firewall_config "iron" ${firewall} \76"pf" \77"block out" \78"ipfw" \79"ipfw -q add 100 deny all from any to any out" \80"ipf" \81"block out all" \8283atf_check -s exit:1 $(atf_get_srcdir)/pft_ping.py \84--sendif ${epair_send}a \85--to 198.51.100.3 \86--recv ${epair_recv}a87}8889v4_cleanup()90{91firewall=$192firewall_cleanup $firewall93}9495setup_tests \96v4 \97pf \98ipfw \99ipf100101102