1# $NetBSD: t_ipaddress.sh,v 1.1 2015/10/07 05:24:41 ozaki-r Exp $ 2# 3# Copyright (c) 2015 Internet Initiative Japan Inc. 4# All rights reserved. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 1. Redistributions of source code must retain the above copyright 10# notice, this list of conditions and the following disclaimer. 11# 2. Redistributions in binary form must reproduce the above copyright 12# notice, this list of conditions and the following disclaimer in the 13# documentation and/or other materials provided with the distribution. 14# 15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25# POSSIBILITY OF SUCH DAMAGE. 26# 27 28SERVER="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif" 29SERVER6="$SERVER -lrumpnet_netinet6" 30SOCK_LOCAL=unix://commsock1 31BUS=bus 32 33DEBUG=false 34 35check_entry() 36{ 37 local ip=$(echo $1 |sed 's/\./\\./g') 38 local word=$2 39 40 atf_check -s exit:0 -o match:"$word" -e ignore -x \ 41 "rump.netstat -rn | grep ^'$ip'" 42} 43 44check_entry_fail() 45{ 46 local ip=$(echo $1 |sed 's/\./\\./g') 47 local flags=$2 # Not used currently 48 49 atf_check -s not-exit:0 -e ignore -x \ 50 "rump.netstat -rn | grep ^'$ip'" 51} 52 53test_same_address() 54{ 55 local ip=10.0.0.1 56 local net=10.0.0/24 57 local macaddr= 58 59 atf_check -s exit:0 ${SERVER} ${SOCK_LOCAL} 60 export RUMP_SERVER=$SOCK_LOCAL 61 62 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 63 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 64 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24 65 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 66 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 67 68 $DEBUG && rump.netstat -nr -f inet 69 70 macaddr=$(rump.ifconfig shmif0 |awk '/address/ {print $2}') 71 72 check_entry $ip UHLl 73 check_entry $ip lo0 74 check_entry $ip $macaddr 75 check_entry $net UC 76 check_entry $net shmif0 77 check_entry $net 'link#2' 78 79 # Delete the address 80 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete 81 82 $DEBUG && rump.netstat -nr -f inet 83 84 check_entry_fail $ip 85 check_entry_fail $net 86 87 # Assign the same address again 88 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24 89 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 90 91 $DEBUG && rump.netstat -nr -f inet 92 93 check_entry $ip UHLl 94 check_entry $ip lo0 95 check_entry $ip $macaddr 96 check_entry $net UC 97 check_entry $net shmif0 98 check_entry $net 'link#2' 99 100 # Delete the address again 101 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete 102 103 $DEBUG && rump.netstat -nr -f inet 104 105 check_entry_fail $ip 106 check_entry_fail $net 107} 108 109test_same_address6() 110{ 111 local ip=fc00::1 112 local net=fc00::/64 113 local macaddr= 114 115 atf_check -s exit:0 ${SERVER6} ${SOCK_LOCAL} 116 export RUMP_SERVER=$SOCK_LOCAL 117 118 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 create 119 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 linkstr ${BUS} 120 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip 121 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 122 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 123 124 $DEBUG && rump.netstat -nr -f inet6 125 126 macaddr=$(rump.ifconfig shmif0 |awk '/address/ {print $2}') 127 128 check_entry $ip UHLl 129 check_entry $ip lo0 130 check_entry $ip $macaddr 131 check_entry $net UC 132 check_entry $net shmif0 133 check_entry $net 'link#2' 134 135 # Delete the address 136 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete 137 138 $DEBUG && rump.netstat -nr -f inet6 139 140 check_entry_fail $ip 141 check_entry_fail $net 142 143 # Assign the same address again 144 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip 145 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 146 147 $DEBUG && rump.netstat -nr -f inet6 148 149 check_entry $ip UHLl 150 check_entry $ip lo0 151 check_entry $ip $macaddr 152 check_entry $net UC 153 check_entry $net shmif0 154 check_entry $net 'link#2' 155 156 # Delete the address again 157 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete 158 159 $DEBUG && rump.netstat -nr -f inet6 160 161 check_entry_fail $ip 162 check_entry_fail $net 163} 164 165cleanup() 166{ 167 168 $DEBUG && shmif_dumpbus -p - $BUS 2>/dev/null | tcpdump -n -e -r - 169 env RUMP_SERVER=$SOCK_LOCAL rump.halt 170} 171 172add_test() 173{ 174 local name=$1 175 local desc="$2" 176 177 atf_test_case "ipaddr_${name}" cleanup 178 eval "ipaddr_${name}_head() { \ 179 atf_set \"descr\" \"${desc}\"; \ 180 atf_set \"require.progs\" \"rump_server\"; \ 181 }; \ 182 ipaddr_${name}_body() { \ 183 test_${name}; \ 184 }; \ 185 ipaddr_${name}_cleanup() { \ 186 cleanup; \ 187 }" 188 atf_add_test_case "ipaddr_${name}" 189} 190 191atf_init_test_cases() 192{ 193 194 add_test same_address "Assigning/deleting an IP address twice" 195 add_test same_address6 "Assigning/deleting an IPv6 address twice" 196} 197