sigterm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2018 Nikos Mavrogiannopoulos
  4. #
  5. # This file is part of ocserv.
  6. #
  7. # ocserv is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by the
  9. # Free Software Foundation; either version 2 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # ocserv is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. # This tests operation/traffic under compression (lzs or lz4).
  21. OCCTL="${OCCTL:-occtl}"
  22. SERV="${OCSERV:-ocserv}"
  23. srcdir=${srcdir:-.}
  24. PORT=4569
  25. PIDFILE=ocserv-pid.$$.tmp
  26. CLIPID=oc-pid.$$.tmp
  27. PATH=${PATH}:/usr/sbin
  28. IP=$(which ip)
  29. OUTFILE=traffic.$$.tmp
  30. export DISCONNECT_FILE=disconnected-ok.$$.tmp
  31. . `dirname $0`/common.sh
  32. rm -f ${DISCONNECT_FILE}
  33. if test -z "${IP}";then
  34. echo "no IP tool is present"
  35. exit 77
  36. fi
  37. if test "$(id -u)" != "0";then
  38. echo "This test must be run as root"
  39. exit 77
  40. fi
  41. echo "Testing ocserv connection with DTLS-PSK..."
  42. function finish {
  43. set +e
  44. echo " * Cleaning up..."
  45. test -n "${PID}" && kill ${PID} >/dev/null 2>&1
  46. test -n "${PIDFILE}" && rm -f ${PIDFILE} >/dev/null 2>&1
  47. test -f "${CLIPID}" && kill $(cat ${CLIPID}) >/dev/null 2>&1
  48. test -f "${CLIPID}" && rm -f ${CLIPID} >/dev/null 2>&1
  49. test -n "${CONFIG}" && rm -f ${CONFIG} >/dev/null 2>&1
  50. rm -f ${OUTFILE} 2>&1
  51. }
  52. trap finish EXIT
  53. # server address
  54. ADDRESS=10.202.2.1
  55. CLI_ADDRESS=10.202.1.1
  56. VPNNET=192.168.3.0/24
  57. VPNADDR=192.168.3.1
  58. VPNNET6=fd91:6d87:8341:dc6a::/112
  59. VPNADDR6=fd91:6d87:8341:dc6a::1
  60. USERNAME=test
  61. TUNDEV=oc-$$-tun0
  62. . `dirname $0`/ns.sh
  63. # Run servers
  64. update_config test-dtls-psk.config
  65. if test "$VERBOSE" = 1;then
  66. DEBUG="-d 3"
  67. fi
  68. ${CMDNS2} ${SERV} -p ${PIDFILE} -f -c ${CONFIG} ${DEBUG} & PID=$!
  69. sleep 4
  70. # Run clients
  71. echo " * Getting cookie from ${ADDRESS}:${PORT}..."
  72. ( echo "test" | ${CMDNS1} ${OPENCONNECT} ${ADDRESS}:${PORT} -u ${USERNAME} --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 --cookieonly )
  73. if test $? != 0;then
  74. echo "Could not get cookie from server"
  75. exit 1
  76. fi
  77. echo " * Connecting to ${ADDRESS}:${PORT}..."
  78. ( echo "test" | ${CMDNS1} ${OPENCONNECT} -Q16 --interface ${TUNDEV} --dtls-ciphers=PSK-NEGOTIATE ${ADDRESS}:${PORT} -u ${USERNAME} --servercert=d66b507ae074d03b02eafca40d35f87dd81049d3 -s ${srcdir}/scripts/vpnc-script-detect-disconnect --pid-file=${CLIPID} --passwd-on-stdin -b )
  79. if test $? != 0;then
  80. echo "Could not connect to server"
  81. exit 1
  82. fi
  83. set -e
  84. echo " * wait for ${TUNDEV}"
  85. TIMEOUT=10
  86. while ! ${CMDNS1} ip link show dev ${TUNDEV} 2>/dev/null | grep -q UP; do
  87. TIMEOUT=$(($TIMEOUT - 1))
  88. if [ $TIMEOUT -eq 0 ]; then
  89. echo "Timed out waiting for ${TUNDEV}"
  90. exit 1
  91. fi
  92. sleep 1
  93. done
  94. echo " * add routes"
  95. ${CMDNS1} ip route add ${VPNADDR} dev ${TUNDEV}
  96. ${CMDNS1} ip -6 route add ${VPNADDR6} dev ${TUNDEV}
  97. echo " * ping remote address"
  98. ${CMDNS1} ping -c 3 ${VPNADDR}
  99. test -f "${CLIPID}" && kill $(cat ${CLIPID}) >/dev/null 2>&1
  100. rm -f "${CLIPID}"
  101. sleep 5
  102. if ! test -f ${DISCONNECT_FILE};then
  103. echo "Could not find ${DISCONNECT_FILE}"
  104. exit 1
  105. fi
  106. exit 0