t_cltsrv.sh 3.0 KB

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