1768c98a7SAlexander V. Chernikov#!/usr/bin/env atf-sh 2768c98a7SAlexander V. Chernikov#- 3768c98a7SAlexander V. Chernikov# SPDX-License-Identifier: BSD-2-Clause 4768c98a7SAlexander V. Chernikov# 5768c98a7SAlexander V. Chernikov# Copyright (c) 2020 Alexander V. Chernikov 6768c98a7SAlexander V. Chernikov# 7768c98a7SAlexander V. Chernikov# Redistribution and use in source and binary forms, with or without 8768c98a7SAlexander V. Chernikov# modification, are permitted provided that the following conditions 9768c98a7SAlexander V. Chernikov# are met: 10768c98a7SAlexander V. Chernikov# 1. Redistributions of source code must retain the above copyright 11768c98a7SAlexander V. Chernikov# notice, this list of conditions and the following disclaimer. 12768c98a7SAlexander V. Chernikov# 2. Redistributions in binary form must reproduce the above copyright 13768c98a7SAlexander V. Chernikov# notice, this list of conditions and the following disclaimer in the 14768c98a7SAlexander V. Chernikov# documentation and/or other materials provided with the distribution. 15768c98a7SAlexander V. Chernikov# 16768c98a7SAlexander V. Chernikov# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17768c98a7SAlexander V. Chernikov# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18768c98a7SAlexander V. Chernikov# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19768c98a7SAlexander V. Chernikov# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20768c98a7SAlexander V. Chernikov# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21768c98a7SAlexander V. Chernikov# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22768c98a7SAlexander V. Chernikov# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23768c98a7SAlexander V. Chernikov# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24768c98a7SAlexander V. Chernikov# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25768c98a7SAlexander V. Chernikov# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26768c98a7SAlexander V. Chernikov# SUCH DAMAGE. 27768c98a7SAlexander V. Chernikov# 28768c98a7SAlexander V. Chernikov# 29768c98a7SAlexander V. Chernikov 30768c98a7SAlexander V. Chernikov. $(atf_get_srcdir)/../common/vnet.subr 31768c98a7SAlexander V. Chernikov 32768c98a7SAlexander V. Chernikovsetup_networking() 33768c98a7SAlexander V. Chernikov{ 34768c98a7SAlexander V. Chernikov jname="$1" 35768c98a7SAlexander V. Chernikov lo_dst="$2" 36768c98a7SAlexander V. Chernikov epair0="$3" 37768c98a7SAlexander V. Chernikov epair1="$4" 38768c98a7SAlexander V. Chernikov 39768c98a7SAlexander V. Chernikov vnet_mkjail ${jname}a ${epair0}a ${epair1}a ${lo_src} 40768c98a7SAlexander V. Chernikov # enable link-local IPv6 41768c98a7SAlexander V. Chernikov jexec ${jname}a ndp -i ${epair0}a -- -disabled 42768c98a7SAlexander V. Chernikov jexec ${jname}a ifconfig ${epair0}a up 43768c98a7SAlexander V. Chernikov jexec ${jname}a ndp -i ${epair1}a -- -disabled 44768c98a7SAlexander V. Chernikov jexec ${jname}a ifconfig ${epair1}a up 45768c98a7SAlexander V. Chernikov jexec ${jname}a ifconfig ${lo_src} up 46768c98a7SAlexander V. Chernikov 47768c98a7SAlexander V. Chernikov vnet_mkjail ${jname}b ${epair0}b ${epair1}b ${lo_dst} 48768c98a7SAlexander V. Chernikov jexec ${jname}b ndp -i ${epair0}b -- -disabled 49768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${epair0}b up 50768c98a7SAlexander V. Chernikov jexec ${jname}b ndp -i ${epair1}b -- -disabled 51768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${epair1}b up 52768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${lo_dst} up 53768c98a7SAlexander V. Chernikov 54768c98a7SAlexander V. Chernikov # wait for DAD to complete 55768c98a7SAlexander V. Chernikov while [ `jexec ${jname}b ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 56768c98a7SAlexander V. Chernikov sleep 0.1 57768c98a7SAlexander V. Chernikov done 58768c98a7SAlexander V. Chernikov while [ `jexec ${jname}a ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 59768c98a7SAlexander V. Chernikov sleep 0.1 60768c98a7SAlexander V. Chernikov done 61768c98a7SAlexander V. Chernikov} 62768c98a7SAlexander V. Chernikov 63768c98a7SAlexander V. Chernikov 64768c98a7SAlexander V. Chernikovatf_test_case "lpm6_test1_success" "cleanup" 65768c98a7SAlexander V. Chernikovlpm6_test1_success_head() 66768c98a7SAlexander V. Chernikov{ 67768c98a7SAlexander V. Chernikov 68768c98a7SAlexander V. Chernikov atf_set descr 'Test IPv6 LPM for the host routes' 69768c98a7SAlexander V. Chernikov atf_set require.user root 70768c98a7SAlexander V. Chernikov} 71768c98a7SAlexander V. Chernikov 72768c98a7SAlexander V. Chernikovlpm6_test1_success_body() 73768c98a7SAlexander V. Chernikov{ 74768c98a7SAlexander V. Chernikov 75768c98a7SAlexander V. Chernikov vnet_init 76768c98a7SAlexander V. Chernikov 77768c98a7SAlexander V. Chernikov net_dst="2001:db8:" 78768c98a7SAlexander V. Chernikov 79768c98a7SAlexander V. Chernikov jname="v6t-lpm6_test1_success" 80768c98a7SAlexander V. Chernikov 81768c98a7SAlexander V. Chernikov epair0=$(vnet_mkepair) 82768c98a7SAlexander V. Chernikov epair1=$(vnet_mkepair) 83768c98a7SAlexander V. Chernikov lo_dst=$(vnet_mkloopback) 84768c98a7SAlexander V. Chernikov 85768c98a7SAlexander V. Chernikov setup_networking ${jname} ${lo_dst} ${epair0} ${epair1} 86768c98a7SAlexander V. Chernikov 87768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:0/128 88768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:1/128 89768c98a7SAlexander V. Chernikov 90768c98a7SAlexander V. Chernikov # Add routes 91768c98a7SAlexander V. Chernikov # A -> towards B via epair0a LL 92768c98a7SAlexander V. Chernikov ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'` 93768c98a7SAlexander V. Chernikov jexec ${jname}a route add -6 -host ${net_dst}:2:0 ${ll}%${epair0}a 94768c98a7SAlexander V. Chernikov # A -> towards B via epair1a LL 95768c98a7SAlexander V. Chernikov ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'` 96768c98a7SAlexander V. Chernikov jexec ${jname}a route add -6 -host ${net_dst}:2:1 ${ll}%${epair1}a 97768c98a7SAlexander V. Chernikov 98768c98a7SAlexander V. Chernikov count=20 99768c98a7SAlexander V. Chernikov valid_message="${count} packets transmitted, ${count} packets received" 100768c98a7SAlexander V. Chernikov 101768c98a7SAlexander V. Chernikov # Check that ${net_dst}:2:0 goes via epair0 102*01f3f354SAlan Somers atf_check -o match:"${valid_message}" jexec ${jname}a ping -6 -f -nc${count} ${net_dst}:2:0 103768c98a7SAlexander V. Chernikov pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'` 104768c98a7SAlexander V. Chernikov pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'` 105768c98a7SAlexander V. Chernikov if [ ${pkt_0} -le ${count} ]; then 106768c98a7SAlexander V. Chernikov echo "LPM failure: 1: ${pkt_0} (should be ${count}) 2: ${pkt_1}" 107768c98a7SAlexander V. Chernikov exit 1 108768c98a7SAlexander V. Chernikov fi 109768c98a7SAlexander V. Chernikov 110768c98a7SAlexander V. Chernikov # Check that ${net_dst}:2:1 goes via epair1 111*01f3f354SAlan Somers atf_check -o match:"${valid_message}" jexec ${jname}a ping -6 -f -nc${count} ${net_dst}:2:1 112768c98a7SAlexander V. Chernikov pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'` 113768c98a7SAlexander V. Chernikov pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'` 114768c98a7SAlexander V. Chernikov if [ ${pkt_1} -le ${count} ]; then 115768c98a7SAlexander V. Chernikov echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})" 116768c98a7SAlexander V. Chernikov exit 1 117768c98a7SAlexander V. Chernikov fi 118768c98a7SAlexander V. Chernikov 119768c98a7SAlexander V. Chernikov echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}" 120768c98a7SAlexander V. Chernikov} 121768c98a7SAlexander V. Chernikov 122768c98a7SAlexander V. Chernikovlpm6_test1_success_cleanup() 123768c98a7SAlexander V. Chernikov{ 124768c98a7SAlexander V. Chernikov vnet_cleanup 125768c98a7SAlexander V. Chernikov} 126768c98a7SAlexander V. Chernikov 127768c98a7SAlexander V. Chernikovatf_test_case "lpm6_test2_success" "cleanup" 128768c98a7SAlexander V. Chernikovlpm6_test2_success_head() 129768c98a7SAlexander V. Chernikov{ 130768c98a7SAlexander V. Chernikov 131768c98a7SAlexander V. Chernikov atf_set descr 'Test IPv6 LPM for /126 and /127' 132768c98a7SAlexander V. Chernikov atf_set require.user root 133768c98a7SAlexander V. Chernikov} 134768c98a7SAlexander V. Chernikov 135768c98a7SAlexander V. Chernikovlpm6_test2_success_body() 136768c98a7SAlexander V. Chernikov{ 137768c98a7SAlexander V. Chernikov 138768c98a7SAlexander V. Chernikov vnet_init 139768c98a7SAlexander V. Chernikov 140768c98a7SAlexander V. Chernikov net_dst="2001:db8:" 141768c98a7SAlexander V. Chernikov 142768c98a7SAlexander V. Chernikov jname="v6t-lpm6_test2_success" 143768c98a7SAlexander V. Chernikov 144768c98a7SAlexander V. Chernikov epair0=$(vnet_mkepair) 145768c98a7SAlexander V. Chernikov epair1=$(vnet_mkepair) 146768c98a7SAlexander V. Chernikov lo_dst=$(vnet_mkloopback) 147768c98a7SAlexander V. Chernikov 148768c98a7SAlexander V. Chernikov setup_networking ${jname} ${lo_dst} ${epair0} ${epair1} 149768c98a7SAlexander V. Chernikov 150768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:0/128 151768c98a7SAlexander V. Chernikov jexec ${jname}b ifconfig ${lo_dst} inet6 ${net_dst}:2:2/128 152768c98a7SAlexander V. Chernikov 153768c98a7SAlexander V. Chernikov # Add routes 154768c98a7SAlexander V. Chernikov # A -> towards B via epair0a LL 155768c98a7SAlexander V. Chernikov ll=`jexec ${jname}b ifconfig ${epair0}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'` 156768c98a7SAlexander V. Chernikov jexec ${jname}a route add -6 -net ${net_dst}:2:0/126 ${ll}%${epair0}a 157768c98a7SAlexander V. Chernikov # A -> towards B via epair1a LL 158768c98a7SAlexander V. Chernikov ll=`jexec ${jname}b ifconfig ${epair1}b inet6 | awk '$2~/^fe80:/{print$2}' | awk -F% '{print$1}'` 159768c98a7SAlexander V. Chernikov jexec ${jname}a route add -6 -net ${net_dst}:2:0/127 ${ll}%${epair1}a 160768c98a7SAlexander V. Chernikov 161768c98a7SAlexander V. Chernikov count=20 162768c98a7SAlexander V. Chernikov valid_message="${count} packets transmitted, ${count} packets received" 163768c98a7SAlexander V. Chernikov 164768c98a7SAlexander V. Chernikov # Check that ${net_dst}:2:0 goes via epair1 165*01f3f354SAlan Somers atf_check -o match:"${valid_message}" jexec ${jname}a ping -6 -f -nc${count} ${net_dst}:2:0 166768c98a7SAlexander V. Chernikov pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'` 167768c98a7SAlexander V. Chernikov pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'` 168768c98a7SAlexander V. Chernikov if [ ${pkt_1} -le ${count} ]; then 169768c98a7SAlexander V. Chernikov echo "LPM failure: 1: ${pkt_0} 2: ${pkt_1} (should be ${count})" 170768c98a7SAlexander V. Chernikov exit 1 171768c98a7SAlexander V. Chernikov fi 172768c98a7SAlexander V. Chernikov 173768c98a7SAlexander V. Chernikov # Check that ${net_dst}:2:2 goes via epair0 174*01f3f354SAlan Somers atf_check -o match:"${valid_message}" jexec ${jname}a ping -6 -f -nc${count} ${net_dst}:2:2 175768c98a7SAlexander V. Chernikov pkt_0=`jexec ${jname}a netstat -Wf link -I ${epair0}a | head | awk '$1!~/^Name/{print$8}'` 176768c98a7SAlexander V. Chernikov pkt_1=`jexec ${jname}a netstat -Wf link -I ${epair1}a | head | awk '$1!~/^Name/{print$8}'` 177768c98a7SAlexander V. Chernikov if [ ${pkt_0} -le ${count} ]; then 178768c98a7SAlexander V. Chernikov echo "LPM failure: 1: ${pkt_0} (should be ${count}) 2: ${pkt_1}" 179768c98a7SAlexander V. Chernikov exit 1 180768c98a7SAlexander V. Chernikov fi 181768c98a7SAlexander V. Chernikov 182768c98a7SAlexander V. Chernikov echo "RAW BALANCING: 1: ${pkt_0} 2: ${pkt_1}" 183768c98a7SAlexander V. Chernikov} 184768c98a7SAlexander V. Chernikov 185768c98a7SAlexander V. Chernikovlpm6_test2_success_cleanup() 186768c98a7SAlexander V. Chernikov{ 187768c98a7SAlexander V. Chernikov vnet_cleanup 188768c98a7SAlexander V. Chernikov} 189768c98a7SAlexander V. Chernikov 190768c98a7SAlexander V. Chernikovatf_init_test_cases() 191768c98a7SAlexander V. Chernikov{ 192768c98a7SAlexander V. Chernikov atf_add_test_case "lpm6_test1_success" 193768c98a7SAlexander V. Chernikov atf_add_test_case "lpm6_test2_success" 194768c98a7SAlexander V. Chernikov} 195768c98a7SAlexander V. Chernikov 196768c98a7SAlexander V. Chernikov# end 197768c98a7SAlexander V. Chernikov 198768c98a7SAlexander V. Chernikov 199