]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/if_pppoe/t_pppoe.sh
MFC r305358,r305449,r305451,r306367,r306397,r309474:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / if_pppoe / t_pppoe.sh
1 #       $NetBSD: t_pppoe.sh,v 1.2 2016/08/07 23:34:31 pgoyette 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
28 server="rump_server -lrump -lrumpnet -lrumpnet_net -lrumpnet_netinet    \
29                     -lrumpnet_netinet6 -lrumpnet_shmif -lrumpdev        \
30                     -lrumpnet_pppoe"
31 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so"
32
33 SERVER=unix://commsock1
34 CLIENT=unix://commsock2
35
36 SERVER_IP=10.3.3.1
37 CLIENT_IP=10.3.3.3
38 AUTHNAME=foobar@baz.com
39 SECRET=oink
40 BUS=bus0
41 TIMEOUT=3
42 WAITTIME=5
43 DEBUG=false
44
45 atf_test_case pap cleanup
46
47 setup()
48 {
49         atf_check -s exit:0 ${server} $SERVER
50         atf_check -s exit:0 ${server} $CLIENT
51
52         export RUMP_SERVER=$SERVER
53         atf_check -s exit:0 rump.ifconfig shmif0 create
54         atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
55         atf_check -s exit:0 rump.ifconfig shmif0 up
56
57         atf_check -s exit:0 rump.ifconfig pppoe0 create
58         atf_check -s exit:0 rump.ifconfig pppoe0 inet $SERVER_IP $CLIENT_IP down
59         atf_check -s exit:0 rump.ifconfig pppoe0 link0
60
61         $DEBUG && rump.ifconfig
62         $DEBUG && $HIJACKING pppoectl -d pppoe0
63
64         atf_check -s exit:0 -x "$HIJACKING pppoectl -e shmif0 pppoe0"
65         unset RUMP_SERVER
66
67         export RUMP_SERVER=$CLIENT
68         atf_check -s exit:0 rump.ifconfig shmif0 create
69         atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS
70         atf_check -s exit:0 rump.ifconfig shmif0 up
71
72         atf_check -s exit:0 rump.ifconfig pppoe0 create
73         atf_check -s exit:0 rump.ifconfig pppoe0 inet 0.0.0.0 0.0.0.1 down
74
75         atf_check -s exit:0 -x "$HIJACKING pppoectl -e shmif0 pppoe0"
76         unset RUMP_SERVER
77 }
78 cleanup()
79 {
80         env RUMP_SERVER=$SERVER rump.halt
81         env RUMP_SERVER=$CLIENT rump.halt
82 }
83
84 pap_head()
85 {
86         atf_set "descr" "Does simple pap tests"
87         atf_set "require.progs" "rump_server pppoectl"
88 }
89
90 wait_for_session_established()
91 {
92         local dontfail=$1
93         local n=$WAITTIME
94
95         for i in $(seq $n); do
96                 $HIJACKING pppoectl -d pppoe0 |grep -q "state = session"
97                 [ $? = 0 ] && return
98                 sleep 1
99         done
100
101         if [ $dontfail != "dontfail" ]; then
102                 atf_fail "Couldn't connect to the server for $n seconds."
103         fi
104 }
105
106 pap_body()
107 {
108         local auth=pap
109         setup
110
111         export RUMP_SERVER=$SERVER
112         local setup_serverparam="pppoectl pppoe0 hisauthproto=$auth \
113                                     'hisauthname=$AUTHNAME' \
114                                     'hisauthsecret=$SECRET' \
115                                     'myauthproto=none'"
116         atf_check -s exit:0 -x "$HIJACKING $setup_serverparam"
117         atf_check -s exit:0 rump.ifconfig pppoe0 up
118         unset RUMP_SERVER
119
120         export RUMP_SERVER=$CLIENT
121         local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
122                                     'myauthname=$AUTHNAME' \
123                                     'myauthsecret=$SECRET' \
124                                     'hisauthproto=none'"
125         atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
126         atf_check -s exit:0 rump.ifconfig pppoe0 up
127         $DEBUG && rump.ifconfig
128         wait_for_session_established
129         atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $SERVER_IP
130         unset RUMP_SERVER
131
132         # test for disconnection from server
133         atf_check -s exit:0 -x "env RUMP_SERVER=$SERVER rump.ifconfig pppoe0 down"
134         export RUMP_SERVER=$CLIENT
135         atf_check -s not-exit:0 -o ignore -e ignore \
136             rump.ping -c 1 -w $TIMEOUT $SERVER_IP
137         atf_check -s exit:0 -o match:'PADI sent' -x "$HIJACKING pppoectl -d pppoe0"
138         unset RUMP_SERVER
139
140         # test for recoonecting
141         atf_check -s exit:0 -x "env RUMP_SERVER=$SERVER rump.ifconfig pppoe0 up"
142         export RUMP_SERVER=$CLIENT
143         wait_for_session_established
144         atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $SERVER_IP
145         unset RUMP_SERVER
146
147         # test for disconnection from client
148         atf_check -s exit:0 -x "env RUMP_SERVER=$CLIENT rump.ifconfig pppoe0 down"
149         export RUMP_SERVER=$SERVER
150         $DEBUG && $HIJACKING pppoectl -d pppoe0
151         atf_check -s not-exit:0 -o ignore -e ignore \
152             rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
153         atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
154         unset RUMP_SERVER
155
156         # test for recconecting
157         export RUMP_SERVER=$CLIENT
158         atf_check -s exit:0 -x rump.ifconfig pppoe0 up
159         wait_for_session_established
160         $DEBUG && rump.ifconfig pppoe0
161         $DEBUG && $HIJACKING pppoectl -d pppoe0
162         unset RUMP_SERVER
163
164         export RUMP_SERVER=$SERVER
165         atf_check -s exit:0 -o ignore rump.ping -c 1 -w $TIMEOUT $CLIENT_IP
166         atf_check -s exit:0 -o match:'session' -x "$HIJACKING pppoectl -d pppoe0"
167         $DEBUG && HIJACKING pppoectl -d pppoe0
168         unset RUMP_SERVER
169
170         # test for invalid password
171         export RUMP_SERVER=$CLIENT
172         atf_check -s exit:0 rump.ifconfig pppoe0 down
173         local setup_clientparam="pppoectl pppoe0 myauthproto=$auth \
174                                     'myauthname=$AUTHNAME' \
175                                     'myauthsecret=invalidsecret' \
176                                     'hisauthproto=none'"
177         atf_check -s exit:0 -x "$HIJACKING $setup_clientparam"
178         atf_check -s exit:0 rump.ifconfig pppoe0 up
179         wait_for_session_established dontfail
180         atf_check -s not-exit:0 -o ignore -e ignore \
181             rump.ping -c 1 -w $TIMEOUT $SERVER_IP
182         atf_check -s exit:0 -o match:'initial' -x "$HIJACKING pppoectl -d pppoe0"
183         unset RUMP_SERVER
184 }
185
186 pap_cleanup()
187 {
188         cleanup
189 }
190 atf_init_test_cases()
191 {
192         atf_add_test_case pap
193 }