1*960a3e1eSozaki-r# $NetBSD: t_rtcache.sh,v 1.1 2017/09/20 09:36:20 ozaki-r Exp $ 2*960a3e1eSozaki-r# 3*960a3e1eSozaki-r# Copyright (c) 2017 Internet Initiative Japan Inc. 4*960a3e1eSozaki-r# All rights reserved. 5*960a3e1eSozaki-r# 6*960a3e1eSozaki-r# Redistribution and use in source and binary forms, with or without 7*960a3e1eSozaki-r# modification, are permitted provided that the following conditions 8*960a3e1eSozaki-r# are met: 9*960a3e1eSozaki-r# 1. Redistributions of source code must retain the above copyright 10*960a3e1eSozaki-r# notice, this list of conditions and the following disclaimer. 11*960a3e1eSozaki-r# 2. Redistributions in binary form must reproduce the above copyright 12*960a3e1eSozaki-r# notice, this list of conditions and the following disclaimer in the 13*960a3e1eSozaki-r# documentation and/or other materials provided with the distribution. 14*960a3e1eSozaki-r# 15*960a3e1eSozaki-r# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*960a3e1eSozaki-r# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*960a3e1eSozaki-r# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*960a3e1eSozaki-r# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*960a3e1eSozaki-r# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*960a3e1eSozaki-r# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*960a3e1eSozaki-r# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*960a3e1eSozaki-r# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*960a3e1eSozaki-r# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*960a3e1eSozaki-r# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*960a3e1eSozaki-r# POSSIBILITY OF SUCH DAMAGE. 26*960a3e1eSozaki-r# 27*960a3e1eSozaki-r 28*960a3e1eSozaki-rSOCK_SRC=unix://rtcache_src 29*960a3e1eSozaki-rSOCK_FWD=unix://rtcache_fwd 30*960a3e1eSozaki-rSOCK_DST1=unix://rtcache_dst1 31*960a3e1eSozaki-rSOCK_DST2=unix://rtcache_dst2 32*960a3e1eSozaki-r 33*960a3e1eSozaki-rBUS_SRC=./src 34*960a3e1eSozaki-rBUS_DST1=./dst1 35*960a3e1eSozaki-rBUS_DST2=./dst2 36*960a3e1eSozaki-r 37*960a3e1eSozaki-rDEBUG=${DEBUG:-false} 38*960a3e1eSozaki-r 39*960a3e1eSozaki-ratf_test_case rtcache_invalidation cleanup 40*960a3e1eSozaki-rrtcache_invalidation_head() 41*960a3e1eSozaki-r{ 42*960a3e1eSozaki-r 43*960a3e1eSozaki-r atf_set "descr" "Tests for rtcache invalidation" 44*960a3e1eSozaki-r atf_set "require.progs" "rump_server" 45*960a3e1eSozaki-r} 46*960a3e1eSozaki-r 47*960a3e1eSozaki-rrtcache_invalidation_body() 48*960a3e1eSozaki-r{ 49*960a3e1eSozaki-r local ip_src=10.0.0.2 50*960a3e1eSozaki-r local ip_gwsrc=10.0.0.1 51*960a3e1eSozaki-r local ip_gwdst1=10.0.1.1 52*960a3e1eSozaki-r local ip_gwdst2=10.0.2.1 53*960a3e1eSozaki-r local ip_dst1=10.0.1.2 54*960a3e1eSozaki-r local ip_dst2=10.0.2.2 55*960a3e1eSozaki-r local ip_dst=10.0.3.1 56*960a3e1eSozaki-r local subnet_src=10.0.0.0 57*960a3e1eSozaki-r local subnet_dst=10.0.3.0 58*960a3e1eSozaki-r 59*960a3e1eSozaki-r rump_server_start $SOCK_SRC 60*960a3e1eSozaki-r rump_server_start $SOCK_FWD 61*960a3e1eSozaki-r rump_server_start $SOCK_DST1 62*960a3e1eSozaki-r rump_server_start $SOCK_DST2 63*960a3e1eSozaki-r 64*960a3e1eSozaki-r rump_server_add_iface $SOCK_SRC shmif0 $BUS_SRC 65*960a3e1eSozaki-r 66*960a3e1eSozaki-r rump_server_add_iface $SOCK_FWD shmif0 $BUS_SRC 67*960a3e1eSozaki-r rump_server_add_iface $SOCK_FWD shmif1 $BUS_DST1 68*960a3e1eSozaki-r rump_server_add_iface $SOCK_FWD shmif2 $BUS_DST2 69*960a3e1eSozaki-r 70*960a3e1eSozaki-r rump_server_add_iface $SOCK_DST1 shmif0 $BUS_DST1 71*960a3e1eSozaki-r rump_server_add_iface $SOCK_DST2 shmif0 $BUS_DST2 72*960a3e1eSozaki-r 73*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_SRC 74*960a3e1eSozaki-r atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 75*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $ip_src/24 76*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.route add default $ip_gwsrc 77*960a3e1eSozaki-r 78*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_FWD 79*960a3e1eSozaki-r atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.forwarding=1 80*960a3e1eSozaki-r atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 81*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $ip_gwsrc/24 82*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif1 $ip_gwdst1/24 83*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif2 $ip_gwdst2/24 84*960a3e1eSozaki-r 85*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_DST1 86*960a3e1eSozaki-r atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 87*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst1/24 88*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.route add default $ip_gwdst1 89*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst/24 alias 90*960a3e1eSozaki-r 91*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_DST2 92*960a3e1eSozaki-r atf_check -s exit:0 rump.sysctl -q -w net.inet.ip.dad_count=0 93*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst2/24 94*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.route add default $ip_gwdst2 95*960a3e1eSozaki-r atf_check -s exit:0 rump.ifconfig shmif0 $ip_dst/24 alias 96*960a3e1eSozaki-r 97*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_SRC 98*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst1 99*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst2 100*960a3e1eSozaki-r # It fails because there is no route to $ip_dst 101*960a3e1eSozaki-r atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 102*960a3e1eSozaki-r 103*960a3e1eSozaki-r extract_new_packets $BUS_DST1 > ./outfile 104*960a3e1eSozaki-r 105*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_FWD 106*960a3e1eSozaki-r # Add the default route so that $ip_dst @ dst1 is reachable now 107*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.route add default $ip_dst1 108*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_DST1 109*960a3e1eSozaki-r # ...but don't response ICMP requests to avoid rtcache pollution 110*960a3e1eSozaki-r atf_check -s exit:0 -o ignore \ 111*960a3e1eSozaki-r rump.route add -net $subnet_src/24 127.0.0.1 -blackhole 112*960a3e1eSozaki-r 113*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_SRC 114*960a3e1eSozaki-r # ping fails expectedly 115*960a3e1eSozaki-r atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 116*960a3e1eSozaki-r 117*960a3e1eSozaki-r # An ICMP request should come to dst1 118*960a3e1eSozaki-r extract_new_packets $BUS_DST1 > ./outfile 119*960a3e1eSozaki-r atf_check -s exit:0 -o match:"$ip_src > $ip_dst: ICMP echo request" \ 120*960a3e1eSozaki-r cat ./outfile 121*960a3e1eSozaki-r 122*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_FWD 123*960a3e1eSozaki-r # Teach the subnet of $ip_dst is at dst2 124*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.route add -net $subnet_dst/24 $ip_dst2 125*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_DST2 126*960a3e1eSozaki-r # ...but don't response ICMP requests to avoid rtcache pollution 127*960a3e1eSozaki-r atf_check -s exit:0 -o ignore \ 128*960a3e1eSozaki-r rump.route add -net $subnet_src/24 127.0.0.1 -blackhole 129*960a3e1eSozaki-r 130*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_SRC 131*960a3e1eSozaki-r # ping fails expectedly 132*960a3e1eSozaki-r atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 133*960a3e1eSozaki-r 134*960a3e1eSozaki-r # An ICMP request should come to dst2. If rtcaches aren't invalidated 135*960a3e1eSozaki-r # correctly, the ICMP request should appear at dst1 136*960a3e1eSozaki-r extract_new_packets $BUS_DST1 > ./outfile 137*960a3e1eSozaki-r atf_check -s exit:0 -o not-match:"$ip_src > $ip_dst: ICMP echo request" \ 138*960a3e1eSozaki-r cat ./outfile 139*960a3e1eSozaki-r 140*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_FWD 141*960a3e1eSozaki-r # Delete the route so the packets heading to $ip_dst should go dst1 again 142*960a3e1eSozaki-r atf_check -s exit:0 -o ignore rump.route delete -net $subnet_dst/24 $ip_dst2 143*960a3e1eSozaki-r 144*960a3e1eSozaki-r export RUMP_SERVER=$SOCK_SRC 145*960a3e1eSozaki-r # ping fails expectedly 146*960a3e1eSozaki-r atf_check -s not-exit:0 -o ignore rump.ping -n -w 3 -c 1 $ip_dst 147*960a3e1eSozaki-r 148*960a3e1eSozaki-r # An ICMP request should come to dst1 149*960a3e1eSozaki-r extract_new_packets $BUS_DST1 > ./outfile 150*960a3e1eSozaki-r atf_check -s exit:0 -o match:"$ip_src > $ip_dst: ICMP echo request" \ 151*960a3e1eSozaki-r cat ./outfile 152*960a3e1eSozaki-r 153*960a3e1eSozaki-r rump_server_destroy_ifaces 154*960a3e1eSozaki-r} 155*960a3e1eSozaki-r 156*960a3e1eSozaki-rrtcache_invalidation_cleanup() 157*960a3e1eSozaki-r{ 158*960a3e1eSozaki-r 159*960a3e1eSozaki-r $DEBUG && dump 160*960a3e1eSozaki-r cleanup 161*960a3e1eSozaki-r} 162*960a3e1eSozaki-r 163*960a3e1eSozaki-ratf_init_test_cases() 164*960a3e1eSozaki-r{ 165*960a3e1eSozaki-r 166*960a3e1eSozaki-r atf_add_test_case rtcache_invalidation 167*960a3e1eSozaki-r} 168