1# $NetBSD: t_mtudisc.sh,v 1.8 2016/12/21 01:16:18 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 28SOCKLOCAL=unix://commsock1 29SOCKGATEWAY=unix://commsock2 30SOCKREMOTE=unix://commsock3 31HTML_FILE=index.html 32 33DEBUG=${DEBUG:-false} 34 35atf_test_case mtudisc_basic cleanup 36 37mtudisc_basic_head() 38{ 39 atf_set "descr" "Tests for IPv4 Path MTU Dicorvery basic behavior" 40 atf_set "require.progs" "rump_server" 41} 42 43setup_server() 44{ 45 local sock=$1 46 local if=$2 47 local bus=$3 48 local ip=$4 49 50 rump_server_add_iface $sock $if $bus 51 52 export RUMP_SERVER=$sock 53 atf_check -s exit:0 rump.ifconfig $if $ip 54 atf_check -s exit:0 rump.ifconfig $if up 55 atf_check -s exit:0 rump.ifconfig -w 10 56 57 $DEBUG && rump.ifconfig $if 58} 59 60prepare_download_file() 61{ 62 local file=$1 63 local data="0123456789" 64 65 touch $file 66 for i in `seq 1 512` 67 do 68 echo $data >> $file 69 done 70} 71 72do_http_get() 73{ 74 local ip=$1 75 local ret=$2 76 local timeout=5 77 78 # get the webpage 79 atf_check -s exit:$ret env LD_PRELOAD=/usr/lib/librumphijack.so \ 80 ftp -q $timeout -o ./out http://$ip/$HTML_FILE 81} 82 83mtudisc_basic_body() 84{ 85 local pkt= 86 local local_ip=10.0.0.2 87 local gateway_local_ip=10.0.0.1 88 local gateway_remote_ip=10.0.1.1 89 local remote_ip=10.0.1.2 90 local prefixlen=24 91 92 rump_server_start $SOCKLOCAL 93 rump_server_start $SOCKGATEWAY 94 rump_server_start $SOCKREMOTE 95 96 # 97 # Setup servers 98 # 99 # [local server] [gateway server] [remote server with httpd] 100 # | 10.0.0.2 10.0.0.1 | | 10.0.1.1 10.0.1.2 | 101 # shmif0(mtu=1500) ----- shmif1(mtu=1280) shmif0(mtu=1500) ----- shmif0(mtu=1500) 102 # 103 104 # Assign IP addresses 105 setup_server $SOCKLOCAL shmif0 bus1 $local_ip/$prefixlen 106 setup_server $SOCKGATEWAY shmif0 bus1 $gateway_local_ip/$prefixlen 107 setup_server $SOCKGATEWAY shmif1 bus2 $gateway_remote_ip/$prefixlen 108 setup_server $SOCKREMOTE shmif0 bus2 $remote_ip/$prefixlen 109 110 ### Setup gateway server 111 export RUMP_SERVER=$SOCKGATEWAY 112 113 # Set mtu of shmif0 to 1280 114 export RUMP_SERVER=$SOCKGATEWAY 115 atf_check -s exit:0 rump.ifconfig shmif0 mtu 1280 116 117 # Enable IPv4 forwarding 118 atf_check -s exit:0 rump.sysctl -w -q net.inet.ip.forwarding=1 119 120 ### Setup remote server 121 export RUMP_SERVER=$SOCKREMOTE 122 123 # Check default value 124 atf_check -s exit:0 -o match:"1" rump.sysctl -n net.inet.ip.mtudisc 125 126 # Start httpd daemon 127 prepare_download_file $HTML_FILE 128 start_httpd $SOCKREMOTE $remote_ip 129 $DEBUG && rump.netstat -a -f inet 130 131 # Teach the peer thar 10.0.0.2(local serer) is behind 10.0.1.1(gateway server) 132 atf_check -s exit:0 -o ignore rump.route add $local_ip/32 $gateway_remote_ip 133 134 ### Setup local server 135 export RUMP_SERVER=$SOCKLOCAL 136 137 # Teach the peer thar 10.0.1.2(remote serer) is behind 10.0.0.1(gateway server) 138 atf_check -s exit:0 -o ignore rump.route add $remote_ip/32 $gateway_local_ip 139 140 # Don't accept fragmented packets 141 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.maxfragpackets=0 142 143 # 144 # Test disabled path mtu discorvery 145 # 146 export RUMP_SERVER=$SOCKREMOTE 147 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=0 148 149 # Get the webpage (expect: failed) 150 export RUMP_SERVER=$SOCKLOCAL 151 do_http_get $remote_ip 1 152 $DEBUG && extract_new_packets bus2 > ./out 153 $DEBUG && cat ./out 154 155 # Check path mtu size on remote server 156 export RUMP_SERVER=$SOCKREMOTE 157 atf_check -s exit:0 \ 158 -o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +- +shmif0" \ 159 rump.netstat -nr -f inet 160 161 # 162 # Test enabled path mtu discorvery 163 # 164 export RUMP_SERVER=$SOCKREMOTE 165 atf_check -s exit:0 -o ignore rump.sysctl -w -q net.inet.ip.mtudisc=1 166 167 # Get the webpage (expect: success) 168 export RUMP_SERVER=$SOCKLOCAL 169 do_http_get $remote_ip 0 170 $DEBUG && extract_new_packets bus2 > ./out 171 $DEBUG && cat ./out 172 173 # Check path mtu size on remote server 174 export RUMP_SERVER=$SOCKREMOTE 175 atf_check -s exit:0 \ 176 -o match:"^10.0.0.2 +10.0.1.1 +UGHS +- +- +1280 +shmif0" \ 177 rump.netstat -nr -f inet 178 179 rump_server_destroy_ifaces 180} 181 182mtudisc_basic_cleanup() 183{ 184 $DEBUG && dump 185 stop_httpd 186 cleanup 187} 188 189atf_init_test_cases() 190{ 191 atf_add_test_case mtudisc_basic 192} 193