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