Add a new test case for PPPoE using PAP

From s-yamaguchi@IIJ (with some tweaks by me)
This commit is contained in:
ozaki-r 2016-04-15 01:38:16 +00:00
parent 4da47673a2
commit c73a69e593
5 changed files with 209 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: mi,v 1.672 2016/04/09 04:39:47 riastradh Exp $
# $NetBSD: mi,v 1.673 2016/04/15 01:38:16 ozaki-r Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@ -3183,6 +3183,10 @@
./usr/tests/net/if_loop/Atffile tests-net-tests atf,rump
./usr/tests/net/if_loop/Kyuafile tests-net-tests atf,rump,kyua
./usr/tests/net/if_loop/t_pr tests-net-tests atf,rump
./usr/tests/net/if_pppoe tests-net-tests compattestfile,atf
./usr/tests/net/if_pppoe/Atffile tests-net-tests atf,rump
./usr/tests/net/if_pppoe/Kyuafile tests-net-tests atf,rump,kyua
./usr/tests/net/if_pppoe/t_pppoe tests-net-tests atf,rump
./usr/tests/net/if_tap tests-net-tests compattestfile,atf
./usr/tests/net/if_tap/Atffile tests-net-tests atf,rump
./usr/tests/net/if_tap/Kyuafile tests-net-tests atf,rump,kyua

View File

@ -1,4 +1,4 @@
# $NetBSD: NetBSD.dist.tests,v 1.126 2016/04/08 10:09:16 gson Exp $
# $NetBSD: NetBSD.dist.tests,v 1.127 2016/04/15 01:38:17 ozaki-r Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@ -324,6 +324,7 @@
./usr/tests/net/if_bridge
./usr/tests/net/if_gif
./usr/tests/net/if_loop
./usr/tests/net/if_pppoe
./usr/tests/net/if_tap
./usr/tests/net/in_cksum
./usr/tests/net/mcast

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.27 2016/03/04 02:44:45 ozaki-r Exp $
# $NetBSD: Makefile,v 1.28 2016/04/15 01:38:17 ozaki-r Exp $
.include <bsd.own.mk>
@ -7,7 +7,7 @@ TESTSDIR= ${TESTSBASE}/net
TESTS_SUBDIRS= fdpass in_cksum net sys
.if (${MKRUMP} != "no") && !defined(BSD_MK_COMPAT_FILE)
TESTS_SUBDIRS+= arp bpf bpfilter carp icmp if if_bridge if_gif if_loop
TESTS_SUBDIRS+= if_tap mcast mpls ndp npf route
TESTS_SUBDIRS+= if_pppoe if_tap mcast mpls ndp npf route
.if (${MKSLJIT} != "no")
TESTS_SUBDIRS+= bpfjit
.endif

View File

@ -0,0 +1,8 @@
.include <bsd.own.mk>
TESTSDIR= ${TESTSBASE}/net/if_pppoe
TESTS_SH= t_pppoe
.include <bsd.test.mk>

View File

@ -0,0 +1,192 @@
# $NetBSD: t_pppoe.sh,v 1.1 2016/04/15 01:38:17 ozaki-r 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 -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
}