From 927b18c962f09ec425493d3c6bf1adb9fa853504 Mon Sep 17 00:00:00 2001 From: ozaki-r Date: Thu, 24 Nov 2016 09:05:16 +0000 Subject: [PATCH] Move route check functions to net_common.sh --- tests/net/icmp/t_icmp_redirect.sh | 53 ++++++---------------- tests/net/net/t_ipaddress.sh | 68 +++++++--------------------- tests/net/net_common.sh | 40 ++++++++++++++++- tests/net/route/Makefile | 8 +++- tests/net/route/t_flags.sh | 73 ++++++++++--------------------- tests/net/route/t_flags6.sh | 59 +++++++------------------ 6 files changed, 114 insertions(+), 187 deletions(-) diff --git a/tests/net/icmp/t_icmp_redirect.sh b/tests/net/icmp/t_icmp_redirect.sh index adcf5d121ebc..c995a615b70d 100644 --- a/tests/net/icmp/t_icmp_redirect.sh +++ b/tests/net/icmp/t_icmp_redirect.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_icmp_redirect.sh,v 1.4 2016/11/07 05:25:36 ozaki-r Exp $ +# $NetBSD: t_icmp_redirect.sh,v 1.5 2016/11/24 09:05:16 ozaki-r Exp $ # # Copyright (c) 2015 The NetBSD Foundation, Inc. # All rights reserved. @@ -111,33 +111,6 @@ teardown_gw() env RUMP_SERVER=$SOCK_GW rump.halt } -check_entry_flags() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local flags=$2 - - atf_check -s exit:0 -o match:" $flags " -e ignore -x \ - "rump.netstat -rn -f inet | grep ^'$ip'" -} - -check_entry_gw() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local gw=$2 - - atf_check -s exit:0 -o match:" $gw " -e ignore -x \ - "rump.netstat -rn -f inet | grep ^'$ip'" -} - -check_entry_fail() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local flags=$2 # Not used currently - - atf_check -s not-exit:0 -e ignore -x \ - "rump.netstat -rn -f inet | grep ^'$ip'" -} - icmp_redirect_timeout_body() { @@ -159,7 +132,7 @@ icmp_redirect_timeout_body() export RUMP_SERVER=$SOCK_PEER atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254 # Up, Gateway, Static - check_entry_flags 10.0.2/24 UGS + check_route_flags 10.0.2/24 UGS # # Setup the default gateway to the peer, 10.0.0.1 @@ -167,20 +140,20 @@ icmp_redirect_timeout_body() export RUMP_SERVER=$SOCK_LOCAL atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1 # Up, Gateway, Static - check_entry_flags default UGS + check_route_flags default UGS # Try ping 10.0.2.1 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1 $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Host, Dynamic - check_entry_flags 10.0.2.1 UGHD - check_entry_gw 10.0.2.1 10.0.0.254 + check_route_flags 10.0.2.1 UGHD + check_route_gw 10.0.2.1 10.0.0.254 atf_check -s exit:0 sleep $((REDIRECT_TIMEOUT + 2)) # The dynamic entry should be expired and removed - check_entry_fail 10.0.2.1 + check_route_no_entry 10.0.2.1 export RUMP_SERVER=$SOCK_PEER $DEBUG && rump.netstat -rn -f inet @@ -249,7 +222,7 @@ icmp_redirect_body() export RUMP_SERVER=$SOCK_PEER atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254 # Up, Gateway, Static - check_entry_flags 10.0.2/24 UGS + check_route_flags 10.0.2/24 UGS # # Setup the default gateway to the peer, 10.0.0.1 @@ -257,7 +230,7 @@ icmp_redirect_body() export RUMP_SERVER=$SOCK_LOCAL atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1 # Up, Gateway, Static - check_entry_flags default UGS + check_route_flags default UGS ### ICMP redirects are NOT sent by the peer ### @@ -274,7 +247,7 @@ icmp_redirect_body() $DEBUG && rump.netstat -rn -f inet # A direct route shouldn't be created - check_entry_fail 10.0.2.1 + check_route_no_entry 10.0.2.1 ### ICMP redirects are sent by the peer ### @@ -291,8 +264,8 @@ icmp_redirect_body() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Host, Dynamic - check_entry_flags 10.0.2.1 UGHD - check_entry_gw 10.0.2.1 10.0.0.254 + check_route_flags 10.0.2.1 UGHD + check_route_gw 10.0.2.1 10.0.0.254 export RUMP_SERVER=$SOCK_PEER $DEBUG && rump.netstat -rn -f inet @@ -301,7 +274,7 @@ icmp_redirect_body() # cleanup export RUMP_SERVER=$SOCK_LOCAL atf_check -s exit:0 -o ignore rump.route delete 10.0.2.1 - check_entry_fail 10.0.2.1 + check_route_no_entry 10.0.2.1 ### ICMP redirects are NOT sent by the peer (again) ### @@ -318,7 +291,7 @@ icmp_redirect_body() $DEBUG && rump.netstat -rn -f inet # A direct route shouldn't be created - check_entry_fail 10.0.2.1 + check_route_no_entry 10.0.2.1 teardown_gw diff --git a/tests/net/net/t_ipaddress.sh b/tests/net/net/t_ipaddress.sh index 6c35f50bf8a0..3cde8b3c9978 100644 --- a/tests/net/net/t_ipaddress.sh +++ b/tests/net/net/t_ipaddress.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_ipaddress.sh,v 1.6 2016/11/24 07:32:19 ozaki-r Exp $ +# $NetBSD: t_ipaddress.sh,v 1.7 2016/11/24 09:05:17 ozaki-r Exp $ # # Copyright (c) 2015 Internet Initiative Japan Inc. # All rights reserved. @@ -32,24 +32,6 @@ BUS=bus DEBUG=${DEBUG:-false} -check_entry() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local word=$2 - - atf_check -s exit:0 -o match:"$word" -e ignore -x \ - "rump.netstat -rn | grep ^'$ip'" -} - -check_entry_fail() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local flags=$2 # Not used currently - - atf_check -s not-exit:0 -e ignore -x \ - "rump.netstat -rn | grep ^'$ip'" -} - test_same_address() { local ip=10.0.0.1 @@ -66,20 +48,16 @@ test_same_address() $DEBUG && rump.netstat -nr -f inet - check_entry $ip UHl - check_entry $ip lo0 - check_entry $ip 'link#2' - check_entry $net UC - check_entry $net shmif0 - check_entry $net 'link#2' + check_route $ip 'link#2' UHl lo0 + check_route $net 'link#2' UC shmif0 # Delete the address atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete $DEBUG && rump.netstat -nr -f inet - check_entry_fail $ip - check_entry_fail $net + check_route_no_entry $ip + check_route_no_entry $net # Assign the same address again atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip/24 @@ -87,20 +65,16 @@ test_same_address() $DEBUG && rump.netstat -nr -f inet - check_entry $ip UHl - check_entry $ip lo0 - check_entry $ip 'link#2' - check_entry $net UC - check_entry $net shmif0 - check_entry $net 'link#2' + check_route $ip 'link#2' UHl lo0 + check_route $net 'link#2' UC shmif0 # Delete the address again atf_check -s exit:0 -o ignore rump.ifconfig shmif0 $ip delete $DEBUG && rump.netstat -nr -f inet - check_entry_fail $ip - check_entry_fail $net + check_route_no_entry $ip + check_route_no_entry $net } test_same_address6() @@ -119,20 +93,16 @@ test_same_address6() $DEBUG && rump.netstat -nr -f inet6 - check_entry $ip UHl - check_entry $ip lo0 - check_entry $ip 'link#2' - check_entry $net UC - check_entry $net shmif0 - check_entry $net 'link#2' + check_route $ip 'link#2' UHl lo0 + check_route $net 'link#2' UC shmif0 # Delete the address atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete $DEBUG && rump.netstat -nr -f inet6 - check_entry_fail $ip - check_entry_fail $net + check_route_no_entry $ip + check_route_no_entry $net # Assign the same address again atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip @@ -140,20 +110,16 @@ test_same_address6() $DEBUG && rump.netstat -nr -f inet6 - check_entry $ip UHl - check_entry $ip lo0 - check_entry $ip 'link#2' - check_entry $net UC - check_entry $net shmif0 - check_entry $net 'link#2' + check_route $ip 'link#2' UHl lo0 + check_route $net 'link#2' UC shmif0 # Delete the address again atf_check -s exit:0 -o ignore rump.ifconfig shmif0 inet6 $ip delete $DEBUG && rump.netstat -nr -f inet6 - check_entry_fail $ip - check_entry_fail $net + check_route_no_entry $ip + check_route_no_entry $net } test_auto_linklocal() diff --git a/tests/net/net_common.sh b/tests/net/net_common.sh index 269c411eae2f..75ea3c1601d9 100644 --- a/tests/net/net_common.sh +++ b/tests/net/net_common.sh @@ -1,4 +1,4 @@ -# $NetBSD: net_common.sh,v 1.2 2016/11/24 09:03:53 ozaki-r Exp $ +# $NetBSD: net_common.sh,v 1.3 2016/11/24 09:05:16 ozaki-r Exp $ # # Copyright (c) 2016 Internet Initiative Japan Inc. # All rights reserved. @@ -47,3 +47,41 @@ extract_new_packets() cat ./.__diff } +check_route() +{ + local target=$1 + local gw=$2 + local flags=${3:-\.\+} + local ifname=${4:-\.\+} + + target=$(echo $target |sed 's/\./\\./g') + if [ "$gw" = "" ]; then + gw=".+" + else + gw=$(echo $gw |sed 's/\./\\./g') + fi + + atf_check -s exit:0 -e ignore \ + -o match:"^$target +$gw +$flags +- +- +.+ +$ifname" \ + rump.netstat -rn +} + +check_route_flags() +{ + + check_route "$1" "" "$2" "" +} + +check_route_gw() +{ + + check_route "$1" "$2" "" "" +} + +check_route_no_entry() +{ + local target=$(echo $1 |sed 's/\./\\./g') + + atf_check -s exit:0 -e ignore -o not-match:"^$target" \ + rump.netstat -rn +} diff --git a/tests/net/route/Makefile b/tests/net/route/Makefile index 7ca14767995e..9a64e6def939 100644 --- a/tests/net/route/Makefile +++ b/tests/net/route/Makefile @@ -1,10 +1,14 @@ -# $NetBSD: Makefile,v 1.4 2016/04/21 05:10:15 ozaki-r Exp $ +# $NetBSD: Makefile,v 1.5 2016/11/24 09:05:17 ozaki-r Exp $ # .include TESTSDIR= ${TESTSBASE}/net/route -TESTS_SH= t_change t_flags t_flags6 t_route +.for name in change flags flags6 route +TESTS_SH+= t_${name} +TESTS_SH_SRC_t_${name}= ../net_common.sh t_${name}.sh +.endfor + .include diff --git a/tests/net/route/t_flags.sh b/tests/net/route/t_flags.sh index 0f22c4d52c59..c08e813591d7 100644 --- a/tests/net/route/t_flags.sh +++ b/tests/net/route/t_flags.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_flags.sh,v 1.12 2016/11/07 05:25:37 ozaki-r Exp $ +# $NetBSD: t_flags.sh,v 1.13 2016/11/24 09:05:17 ozaki-r Exp $ # # Copyright (c) 2015 The NetBSD Foundation, Inc. # All rights reserved. @@ -97,40 +97,13 @@ teardown_gw() env RUMP_SERVER=$SOCK_GW rump.halt } -check_entry_flags() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local flags=$2 - - atf_check -s exit:0 -o match:" $flags " -e ignore -x \ - "rump.netstat -rn -f inet | grep ^'$ip'" -} - -check_entry_gw() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local gw=$2 - - atf_check -s exit:0 -o match:" $gw " -e ignore -x \ - "rump.netstat -rn -f inet | grep ^'$ip'" -} - -check_entry_fail() -{ - ip=$(echo $1 |sed 's/\./\\./g') - flags=$2 # Not used currently - - atf_check -s not-exit:0 -e ignore -x \ - "rump.netstat -rn -f inet | grep ^'$ip'" -} - test_lo() { export RUMP_SERVER=$SOCK_LOCAL # Up, Host, local - check_entry_flags 127.0.0.1 UHl + check_route_flags 127.0.0.1 UHl } test_connected() @@ -139,10 +112,10 @@ test_connected() export RUMP_SERVER=$SOCK_LOCAL # Up, Host, LLINFO, local - check_entry_flags 10.0.0.2 UHl + check_route_flags 10.0.0.2 UHl # Up, Cloning - check_entry_flags 10.0.0/24 UC + check_route_flags 10.0.0/24 UC } test_default_gateway() @@ -154,7 +127,7 @@ test_default_gateway() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Static - check_entry_flags default UGS + check_route_flags default UGS } test_static() @@ -167,14 +140,14 @@ test_static() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Host, Static - check_entry_flags 10.0.1.1 UGHS + check_route_flags 10.0.1.1 UGHS # Static route to network atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.1 $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Static - check_entry_flags 10.0.2/24 UGS + check_route_flags 10.0.2/24 UGS } test_blackhole() @@ -193,14 +166,14 @@ test_blackhole() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Blackhole, Static - check_entry_flags 10.0.0/24 UGBS + check_route_flags 10.0.0/24 UGBS atf_check -s not-exit:0 -o match:'100.0% packet loss' \ rump.ping -n -w 1 -c 1 10.0.0.1 $DEBUG && rump.netstat -rn -f inet # Shouldn't be created - check_entry_fail 10.0.0.1 UH + check_route_no_entry 10.0.0.1 } test_reject() @@ -215,14 +188,14 @@ test_reject() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Reject, Static - check_entry_flags 10.0.0/24 UGRS + check_route_flags 10.0.0/24 UGRS atf_check -s not-exit:0 -o ignore -e match:'No route to host' \ rump.ping -n -w 1 -c 1 10.0.0.1 $DEBUG && rump.netstat -rn -f inet # Shouldn't be created - check_entry_fail 10.0.0.1 UH + check_route_no_entry 10.0.0.1 # Gateway is lo0 (RTF_GATEWAY) @@ -234,14 +207,14 @@ test_reject() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Reject, Static - check_entry_flags 10.0.0/24 UGRS + check_route_flags 10.0.0/24 UGRS atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \ rump.ping -n -w 1 -c 1 10.0.0.1 $DEBUG && rump.netstat -rn -f inet # Shouldn't be created - check_entry_fail 10.0.0.1 UH + check_route_no_entry 10.0.0.1 # Gateway is lo0 (RTF_HOST) @@ -253,7 +226,7 @@ test_reject() $DEBUG && rump.netstat -rn -f inet # Up, Host, Reject, Static - check_entry_flags 10.0.0.1 UHRS + check_route_flags 10.0.0.1 UHRS atf_check -s not-exit:0 -o ignore -e match:'No route to host' \ rump.ping -n -w 1 -c 1 10.0.0.1 @@ -278,7 +251,7 @@ test_icmp_redirect() export RUMP_SERVER=$SOCK_PEER atf_check -s exit:0 -o ignore rump.route add -net 10.0.2.0/24 10.0.0.254 # Up, Gateway, Static - check_entry_flags 10.0.2/24 UGS + check_route_flags 10.0.2/24 UGS # # Setup the default gateway to the peer, 10.0.0.1 @@ -286,15 +259,15 @@ test_icmp_redirect() export RUMP_SERVER=$SOCK_LOCAL atf_check -s exit:0 -o ignore rump.route add default 10.0.0.1 # Up, Gateway, Static - check_entry_flags default UGS + check_route_flags default UGS # Try ping 10.0.2.1 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.1 $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Host, Dynamic - check_entry_flags 10.0.2.1 UGHD - check_entry_gw 10.0.2.1 10.0.0.254 + check_route_flags 10.0.2.1 UGHD + check_route_gw 10.0.2.1 10.0.0.254 export RUMP_SERVER=$SOCK_PEER $DEBUG && rump.netstat -rn -f inet @@ -307,16 +280,16 @@ test_icmp_redirect() export RUMP_SERVER=$SOCK_LOCAL atf_check -s exit:0 -o ignore rump.route add 10.0.2.2 10.0.0.1 # Up, Gateway, Host, Static - check_entry_flags 10.0.2.2 UGHS - check_entry_gw 10.0.2.2 10.0.0.1 + check_route_flags 10.0.2.2 UGHS + check_route_gw 10.0.2.2 10.0.0.1 # Try ping 10.0.2.2 atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 10.0.2.2 $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Host, Modified, Static - check_entry_flags 10.0.2.2 UGHMS - check_entry_gw 10.0.2.2 10.0.0.254 + check_route_flags 10.0.2.2 UGHMS + check_route_gw 10.0.2.2 10.0.0.254 teardown_gw } @@ -332,7 +305,7 @@ test_announce() $DEBUG && rump.netstat -rn -f inet # Up, Gateway, Static, proxy - check_entry_flags 10.0.0/24 UGSp + check_route_flags 10.0.0/24 UGSp # TODO test its behavior } diff --git a/tests/net/route/t_flags6.sh b/tests/net/route/t_flags6.sh index 8b8d80bb295b..4c4bcb32b506 100644 --- a/tests/net/route/t_flags6.sh +++ b/tests/net/route/t_flags6.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_flags6.sh,v 1.9 2016/11/07 05:25:37 ozaki-r Exp $ +# $NetBSD: t_flags6.sh,v 1.10 2016/11/24 09:05:17 ozaki-r Exp $ # # Copyright (c) 2016 Internet Initiative Japan Inc. # All rights reserved. @@ -69,43 +69,16 @@ setup_peer() $DEBUG && rump.netstat -rn -f inet6 } -check_entry_flags() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local flags=$2 - - atf_check -s exit:0 -o match:" $flags " -e ignore -x \ - "rump.netstat -rn -f inet6 | grep ^'$ip'" -} - -check_entry_gw() -{ - local ip=$(echo $1 |sed 's/\./\\./g') - local gw=$2 - - atf_check -s exit:0 -o match:" $gw " -e ignore -x \ - "rump.netstat -rn -f inet6 | grep ^'$ip'" -} - -check_entry_fail() -{ - ip=$(echo $1 |sed 's/\./\\./g') - flags=$2 # Not used currently - - atf_check -s not-exit:0 -e ignore -x \ - "rump.netstat -rn -f inet6 | grep ^'$ip'" -} - test_lo6() { export RUMP_SERVER=$SOCK_LOCAL # Up, Host, local - check_entry_flags fe80::1 UHl + check_route_flags fe80::1 UHl # Up, Host, local - check_entry_flags ::1 UHl + check_route_flags ::1 UHl } test_connected6() @@ -114,10 +87,10 @@ test_connected6() export RUMP_SERVER=$SOCK_LOCAL # Up, Host, local - check_entry_flags $IP6_LOCAL UHl + check_route_flags $IP6_LOCAL UHl # Up, Connected - check_entry_flags fc00::/64 UC + check_route_flags fc00::/64 UC } test_default_gateway6() @@ -129,7 +102,7 @@ test_default_gateway6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Static - check_entry_flags default UGS + check_route_flags default UGS } test_static6() @@ -143,7 +116,7 @@ test_static6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Host, Static - check_entry_flags fc00::1:1 UGHS + check_route_flags fc00::1:1 UGHS # Static route to network atf_check -s exit:0 -o ignore \ @@ -151,7 +124,7 @@ test_static6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Static - check_entry_flags fc00::/24 UGS + check_route_flags fc00::/24 UGS } test_blackhole6() @@ -171,14 +144,14 @@ test_blackhole6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Blackhole, Static - check_entry_flags fc00::/64 UGBS + check_route_flags fc00::/64 UGBS atf_check -s not-exit:0 -o match:'100.0% packet loss' \ rump.ping6 -n -X 1 -c 1 $IP6_PEER $DEBUG && rump.netstat -rn -f inet6 # Shouldn't be created - check_entry_fail $IP6_PEER UH + check_route_no_entry $IP6_PEER } test_reject6() @@ -195,14 +168,14 @@ test_reject6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Reject, Static - check_entry_flags fc00::/64 UGRS + check_route_flags fc00::/64 UGRS atf_check -s not-exit:0 -o ignore -e match:'No route to host' \ rump.ping6 -n -X 1 -c 1 $IP6_PEER $DEBUG && rump.netstat -rn -f inet6 # Shouldn't be created - check_entry_fail $IP6_PEER UH + check_route_no_entry $IP6_PEER # Gateway is lo0 (RTF_GATEWAY) @@ -215,14 +188,14 @@ test_reject6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Reject, Static - check_entry_flags fc00::/64 UGRS + check_route_flags fc00::/64 UGRS atf_check -s not-exit:0 -o ignore -e match:'Network is unreachable' \ rump.ping6 -n -X 1 -c 1 $IP6_PEER $DEBUG && rump.netstat -rn -f inet6 # Shouldn't be created - check_entry_fail $IP6_PEER UH + check_route_no_entry $IP6_PEER # Gateway is lo0 (RTF_HOST) @@ -235,7 +208,7 @@ test_reject6() $DEBUG && rump.netstat -rn -f inet6 # Up, Host, Reject, Static - check_entry_flags fc00:: UHRS + check_route_flags fc00:: UHRS atf_check -s not-exit:0 -o ignore -e match:'No route to host' \ rump.ping6 -n -X 1 -c 1 $IP6_PEER @@ -257,7 +230,7 @@ test_announce6() $DEBUG && rump.netstat -rn -f inet6 # Up, Gateway, Static, proxy - check_entry_flags fc00::/64 UGSp + check_route_flags fc00::/64 UGSp # TODO test its behavior }