#!/usr/bin/env atf-sh1#-2# SPDX-License-Identifier: BSD-2-Clause3#4# Copyright (c) 2020 Alexander V. Chernikov5#6# Redistribution and use in source and binary forms, with or without7# modification, are permitted provided that the following conditions8# are met:9# 1. Redistributions of source code must retain the above copyright10# notice, this list of conditions and the following disclaimer.11# 2. Redistributions in binary form must reproduce the above copyright12# notice, this list of conditions and the following disclaimer in the13# documentation and/or other materials provided with the distribution.14#15# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25# SUCH DAMAGE.26#27#2829. $(atf_get_srcdir)/../common/vnet.subr3031atf_test_case "valid_redirect" "cleanup"32valid_redirect_head() {3334atf_set descr 'Test valid IPv6 redirect'35atf_set require.user root36atf_set require.progs python3 scapy37}3839valid_redirect_body() {4041ids=6553342id=`printf "%x" ${ids}`43if [ $$ -gt 65535 ]; then44xl=`printf "%x" $(($$ - 65535))`45yl="1"46else47xl=`printf "%x" $$`48yl=""49fi5051vnet_init5253ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"54ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"5556net6="2001:db8:6667::/64"57dst_addr6=`echo ${net6} | awk -F/ '{printf"%s4242", $1}'`58new_rtr_ll_ip="fe80::5555"5960# remote_rtr61remote_rtr_ll_ip="fe80::4242"62remote_rtr_mac="00:00:5E:00:53:42"6364script_name="redirect.py"6566epair=$(vnet_mkepair)67ifconfig ${epair}a up68ifconfig ${epair}a inet6 ${ip6a}/646970jname="v6t-${id}-${yl}-${xl}"71vnet_mkjail ${jname} ${epair}b72jexec ${jname} ifconfig ${epair}b up73jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/647475# Setup static entry for the remote router76jexec ${jname} ndp -s ${remote_rtr_ll_ip}%${epair}b ${remote_rtr_mac}77# setup prefix reachable via router78jexec ${jname} route add -6 -net ${net6} ${remote_rtr_ll_ip}%${epair}b7980local_ll_ip=`jexec ${jname} ifconfig ${epair}b inet6 | awk '$1 ~ /inet6/&&$2~/^fe80/ {print$2}'|awk -F% '{print$1}'`81local_ll_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`8283# wait for DAD to complete84while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do85sleep 0.186done87while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do88sleep 0.189done9091# enable ND debugging in the target jail to ease catching errors92jexec ${jname} sysctl net.inet6.icmp6.nd6_debug=19394# echo "LOCAL: ${local_ll_ip} ${local_ll_mac}"95# echo "REMOTE: ${remote_rtr_ll_ip} ${remote_rtr_mac}"9697atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \98--smac ${remote_rtr_mac} --dmac ${local_ll_mac} \99--sip ${remote_rtr_ll_ip} --dip ${local_ll_ip} \100--route ${dst_addr6} --gw ${new_rtr_ll_ip} \101--iface ${epair}a102103# Verify redirect got installed104atf_check -o match:"destination: ${dst_addr6}\$" jexec ${jname} route -n get -6 ${dst_addr6}105atf_check -o match:'flags: <UP,GATEWAY,HOST,DYNAMIC,DONE>' jexec ${jname} route -n get -6 ${dst_addr6}106}107108valid_redirect_cleanup() {109110vnet_cleanup111}112113atf_init_test_cases()114{115116atf_add_test_case "valid_redirect"117}118119# end120121122123