1 # $NetBSD: t_tun.sh,v 1.6 2019/05/13 17:55:09 bad 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 28 RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6" 29 RUMP_FLAGS="$RUMP_FLAGS -lrumpnet_shmif -lrumpnet_tun" 30 31 BUS=bus 32 SOCK_LOCAL=unix://commsock1 33 SOCK_REMOTE=unix://commsock2 34 IP_LOCAL=10.0.0.1 35 IP_REMOTE=10.0.0.2 36 37 DEBUG=${DEBUG:-true} 38 39 atf_test_case tun_create_destroy cleanup 40 tun_create_destroy_head() 41 { 42 43 atf_set "descr" "tests of creation and deletion of tun interface" 44 atf_set "require.progs" "rump_server" 45 } 46 47 tun_create_destroy_body() 48 { 49 50 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL} 51 52 test_create_destroy_common $SOCK_LOCAL tun0 53 } 54 55 tun_create_destroy_cleanup() 56 { 57 58 RUMP_SERVER=${SOCK_LOCAL} rump.halt 59 } 60 61 atf_test_case tun_setup cleanup 62 tun_setup_head() 63 { 64 65 atf_set "descr" "tests of setting up a tunnel" 66 atf_set "require.progs" "rump_server" 67 } 68 69 check_route_entry() 70 { 71 local ip=$(echo $1 |sed 's/\./\\./g') 72 local gw=$2 73 local flags=$3 74 local iface=$4 75 76 atf_check -s exit:0 -o match:" $flags " -e ignore -x \ 77 "rump.netstat -rn -f inet | grep ^'$ip'" 78 atf_check -s exit:0 -o match:" $gw " -e ignore -x \ 79 "rump.netstat -rn -f inet | grep ^'$ip'" 80 atf_check -s exit:0 -o match:" $iface" -e ignore -x \ 81 "rump.netstat -rn -f inet | grep ^'$ip'" 82 } 83 84 tun_setup_body() 85 { 86 87 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL} 88 atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE} 89 90 export RUMP_SERVER=${SOCK_LOCAL} 91 92 atf_check -s exit:0 rump.ifconfig shmif0 create 93 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS 94 atf_check -s exit:0 rump.ifconfig shmif0 ${IP_LOCAL}/24 up 95 atf_check -s exit:0 rump.ifconfig -w 10 96 97 export RUMP_SERVER=${SOCK_REMOTE} 98 99 atf_check -s exit:0 rump.ifconfig shmif0 create 100 atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS 101 atf_check -s exit:0 rump.ifconfig shmif0 ${IP_REMOTE}/24 up 102 atf_check -s exit:0 rump.ifconfig -w 10 103 104 export RUMP_SERVER=${SOCK_LOCAL} 105 atf_check -s exit:0 rump.ifconfig tun0 create 106 atf_check -s exit:0 rump.ifconfig tun0 ${IP_LOCAL} ${IP_REMOTE} up 107 atf_check -s exit:0 \ 108 -o match:"inet ${IP_LOCAL}/32 -> ${IP_REMOTE}" rump.ifconfig tun0 109 $DEBUG && rump.netstat -nr -f inet 110 check_route_entry ${IP_REMOTE} ${IP_LOCAL} UH tun0 111 112 export RUMP_SERVER=${SOCK_REMOTE} 113 atf_check -s exit:0 rump.ifconfig tun0 create 114 atf_check -s exit:0 rump.ifconfig tun0 ${IP_REMOTE} ${IP_LOCAL} up 115 atf_check -s exit:0 \ 116 -o match:"inet ${IP_REMOTE}/32 -> ${IP_LOCAL}" rump.ifconfig tun0 117 $DEBUG && rump.netstat -nr -f inet 118 check_route_entry ${IP_LOCAL} ${IP_REMOTE} UH tun0 119 } 120 121 tun_setup_cleanup() 122 { 123 124 RUMP_SERVER=${SOCK_LOCAL} rump.halt 125 RUMP_SERVER=${SOCK_REMOTE} rump.halt 126 } 127 128 atf_init_test_cases() 129 { 130 131 atf_add_test_case tun_create_destroy 132 atf_add_test_case tun_setup 133 } 134