1# $NetBSD: t_ipaddress.sh,v 1.9 2016/12/15 02:43:56 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 28SOCK_LOCAL=unix://commsock1 29BUS=bus 30 31DEBUG=${DEBUG:-false} 32 33test_same_address() 34{ 35 local ip=10.0.0.1 36 local net=10.0.0/24 37 38 rump_server_start $SOCK_LOCAL 39 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS 40 41 export RUMP_SERVER=$SOCK_LOCAL 42 43 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24 44 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 45 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 46 47 $DEBUG && rump.netstat -nr -f inet 48 49 check_route $ip 'link#2' UHl lo0 50 check_route $net 'link#2' UC shmif0 51 52 # Delete the address 53 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete 54 55 $DEBUG && rump.netstat -nr -f inet 56 57 check_route_no_entry $ip 58 check_route_no_entry $net 59 60 # Assign the same address again 61 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24 62 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 63 64 $DEBUG && rump.netstat -nr -f inet 65 66 check_route $ip 'link#2' UHl lo0 67 check_route $net 'link#2' UC shmif0 68 69 # Delete the address again 70 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete 71 72 $DEBUG && rump.netstat -nr -f inet 73 74 check_route_no_entry $ip 75 check_route_no_entry $net 76 77 rump_server_destroy_ifaces 78} 79 80test_same_address6() 81{ 82 local ip=fc00::1 83 local net=fc00::/64 84 85 rump_server_start $SOCK_LOCAL netinet6 86 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS 87 88 export RUMP_SERVER=$SOCK_LOCAL 89 90 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip 91 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 92 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 93 94 $DEBUG && rump.netstat -nr -f inet6 95 96 check_route $ip 'link#2' UHl lo0 97 check_route $net 'link#2' UC shmif0 98 99 # Delete the address 100 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete 101 102 $DEBUG && rump.netstat -nr -f inet6 103 104 check_route_no_entry $ip 105 check_route_no_entry $net 106 107 # Assign the same address again 108 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip 109 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 110 111 $DEBUG && rump.netstat -nr -f inet6 112 113 check_route $ip 'link#2' UHl lo0 114 check_route $net 'link#2' UC shmif0 115 116 # Delete the address again 117 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete 118 119 $DEBUG && rump.netstat -nr -f inet6 120 121 check_route_no_entry $ip 122 check_route_no_entry $net 123 124 rump_server_destroy_ifaces 125} 126 127test_auto_linklocal() 128{ 129 130 rump_server_start $SOCK_LOCAL netinet6 131 rump_server_add_iface $SOCK_LOCAL shmif0 $BUS 132 133 export RUMP_SERVER=$SOCK_LOCAL 134 135 # 136 # Test enabled auto linklocal 137 # 138 139 # Check default value 140 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet6.ip6.auto_linklocal 141 142 atf_check -s exit:0 -o ignore rump.ifconfig shmif0 up 143 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 144 145 $DEBUG && rump.netstat -nr -f inet 146 147 # IPv6 link-local address is set 148 atf_check -s exit:0 -o match:"inet6 fe80::" rump.ifconfig shmif0 149 150 # 151 # Test disabled auto linklocal 152 # 153 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet6.ip6.auto_linklocal=0 154 155 rump_server_add_iface $SOCK_LOCAL shmif1 $BUS 156 atf_check -s exit:0 -o ignore rump.ifconfig shmif1 up 157 atf_check -s exit:0 -o ignore rump.ifconfig -w 10 158 159 $DEBUG && rump.netstat -nr -f inet 160 161 # IPv6 link-local address is not set 162 atf_check -s exit:0 -o not-match:"inet6 fe80::" rump.ifconfig shmif1 163 164 rump_server_destroy_ifaces 165} 166 167add_test() 168{ 169 local name=$1 170 local desc="$2" 171 172 atf_test_case "ipaddr_${name}" cleanup 173 eval "ipaddr_${name}_head() { \ 174 atf_set \"descr\" \"${desc}\"; \ 175 atf_set \"require.progs\" \"rump_server\"; \ 176 }; \ 177 ipaddr_${name}_body() { \ 178 test_${name}; \ 179 }; \ 180 ipaddr_${name}_cleanup() { \ 181 $DEBUG && dump; \ 182 cleanup; \ 183 }" 184 atf_add_test_case "ipaddr_${name}" 185} 186 187atf_init_test_cases() 188{ 189 190 add_test same_address "Assigning/deleting an IP address twice" 191 add_test same_address6 "Assigning/deleting an IPv6 address twice" 192 add_test auto_linklocal "Assigning an IPv6 link-local address automatically" 193} 194