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