xref: /freebsd/contrib/netbsd-tests/net/if_pppoe/t_pppoe.sh (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1#	$NetBSD: t_pppoe.sh,v 1.16 2016/12/14 03:30:30 knakahara Exp $
2#
3# Copyright (c) 2016 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="rump_server -lrump -lrumpnet -lrumpnet_net -lrumpnet_netinet	\
29		    -lrumpnet_netinet6 -lrumpnet_shmif -lrumpdev	\
30		    -lrumpnet_pppoe"
31# pppoectl doesn't work with RUMPHIJACK=sysctl=yes
32HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so"
33
34SERVER=unix://commsock1
35CLIENT=unix://commsock2
36
37SERVER_IP=10.3.3.1
38CLIENT_IP=10.3.3.3
39SERVER_IP6=fc00::1
40CLIENT_IP6=fc00::3
41AUTHNAME=foobar@baz.com
42SECRET=oink
43BUS=bus0
44TIMEOUT=3
45WAITTIME=10
46DEBUG=${DEBUG:-false}
47
48setup()
49{
50	inet=true
51
52	if [ $# -ne 0 ]; then
53		eval $@
54	fi
55
56	atf_check -s exit:0 ${server} $SERVER
57	atf_check -s exit:0 ${server} $CLIENT
58
59	export RUMP_SERVER=$SERVER
60	atf_check -s exit:0 rump.ifconfig shmif0 create
61	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
62	atf_check -s exit:0 rump.ifconfig shmif0 up
63
64	atf_check -s exit:0 rump.ifconfig pppoe0 create
65	$inet && atf_check -s exit:0 rump.ifconfig pppoe0 \
66	    inet $SERVER_IP $CLIENT_IP down
67	atf_check -s exit:0 rump.ifconfig pppoe0 link0
68
69	$DEBUG && rump.ifconfig
70	$DEBUG && $HIJACKING pppoectl -d pppoe0
71
72	atf_check -s exit:0 -x "$HIJACKING pppoectl -e shmif0 pppoe0"
73	unset RUMP_SERVER
74
75	export RUMP_SERVER=$CLIENT
76	atf_check -s exit:0 rump.ifconfig shmif0 create
77	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
78	atf_check -s exit:0 rump.ifconfig shmif0 up
79
80	atf_check -s exit:0 rump.ifconfig pppoe0 create
81	$inet && atf_check -s exit:0 rump.ifconfig pppoe0 \
82	    inet 0.0.0.0 0.0.0.1 down
83
84	atf_check -s exit:0 -x "$HIJACKING pppoectl -e shmif0 pppoe0"
85	unset RUMP_SERVER
86}
87
88cleanup()
89{
90	env RUMP_SERVER=$SERVER rump.halt
91	env RUMP_SERVER=$CLIENT rump.halt
92}
93
94
95wait_for_session_established()
96{
97	local dontfail=$1
98	local n=$WAITTIME
99
100	for i in $(seq $n); do
101		$HIJACKING pppoectl -d pppoe0 |grep -q "state = session"
102		[ $? = 0 ] && return
103		sleep 1
104	done
105
106	if [ "$dontfail" != "dontfail" ]; then
107		atf_fail "Couldn't connect to the server for $n seconds."
108	fi
109}
110
111wait_for_disconnected()
112{
113	local dontfail=$1
114	local n=$WAITTIME
115
116	for i in $(seq $n); do
117		$HIJACKING pppoectl -d pppoe0 | grep -q "state = initial"
118		[ $? = 0 ] && return
119		# If PPPoE client is disconnected by PPPoE server and then
120		# the client kicks callout of pppoe_timeout(), the client
121		# state is changed to PPPOE_STATE_PADI_SENT while padi retrying.
122		$HIJACKING pppoectl -d pppoe0 | grep -q "state = PADI sent"
123		[ $? = 0 ] && return
124
125		sleep 1
126	done
127
128	if [ "$dontfail" != "dontfail" ]; then
129		atf_fail "Couldn't disconnect for $n seconds."
130	fi
131}
132
133run_test()
134{
135	local auth=$1
136	setup
137
138	# As pppoe client doesn't support rechallenge yet.
139	local server_optparam=""
140	if [ $auth = "chap" ]; then
141		server_optparam="norechallenge"
142	fi
143
144	export RUMP_SERVER=$SERVER
145	local setup_serverparam="pppoectl pppoe0 hisauthproto=$auth \
146				    'hisauthname=$AUTHNAME' \
147				    'hisauthsecret=$SECRET' \
148				    'myauthproto=none' \
149				    $server_optparam"
150	atf_check -s exit:0 -x "$HIJACKING $setup_serverparam"
151	atf_check -s exit:0 rump.ifconfig pppoe0 up
152	unset RUMP_SERVER
153
154	export RUMP_SERVER=$CLIENT
155	local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
156				    'myauthname=$AUTHNAME' \
157				    'myauthsecret=$SECRET' \
158				    'hisauthproto=none'"
159	atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
160	atf_check -s exit:0 rump.ifconfig pppoe0 up
161	$DEBUG && rump.ifconfig
162	wait_for_session_established
163	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $SERVER_IP
164	unset RUMP_SERVER
165
166	# test for disconnection from server
167	export RUMP_SERVER=$SERVER
168	atf_check -s exit:0 rump.ifconfig pppoe0 down
169	wait_for_disconnected
170	export RUMP_SERVER=$CLIENT
171	wait_for_disconnected
172	atf_check -s not-exit:0 -o ignore -e ignore \
173	    rump.ping -c 1 -w $TIMEOUT $SERVER_IP
174	atf_check -s exit:0 -o match:'PADI sent' -x "$HIJACKING pppoectl -d pppoe0"
175	unset RUMP_SERVER
176
177	# test for recoonecting
178	atf_check -s exit:0 -x "env RUMP_SERVER=$SERVER rump.ifconfig pppoe0 up"
179	export RUMP_SERVER=$CLIENT
180	wait_for_session_established
181	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $SERVER_IP
182	unset RUMP_SERVER
183
184	# test for disconnection from client
185	export RUMP_SERVER=$CLIENT
186	atf_check -s exit:0 -x rump.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	# test for reconnecting
197	export RUMP_SERVER=$CLIENT
198	atf_check -s exit:0 -x rump.ifconfig pppoe0 up
199	wait_for_session_established
200	$DEBUG && rump.ifconfig pppoe0
201	$DEBUG && $HIJACKING pppoectl -d pppoe0
202	unset RUMP_SERVER
203
204	export RUMP_SERVER=$SERVER
205	atf_check -s exit:0 rump.ifconfig -w 10
206	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
207	atf_check -s exit:0 -o match:'session' -x "$HIJACKING pppoectl -d pppoe0"
208	$DEBUG && HIJACKING pppoectl -d pppoe0
209	unset RUMP_SERVER
210
211	# test for invalid password
212	export RUMP_SERVER=$CLIENT
213	atf_check -s exit:0 rump.ifconfig pppoe0 down
214	wait_for_disconnected
215	local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
216				    'myauthname=$AUTHNAME' \
217				    'myauthsecret=invalidsecret' \
218				    'hisauthproto=none'"
219	atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
220	atf_check -s exit:0 rump.ifconfig pppoe0 up
221	wait_for_session_established dontfail
222	atf_check -s not-exit:0 -o ignore -e ignore \
223	    rump.ping -c 1 -w $TIMEOUT $SERVER_IP
224	atf_check -s exit:0 -o match:'DETACHED' rump.ifconfig pppoe0
225	unset RUMP_SERVER
226}
227
228atf_test_case pppoe_pap cleanup
229
230pppoe_pap_head()
231{
232	atf_set "descr" "Does simple pap tests"
233	atf_set "require.progs" "rump_server pppoectl"
234}
235
236pppoe_pap_body()
237{
238	run_test pap
239}
240
241pppoe_pap_cleanup()
242{
243	cleanup
244}
245
246atf_test_case pppoe_chap cleanup
247
248pppoe_chap_head()
249{
250	atf_set "descr" "Does simple chap tests"
251	atf_set "require.progs" "rump_server pppoectl"
252}
253
254pppoe_chap_body()
255{
256	run_test chap
257}
258
259pppoe_chap_cleanup()
260{
261	cleanup
262}
263
264run_test6()
265{
266	local auth=$1
267	setup "inet=false"
268
269	# As pppoe client doesn't support rechallenge yet.
270	local server_optparam=""
271	if [ $auth = "chap" ]; then
272		server_optparam="norechallenge"
273	fi
274
275	export RUMP_SERVER=$SERVER
276	local setup_serverparam="pppoectl pppoe0 hisauthproto=$auth \
277				    'hisauthname=$AUTHNAME' \
278				    'hisauthsecret=$SECRET' \
279				    'myauthproto=none' \
280				    $server_optparam"
281	atf_check -s exit:0 -x "$HIJACKING $setup_serverparam"
282	atf_check -s exit:0 rump.ifconfig pppoe0 inet6 $SERVER_IP6/64 down
283	atf_check -s exit:0 rump.ifconfig pppoe0 up
284	unset RUMP_SERVER
285
286	export RUMP_SERVER=$CLIENT
287	local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
288				    'myauthname=$AUTHNAME' \
289				    'myauthsecret=$SECRET' \
290				    'hisauthproto=none'"
291	atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
292	atf_check -s exit:0 rump.ifconfig pppoe0 inet6 $CLIENT_IP6/64 down
293	atf_check -s exit:0 rump.ifconfig pppoe0 up
294	$DEBUG && rump.ifconfig
295	wait_for_session_established
296	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
297	export RUMP_SERVER=$SERVER
298	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
299	export RUMP_SERVER=$CLIENT
300	atf_check -s exit:0 -o ignore rump.ping6 -c 1 -X $TIMEOUT $SERVER_IP6
301	unset RUMP_SERVER
302
303	# test for disconnection from server
304	export RUMP_SERVER=$SERVER
305	session_id=`$HIJACKING pppoectl -d pppoe0 | grep state`
306	atf_check -s exit:0 rump.ifconfig pppoe0 down
307	wait_for_disconnected
308	export RUMP_SERVER=$CLIENT
309	wait_for_disconnected
310	atf_check -s not-exit:0 -o ignore -e ignore \
311	    rump.ping6 -c 1 -X $TIMEOUT $SERVER_IP6
312	atf_check -s exit:0 -o not-match:"$session_id" -x "$HIJACKING pppoectl -d pppoe0"
313	unset RUMP_SERVER
314
315	# test for recoonecting
316	export RUMP_SERVER=$SERVER
317	atf_check -s exit:0 rump.ifconfig pppoe0 up
318	wait_for_session_established
319	atf_check -s exit:0 rump.ifconfig -w 10
320	$DEBUG && $HIJACKING pppoectl -d pppoe0
321	$DEBUG && rump.ifconfig pppoe0
322	export RUMP_SERVER=$CLIENT
323	atf_check -s exit:0 -o ignore rump.ifconfig -w 10
324	atf_check -s exit:0 -o ignore rump.ping6 -c 1 -X $TIMEOUT $SERVER_IP6
325	unset RUMP_SERVER
326
327	# test for disconnection from client
328	export RUMP_SERVER=$CLIENT
329	atf_check -s exit:0 rump.ifconfig pppoe0 down
330	wait_for_disconnected
331
332	export RUMP_SERVER=$SERVER
333	wait_for_disconnected
334	$DEBUG && $HIJACKING pppoectl -d pppoe0
335	atf_check -s not-exit:0 -o ignore -e ignore \
336	    rump.ping6 -c 1 -X $TIMEOUT $CLIENT_IP6
337	atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
338	unset RUMP_SERVER
339
340	# test for reconnecting
341	export RUMP_SERVER=$CLIENT
342	atf_check -s exit:0 rump.ifconfig pppoe0 up
343	wait_for_session_established
344	atf_check -s exit:0 rump.ifconfig -w 10
345
346	$DEBUG && rump.ifconfig pppoe0
347	$DEBUG && $HIJACKING pppoectl -d pppoe0
348	unset RUMP_SERVER
349
350	export RUMP_SERVER=$SERVER
351	atf_check -s exit:0 rump.ifconfig -w 10
352	atf_check -s exit:0 -o ignore rump.ping6 -c 1 -X $TIMEOUT $CLIENT_IP6
353	atf_check -s exit:0 -o match:'session' -x "$HIJACKING pppoectl -d pppoe0"
354	$DEBUG && HIJACKING pppoectl -d pppoe0
355	unset RUMP_SERVER
356
357	# test for invalid password
358	export RUMP_SERVER=$CLIENT
359	atf_check -s exit:0 rump.ifconfig pppoe0 down
360	wait_for_disconnected
361	local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
362				    'myauthname=$AUTHNAME' \
363				    'myauthsecret=invalidsecret' \
364				    'hisauthproto=none'"
365	atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
366	atf_check -s exit:0 rump.ifconfig pppoe0 up
367	wait_for_session_established dontfail
368	atf_check -s not-exit:0 -o ignore -e ignore \
369	    rump.ping6 -c 1 -X $TIMEOUT $SERVER_IP6
370	atf_check -s exit:0 -o match:'DETACHED' rump.ifconfig pppoe0
371	unset RUMP_SERVER
372}
373
374atf_test_case pppoe6_pap cleanup
375
376pppoe6_pap_head()
377{
378	atf_set "descr" "Does simple pap using IPv6 tests"
379	atf_set "require.progs" "rump_server pppoectl"
380}
381
382pppoe6_pap_body()
383{
384	run_test6 pap
385}
386
387pppoe6_pap_cleanup()
388{
389	cleanup
390}
391
392atf_test_case pppoe6_chap cleanup
393
394pppoe6_chap_head()
395{
396	atf_set "descr" "Does simple chap using IPv6 tests"
397	atf_set "require.progs" "rump_server pppoectl"
398}
399
400pppoe6_chap_body()
401{
402	run_test6 chap
403}
404
405pppoe6_chap_cleanup()
406{
407	cleanup
408}
409
410atf_init_test_cases()
411{
412	atf_add_test_case pppoe_pap
413	atf_add_test_case pppoe_chap
414	atf_add_test_case pppoe6_pap
415	atf_add_test_case pppoe6_chap
416}
417