#1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2021 Kristof Provost <[email protected]>4#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.2526. $(atf_get_srcdir)/utils.subr2728common_dir=$(atf_get_srcdir)/../common2930atf_test_case "dup_to" "cleanup"31dup_to_head()32{33atf_set descr 'dup-to test'34atf_set require.user root35atf_set require.progs python3 scapy36}3738dup_to_body()39{40pft_init4142epair_send=$(vnet_mkepair)43ifconfig ${epair_send}a 192.0.2.1/24 up4445epair_recv=$(vnet_mkepair)46ifconfig ${epair_recv}a up4748epair_dupto=$(vnet_mkepair)49ifconfig ${epair_dupto}a up5051vnet_mkjail alcatraz ${epair_send}b ${epair_recv}b ${epair_dupto}b52jexec alcatraz ifconfig ${epair_send}b 192.0.2.2/24 up53jexec alcatraz ifconfig ${epair_recv}b 198.51.100.2/24 up54jexec alcatraz ifconfig ${epair_dupto}b 203.0.113.2/24 up55jexec alcatraz sysctl net.inet.ip.forwarding=156jexec alcatraz arp -s 198.51.100.3 00:01:02:03:04:0557jexec alcatraz arp -s 203.0.113.3 01:02:03:04:05:0658route add -net 198.51.100.0/24 192.0.2.25960jexec alcatraz pfctl -e6162pft_set_rules alcatraz "pass out on { ${epair_recv}b } \63dup-to (${epair_dupto}b 203.0.113.3)"6465atf_check -s exit:0 ${common_dir}/pft_ping.py \66--sendif ${epair_send}a \67--to 198.51.100.3 \68--recv ${epair_recv}a ${epair_dupto}a69}7071dup_to_cleanup()72{73pft_cleanup74}7576atf_init_test_cases()77{78atf_add_test_case "dup_to"79}808182