Home | History | Annotate | Line # | Download | only in if_tun
t_tun.sh revision 1.2.2.4
      1  1.2.2.4  pgoyette #	$NetBSD: t_tun.sh,v 1.2.2.4 2017/01/07 08:56:56 pgoyette Exp $
      2  1.2.2.2  pgoyette #
      3  1.2.2.2  pgoyette # Copyright (c) 2016 Internet Initiative Japan Inc.
      4  1.2.2.2  pgoyette # All rights reserved.
      5  1.2.2.2  pgoyette #
      6  1.2.2.2  pgoyette # Redistribution and use in source and binary forms, with or without
      7  1.2.2.2  pgoyette # modification, are permitted provided that the following conditions
      8  1.2.2.2  pgoyette # are met:
      9  1.2.2.2  pgoyette # 1. Redistributions of source code must retain the above copyright
     10  1.2.2.2  pgoyette #    notice, this list of conditions and the following disclaimer.
     11  1.2.2.2  pgoyette # 2. Redistributions in binary form must reproduce the above copyright
     12  1.2.2.2  pgoyette #    notice, this list of conditions and the following disclaimer in the
     13  1.2.2.2  pgoyette #    documentation and/or other materials provided with the distribution.
     14  1.2.2.2  pgoyette #
     15  1.2.2.2  pgoyette # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16  1.2.2.2  pgoyette # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17  1.2.2.2  pgoyette # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18  1.2.2.2  pgoyette # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19  1.2.2.2  pgoyette # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20  1.2.2.2  pgoyette # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21  1.2.2.2  pgoyette # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22  1.2.2.2  pgoyette # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23  1.2.2.2  pgoyette # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24  1.2.2.2  pgoyette # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25  1.2.2.2  pgoyette # POSSIBILITY OF SUCH DAMAGE.
     26  1.2.2.2  pgoyette #
     27  1.2.2.2  pgoyette 
     28  1.2.2.2  pgoyette RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6"
     29  1.2.2.2  pgoyette RUMP_FLAGS="$RUMP_FLAGS -lrumpnet_shmif -lrumpnet_tun -lrumpdev"
     30  1.2.2.2  pgoyette 
     31  1.2.2.2  pgoyette BUS=bus
     32  1.2.2.2  pgoyette SOCK_LOCAL=unix://commsock1
     33  1.2.2.2  pgoyette SOCK_REMOTE=unix://commsock2
     34  1.2.2.2  pgoyette IP_LOCAL=10.0.0.1
     35  1.2.2.2  pgoyette IP_REMOTE=10.0.0.2
     36  1.2.2.2  pgoyette 
     37  1.2.2.4  pgoyette DEBUG=${DEBUG:-true}
     38  1.2.2.2  pgoyette 
     39  1.2.2.2  pgoyette atf_test_case tun_create_destroy cleanup
     40  1.2.2.2  pgoyette tun_create_destroy_head()
     41  1.2.2.2  pgoyette {
     42  1.2.2.2  pgoyette 
     43  1.2.2.2  pgoyette 	atf_set "descr" "tests of creation and deletion of tun interface"
     44  1.2.2.2  pgoyette 	atf_set "require.progs" "rump_server"
     45  1.2.2.2  pgoyette }
     46  1.2.2.2  pgoyette 
     47  1.2.2.2  pgoyette tun_create_destroy_body()
     48  1.2.2.2  pgoyette {
     49  1.2.2.2  pgoyette 
     50  1.2.2.2  pgoyette 	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
     51  1.2.2.2  pgoyette 
     52  1.2.2.2  pgoyette 	export RUMP_SERVER=${SOCK_LOCAL}
     53  1.2.2.2  pgoyette 
     54  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 create
     55  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 up
     56  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 down
     57  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 destroy
     58  1.2.2.2  pgoyette }
     59  1.2.2.2  pgoyette 
     60  1.2.2.2  pgoyette tun_create_destroy_cleanup()
     61  1.2.2.2  pgoyette {
     62  1.2.2.2  pgoyette 
     63  1.2.2.2  pgoyette 	RUMP_SERVER=${SOCK_LOCAL} rump.halt
     64  1.2.2.2  pgoyette }
     65  1.2.2.2  pgoyette 
     66  1.2.2.2  pgoyette atf_test_case tun_setup cleanup
     67  1.2.2.2  pgoyette tun_setup_head()
     68  1.2.2.2  pgoyette {
     69  1.2.2.2  pgoyette 
     70  1.2.2.2  pgoyette 	atf_set "descr" "tests of setting up a tunnel"
     71  1.2.2.2  pgoyette 	atf_set "require.progs" "rump_server"
     72  1.2.2.2  pgoyette }
     73  1.2.2.2  pgoyette 
     74  1.2.2.2  pgoyette check_route_entry()
     75  1.2.2.2  pgoyette {
     76  1.2.2.2  pgoyette 	local ip=$(echo $1 |sed 's/\./\\./g')
     77  1.2.2.2  pgoyette 	local gw=$2
     78  1.2.2.2  pgoyette 	local flags=$3
     79  1.2.2.2  pgoyette 	local iface=$4
     80  1.2.2.2  pgoyette 
     81  1.2.2.2  pgoyette 	atf_check -s exit:0 -o match:" $flags " -e ignore -x \
     82  1.2.2.2  pgoyette 	    "rump.netstat -rn -f inet | grep ^'$ip'"
     83  1.2.2.2  pgoyette 	atf_check -s exit:0 -o match:" $gw " -e ignore -x \
     84  1.2.2.2  pgoyette 	    "rump.netstat -rn -f inet | grep ^'$ip'"
     85  1.2.2.2  pgoyette 	atf_check -s exit:0 -o match:" $iface" -e ignore -x \
     86  1.2.2.2  pgoyette 	    "rump.netstat -rn -f inet | grep ^'$ip'"
     87  1.2.2.2  pgoyette }
     88  1.2.2.2  pgoyette 
     89  1.2.2.2  pgoyette tun_setup_body()
     90  1.2.2.2  pgoyette {
     91  1.2.2.2  pgoyette 
     92  1.2.2.2  pgoyette 	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL}
     93  1.2.2.2  pgoyette 	atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE}
     94  1.2.2.2  pgoyette 
     95  1.2.2.2  pgoyette 	export RUMP_SERVER=${SOCK_LOCAL}
     96  1.2.2.2  pgoyette 
     97  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig shmif0 create
     98  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
     99  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig shmif0 ${IP_LOCAL}/24 up
    100  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig -w 10
    101  1.2.2.2  pgoyette 
    102  1.2.2.2  pgoyette 	export RUMP_SERVER=${SOCK_REMOTE}
    103  1.2.2.2  pgoyette 
    104  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig shmif0 create
    105  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
    106  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig shmif0 ${IP_REMOTE}/24 up
    107  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig -w 10
    108  1.2.2.2  pgoyette 
    109  1.2.2.2  pgoyette 	export RUMP_SERVER=${SOCK_LOCAL}
    110  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 create
    111  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 ${IP_LOCAL} ${IP_REMOTE} up
    112  1.2.2.2  pgoyette 	atf_check -s exit:0 \
    113  1.2.2.3  pgoyette 	    -o match:"inet ${IP_LOCAL}/32 -> ${IP_REMOTE}" rump.ifconfig tun0
    114  1.2.2.2  pgoyette 	$DEBUG && rump.netstat -nr -f inet
    115  1.2.2.2  pgoyette 	check_route_entry ${IP_REMOTE} ${IP_LOCAL} UH tun0
    116  1.2.2.2  pgoyette 
    117  1.2.2.2  pgoyette 	export RUMP_SERVER=${SOCK_REMOTE}
    118  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 create
    119  1.2.2.2  pgoyette 	atf_check -s exit:0 rump.ifconfig tun0 ${IP_REMOTE} ${IP_LOCAL} up
    120  1.2.2.2  pgoyette 	atf_check -s exit:0 \
    121  1.2.2.3  pgoyette 	    -o match:"inet ${IP_REMOTE}/32 -> ${IP_LOCAL}" rump.ifconfig tun0
    122  1.2.2.2  pgoyette 	$DEBUG && rump.netstat -nr -f inet
    123  1.2.2.2  pgoyette 	check_route_entry ${IP_LOCAL} ${IP_REMOTE} UH tun0
    124  1.2.2.2  pgoyette }
    125  1.2.2.2  pgoyette 
    126  1.2.2.2  pgoyette tun_setup_cleanup()
    127  1.2.2.2  pgoyette {
    128  1.2.2.2  pgoyette 
    129  1.2.2.2  pgoyette 	RUMP_SERVER=${SOCK_LOCAL} rump.halt
    130  1.2.2.2  pgoyette 	RUMP_SERVER=${SOCK_REMOTE} rump.halt
    131  1.2.2.2  pgoyette }
    132  1.2.2.2  pgoyette 
    133  1.2.2.2  pgoyette atf_init_test_cases()
    134  1.2.2.2  pgoyette {
    135  1.2.2.2  pgoyette 
    136  1.2.2.2  pgoyette 	atf_add_test_case tun_create_destroy
    137  1.2.2.2  pgoyette 	atf_add_test_case tun_setup
    138  1.2.2.2  pgoyette }
    139