xref: /freebsd/contrib/netbsd-tests/net/ndp/t_ra.sh (revision 69718b786d3943ea9a99eeeb5f5f6162f11c78b7)
1#	$NetBSD: t_ra.sh,v 1.3 2016/08/10 23:07:57 kre Exp $
2#
3# Copyright (c) 2015 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
28RUMPFLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6"
29RUMPFLAGS="${RUMPFLAGS} -lrumpnet_shmif -lrumpdev"
30RUMPFLAGS="${RUMPFLAGS} -lrumpvfs -lrumpfs_ffs"
31
32RUMPSRV=unix://r1
33RUMPCLI=unix://r2
34IP6SRV=fc00:1::1
35IP6CLI=fc00:2::2
36PIDFILE=/var/run/rump.rtadvd.pid
37CONFIG=./rtadvd.conf
38DEBUG=true
39
40setup_shmif0()
41{
42	local IP6ADDR=${1}
43	shift
44
45	atf_check -s exit:0 rump.ifconfig shmif0 create
46	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
47	atf_check -s exit:0 rump.ifconfig shmif0 inet6 ${IP6ADDR}
48	atf_check -s exit:0 rump.ifconfig shmif0 up
49
50	$DEBUG && rump.ifconfig
51}
52
53wait_term()
54{
55	local PIDFILE=${1}
56	shift
57
58	while [ -f ${PIDFILE} ]
59	do
60		sleep 0.2
61	done
62
63	return 0
64}
65
66create_rtadvdconfig()
67{
68
69	cat << _EOF > ${CONFIG}
70shmif0:\
71	:mtu#1300:maxinterval#4:mininterval#3:
72_EOF
73}
74
75atf_test_case basic cleanup
76basic_head()
77{
78
79	atf_set "descr" "Tests for basic functions of router advaertisement(RA)"
80	atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig"
81}
82
83basic_body()
84{
85
86	atf_check -s exit:0 rump_server ${RUMPFLAGS} ${RUMPSRV}
87	atf_check -s exit:0 rump_server ${RUMPFLAGS} ${RUMPCLI}
88
89	export RUMP_SERVER=${RUMPSRV}
90	setup_shmif0 ${IP6SRV}
91	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.forwarding=1
92	export LD_PRELOAD=/usr/lib/librumphijack.so
93	atf_check -s exit:0 mkdir -p /rump/var/chroot/rtadvd
94	unset LD_PRELOAD
95	unset RUMP_SERVER
96
97	export RUMP_SERVER=${RUMPCLI}
98	setup_shmif0 ${IP6CLI}
99	$DEBUG && rump.ndp -n -a
100	atf_check -s exit:0 -o match:'= 0' rump.sysctl net.inet6.ip6.accept_rtadv
101	unset RUMP_SERVER
102
103	create_rtadvdconfig
104
105	export RUMP_SERVER=${RUMPSRV}
106	atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0
107	atf_check -s exit:0 sleep 3
108	atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE}
109	unset RUMP_SERVER
110
111	export RUMP_SERVER=${RUMPCLI}
112	atf_check -s exit:0 -o empty rump.ndp -r
113	atf_check -s exit:0 -o not-match:'advertised' rump.ndp -p
114	atf_check -s exit:0 -o match:'linkmtu=0' rump.ndp -n -i shmif0
115	atf_check -s exit:0 -o not-match:'S R' rump.ndp -n -a
116	atf_check -s exit:0 -o not-match:'fc00:1:' rump.ndp -n -a
117	atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6
118	unset RUMP_SERVER
119
120	atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
121	wait_term ${PIDFILE}
122
123	export RUMP_SERVER=${RUMPCLI}
124	atf_check -s exit:0 -o match:'0.->.1' rump.sysctl -w net.inet6.ip6.accept_rtadv=1
125	unset RUMP_SERVER
126
127	export RUMP_SERVER=${RUMPSRV}
128	atf_check -s exit:0 rump.rtadvd -c ${CONFIG} shmif0
129	atf_check -s exit:0 sleep 3
130	atf_check -s exit:0 -o ignore -e empty cat ${PIDFILE}
131	unset RUMP_SERVER
132
133	export RUMP_SERVER=${RUMPCLI}
134	$DEBUG && rump.ndp -n -a
135	$DEBUG && rump.ndp -r
136	atf_check -s exit:0 -o match:'if=shmif0' rump.ndp -r
137	atf_check -s exit:0 -o match:'advertised' rump.ndp -p
138	atf_check -s exit:0 -o match:'linkmtu=1300' rump.ndp -n -i shmif0
139	atf_check -s exit:0 -o match:'23h59m..s S R' rump.ndp -n -a
140	atf_check -s exit:0 -o match:'fc00:1:' rump.ndp -n -a
141	atf_check -s exit:0 -o match:'fc00:1:' rump.ifconfig shmif0 inet6
142	unset RUMP_SERVER
143
144	atf_check -s exit:0 kill -TERM `cat ${PIDFILE}`
145	wait_term ${PIDFILE}
146
147	return 0
148}
149
150basic_cleanup()
151{
152
153	if [ -f ${PIDFILE} ]; then
154		kill -TERM `cat ${PIDFILE}`
155		wait_term ${PIDFILE}
156	fi
157
158	env RUMP_SERVER=${RUMPSRV} rump.halt
159	env RUMP_SERVER=${RUMPCLI} rump.halt
160}
161
162atf_init_test_cases()
163{
164
165	atf_add_test_case basic
166}
167