1# $NetBSD: t_rtcache.sh,v 1.1 2017/09/20 09:36:20 ozaki-r Exp $ 2# 3# Copyright (c) 2017 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 28SOCK_SRC=unix://rtcache_src 29SOCK_FWD=unix://rtcache_fwd 30SOCK_DST1=unix://rtcache_dst1 31SOCK_DST2=unix://rtcache_dst2 32 33BUS_SRC=./src 34BUS_DST1=./dst1 35BUS_DST2=./dst2 36 37DEBUG=${DEBUG:-false} 38 39atf_test_case rtcache_invalidation cleanup 40rtcache_invalidation_head() 41{ 42 43 atf_set "descr" "Tests for rtcache invalidation" 44 atf_set "require.progs" "rump_server" 45} 46 47rtcache_invalidation_body() 48{ 49 local ip_src=10.0.0.2 50 local ip_gwsrc=10.0.0.1 51 local ip_gwdst1=10.0.1.1 52 local ip_gwdst2=10.0.2.1 53 local ip_dst1=10.0.1.2 54 local ip_dst2=10.0.2.2 55 local ip_dst=10.0.3.1 56 local subnet_src=10.0.0.0 57 local subnet_dst=10.0.3.0 58 59 rump_server_start $SOCK_SRC 60 rump_server_start $SOCK_FWD 61 rump_server_start $SOCK_DST1 62 rump_server_start $SOCK_DST2 63 64 rump_server_add_iface $SOCK_SRC shmif0 $BUS_SRC 65 66 rump_server_add_iface $SOCK_FWD shmif0 $BUS_SRC 67 rump_server_add_iface $SOCK_FWD shmif1 $BUS_DST1 68 rump_server_add_iface $SOCK_FWD shmif2 $BUS_DST2 69 70 rump_server_add_iface $SOCK_DST1 shmif0 $BUS_DST1 71 rump_server_add_iface $SOCK_DST2 shmif0 $BUS_DST2 72 73 export RUMP_SERVER=$SOCK_SRC 74 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 75 atf_check -s exit:0 rump.ifconfig shmif0 $ip_src/24 76 atf_check -s exit:0 -o ignore rump.route add default $ip_gwsrc 77 78 export RUMP_SERVER=$SOCK_FWD 79 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=1 80 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 81 atf_check -s exit:0 rump.ifconfig shmif0 $ip_gwsrc/24 82 atf_check -s exit:0 rump.ifconfig shmif1 $ip_gwdst1/24 83 atf_check -s exit:0 rump.ifconfig shmif2 $ip_gwdst2/24 84 85 export RUMP_SERVER=$SOCK_DST1 86 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 87 atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst1/24 88 atf_check -s exit:0 -o ignore rump.route add default $ip_gwdst1 89 atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst/24 alias 90 91 export RUMP_SERVER=$SOCK_DST2 92 atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 93 atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst2/24 94 atf_check -s exit:0 -o ignore rump.route add default $ip_gwdst2 95 atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst/24 alias 96 97 export RUMP_SERVER=$SOCK_SRC 98 atf_check -s exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst1 99 atf_check -s exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst2 100 # It fails because there is no route to $ip_dst 101 atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 102 103 extract_new_packets $BUS_DST1 > ./outfile 104 105 export RUMP_SERVER=$SOCK_FWD 106 # Add the default route so that $ip_dst @ dst1 is reachable now 107 atf_check -s exit:0 -o ignore rump.route add default $ip_dst1 108 export RUMP_SERVER=$SOCK_DST1 109 # ...but don't response ICMP requests to avoid rtcache pollution 110 atf_check -s exit:0 -o ignore \ 111 rump.route add -net $subnet_src/24 127.0.0.1 -blackhole 112 113 export RUMP_SERVER=$SOCK_SRC 114 # ping fails expectedly 115 atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 116 117 # An ICMP request should come to dst1 118 extract_new_packets $BUS_DST1 > ./outfile 119 atf_check -s exit:0 -o match:"$ip_src > $ip_dst: ICMP echo request" \ 120 cat ./outfile 121 122 export RUMP_SERVER=$SOCK_FWD 123 # Teach the subnet of $ip_dst is at dst2 124 atf_check -s exit:0 -o ignore rump.route add -net $subnet_dst/24 $ip_dst2 125 export RUMP_SERVER=$SOCK_DST2 126 # ...but don't response ICMP requests to avoid rtcache pollution 127 atf_check -s exit:0 -o ignore \ 128 rump.route add -net $subnet_src/24 127.0.0.1 -blackhole 129 130 export RUMP_SERVER=$SOCK_SRC 131 # ping fails expectedly 132 atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 133 134 # An ICMP request should come to dst2. If rtcaches aren't invalidated 135 # correctly, the ICMP request should appear at dst1 136 extract_new_packets $BUS_DST1 > ./outfile 137 atf_check -s exit:0 -o not-match:"$ip_src > $ip_dst: ICMP echo request" \ 138 cat ./outfile 139 140 export RUMP_SERVER=$SOCK_FWD 141 # Delete the route so the packets heading to $ip_dst should go dst1 again 142 atf_check -s exit:0 -o ignore rump.route delete -net $subnet_dst/24 $ip_dst2 143 144 export RUMP_SERVER=$SOCK_SRC 145 # ping fails expectedly 146 atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 147 148 # An ICMP request should come to dst1 149 extract_new_packets $BUS_DST1 > ./outfile 150 atf_check -s exit:0 -o match:"$ip_src > $ip_dst: ICMP echo request" \ 151 cat ./outfile 152 153 rump_server_destroy_ifaces 154} 155 156rtcache_invalidation_cleanup() 157{ 158 159 $DEBUG && dump 160 cleanup 161} 162 163atf_init_test_cases() 164{ 165 166 atf_add_test_case rtcache_invalidation 167} 168