Deleted Added
full compact
routing_test.sh (283056) routing_test.sh (300882)
1#
2# Copyright (c) 2014 Spectra Logic Corporation
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGES.
29#
30# Authors: Alan Somers (Spectra Logic Corporation)
31#
1#
2# Copyright (c) 2014 Spectra Logic Corporation
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms, with or without
6# modification, are permitted provided that the following conditions
7# are met:
8# 1. Redistributions of source code must retain the above copyright

--- 15 unchanged lines hidden (view full) ---

24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28# POSSIBILITY OF SUCH DAMAGES.
29#
30# Authors: Alan Somers (Spectra Logic Corporation)
31#
32# $FreeBSD: head/tests/etc/rc.d/routing_test.sh 281491 2015-04-13 10:30:30Z ngie $
32# $FreeBSD: head/tests/etc/rc.d/routing_test.sh 300882 2016-05-27 22:40:40Z asomers $
33
33
34atf_test_case static_ipv4_loopback_route_for_each_fib cleanup
35static_ipv4_loopback_route_for_each_fib_head()
36{
37 atf_set "descr" "Every FIB should have a static IPv4 loopback route"
38}
39static_ipv4_loopback_route_for_each_fib_body()
40{
41 local nfibs fib
42 nfibs=`sysctl -n net.fibs`
43
44 # Check for an IPv4 loopback route
45 for fib in `seq 0 $((${nfibs} - 1))`; do
46 atf_check -o match:"interface: lo0" -s exit:0 \
47 setfib -F ${fib} route -4 get 127.0.0.1
48 done
49}
50
34atf_test_case static_ipv6_loopback_route_for_each_fib cleanup
35static_ipv6_loopback_route_for_each_fib_head()
36{
37 atf_set "descr" "Every FIB should have a static IPv6 loopback route"
51atf_test_case static_ipv6_loopback_route_for_each_fib cleanup
52static_ipv6_loopback_route_for_each_fib_head()
53{
54 atf_set "descr" "Every FIB should have a static IPv6 loopback route"
38 atf_set "require.user" "root"
39 atf_set "require.config" "fibs"
40 atf_set "require.progs" "sysrc"
41}
42static_ipv6_loopback_route_for_each_fib_body()
43{
55}
56static_ipv6_loopback_route_for_each_fib_body()
57{
44 # Configure the TAP interface to use an RFC5737 nonrouteable address
45 # and a non-default fib
46 ADDR="192.0.2.2"
47 SUBNET="192.0.2.0"
48 MASK="24"
58 local nfibs fib
59 nfibs=`sysctl -n net.fibs`
49
60
50 # Check system configuration
51 if [ 0 != `sysctl -n net.add_addr_allfibs` ]; then
52 atf_skip "This test requires net.add_addr_allfibs=0"
53 fi
54
55 get_fibs 1
56 get_tap
57
58 # Configure a TAP interface in /etc/rc.conf. Register the sysrc
59 # variable for cleanup.
60 echo "ifconfig_${TAP}" >> "sysrc_vars_to_cleanup"
61 sysrc ifconfig_${TAP}="${ADDR}/${MASK} fib ${FIB0}"
62
63 # Start the interface
64 service netif start ${TAP}
65 # Check for an IPv6 loopback route
61 # Check for an IPv6 loopback route
66 setfib ${FIB0} netstat -rn -f inet6 | grep -q "^::1.*lo0$"
67 if [ 0 -eq $? ]; then
68 atf_pass
69 else
70 setfib ${FIB0} netstat -rn -f inet6
71 atf_fail "Did not find an IPv6 loopback route"
72 fi
62 for fib in `seq 0 $((${nfibs} - 1))`; do
63 atf_check -o match:"interface: lo0" -s exit:0 \
64 setfib -F ${fib} route -6 get ::1
65 done
73}
66}
74static_ipv6_loopback_route_for_each_fib_cleanup()
75{
76 cleanup_sysrc
77 cleanup_tap
78}
79
80atf_init_test_cases()
81{
67
68atf_init_test_cases()
69{
70 atf_add_test_case static_ipv4_loopback_route_for_each_fib
82 atf_add_test_case static_ipv6_loopback_route_for_each_fib
83}
84
71 atf_add_test_case static_ipv6_loopback_route_for_each_fib
72}
73
85# Looks up one or more fibs from the configuration data and validates them.
86# Returns the results in the env varilables FIB0, FIB1, etc.
87# parameter numfibs The number of fibs to lookup
88get_fibs()
89{
90 NUMFIBS=$1
91 net_fibs=`sysctl -n net.fibs`
92 i=0
93 while [ $i -lt "$NUMFIBS" ]; do
94 fib=`atf_config_get "fibs" | \
95 awk -v i=$(( i + 1 )) '{print $i}'`
96 echo "fib is ${fib}"
97 eval FIB${i}=${fib}
98 if [ "$fib" -ge "$net_fibs" ]; then
99 msg="The ${i}th configured fib is ${fub}, which is "
100 msg="$msg not less than net.fibs (${net_fibs})"
101 atf_skip "$msg"
102 fi
103 i=$(( $i + 1 ))
104 done
105}
106
107
108# Creates a new tap(4) interface, registers it for cleanup, and returns the
109# name via the environment variable TAP
110get_tap()
111{
112 local TAPN=0
113 while ! ifconfig tap${TAPN} create > /dev/null 2>&1; do
114 if [ "$TAPN" -ge 8 ]; then
115 atf_skip "Could not create a tap(4) interface"
116 else
117 TAPN=$(($TAPN + 1))
118 fi
119 done
120 local TAPD=tap${TAPN}
121 # Record the TAP device so we can clean it up later
122 echo ${TAPD} >> "tap_devices_to_cleanup"
123 TAP=${TAPD}
124}
125
126cleanup_sysrc()
127{
128 for var in `cat "sysrc_vars_to_cleanup"`; do
129 sysrc -x $var
130 done
131}
132
133cleanup_tap()
134{
135 for TAPD in `cat "tap_devices_to_cleanup"`; do
136 ifconfig ${TAPD} destroy
137 done
138}