1*d6cd20ccSKUROSAWA Takahiro#!/usr/bin/env atf-sh 2*d6cd20ccSKUROSAWA Takahiro#- 3*d6cd20ccSKUROSAWA Takahiro# SPDX-License-Identifier: BSD-2-Clause 4*d6cd20ccSKUROSAWA Takahiro# 5*d6cd20ccSKUROSAWA Takahiro# Copyright (c) 2022 KUROSAWA Takahiro <takahiro.kurosawa@gmail.com> 6*d6cd20ccSKUROSAWA Takahiro# 7*d6cd20ccSKUROSAWA Takahiro# Redistribution and use in source and binary forms, with or without 8*d6cd20ccSKUROSAWA Takahiro# modification, are permitted provided that the following conditions 9*d6cd20ccSKUROSAWA Takahiro# are met: 10*d6cd20ccSKUROSAWA Takahiro# 1. Redistributions of source code must retain the above copyright 11*d6cd20ccSKUROSAWA Takahiro# notice, this list of conditions and the following disclaimer. 12*d6cd20ccSKUROSAWA Takahiro# 2. Redistributions in binary form must reproduce the above copyright 13*d6cd20ccSKUROSAWA Takahiro# notice, this list of conditions and the following disclaimer in the 14*d6cd20ccSKUROSAWA Takahiro# documentation and/or other materials provided with the distribution. 15*d6cd20ccSKUROSAWA Takahiro# 16*d6cd20ccSKUROSAWA Takahiro# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*d6cd20ccSKUROSAWA Takahiro# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*d6cd20ccSKUROSAWA Takahiro# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*d6cd20ccSKUROSAWA Takahiro# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*d6cd20ccSKUROSAWA Takahiro# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*d6cd20ccSKUROSAWA Takahiro# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*d6cd20ccSKUROSAWA Takahiro# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*d6cd20ccSKUROSAWA Takahiro# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*d6cd20ccSKUROSAWA Takahiro# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*d6cd20ccSKUROSAWA Takahiro# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*d6cd20ccSKUROSAWA Takahiro# SUCH DAMAGE. 27*d6cd20ccSKUROSAWA Takahiro# 28*d6cd20ccSKUROSAWA Takahiro# 29*d6cd20ccSKUROSAWA Takahiro 30*d6cd20ccSKUROSAWA Takahiro. $(atf_get_srcdir)/../common/vnet.subr 31*d6cd20ccSKUROSAWA Takahiro 32*d6cd20ccSKUROSAWA Takahiroatf_test_case "pndp_add_gu_success" "cleanup" 33*d6cd20ccSKUROSAWA Takahiropndp_add_gu_success_head() { 34*d6cd20ccSKUROSAWA Takahiro atf_set descr 'Test proxy ndp record addition' 35*d6cd20ccSKUROSAWA Takahiro atf_set require.user root 36*d6cd20ccSKUROSAWA Takahiro} 37*d6cd20ccSKUROSAWA Takahiro 38*d6cd20ccSKUROSAWA Takahiropndp_add_gu_success_body() { 39*d6cd20ccSKUROSAWA Takahiro 40*d6cd20ccSKUROSAWA Takahiro vnet_init 41*d6cd20ccSKUROSAWA Takahiro 42*d6cd20ccSKUROSAWA Takahiro jname="v6t-pndp_add_success" 43*d6cd20ccSKUROSAWA Takahiro 44*d6cd20ccSKUROSAWA Takahiro epair0=$(vnet_mkepair) 45*d6cd20ccSKUROSAWA Takahiro 46*d6cd20ccSKUROSAWA Takahiro vnet_mkjail ${jname} ${epair0}a 47*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ndp -i ${epair0}a -- -disabled 48*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifconfig ${epair0}a up 49*d6cd20ccSKUROSAWA Takahiro 50*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifconfig ${epair0}a inet6 2001:db8::1/64 51*d6cd20ccSKUROSAWA Takahiro proxy_mac=`jexec ${jname} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'` 52*d6cd20ccSKUROSAWA Takahiro 53*d6cd20ccSKUROSAWA Takahiro # wait for DAD to complete 54*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 55*d6cd20ccSKUROSAWA Takahiro sleep 0.1 56*d6cd20ccSKUROSAWA Takahiro done 57*d6cd20ccSKUROSAWA Takahiro 58*d6cd20ccSKUROSAWA Takahiro atf_check jexec ${jname} ndp -s 2001:db8::2 ${proxy_mac} proxy 59*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do 60*d6cd20ccSKUROSAWA Takahiro sleep 0.1 61*d6cd20ccSKUROSAWA Takahiro done 62*d6cd20ccSKUROSAWA Takahiro 63*d6cd20ccSKUROSAWA Takahiro # checking the output of ndp -an is covered by ndp.sh. 64*d6cd20ccSKUROSAWA Takahiro # we check the output of ifmcstat output here. 65*d6cd20ccSKUROSAWA Takahiro t=`jexec ${jname} ifmcstat -i ${epair0}a -f inet6 | grep -A1 'group ff02::1:ff00:2'` 66*d6cd20ccSKUROSAWA Takahiro atf_check -o match:'mcast-macaddr 33:33:ff:00:00:02' echo $t 67*d6cd20ccSKUROSAWA Takahiro} 68*d6cd20ccSKUROSAWA Takahiro 69*d6cd20ccSKUROSAWA Takahiropndp_add_gu_success_cleanup() { 70*d6cd20ccSKUROSAWA Takahiro vnet_cleanup 71*d6cd20ccSKUROSAWA Takahiro} 72*d6cd20ccSKUROSAWA Takahiro 73*d6cd20ccSKUROSAWA Takahiroatf_test_case "pndp_del_gu_success" "cleanup" 74*d6cd20ccSKUROSAWA Takahiropndp_del_gu_success_head() { 75*d6cd20ccSKUROSAWA Takahiro atf_set descr 'Test proxy ndp record deletion' 76*d6cd20ccSKUROSAWA Takahiro atf_set require.user root 77*d6cd20ccSKUROSAWA Takahiro} 78*d6cd20ccSKUROSAWA Takahiro 79*d6cd20ccSKUROSAWA Takahiropndp_del_gu_success_body() { 80*d6cd20ccSKUROSAWA Takahiro 81*d6cd20ccSKUROSAWA Takahiro vnet_init 82*d6cd20ccSKUROSAWA Takahiro 83*d6cd20ccSKUROSAWA Takahiro jname="v6t-pndp_del_gu_success" 84*d6cd20ccSKUROSAWA Takahiro 85*d6cd20ccSKUROSAWA Takahiro epair0=$(vnet_mkepair) 86*d6cd20ccSKUROSAWA Takahiro 87*d6cd20ccSKUROSAWA Takahiro vnet_mkjail ${jname} ${epair0}a 88*d6cd20ccSKUROSAWA Takahiro 89*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ndp -i ${epair0}a -- -disabled 90*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifconfig ${epair0}a up 91*d6cd20ccSKUROSAWA Takahiro 92*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifconfig ${epair0}a inet6 2001:db8::1/64 93*d6cd20ccSKUROSAWA Takahiro proxy_mac=`jexec ${jname} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'` 94*d6cd20ccSKUROSAWA Takahiro 95*d6cd20ccSKUROSAWA Takahiro # wait for DAD to complete 96*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 97*d6cd20ccSKUROSAWA Takahiro sleep 0.1 98*d6cd20ccSKUROSAWA Takahiro done 99*d6cd20ccSKUROSAWA Takahiro 100*d6cd20ccSKUROSAWA Takahiro atf_check jexec ${jname} ndp -s 2001:db8::2 ${proxy_mac} proxy 101*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do 102*d6cd20ccSKUROSAWA Takahiro sleep 0.1 103*d6cd20ccSKUROSAWA Takahiro done 104*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ping -c1 -t1 2001:db8::2 105*d6cd20ccSKUROSAWA Takahiro 106*d6cd20ccSKUROSAWA Takahiro atf_check -o match:"2001:db8::2 \(2001:db8::2\) deleted" jexec ${jname} ndp -nd 2001:db8::2 107*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do 108*d6cd20ccSKUROSAWA Takahiro sleep 0.1 109*d6cd20ccSKUROSAWA Takahiro done 110*d6cd20ccSKUROSAWA Takahiro atf_check \ 111*d6cd20ccSKUROSAWA Takahiro -o not-match:'group ff02::1:ff00:2' \ 112*d6cd20ccSKUROSAWA Takahiro -o not-match:'mcast-macaddr 33:33:ff:00:00:02' \ 113*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifmcstat -i ${epair0}a -f inet6 114*d6cd20ccSKUROSAWA Takahiro} 115*d6cd20ccSKUROSAWA Takahiro 116*d6cd20ccSKUROSAWA Takahiropndp_del_gu_success_cleanup() { 117*d6cd20ccSKUROSAWA Takahiro vnet_cleanup 118*d6cd20ccSKUROSAWA Takahiro} 119*d6cd20ccSKUROSAWA Takahiro 120*d6cd20ccSKUROSAWA Takahiroatf_test_case "pndp_ifdestroy_success" "cleanup" 121*d6cd20ccSKUROSAWA Takahiropndp_ifdetroy_success_head() { 122*d6cd20ccSKUROSAWA Takahiro atf_set descr 'Test interface destruction with proxy ndp' 123*d6cd20ccSKUROSAWA Takahiro atf_set require.user root 124*d6cd20ccSKUROSAWA Takahiro} 125*d6cd20ccSKUROSAWA Takahiro 126*d6cd20ccSKUROSAWA Takahiropndp_ifdestroy_success_body() { 127*d6cd20ccSKUROSAWA Takahiro 128*d6cd20ccSKUROSAWA Takahiro vnet_init 129*d6cd20ccSKUROSAWA Takahiro 130*d6cd20ccSKUROSAWA Takahiro jname="v6t-pndp_ifdestroy_success" 131*d6cd20ccSKUROSAWA Takahiro 132*d6cd20ccSKUROSAWA Takahiro epair0=$(vnet_mkepair) 133*d6cd20ccSKUROSAWA Takahiro 134*d6cd20ccSKUROSAWA Takahiro vnet_mkjail ${jname} ${epair0}a 135*d6cd20ccSKUROSAWA Takahiro 136*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ndp -i ${epair0}a -- -disabled 137*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifconfig ${epair0}a up 138*d6cd20ccSKUROSAWA Takahiro 139*d6cd20ccSKUROSAWA Takahiro jexec ${jname} ifconfig ${epair0}a inet6 2001:db8::1/64 140*d6cd20ccSKUROSAWA Takahiro proxy_mac=`jexec ${jname} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'` 141*d6cd20ccSKUROSAWA Takahiro 142*d6cd20ccSKUROSAWA Takahiro # wait for DAD to complete 143*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 144*d6cd20ccSKUROSAWA Takahiro sleep 0.1 145*d6cd20ccSKUROSAWA Takahiro done 146*d6cd20ccSKUROSAWA Takahiro 147*d6cd20ccSKUROSAWA Takahiro atf_check jexec ${jname} ndp -s 2001:db8::2 ${proxy_mac} proxy 148*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do 149*d6cd20ccSKUROSAWA Takahiro sleep 0.1 150*d6cd20ccSKUROSAWA Takahiro done 151*d6cd20ccSKUROSAWA Takahiro 152*d6cd20ccSKUROSAWA Takahiro atf_check jexec ${jname} ifconfig ${epair0}a destroy 153*d6cd20ccSKUROSAWA Takahiro} 154*d6cd20ccSKUROSAWA Takahiro 155*d6cd20ccSKUROSAWA Takahiropndp_ifdestroy_success_cleanup() { 156*d6cd20ccSKUROSAWA Takahiro vnet_cleanup 157*d6cd20ccSKUROSAWA Takahiro} 158*d6cd20ccSKUROSAWA Takahiro 159*d6cd20ccSKUROSAWA Takahiroatf_test_case "pndp_neighbor_advert" "cleanup" 160*d6cd20ccSKUROSAWA Takahiropndp_neighbor_advert_head() { 161*d6cd20ccSKUROSAWA Takahiro atf_set descr 'Test Neighbor Advertisement for proxy ndp' 162*d6cd20ccSKUROSAWA Takahiro atf_set require.user root 163*d6cd20ccSKUROSAWA Takahiro} 164*d6cd20ccSKUROSAWA Takahiro 165*d6cd20ccSKUROSAWA Takahiropndp_neighbor_advert_body() { 166*d6cd20ccSKUROSAWA Takahiro 167*d6cd20ccSKUROSAWA Takahiro vnet_init 168*d6cd20ccSKUROSAWA Takahiro 169*d6cd20ccSKUROSAWA Takahiro jname_a="v6t-pndp_neighbor_advert_a" # NA sender (w/proxy ndp entry) 170*d6cd20ccSKUROSAWA Takahiro jname_b="v6t-pndp_neighbor_advert_b" # NA receiver (checker) 171*d6cd20ccSKUROSAWA Takahiro proxy_addr="2001:db8::aaaa" 172*d6cd20ccSKUROSAWA Takahiro 173*d6cd20ccSKUROSAWA Takahiro epair0=$(vnet_mkepair) 174*d6cd20ccSKUROSAWA Takahiro 175*d6cd20ccSKUROSAWA Takahiro vnet_mkjail ${jname_a} ${epair0}a 176*d6cd20ccSKUROSAWA Takahiro jexec ${jname_a} ndp -i ${epair0}a -- -disabled 177*d6cd20ccSKUROSAWA Takahiro jexec ${jname_a} ifconfig ${epair0}a up 178*d6cd20ccSKUROSAWA Takahiro jexec ${jname_a} ifconfig ${epair0}a inet6 2001:db8::1/64 179*d6cd20ccSKUROSAWA Takahiro proxy_mac=`jexec ${jname_a} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'` 180*d6cd20ccSKUROSAWA Takahiro # wait for DAD to complete 181*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname_a} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 182*d6cd20ccSKUROSAWA Takahiro sleep 0.1 183*d6cd20ccSKUROSAWA Takahiro done 184*d6cd20ccSKUROSAWA Takahiro atf_check jexec ${jname_a} ndp -s ${proxy_addr} ${proxy_mac} proxy 185*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname_a} ifmcstat | grep -c undefined` != "0" ]; do 186*d6cd20ccSKUROSAWA Takahiro sleep 0.1 187*d6cd20ccSKUROSAWA Takahiro done 188*d6cd20ccSKUROSAWA Takahiro 189*d6cd20ccSKUROSAWA Takahiro vnet_mkjail ${jname_b} ${epair0}b 190*d6cd20ccSKUROSAWA Takahiro jexec ${jname_b} ndp -i ${epair0}b -- -disabled 191*d6cd20ccSKUROSAWA Takahiro jexec ${jname_b} ifconfig ${epair0}b up 192*d6cd20ccSKUROSAWA Takahiro jexec ${jname_b} ifconfig ${epair0}b inet6 2001:db8::2/64 193*d6cd20ccSKUROSAWA Takahiro # wait for DAD to complete 194*d6cd20ccSKUROSAWA Takahiro while [ `jexec ${jname_b} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do 195*d6cd20ccSKUROSAWA Takahiro sleep 0.1 196*d6cd20ccSKUROSAWA Takahiro done 197*d6cd20ccSKUROSAWA Takahiro 198*d6cd20ccSKUROSAWA Takahiro jexec ${jname_b} ndp -nc 199*d6cd20ccSKUROSAWA Takahiro # jname_b sends a NS before ICMPv6 Echo Request for the proxy address. 200*d6cd20ccSKUROSAWA Takahiro # jname_a responds with a NA resolving the proxy address. 201*d6cd20ccSKUROSAWA Takahiro # Then there must be a NDP entry of the proxy address in jname_b. 202*d6cd20ccSKUROSAWA Takahiro jexec ${jname_b} ping -c1 -t1 ${proxy_addr} 203*d6cd20ccSKUROSAWA Takahiro atf_check -o match:"${proxy_addr} +${proxy_mac} +${epair0}b" \ 204*d6cd20ccSKUROSAWA Takahiro jexec ${jname_b} ndp -an 205*d6cd20ccSKUROSAWA Takahiro} 206*d6cd20ccSKUROSAWA Takahiro 207*d6cd20ccSKUROSAWA Takahiropndp_neighbor_advert_cleanup() { 208*d6cd20ccSKUROSAWA Takahiro vnet_cleanup 209*d6cd20ccSKUROSAWA Takahiro} 210*d6cd20ccSKUROSAWA Takahiro 211*d6cd20ccSKUROSAWA Takahiroatf_init_test_cases() 212*d6cd20ccSKUROSAWA Takahiro{ 213*d6cd20ccSKUROSAWA Takahiro 214*d6cd20ccSKUROSAWA Takahiro atf_add_test_case "pndp_add_gu_success" 215*d6cd20ccSKUROSAWA Takahiro atf_add_test_case "pndp_del_gu_success" 216*d6cd20ccSKUROSAWA Takahiro atf_add_test_case "pndp_ifdestroy_success" 217*d6cd20ccSKUROSAWA Takahiro atf_add_test_case "pndp_neighbor_advert" 218*d6cd20ccSKUROSAWA Takahiro} 219*d6cd20ccSKUROSAWA Takahiro 220*d6cd20ccSKUROSAWA Takahiro# end 221*d6cd20ccSKUROSAWA Takahiro 222