summaryrefslogtreecommitdiffstats
path: root/contrib/netbsd-tests/net/if_pppoe/t_pppoe.sh
blob: 3199ca0a73e9c727630ce98b6b7788a1eaad1833 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#	$NetBSD: t_pppoe.sh,v 1.2 2016/08/07 23:34:31 pgoyette Exp $
#
# Copyright (c) 2016 Internet Initiative Japan Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#

server="rump_server -lrump -lrumpnet -lrumpnet_net -lrumpnet_netinet	\
		    -lrumpnet_netinet6 -lrumpnet_shmif -lrumpdev	\
		    -lrumpnet_pppoe"
HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so"

SERVER=unix://commsock1
CLIENT=unix://commsock2

SERVER_IP=10.3.3.1
CLIENT_IP=10.3.3.3
AUTHNAME=foobar@baz.com
SECRET=oink
BUS=bus0
TIMEOUT=3
WAITTIME=5
DEBUG=false

atf_test_case pap cleanup

setup()
{
	atf_check -s exit:0 ${server} $SERVER
	atf_check -s exit:0 ${server} $CLIENT

	export RUMP_SERVER=$SERVER
	atf_check -s exit:0 rump.ifconfig shmif0 create
	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
	atf_check -s exit:0 rump.ifconfig shmif0 up

	atf_check -s exit:0 rump.ifconfig pppoe0 create
	atf_check -s exit:0 rump.ifconfig pppoe0 inet $SERVER_IP $CLIENT_IP down
	atf_check -s exit:0 rump.ifconfig pppoe0 link0

	$DEBUG && rump.ifconfig
	$DEBUG && $HIJACKING pppoectl -d pppoe0

	atf_check -s exit:0 -x "$HIJACKING pppoectl -e shmif0 pppoe0"
	unset RUMP_SERVER

	export RUMP_SERVER=$CLIENT
	atf_check -s exit:0 rump.ifconfig shmif0 create
	atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
	atf_check -s exit:0 rump.ifconfig shmif0 up

	atf_check -s exit:0 rump.ifconfig pppoe0 create
	atf_check -s exit:0 rump.ifconfig pppoe0 inet 0.0.0.0 0.0.0.1 down

	atf_check -s exit:0 -x "$HIJACKING pppoectl -e shmif0 pppoe0"
	unset RUMP_SERVER
}
cleanup()
{
	env RUMP_SERVER=$SERVER rump.halt
	env RUMP_SERVER=$CLIENT rump.halt
}

pap_head()
{
	atf_set "descr" "Does simple pap tests"
	atf_set "require.progs" "rump_server pppoectl"
}

wait_for_session_established()
{
	local dontfail=$1
	local n=$WAITTIME

	for i in $(seq $n); do
		$HIJACKING pppoectl -d pppoe0 |grep -q "state = session"
		[ $? = 0 ] && return
		sleep 1
	done

	if [ $dontfail != "dontfail" ]; then
		atf_fail "Couldn't connect to the server for $n seconds."
	fi
}

pap_body()
{
	local auth=pap
	setup

	export RUMP_SERVER=$SERVER
	local setup_serverparam="pppoectl pppoe0 hisauthproto=$auth \
				    'hisauthname=$AUTHNAME' \
				    'hisauthsecret=$SECRET' \
				    'myauthproto=none'"
	atf_check -s exit:0 -x "$HIJACKING $setup_serverparam"
	atf_check -s exit:0 rump.ifconfig pppoe0 up
	unset RUMP_SERVER

	export RUMP_SERVER=$CLIENT
	local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
				    'myauthname=$AUTHNAME' \
				    'myauthsecret=$SECRET' \
				    'hisauthproto=none'"
	atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
	atf_check -s exit:0 rump.ifconfig pppoe0 up
	$DEBUG && rump.ifconfig
	wait_for_session_established
	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $SERVER_IP
	unset RUMP_SERVER

	# test for disconnection from server
	atf_check -s exit:0 -x "env RUMP_SERVER=$SERVER rump.ifconfig pppoe0 down"
	export RUMP_SERVER=$CLIENT
	atf_check -s not-exit:0 -o ignore -e ignore \
	    rump.ping -c 1 -w $TIMEOUT $SERVER_IP
	atf_check -s exit:0 -o match:'PADI sent' -x "$HIJACKING pppoectl -d pppoe0"
	unset RUMP_SERVER

	# test for recoonecting
	atf_check -s exit:0 -x "env RUMP_SERVER=$SERVER rump.ifconfig pppoe0 up"
	export RUMP_SERVER=$CLIENT
	wait_for_session_established
	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $SERVER_IP
	unset RUMP_SERVER

	# test for disconnection from client
	atf_check -s exit:0 -x "env RUMP_SERVER=$CLIENT rump.ifconfig pppoe0 down"
	export RUMP_SERVER=$SERVER
	$DEBUG && $HIJACKING pppoectl -d pppoe0
	atf_check -s not-exit:0 -o ignore -e ignore \
	    rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
	atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
	unset RUMP_SERVER

	# test for recconecting
	export RUMP_SERVER=$CLIENT
	atf_check -s exit:0 -x rump.ifconfig pppoe0 up
	wait_for_session_established
	$DEBUG && rump.ifconfig pppoe0
	$DEBUG && $HIJACKING pppoectl -d pppoe0
	unset RUMP_SERVER

	export RUMP_SERVER=$SERVER
	atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
	atf_check -s exit:0 -o match:'session' -x "$HIJACKING pppoectl -d pppoe0"
	$DEBUG && HIJACKING pppoectl -d pppoe0
	unset RUMP_SERVER

	# test for invalid password
	export RUMP_SERVER=$CLIENT
	atf_check -s exit:0 rump.ifconfig pppoe0 down
	local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
				    'myauthname=$AUTHNAME' \
				    'myauthsecret=invalidsecret' \
				    'hisauthproto=none'"
	atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
	atf_check -s exit:0 rump.ifconfig pppoe0 up
	wait_for_session_established dontfail
	atf_check -s not-exit:0 -o ignore -e ignore \
	    rump.ping -c 1 -w $TIMEOUT $SERVER_IP
	atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
	unset RUMP_SERVER
}

pap_cleanup()
{
	cleanup
}
atf_init_test_cases()
{
	atf_add_test_case pap
}
OpenPOWER on IntegriCloud