1#! /bin/sh 2# 3# t_cltsrv.sh - script to test OpenVPN's crypto loopback 4# Copyright (C) 2005, 2006, 2008 Matthias Andree 5# 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. 10# 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. 15# 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. 20 21set -e 22srcdir="${srcdir:-.}" 23top_srcdir="${top_srcdir:-..}" 24top_builddir="${top_builddir:-..}" 25trap "rm -f log.$$ log.$$.signal ; trap 0 ; exit 77" 1 2 15 26trap "rm -f log.$$ log.$$.signal ; exit 1" 0 3 27addopts= 28case `uname -s` in 29 FreeBSD) 30 # FreeBSD jails map the outgoing IP to the jail IP - we need to 31 # allow the real IP unless we want the test to run forever. 32 if test "`sysctl 2>/dev/null -n security.jail.jailed`" = 1 \ 33 || ps -ostate= -p $$ | grep -q J; then 34 addopts="--float" 35 if test "x`ifconfig | grep inet`" = x ; then 36 echo "###" 37 echo "### To run the test in a FreeBSD jail, you MUST add an IP alias for the jail's IP." 38 echo "###" 39 exit 77 40 fi 41 fi 42 ;; 43esac 44 45# make sure that the --down script is executable -- fail (rather than 46# skip) test if it isn't. 47downscript="../tests/t_cltsrv-down.sh" 48root="${top_srcdir}/sample" 49test -x "${root}/${downscript}" || chmod +x "${root}/${downscript}" || { echo >&2 "${root}/${downscript} is not executable, failing." ; exit 1 ; } 50echo "The following test will take about two minutes." >&2 51echo "If the addresses are in use, this test will retry up to two times." >&2 52 53# go 54success=0 55for i in 1 2 3 ; do 56 set +e 57 ( 58 "${top_builddir}/src/openvpn/openvpn" --script-security 2 --cd "${root}" ${addopts} --setenv role srv --down "${downscript}" --tls-exit --ping-exit 180 --config "sample-config-files/loopback-server" & 59 "${top_builddir}/src/openvpn/openvpn" --script-security 2 --cd "${top_srcdir}/sample" ${addopts} --setenv role clt --down "${downscript}" --tls-exit --ping-exit 180 --config "sample-config-files/loopback-client" 60 ) 3>log.$$.signal >log.$$ 2>&1 61 e1=$? 62 wait $! 63 e2=$? 64 grep 'TCP/UDP: Socket bind failed on local address.*in use' log.$$ >/dev/null && { 65 echo 'address in use, retrying in 150 s' 66 sleep 150 67 continue 68 } 69 grep -v ':inactive$' log.$$.signal >/dev/null && { cat log.$$.signal ; echo ; cat log.$$ ; exit 1 ; } 70 success=1 71 break 72done 73 74set -e 75 76# exit code - defaults to 0, PASS 77ec=0 78 79if [ $success != 1 ] ; then 80 # couldn't run test -- addresses in use, skip test 81 cat log.$$ 82 ec=77 83elif [ $e1 != 0 ] || [ $e2 != 0 ] ; then 84 # failure -- fail test 85 cat log.$$ 86 ec=1 87fi 88 89rm log.$$ log.$$.signal 90trap 0 91exit $ec 92