This is now built using "configure", knows how to find "ip", "ifconfig" and "netstat" (configure
does the work :-) ), *and* has been tested on Solaris (works!).
extend configure.ac to find "netstat" binary and to chmod +x "t_client.sh"
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Acked-by: David Sommerseth <dazo@users.sourceforge.net>
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
| ... | ... |
@@ -266,6 +266,13 @@ AC_ARG_WITH(route-path, |
| 266 | 266 |
) |
| 267 | 267 |
AC_DEFINE_UNQUOTED(ROUTE_PATH, "$ROUTE", [Path to route tool]) |
| 268 | 268 |
|
| 269 |
+AC_ARG_WITH(netstat-path, |
|
| 270 |
+ [ --with-netstat-path=PATH Path to netstat tool], |
|
| 271 |
+ [NETSTAT="$withval"], |
|
| 272 |
+ [AC_PATH_PROG([NETSTAT], [netstat], [netstat], [$PATH:/usr/local/sbin:/usr/sbin:/sbin:/etc])] |
|
| 273 |
+) |
|
| 274 |
+AC_DEFINE_UNQUOTED(NETSTAT_PATH, "$NETSTAT", [Path to netstat tool]) |
|
| 275 |
+ |
|
| 269 | 276 |
AC_ARG_WITH(mem-check, |
| 270 | 277 |
[ --with-mem-check=TYPE Build with debug memory checking, TYPE = dmalloc or valgrind], |
| 271 | 278 |
[MEMCHECK="$withval"] |
| ... | ... |
@@ -913,6 +920,7 @@ if test -z "${htmldir}"; then
|
| 913 | 913 |
fi |
| 914 | 914 |
# end workaround |
| 915 | 915 |
|
| 916 |
+AC_CONFIG_FILES([t_client.sh], [chmod +x t_client.sh]) |
|
| 916 | 917 |
AC_OUTPUT([ |
| 917 | 918 |
Makefile |
| 918 | 919 |
openvpn.spec |
| 919 | 920 |
deleted file mode 100644 |
| ... | ... |
@@ -1,298 +0,0 @@ |
| 1 |
-#!/bin/sh |
|
| 2 |
-# |
|
| 3 |
-# run OpenVPN client against ``test reference'' server |
|
| 4 |
-# - check that ping, http, ... via tunnel works |
|
| 5 |
-# - check that interface config / routes are properly cleaned after test end |
|
| 6 |
-# |
|
| 7 |
-# prerequisites: |
|
| 8 |
-# - openvpn binary in current directory |
|
| 9 |
-# - writable current directory to create subdir for logs |
|
| 10 |
-# - t_client.rc in current directory OR source dir that specifies tests |
|
| 11 |
-# - for "ping4" checks: fping binary in $PATH |
|
| 12 |
-# - for "ping6" checks: fping6 binary in $PATH |
|
| 13 |
-# |
|
| 14 |
- |
|
| 15 |
-if [ ! -x ./openvpn ] |
|
| 16 |
-then |
|
| 17 |
- echo "no (executable) openvpn binary in current directory. FAIL." >&2 |
|
| 18 |
- exit 1 |
|
| 19 |
-fi |
|
| 20 |
- |
|
| 21 |
-if [ ! -w . ] |
|
| 22 |
-then |
|
| 23 |
- echo "current directory is not writable (required for logging). FAIL." >&2 |
|
| 24 |
- exit 1 |
|
| 25 |
-fi |
|
| 26 |
- |
|
| 27 |
-if [ -r ./t_client.rc ] ; then |
|
| 28 |
- . ./t_client.rc |
|
| 29 |
-elif [ -r "${srcdir}"/t_client.rc ] ; then
|
|
| 30 |
- . "${srcdir}"/t_client.rc
|
|
| 31 |
-else |
|
| 32 |
- echo "cannot find 't_client.rc' in current directory or" >&2 |
|
| 33 |
- echo "source dir ('${srcdir}'). FAIL." >&2
|
|
| 34 |
- exit 1 |
|
| 35 |
-fi |
|
| 36 |
- |
|
| 37 |
-if [ -z "$CA_CERT" ] ; then |
|
| 38 |
- echo "CA_CERT not defined in 't_client.rc'. SKIP test." >&2 |
|
| 39 |
- exit 0 |
|
| 40 |
-fi |
|
| 41 |
- |
|
| 42 |
-if [ -z "$TEST_RUN_LIST" ] ; then |
|
| 43 |
- echo "TEST_RUN_LIST empty, no tests defined. SKIP test." >&2 |
|
| 44 |
- exit 0 |
|
| 45 |
-fi |
|
| 46 |
- |
|
| 47 |
-# make sure we have permissions to run ifconfig/route from OpenVPN |
|
| 48 |
-# can't use "id -u" here - doesn't work on Solaris |
|
| 49 |
-ID=`id` |
|
| 50 |
-if expr "$ID" : "uid=0" >/dev/null |
|
| 51 |
-then : |
|
| 52 |
-else |
|
| 53 |
- echo "$0: this test must run be as root. SKIP." >&2 |
|
| 54 |
- exit 0 |
|
| 55 |
-fi |
|
| 56 |
- |
|
| 57 |
-LOGDIR=t_client-`hostname`-`date +%Y%m%d-%H%M%S` |
|
| 58 |
-if mkdir $LOGDIR |
|
| 59 |
-then : |
|
| 60 |
-else |
|
| 61 |
- echo "can't create log directory '$LOGDIR'. FAIL." >&2 |
|
| 62 |
- exit 1 |
|
| 63 |
-fi |
|
| 64 |
- |
|
| 65 |
-exit_code=0 |
|
| 66 |
- |
|
| 67 |
-# ---------------------------------------------------------- |
|
| 68 |
-# helper functions |
|
| 69 |
-# ---------------------------------------------------------- |
|
| 70 |
-# print failure message, increase FAIL counter |
|
| 71 |
-fail() |
|
| 72 |
-{
|
|
| 73 |
- echo "" |
|
| 74 |
- echo "FAIL: $@" >&2 |
|
| 75 |
- fail_count=$(( $fail_count + 1 )) |
|
| 76 |
-} |
|
| 77 |
- |
|
| 78 |
-# print "all interface IP addresses" + "all routes" |
|
| 79 |
-# this is higly system dependent... |
|
| 80 |
-get_ifconfig_route() |
|
| 81 |
-{
|
|
| 82 |
- # linux / iproute2? |
|
| 83 |
- if [ -x /sbin/ip -o -x /usr/sbin/ip ] |
|
| 84 |
- then |
|
| 85 |
- echo "-- linux iproute2 --" |
|
| 86 |
- ip addr show | grep -v valid_lft |
|
| 87 |
- ip route show |
|
| 88 |
- ip -6 route show | sed -e 's/expires [0-9]*sec //' |
|
| 89 |
- return |
|
| 90 |
- fi |
|
| 91 |
- |
|
| 92 |
- # try uname |
|
| 93 |
- case `uname -s` in |
|
| 94 |
- Linux) |
|
| 95 |
- echo "-- linux / ifconfig --" |
|
| 96 |
- LANG=C ifconfig -a |egrep "( addr:|encap:)" |
|
| 97 |
- LANG=C netstat -rn -4 -6 |
|
| 98 |
- return |
|
| 99 |
- ;; |
|
| 100 |
- FreeBSD|NetBSD|Darwin) |
|
| 101 |
- echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --" |
|
| 102 |
- ifconfig -a | egrep "(flags=|inet)" |
|
| 103 |
- netstat -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
|
|
| 104 |
- return |
|
| 105 |
- ;; |
|
| 106 |
- OpenBSD) |
|
| 107 |
- echo "-- OpenBSD --" |
|
| 108 |
- ifconfig -a | egrep "(flags=|inet)" | \ |
|
| 109 |
- sed -e 's/pltime [0-9]*//' -e 's/vltime [0-9]*//' |
|
| 110 |
- netstat -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
|
|
| 111 |
- return |
|
| 112 |
- ;; |
|
| 113 |
- SunOS) |
|
| 114 |
- echo "-- Solaris --" |
|
| 115 |
- ifconfig -a | egrep "(flags=|inet)" |
|
| 116 |
- netstat -rn |
|
| 117 |
- return |
|
| 118 |
- ;; |
|
| 119 |
- esac |
|
| 120 |
- |
|
| 121 |
- echo "get_ifconfig_route(): no idea how to get info on your OS. FAIL." >&2 |
|
| 122 |
- exit 20 |
|
| 123 |
-} |
|
| 124 |
- |
|
| 125 |
-# ---------------------------------------------------------- |
|
| 126 |
-# check ifconfig |
|
| 127 |
-# arg1: "4" or "6" -> for message |
|
| 128 |
-# arg2: IPv4/IPv6 address that must show up in out of "get_ifconfig_route" |
|
| 129 |
-check_ifconfig() |
|
| 130 |
-{
|
|
| 131 |
- proto=$1 ; shift |
|
| 132 |
- expect_list="$@" |
|
| 133 |
- |
|
| 134 |
- if [ -z "$expect_list" ] ; then return ; fi |
|
| 135 |
- |
|
| 136 |
- for expect in $expect_list |
|
| 137 |
- do |
|
| 138 |
- if get_ifconfig_route | fgrep "$expect" >/dev/null |
|
| 139 |
- then : |
|
| 140 |
- else |
|
| 141 |
- fail "check_ifconfig(): expected IPv$proto address '$expect' not found in ifconfig output." |
|
| 142 |
- fi |
|
| 143 |
- done |
|
| 144 |
-} |
|
| 145 |
- |
|
| 146 |
-# ---------------------------------------------------------- |
|
| 147 |
-# run pings |
|
| 148 |
-# arg1: "4" or "6" -> fping/fing6 |
|
| 149 |
-# arg2: "want_ok" or "want_fail" (expected ping result) |
|
| 150 |
-# arg3... -> fping arguments (host list) |
|
| 151 |
-run_ping_tests() |
|
| 152 |
-{
|
|
| 153 |
- proto=$1 ; want=$2 ; shift ; shift |
|
| 154 |
- targetlist="$@" |
|
| 155 |
- |
|
| 156 |
- # "no targets" is fine |
|
| 157 |
- if [ -z "$targetlist" ] ; then return ; fi |
|
| 158 |
- |
|
| 159 |
- case $proto in |
|
| 160 |
- 4) cmd=fping ;; |
|
| 161 |
- 6) cmd=fping6 ;; |
|
| 162 |
- *) echo "internal error in run_ping_tests arg 1: '$proto'" >&2 |
|
| 163 |
- exit 1 ;; |
|
| 164 |
- esac |
|
| 165 |
- |
|
| 166 |
- case $want in |
|
| 167 |
- want_ok) sizes_list="64 1440 3000" ;; |
|
| 168 |
- want_fail) sizes_list="64" ;; |
|
| 169 |
- esac |
|
| 170 |
- |
|
| 171 |
- for bytes in $sizes_list |
|
| 172 |
- do |
|
| 173 |
- echo "run IPv$proto ping tests ($want), $bytes byte packets..." |
|
| 174 |
- |
|
| 175 |
- echo "$cmd -b $bytes -C 20 -p 250 -q $targetlist" >>$LOGDIR/$SUF:fping.out |
|
| 176 |
- $cmd -b $bytes -C 20 -p 250 -q $targetlist >>$LOGDIR/$SUF:fping.out 2>&1 |
|
| 177 |
- |
|
| 178 |
- # while OpenVPN is running, pings must succeed (want='want_ok') |
|
| 179 |
- # before OpenVPN is up, pings must NOT succeed (want='want_fail') |
|
| 180 |
- |
|
| 181 |
- rc=$? |
|
| 182 |
- if [ $rc = 0 ] # all ping OK |
|
| 183 |
- then |
|
| 184 |
- if [ $want = "want_fail" ] # not what we want |
|
| 185 |
- then |
|
| 186 |
- fail "IPv$proto ping test succeeded, but needs to *fail*." |
|
| 187 |
- fi |
|
| 188 |
- else # ping failed |
|
| 189 |
- if [ $want = "want_ok" ] # not what we wanted |
|
| 190 |
- then |
|
| 191 |
- fail "IPv$proto ping test ($bytes bytes) failed, but should succeed." |
|
| 192 |
- fi |
|
| 193 |
- fi |
|
| 194 |
- done |
|
| 195 |
-} |
|
| 196 |
- |
|
| 197 |
-# ---------------------------------------------------------- |
|
| 198 |
-# main test loop |
|
| 199 |
-# ---------------------------------------------------------- |
|
| 200 |
-for SUF in $TEST_RUN_LIST |
|
| 201 |
-do |
|
| 202 |
- echo -e "\n### test run $SUF ###\n" |
|
| 203 |
- fail_count=0 |
|
| 204 |
- |
|
| 205 |
- echo "save pre-openvpn ifconfig + route" |
|
| 206 |
- get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt |
|
| 207 |
- |
|
| 208 |
- # get config variables |
|
| 209 |
- eval openvpn_conf=\"\$OPENVPN_CONF_$SUF\" |
|
| 210 |
- eval expect_ifconfig4=\"\$EXPECT_IFCONFIG4_$SUF\" |
|
| 211 |
- eval expect_ifconfig6=\"\$EXPECT_IFCONFIG6_$SUF\" |
|
| 212 |
- eval ping4_hosts=\"\$PING4_HOSTS_$SUF\" |
|
| 213 |
- eval ping6_hosts=\"\$PING6_HOSTS_$SUF\" |
|
| 214 |
- |
|
| 215 |
- echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..." |
|
| 216 |
- run_ping_tests 4 want_fail "$ping4_hosts" |
|
| 217 |
- run_ping_tests 6 want_fail "$ping6_hosts" |
|
| 218 |
- if [ "$fail_count" = 0 ] ; then |
|
| 219 |
- echo -e "OK.\n" |
|
| 220 |
- else |
|
| 221 |
- echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF". |
|
| 222 |
- exit_code=31 |
|
| 223 |
- continue |
|
| 224 |
- fi |
|
| 225 |
- |
|
| 226 |
- echo " run ./openvpn $openvpn_conf" |
|
| 227 |
- ./openvpn $openvpn_conf >$LOGDIR/$SUF:openvpn.log & |
|
| 228 |
- opid=$! |
|
| 229 |
- |
|
| 230 |
- # make sure openvpn client is terminated in case shell exits |
|
| 231 |
- trap "kill $opid" 0 |
|
| 232 |
- trap "kill $opid ; trap - 0 ; exit 1" 1 2 3 15 |
|
| 233 |
- |
|
| 234 |
- echo "wait for connection to establish..." |
|
| 235 |
- sleep 10 |
|
| 236 |
- |
|
| 237 |
- # test whether OpenVPN process is still there |
|
| 238 |
- if kill -0 $opid |
|
| 239 |
- then : |
|
| 240 |
- else |
|
| 241 |
- echo -e "OpenVPN process has failed to start up, check log ($LOGDIR/$SUF:openvpn.log). FAIL.\ntail of logfile follows:\n..." >&2 |
|
| 242 |
- tail $LOGDIR/$SUF:openvpn.log >&2 |
|
| 243 |
- trap - 0 1 2 3 15 |
|
| 244 |
- exit 10 |
|
| 245 |
- fi |
|
| 246 |
- |
|
| 247 |
- # compare whether anything changed in ifconfig/route setup? |
|
| 248 |
- echo "save ifconfig+route" |
|
| 249 |
- get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt |
|
| 250 |
- |
|
| 251 |
- echo -n "compare pre-openvpn ifconfig+route with current values..." |
|
| 252 |
- if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \ |
|
| 253 |
- $LOGDIR/$SUF:ifconfig_route.txt >/dev/null |
|
| 254 |
- then |
|
| 255 |
- fail "no differences between ifconfig/route before OpenVPN start and now." |
|
| 256 |
- else |
|
| 257 |
- echo -e " OK!\n" |
|
| 258 |
- fi |
|
| 259 |
- |
|
| 260 |
- # expected ifconfig values in there? |
|
| 261 |
- check_ifconfig 4 "$expect_ifconfig4" |
|
| 262 |
- check_ifconfig 6 "$expect_ifconfig6" |
|
| 263 |
- |
|
| 264 |
- run_ping_tests 4 want_ok "$ping4_hosts" |
|
| 265 |
- run_ping_tests 6 want_ok "$ping6_hosts" |
|
| 266 |
- echo -e "ping tests done.\n" |
|
| 267 |
- |
|
| 268 |
- echo "stopping OpenVPN" |
|
| 269 |
- kill $opid |
|
| 270 |
- wait $! |
|
| 271 |
- rc=$? |
|
| 272 |
- if [ $rc != 0 ] ; then |
|
| 273 |
- fail "OpenVPN return code $rc, expect 0" |
|
| 274 |
- fi |
|
| 275 |
- |
|
| 276 |
- echo -e "\nsave post-openvpn ifconfig + route..." |
|
| 277 |
- get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt |
|
| 278 |
- |
|
| 279 |
- echo -n "compare pre- and post-openvpn ifconfig + route..." |
|
| 280 |
- if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \ |
|
| 281 |
- $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt |
|
| 282 |
- then |
|
| 283 |
- echo -e " OK.\n" |
|
| 284 |
- else |
|
| 285 |
- cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2 |
|
| 286 |
- fail "differences between pre- and post-ifconfig/route" |
|
| 287 |
- fi |
|
| 288 |
- if [ "$fail_count" = 0 ] ; then |
|
| 289 |
- echo -e "test run $SUF: all tests OK.\n" |
|
| 290 |
- else |
|
| 291 |
- echo -e "test run $SUF: $fail_count test failures. FAIL.\n"; |
|
| 292 |
- exit_code=30 |
|
| 293 |
- fi |
|
| 294 |
-done |
|
| 295 |
- |
|
| 296 |
-# remove trap handler |
|
| 297 |
-trap - 0 1 2 3 15 |
|
| 298 |
-exit $exit_code |
| 299 | 1 |
new file mode 100755 |
| ... | ... |
@@ -0,0 +1,298 @@ |
| 0 |
+#!@SHELL@ |
|
| 1 |
+# |
|
| 2 |
+# run OpenVPN client against ``test reference'' server |
|
| 3 |
+# - check that ping, http, ... via tunnel works |
|
| 4 |
+# - check that interface config / routes are properly cleaned after test end |
|
| 5 |
+# |
|
| 6 |
+# prerequisites: |
|
| 7 |
+# - openvpn binary in current directory |
|
| 8 |
+# - writable current directory to create subdir for logs |
|
| 9 |
+# - t_client.rc in current directory OR source dir that specifies tests |
|
| 10 |
+# - for "ping4" checks: fping binary in $PATH |
|
| 11 |
+# - for "ping6" checks: fping6 binary in $PATH |
|
| 12 |
+# |
|
| 13 |
+ |
|
| 14 |
+if [ ! -x ./openvpn ] |
|
| 15 |
+then |
|
| 16 |
+ echo "no (executable) openvpn binary in current directory. FAIL." >&2 |
|
| 17 |
+ exit 1 |
|
| 18 |
+fi |
|
| 19 |
+ |
|
| 20 |
+if [ ! -w . ] |
|
| 21 |
+then |
|
| 22 |
+ echo "current directory is not writable (required for logging). FAIL." >&2 |
|
| 23 |
+ exit 1 |
|
| 24 |
+fi |
|
| 25 |
+ |
|
| 26 |
+if [ -r ./t_client.rc ] ; then |
|
| 27 |
+ . ./t_client.rc |
|
| 28 |
+elif [ -r "${srcdir}"/t_client.rc ] ; then
|
|
| 29 |
+ . "${srcdir}"/t_client.rc
|
|
| 30 |
+else |
|
| 31 |
+ echo "cannot find 't_client.rc' in current directory or" >&2 |
|
| 32 |
+ echo "source dir ('${srcdir}'). FAIL." >&2
|
|
| 33 |
+ exit 1 |
|
| 34 |
+fi |
|
| 35 |
+ |
|
| 36 |
+if [ -z "$CA_CERT" ] ; then |
|
| 37 |
+ echo "CA_CERT not defined in 't_client.rc'. SKIP test." >&2 |
|
| 38 |
+ exit 0 |
|
| 39 |
+fi |
|
| 40 |
+ |
|
| 41 |
+if [ -z "$TEST_RUN_LIST" ] ; then |
|
| 42 |
+ echo "TEST_RUN_LIST empty, no tests defined. SKIP test." >&2 |
|
| 43 |
+ exit 0 |
|
| 44 |
+fi |
|
| 45 |
+ |
|
| 46 |
+# make sure we have permissions to run ifconfig/route from OpenVPN |
|
| 47 |
+# can't use "id -u" here - doesn't work on Solaris |
|
| 48 |
+ID=`id` |
|
| 49 |
+if expr "$ID" : "uid=0" >/dev/null |
|
| 50 |
+then : |
|
| 51 |
+else |
|
| 52 |
+ echo "$0: this test must run be as root. SKIP." >&2 |
|
| 53 |
+ exit 0 |
|
| 54 |
+fi |
|
| 55 |
+ |
|
| 56 |
+LOGDIR=t_client-`hostname`-`date +%Y%m%d-%H%M%S` |
|
| 57 |
+if mkdir $LOGDIR |
|
| 58 |
+then : |
|
| 59 |
+else |
|
| 60 |
+ echo "can't create log directory '$LOGDIR'. FAIL." >&2 |
|
| 61 |
+ exit 1 |
|
| 62 |
+fi |
|
| 63 |
+ |
|
| 64 |
+exit_code=0 |
|
| 65 |
+ |
|
| 66 |
+# ---------------------------------------------------------- |
|
| 67 |
+# helper functions |
|
| 68 |
+# ---------------------------------------------------------- |
|
| 69 |
+# print failure message, increase FAIL counter |
|
| 70 |
+fail() |
|
| 71 |
+{
|
|
| 72 |
+ echo "" |
|
| 73 |
+ echo "FAIL: $@" >&2 |
|
| 74 |
+ fail_count=$(( $fail_count + 1 )) |
|
| 75 |
+} |
|
| 76 |
+ |
|
| 77 |
+# print "all interface IP addresses" + "all routes" |
|
| 78 |
+# this is higly system dependent... |
|
| 79 |
+get_ifconfig_route() |
|
| 80 |
+{
|
|
| 81 |
+ # linux / iproute2? (-> if configure got a path) |
|
| 82 |
+ if [ "@IPROUTE@" != "ip" ] |
|
| 83 |
+ then |
|
| 84 |
+ echo "-- linux iproute2 --" |
|
| 85 |
+ @IPROUTE@ addr show | grep -v valid_lft |
|
| 86 |
+ @IPROUTE@ route show |
|
| 87 |
+ @IPROUTE@ -6 route show | sed -e 's/expires [0-9]*sec //' |
|
| 88 |
+ return |
|
| 89 |
+ fi |
|
| 90 |
+ |
|
| 91 |
+ # try uname |
|
| 92 |
+ case `uname -s` in |
|
| 93 |
+ Linux) |
|
| 94 |
+ echo "-- linux / ifconfig --" |
|
| 95 |
+ LANG=C @IFCONFIG@ -a |egrep "( addr:|encap:)" |
|
| 96 |
+ LANG=C @NETSTAT@ -rn -4 -6 |
|
| 97 |
+ return |
|
| 98 |
+ ;; |
|
| 99 |
+ FreeBSD|NetBSD|Darwin) |
|
| 100 |
+ echo "-- FreeBSD/NetBSD/Darwin [MacOS X] --" |
|
| 101 |
+ @IFCONFIG@ -a | egrep "(flags=|inet)" |
|
| 102 |
+ @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
|
|
| 103 |
+ return |
|
| 104 |
+ ;; |
|
| 105 |
+ OpenBSD) |
|
| 106 |
+ echo "-- OpenBSD --" |
|
| 107 |
+ @IFCONFIG@ -a | egrep "(flags=|inet)" | \ |
|
| 108 |
+ sed -e 's/pltime [0-9]*//' -e 's/vltime [0-9]*//' |
|
| 109 |
+ @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$NF }'
|
|
| 110 |
+ return |
|
| 111 |
+ ;; |
|
| 112 |
+ SunOS) |
|
| 113 |
+ echo "-- Solaris --" |
|
| 114 |
+ @IFCONFIG@ -a | egrep "(flags=|inet)" |
|
| 115 |
+ @NETSTAT@ -rn | awk '$3 !~ /^UHL/ { print $1,$2,$3,$6 }'
|
|
| 116 |
+ return |
|
| 117 |
+ ;; |
|
| 118 |
+ esac |
|
| 119 |
+ |
|
| 120 |
+ echo "get_ifconfig_route(): no idea how to get info on your OS. FAIL." >&2 |
|
| 121 |
+ exit 20 |
|
| 122 |
+} |
|
| 123 |
+ |
|
| 124 |
+# ---------------------------------------------------------- |
|
| 125 |
+# check ifconfig |
|
| 126 |
+# arg1: "4" or "6" -> for message |
|
| 127 |
+# arg2: IPv4/IPv6 address that must show up in out of "get_ifconfig_route" |
|
| 128 |
+check_ifconfig() |
|
| 129 |
+{
|
|
| 130 |
+ proto=$1 ; shift |
|
| 131 |
+ expect_list="$@" |
|
| 132 |
+ |
|
| 133 |
+ if [ -z "$expect_list" ] ; then return ; fi |
|
| 134 |
+ |
|
| 135 |
+ for expect in $expect_list |
|
| 136 |
+ do |
|
| 137 |
+ if get_ifconfig_route | fgrep "$expect" >/dev/null |
|
| 138 |
+ then : |
|
| 139 |
+ else |
|
| 140 |
+ fail "check_ifconfig(): expected IPv$proto address '$expect' not found in ifconfig output." |
|
| 141 |
+ fi |
|
| 142 |
+ done |
|
| 143 |
+} |
|
| 144 |
+ |
|
| 145 |
+# ---------------------------------------------------------- |
|
| 146 |
+# run pings |
|
| 147 |
+# arg1: "4" or "6" -> fping/fing6 |
|
| 148 |
+# arg2: "want_ok" or "want_fail" (expected ping result) |
|
| 149 |
+# arg3... -> fping arguments (host list) |
|
| 150 |
+run_ping_tests() |
|
| 151 |
+{
|
|
| 152 |
+ proto=$1 ; want=$2 ; shift ; shift |
|
| 153 |
+ targetlist="$@" |
|
| 154 |
+ |
|
| 155 |
+ # "no targets" is fine |
|
| 156 |
+ if [ -z "$targetlist" ] ; then return ; fi |
|
| 157 |
+ |
|
| 158 |
+ case $proto in |
|
| 159 |
+ 4) cmd=fping ;; |
|
| 160 |
+ 6) cmd=fping6 ;; |
|
| 161 |
+ *) echo "internal error in run_ping_tests arg 1: '$proto'" >&2 |
|
| 162 |
+ exit 1 ;; |
|
| 163 |
+ esac |
|
| 164 |
+ |
|
| 165 |
+ case $want in |
|
| 166 |
+ want_ok) sizes_list="64 1440 3000" ;; |
|
| 167 |
+ want_fail) sizes_list="64" ;; |
|
| 168 |
+ esac |
|
| 169 |
+ |
|
| 170 |
+ for bytes in $sizes_list |
|
| 171 |
+ do |
|
| 172 |
+ echo "run IPv$proto ping tests ($want), $bytes byte packets..." |
|
| 173 |
+ |
|
| 174 |
+ echo "$cmd -b $bytes -C 20 -p 250 -q $targetlist" >>$LOGDIR/$SUF:fping.out |
|
| 175 |
+ $cmd -b $bytes -C 20 -p 250 -q $targetlist >>$LOGDIR/$SUF:fping.out 2>&1 |
|
| 176 |
+ |
|
| 177 |
+ # while OpenVPN is running, pings must succeed (want='want_ok') |
|
| 178 |
+ # before OpenVPN is up, pings must NOT succeed (want='want_fail') |
|
| 179 |
+ |
|
| 180 |
+ rc=$? |
|
| 181 |
+ if [ $rc = 0 ] # all ping OK |
|
| 182 |
+ then |
|
| 183 |
+ if [ $want = "want_fail" ] # not what we want |
|
| 184 |
+ then |
|
| 185 |
+ fail "IPv$proto ping test succeeded, but needs to *fail*." |
|
| 186 |
+ fi |
|
| 187 |
+ else # ping failed |
|
| 188 |
+ if [ $want = "want_ok" ] # not what we wanted |
|
| 189 |
+ then |
|
| 190 |
+ fail "IPv$proto ping test ($bytes bytes) failed, but should succeed." |
|
| 191 |
+ fi |
|
| 192 |
+ fi |
|
| 193 |
+ done |
|
| 194 |
+} |
|
| 195 |
+ |
|
| 196 |
+# ---------------------------------------------------------- |
|
| 197 |
+# main test loop |
|
| 198 |
+# ---------------------------------------------------------- |
|
| 199 |
+for SUF in $TEST_RUN_LIST |
|
| 200 |
+do |
|
| 201 |
+ echo -e "\n### test run $SUF ###\n" |
|
| 202 |
+ fail_count=0 |
|
| 203 |
+ |
|
| 204 |
+ echo "save pre-openvpn ifconfig + route" |
|
| 205 |
+ get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_pre.txt |
|
| 206 |
+ |
|
| 207 |
+ # get config variables |
|
| 208 |
+ eval openvpn_conf=\"\$OPENVPN_CONF_$SUF\" |
|
| 209 |
+ eval expect_ifconfig4=\"\$EXPECT_IFCONFIG4_$SUF\" |
|
| 210 |
+ eval expect_ifconfig6=\"\$EXPECT_IFCONFIG6_$SUF\" |
|
| 211 |
+ eval ping4_hosts=\"\$PING4_HOSTS_$SUF\" |
|
| 212 |
+ eval ping6_hosts=\"\$PING6_HOSTS_$SUF\" |
|
| 213 |
+ |
|
| 214 |
+ echo -e "\nrun pre-openvpn ping tests - targets must not be reachable..." |
|
| 215 |
+ run_ping_tests 4 want_fail "$ping4_hosts" |
|
| 216 |
+ run_ping_tests 6 want_fail "$ping6_hosts" |
|
| 217 |
+ if [ "$fail_count" = 0 ] ; then |
|
| 218 |
+ echo -e "OK.\n" |
|
| 219 |
+ else |
|
| 220 |
+ echo -e "FAIL: make sure that ping hosts are ONLY reachable via VPN, SKIP test $SUF". |
|
| 221 |
+ exit_code=31 |
|
| 222 |
+ continue |
|
| 223 |
+ fi |
|
| 224 |
+ |
|
| 225 |
+ echo " run ./openvpn $openvpn_conf" |
|
| 226 |
+ ./openvpn $openvpn_conf >$LOGDIR/$SUF:openvpn.log & |
|
| 227 |
+ opid=$! |
|
| 228 |
+ |
|
| 229 |
+ # make sure openvpn client is terminated in case shell exits |
|
| 230 |
+ trap "kill $opid" 0 |
|
| 231 |
+ trap "kill $opid ; trap - 0 ; exit 1" 1 2 3 15 |
|
| 232 |
+ |
|
| 233 |
+ echo "wait for connection to establish..." |
|
| 234 |
+ sleep 10 |
|
| 235 |
+ |
|
| 236 |
+ # test whether OpenVPN process is still there |
|
| 237 |
+ if kill -0 $opid |
|
| 238 |
+ then : |
|
| 239 |
+ else |
|
| 240 |
+ echo -e "OpenVPN process has failed to start up, check log ($LOGDIR/$SUF:openvpn.log). FAIL.\ntail of logfile follows:\n..." >&2 |
|
| 241 |
+ tail $LOGDIR/$SUF:openvpn.log >&2 |
|
| 242 |
+ trap - 0 1 2 3 15 |
|
| 243 |
+ exit 10 |
|
| 244 |
+ fi |
|
| 245 |
+ |
|
| 246 |
+ # compare whether anything changed in ifconfig/route setup? |
|
| 247 |
+ echo "save ifconfig+route" |
|
| 248 |
+ get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route.txt |
|
| 249 |
+ |
|
| 250 |
+ echo -n "compare pre-openvpn ifconfig+route with current values..." |
|
| 251 |
+ if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \ |
|
| 252 |
+ $LOGDIR/$SUF:ifconfig_route.txt >/dev/null |
|
| 253 |
+ then |
|
| 254 |
+ fail "no differences between ifconfig/route before OpenVPN start and now." |
|
| 255 |
+ else |
|
| 256 |
+ echo -e " OK!\n" |
|
| 257 |
+ fi |
|
| 258 |
+ |
|
| 259 |
+ # expected ifconfig values in there? |
|
| 260 |
+ check_ifconfig 4 "$expect_ifconfig4" |
|
| 261 |
+ check_ifconfig 6 "$expect_ifconfig6" |
|
| 262 |
+ |
|
| 263 |
+ run_ping_tests 4 want_ok "$ping4_hosts" |
|
| 264 |
+ run_ping_tests 6 want_ok "$ping6_hosts" |
|
| 265 |
+ echo -e "ping tests done.\n" |
|
| 266 |
+ |
|
| 267 |
+ echo "stopping OpenVPN" |
|
| 268 |
+ kill $opid |
|
| 269 |
+ wait $! |
|
| 270 |
+ rc=$? |
|
| 271 |
+ if [ $rc != 0 ] ; then |
|
| 272 |
+ fail "OpenVPN return code $rc, expect 0" |
|
| 273 |
+ fi |
|
| 274 |
+ |
|
| 275 |
+ echo -e "\nsave post-openvpn ifconfig + route..." |
|
| 276 |
+ get_ifconfig_route >$LOGDIR/$SUF:ifconfig_route_post.txt |
|
| 277 |
+ |
|
| 278 |
+ echo -n "compare pre- and post-openvpn ifconfig + route..." |
|
| 279 |
+ if diff $LOGDIR/$SUF:ifconfig_route_pre.txt \ |
|
| 280 |
+ $LOGDIR/$SUF:ifconfig_route_post.txt >$LOGDIR/$SUF:ifconfig_route_diff.txt |
|
| 281 |
+ then |
|
| 282 |
+ echo -e " OK.\n" |
|
| 283 |
+ else |
|
| 284 |
+ cat $LOGDIR/$SUF:ifconfig_route_diff.txt >&2 |
|
| 285 |
+ fail "differences between pre- and post-ifconfig/route" |
|
| 286 |
+ fi |
|
| 287 |
+ if [ "$fail_count" = 0 ] ; then |
|
| 288 |
+ echo -e "test run $SUF: all tests OK.\n" |
|
| 289 |
+ else |
|
| 290 |
+ echo -e "test run $SUF: $fail_count test failures. FAIL.\n"; |
|
| 291 |
+ exit_code=30 |
|
| 292 |
+ fi |
|
| 293 |
+done |
|
| 294 |
+ |
|
| 295 |
+# remove trap handler |
|
| 296 |
+trap - 0 1 2 3 15 |
|
| 297 |
+exit $exit_code |