t_mtudisc.sh revision 1.4
1# $NetBSD: t_mtudisc.sh,v 1.4 2016/11/24 08:52:20 ozaki-r Exp $ 2# 3# Copyright (c) 2016 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 28inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet" 29inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif" 30inetserver="$inetserver -lrumpdev" 31HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes" 32 33SOCKLOCAL=unix://commsock1 34SOCKGATEWAY=unix://commsock2 35SOCKREMOTE=unix://commsock3 36HTTPD_PID=httpd.pid 37HTML_FILE=index.html 38 39DEBUG=${DEBUG:-false} 40 41atf_test_case mtudisc_basic cleanup 42 43mtudisc_basic_head() 44{ 45 atf_set "descr" "Tests for IPv4 Path MTU Dicorvery basic behavior" 46 atf_set "require.progs" "rump_server" 47} 48 49setup_server() 50{ 51 local sock=$1 52 local if=$2 53 local bus=$3 54 local ip=$4 55 56 export RUMP_SERVER=$sock 57 58 atf_check -s exit:0 rump.ifconfig $if create 59 atf_check -s exit:0 rump.ifconfig $if linkstr $bus 60 atf_check -s exit:0 rump.ifconfig $if $ip 61 atf_check -s exit:0 rump.ifconfig $if up 62 atf_check -s exit:0 rump.ifconfig -w 10 63 64 $DEBUG && rump.ifconfig $if 65} 66 67setup_httpd() 68{ 69 local sock=$1 70 local ip=$2 71 local data="0123456789" 72 73 export RUMP_SERVER=$sock 74 75 touch $HTML_FILE 76 for i in `seq 1 512` 77 do 78 echo $data >> $HTML_FILE 79 done 80 81 # start httpd in daemon mode 82 atf_check -s exit:0 env LD_PRELOAD=/usr/lib/librumphijack.so \ 83 /usr/libexec/httpd -P $HTTPD_PID -i $ip -b -s $(pwd) 84 85 $DEBUG && rump.netstat -a 86 87 sleep 5 88} 89 90do_http_get() 91{ 92 local ip=$1 93 local ret=$2 94 local timeout=5 95 96 # get the webpage 97 atf_check -s exit:$ret env LD_PRELOAD=/usr/lib/librumphijack.so \ 98 ftp -q $timeout -o ./out http://$ip/$HTML_FILE 99} 100 101mtudisc_basic_body() 102{ 103 local pkt= 104 local local_ip=10.0.0.2 105 local gateway_local_ip=10.0.0.1 106 local gateway_remote_ip=10.0.1.1 107 local remote_ip=10.0.1.2 108 local prefixlen=24 109 110 atf_check -s exit:0 ${inetserver} $SOCKLOCAL 111 atf_check -s exit:0 ${inetserver} $SOCKGATEWAY 112 atf_check -s exit:0 ${inetserver} $SOCKREMOTE 113 114 # 115 # Setup servers 116 # 117 # [local server] [gateway server] [remote server with httpd] 118 # | 10.0.0.2 10.0.0.1 | | 10.0.1.1 10.0.1.2 | 119 # shmif0(mtu=1500) ----- shmif1(mtu=1280) shmif0(mtu=1500) ----- shmif0(mtu=1500) 120 # 121 122 # Assign IP addresses 123 setup_server $SOCKLOCAL shmif0 bus1 $local_ip/$prefixlen 124 setup_server $SOCKGATEWAY shmif0 bus1 $gateway_local_ip/$prefixlen 125 setup_server $SOCKGATEWAY shmif1 bus2 $gateway_remote_ip/$prefixlen 126 setup_server $SOCKREMOTE shmif0 bus2 $remote_ip/$prefixlen 127 128 ### Setup gateway server 129 export RUMP_SERVER=$SOCKGATEWAY 130 131 # Set mtu of shmif0 to 1280 132 export RUMP_SERVER=$SOCKGATEWAY 133 atf_check -s exit:0 rump.ifconfig shmif0 mtu 1280 134 135 # Enable IPv4 forwarding 136 atf_check -s exit:0 rump.sysctl -w -q net.inet.ip.forwarding=1 137 138 ### Setup remote server 139 export RUMP_SERVER=$SOCKREMOTE 140 141 # Check default value 142 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet.ip.mtudisc 143 144 # Start httpd daemon 145 setup_httpd $SOCKREMOTE $remote_ip 146 147 # Teach the peer thar 10.0.0.2(local serer) is behind 10.0.1.1(gateway server) 148 atf_check -s exit:0 -o ignore rump.route add $local_ip/32 $gateway_remote_ip 149 150 ### Setup local server 151 export RUMP_SERVER=$SOCKLOCAL 152 153 # Teach the peer thar 10.0.1.2(remote serer) is behind 10.0.0.1(gateway server) 154 atf_check -s exit:0 -o ignore rump.route add $remote_ip/32 $gateway_local_ip 155 156 # Don't accept fragmented packets 157 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.maxfragpackets=0 158 159 # 160 # Test disabled path mtu discorvery 161 # 162 export RUMP_SERVER=$SOCKREMOTE 163 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=0 164 165 # Get the webpage (expect: failed) 166 export RUMP_SERVER=$SOCKLOCAL 167 do_http_get $remote_ip 1 168 $DEBUG && extract_new_packets bus2 > ./out 169 $DEBUG && cat ./out 170 171 # Check path mtu size on remote server 172 export RUMP_SERVER=$SOCKREMOTE 173 atf_check -s exit:0 \ 174 -o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +- +shmif0" \ 175 rump.netstat -nr -f inet 176 177 # 178 # Test enabled path mtu discorvery 179 # 180 export RUMP_SERVER=$SOCKREMOTE 181 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=1 182 183 # Get the webpage (expect: success) 184 export RUMP_SERVER=$SOCKLOCAL 185 do_http_get $remote_ip 0 186 $DEBUG && extract_new_packets bus2 > ./out 187 $DEBUG && cat ./out 188 189 # Check path mtu size on remote server 190 export RUMP_SERVER=$SOCKREMOTE 191 atf_check -s exit:0 \ 192 -o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +1280 +shmif0" \ 193 rump.netstat -nr -f inet 194 195} 196 197cleanup() 198{ 199 gdb -ex bt /usr/bin/rump_server rump_server.core 200 gdb -ex bt /usr/sbin/arp arp.core 201 env RUMP_SERVER=$SOCKLOCAL rump.halt 202 env RUMP_SERVER=$SOCKGATEWAY rump.halt 203 env RUMP_SERVER=$SOCKREMOTE rump.halt 204} 205 206dump_server() 207{ 208 local sock=$1 209 export RUMP_SERVER=$sock 210 rump.netstat -nr 211 rump.arp -n -a 212 rump.ifconfig 213 $HIJACKING dmesg 214} 215 216dump() 217{ 218 dump_server $SOCKLOCAL 219 dump_server $SOCKGATEWAY 220 dump_server $SOCKREMOTE 221 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - 222 shmif_dumpbus -p - bus2 2>/dev/null| tcpdump -n -e -r - 223} 224 225mtudisc_basic_cleanup() 226{ 227 $DEBUG && dump 228 kill "$(cat ${HTTPD_PID})" 229 env RUMP_SERVER=$SOCKLOCAL rump.halt 230 env RUMP_SERVER=$SOCKGATEWAY rump.halt 231 env RUMP_SERVER=$SOCKREMOTE rump.halt 232} 233 234atf_init_test_cases() 235{ 236 atf_add_test_case mtudisc_basic 237} 238