xref: /netbsd-src/tests/net/if_pppoe/t_pppoe_unnumbered.sh (revision 867d70fc718005c0918b8b8b2f9d7f2d52d0a0db)
1#	$NetBSD: t_pppoe_unnumbered.sh,v 1.1 2022/11/25 08:43:16 knakahara Exp $
2#
3# Copyright (c) 2022 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
28SERVER=unix://pppoe_server
29CLIENT=unix://pppoe_client
30
31SERVER_IP=10.0.0.1
32CLIENT_IP=10.1.1.1
33AUTHNAME=foobar@baz.com
34SECRET=oink
35BUS_G=bus_global
36BUS_CLIENT_L=bus_client_local
37TIMEOUT=3
38WAITTIME=10
39DEBUG=${DEBUG:-false}
40
41atf_ifconfig()
42{
43
44	atf_check -s exit:0 rump.ifconfig $*
45}
46
47atf_pppoectl()
48{
49
50	atf_check -s exit:0 -x "$HIJACKING pppoectl $*"
51}
52
53setup_ifaces()
54{
55
56	rump_server_add_iface $SERVER shmif0 $BUS_G
57	rump_server_add_iface $CLIENT shmif0 $BUS_G
58	rump_server_add_iface $CLIENT shmif1 $BUS_CLIENT_L
59	rump_server_add_iface $SERVER pppoe0
60	rump_server_add_iface $CLIENT pppoe0
61
62	export RUMP_SERVER=$SERVER
63
64	atf_ifconfig shmif0 up
65	$inet && atf_ifconfig pppoe0 \
66	    inet $SERVER_IP $CLIENT_IP down
67	atf_ifconfig pppoe0 link0
68
69	$DEBUG && rump.ifconfig pppoe0 debug
70	$DEBUG && rump.ifconfig
71	$DEBUG && $HIJACKING pppoectl -d pppoe0
72	unset RUMP_SERVER
73
74	export RUMP_SERVER=$CLIENT
75	atf_ifconfig shmif0 up
76
77	$inet && atf_ifconfig pppoe0 \
78	    inet $CLIENT_IP/32 0.0.0.1 down
79
80	$DEBUG && rump.ifconfig pppoe0 debug
81	$DEBUG && rump.ifconfig
82	$DEBUG && $HIJACKING pppoectl -d pppoe0
83
84	atf_ifconfig shmif1 inet $CLIENT_IP/29
85	unset RUMP_SERVER
86}
87
88setup()
89{
90	inet=true
91
92	if [ $# -ne 0 ]; then
93		eval $@
94	fi
95
96	rump_server_start $SERVER pppoe
97	rump_server_start $CLIENT pppoe
98
99	setup_ifaces
100
101	export RUMP_SERVER=$SERVER
102	atf_pppoectl -e shmif0 pppoe0
103	unset RUMP_SERVER
104
105	export RUMP_SERVER=$CLIENT
106	atf_pppoectl -e shmif0 pppoe0
107	unset RUMP_SERVER
108}
109
110wait_for_opened()
111{
112	local cp=$1
113	local dontfail=$2
114	local n=$WAITTIME
115
116	for i in $(seq $n); do
117		$HIJACKING pppoectl -dd pppoe0 | grep -q "$cp state: opened"
118		if [ $? = 0 ]; then
119			rump.ifconfig -w 10
120			return
121		fi
122		sleep 1
123	done
124
125	if [ "$dontfail" != "dontfail" ]; then
126		atf_fail "Couldn't connect to the server for $n seconds."
127	fi
128}
129
130wait_for_disconnected()
131{
132	local dontfail=$1
133	local n=$WAITTIME
134
135	for i in $(seq $n); do
136		# If PPPoE client is disconnected by PPPoE server, then
137		# the LCP state will of the client is in a starting to send PADI.
138		$HIJACKING pppoectl -dd pppoe0 | grep -q \
139		    -e "LCP state: initial" -e "LCP state: starting"
140		[ $? = 0 ] && return
141
142		sleep 1
143	done
144
145	if [ "$dontfail" != "dontfail" ]; then
146		atf_fail "Couldn't disconnect for $n seconds."
147	fi
148}
149
150run_test_unnumbered()
151{
152	local auth="chap"
153	local cp="IPCP"
154	setup
155
156	# As pppoe client doesn't support rechallenge yet.
157	local server_optparam=""
158	if [ $auth = "chap" ]; then
159		server_optparam="norechallenge"
160	fi
161
162	export RUMP_SERVER=$SERVER
163	atf_pppoectl pppoe0 "hisauthproto=$auth" \
164	    "hisauthname=$AUTHNAME" "hisauthsecret=$SECRET" \
165	    "myauthproto=none" $server_optparam
166	atf_ifconfig pppoe0 up
167	unset RUMP_SERVER
168
169	export RUMP_SERVER=$CLIENT
170	atf_pppoectl pppoe0 \
171	    "myauthname=$AUTHNAME" "myauthsecret=$SECRET" \
172	    "myauthproto=$auth" "hisauthproto=none"
173	atf_ifconfig pppoe0 unnumbered
174	atf_ifconfig pppoe0 up
175	$DEBUG && rump.ifconfig
176	$DEBUG && rump.route -nL show
177	wait_for_opened $cp
178	atf_check -s exit:0 -o ignore \
179		  rump.route add -inet default -ifp pppoe0 $CLIENT_IP
180	atf_check -s exit:0 -o ignore \
181		  rump.ping -c 1 -w $TIMEOUT -I $CLIENT_IP $SERVER_IP
182	unset RUMP_SERVER
183
184	# test for disconnection from client just in case
185	export RUMP_SERVER=$CLIENT
186	atf_ifconfig pppoe0 down
187	wait_for_disconnected
188	export RUMP_SERVER=$SERVER
189	wait_for_disconnected
190	$DEBUG && $HIJACKING pppoectl -d pppoe0
191	atf_check -s not-exit:0 -o ignore -e ignore \
192	    rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
193	atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
194	unset RUMP_SERVER
195}
196
197atf_test_case pppoe_unnumbered cleanup
198
199pppoe_unnumbered_head()
200{
201
202	atf_set "descr" "Does pppoe unnumbered tests"
203	atf_set "require.progs" "rump_server pppoectl"
204}
205
206pppoe_unnumbered_body()
207{
208
209	run_test_unnumbered
210}
211
212pppoe_unnumbered_cleanup()
213{
214
215	$DEBUG && dump
216	cleanup
217}
218
219atf_init_test_cases()
220{
221
222	atf_add_test_case pppoe_unnumbered
223}
224