#!/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.subr3031load_divert_module() {32kldstat -q -m ipdivert33if [ $? -ne 0 ]; then34atf_skip "ipdivert module is not loaded"35fi36}3738atf_test_case "ipdivert_ip6_output_remote_success" "cleanup"39ipdivert_ip6_output_remote_success_head() {4041atf_set descr 'Test valid IPv6 redirect'42atf_set require.user root43atf_set require.progs python3 scapy44}4546ipdivert_ip6_output_remote_success_body() {47ids=6553048id=`printf "%x" ${ids}`49if [ $$ -gt 65535 ]; then50xl=`printf "%x" $(($$ - 65535))`51yl="1"52else53xl=`printf "%x" $$`54yl=""55fi5657vnet_init58load_divert_module5960ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"61ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"6263script_name="../common/divert.py"6465epair=$(vnet_mkepair)66ifconfig ${epair}a up67ifconfig ${epair}a inet6 ${ip6a}/646869jname="v6t-${id}-${yl}-${xl}"70vnet_mkjail ${jname} ${epair}b71jexec ${jname} ifconfig ${epair}b up72jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/647374# wait for DAD to complete75sleep 27677# echo "LOCAL: ${local_ll_ip} ${local_ll_mac}"78# echo "REMOTE: ${remote_rtr_ll_ip} ${remote_rtr_mac}"7980atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \81--dip ${ip6b} --test_name ipdivert_ip6_output_remote_success8283count=`jexec ${jname} netstat -s -p icmp6 | grep 'Input histogram:' -A1 | grep -c 'echo:'`84# Verify redirect got installed85atf_check_equal "1" "${count}"86}8788ipdivert_ip6_output_remote_success_cleanup() {8990vnet_cleanup91}9293atf_init_test_cases()94{9596atf_add_test_case "ipdivert_ip6_output_remote_success"97}9899# end100101102103