Upgrade to OpenVPN 2.1.0
[tomato.git] / release / src / router / openvpn / t_cltsrv.sh
blob808d719b12e4cdf21d513dba45da707081d4bc10
1 #! /bin/sh
3 # t_cltsrv.sh - script to test OpenVPN's crypto loopback
4 # Copyright (C) 2005, 2006, 2008 Matthias Andree
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 set -e
22 trap "rm -f log.$$ log.$$.signal ; trap 0 ; exit 77" 1 2 15
23 trap "rm -f log.$$ log.$$.signal ; exit 1" 0 3
24 addopts=
25 case `uname -s` in
26 FreeBSD)
27 # FreeBSD jails map the outgoing IP to the jail IP - we need to
28 # allow the real IP unless we want the test to run forever.
29 if test "`sysctl 2>/dev/null -n security.jail.jailed`" = 1 \
30 || ps -ostate= -p $$ | grep -q J; then
31 addopts="--float"
32 if test "x`ifconfig | grep inet`" = x ; then
33 echo "###"
34 echo "### To run the test in a FreeBSD jail, you MUST add an IP alias for the jail's IP."
35 echo "###"
36 exit 1
40 esac
42 # make sure that the --down script is executable -- fail (rather than
43 # skip) test if it isn't.
44 downscript="t_cltsrv-down.sh"
45 test -x "${srcdir}"/$downscript || chmod +x "${srcdir}"/$downscript || { echo >&2 "$downscript is not executable, failing." ; exit 1 ; }
46 echo "The following test will take about two minutes." >&2
47 echo "If the addresses are in use, this test will retry up to two times." >&2
49 # go
50 success=0
51 for i in 1 2 3 ; do
52 set +e
54 ./openvpn --script-security 2 --cd "${srcdir}" ${addopts} --setenv role srv --down "$downscript" --tls-exit --ping-exit 180 --config sample-config-files/loopback-server &
55 ./openvpn --script-security 2 --cd "${srcdir}" ${addopts} --setenv role clt --down "$downscript" --tls-exit --ping-exit 180 --config sample-config-files/loopback-client
56 ) 3>log.$$.signal >log.$$ 2>&1
57 e1=$?
58 wait $!
59 e2=$?
60 grep 'TCP/UDP: Socket bind failed on local address.*in use' log.$$ >/dev/null && {
61 echo 'address in use, retrying in 150 s'
62 sleep 150
63 continue
65 grep -v ':inactive$' log.$$.signal >/dev/null && { cat log.$$.signal ; echo ; cat log.$$ ; exit 1 ; }
66 success=1
67 break
68 done
70 set -e
72 # exit code - defaults to 0, PASS
73 ec=0
75 if [ $success != 1 ] ; then
76 # couldn't run test -- addresses in use, skip test
77 cat log.$$
78 ec=77
79 elif [ $e1 != 0 ] || [ $e2 != 0 ] ; then
80 # failure -- fail test
81 cat log.$$
82 ec=1
85 rm log.$$ log.$$.signal
86 trap 0
87 exit $ec