do-tests 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. #!/bin/bash
  2. # Automatically execute the strongSwan test cases
  3. #
  4. # Copyright (C) 2004 Eric Marchionni, Patrik Rayo
  5. # Zuercher Hochschule Winterthur
  6. #
  7. # This program 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 your
  10. # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  14. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  15. # for more details.
  16. DIR=$(dirname `readlink -f $0`)
  17. . $DIR/testing.conf
  18. . $DIR/scripts/function.sh
  19. SSHCONF="-F $DIR/ssh_config"
  20. [ -d $DIR/hosts ] || die "Directory 'hosts' not found"
  21. [ -d $DIR/tests ] || die "Directory 'tests' not found"
  22. [ -d $BUILDDIR ] ||
  23. die "Directory '$BUILDDIR' does not exist, please run make-testing first"
  24. running_any $STRONGSWANHOSTS || die "Please start test environment before running $0"
  25. ln -sfT $DIR $TESTDIR/testing
  26. ##############################################################################
  27. # take care of new path and file variables
  28. #
  29. [ -d $TESTRESULTSDIR ] || mkdir $TESTRESULTSDIR
  30. TESTDATE=`date +%Y%m%d-%H%M-%S`
  31. TODAYDIR=$TESTRESULTSDIR/$TESTDATE
  32. mkdir $TODAYDIR
  33. TESTRESULTSHTML=$TODAYDIR/all.html
  34. INDEX=$TODAYDIR/index.html
  35. DEFAULTTESTSDIR=$TESTDIR/testing/tests
  36. SOURCEIP_ROUTING_TABLE=220
  37. testnumber="0"
  38. failed_cnt="0"
  39. passed_cnt="0"
  40. subdir_cnt="0"
  41. ##############################################################################
  42. # parse optional arguments
  43. #
  44. while getopts "vt" opt
  45. do
  46. case "$opt" in
  47. v)
  48. verbose=YES
  49. timestamps=YES
  50. ;;
  51. t)
  52. timestamps=YES
  53. ;;
  54. esac
  55. done
  56. shift $((OPTIND-1))
  57. function print_time()
  58. {
  59. [ "$timestamps" == "YES" ] && echo "$(date +%T.%N) ~ "
  60. }
  61. ##############################################################################
  62. # copy default tests to $BUILDDIR
  63. #
  64. TESTSDIR=$BUILDDIR/tests
  65. [ -d $TESTSDIR ] || mkdir $TESTSDIR
  66. ##############################################################################
  67. # assign IP for each host to hostname
  68. #
  69. for host in $STRONGSWANHOSTS
  70. do
  71. eval ipv4_${host}="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
  72. eval ipv6_${host}="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $1 }' | awk '{ print $1 }'`"
  73. case $host in
  74. moon)
  75. eval ipv4_moon1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  76. eval ipv6_moon1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  77. ;;
  78. sun)
  79. eval ipv4_sun1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  80. eval ipv6_sun1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  81. ;;
  82. alice)
  83. eval ipv4_alice1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  84. eval ipv6_alice1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  85. ;;
  86. venus)
  87. ;;
  88. bob)
  89. ;;
  90. carol)
  91. eval ipv4_carol1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  92. eval ipv6_carol1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  93. ;;
  94. dave)
  95. eval ipv4_dave1="`echo $HOSTNAMEIPV4 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  96. eval ipv6_dave1="`echo $HOSTNAMEIPV6 | sed -n -e "s/^.*${host},//gp" | awk -F, '{ print $2 }' | awk '{ print $1 }'`"
  97. ;;
  98. winnetou)
  99. ;;
  100. esac
  101. done
  102. ##############################################################################
  103. # open ssh sessions
  104. #
  105. for host in $STRONGSWANHOSTS
  106. do
  107. ssh $SSHCONF -N root@`eval echo \\\$ipv4_$host` >/dev/null 2>&1 &
  108. eval ssh_pid_$host="`echo $!`"
  109. do_on_exit kill `eval echo \\\$ssh_pid_$host`
  110. done
  111. ##############################################################################
  112. # determine actual software versions
  113. #
  114. [ -f $SHAREDDIR/.strongswan-version ] && SWANVERSION=`cat $SHAREDDIR/.strongswan-version`
  115. KERNELVERSION=`ssh $SSHCONF root@\$ipv4_winnetou uname -r 2>/dev/null`
  116. # check if tcpdump supports --immediate-mode
  117. ssh $SSHCONF root@$ipv4_winnetou tcpdump --immediate-mode -c 1 >/dev/null 2>&1
  118. if [ $? -eq 0 ]
  119. then
  120. TCPDUMP_IM=--immediate-mode
  121. fi
  122. ##############################################################################
  123. # create header for the results html file
  124. #
  125. ENVIRONMENT_HEADER=$(cat <<@EOF
  126. <table border="0" cellspacing="2" cellpadding="2">
  127. <tr valign="top">
  128. <td><b>Host</b></td>
  129. <td colspan="3">`uname -a`</td>
  130. </tr>
  131. <tr valign="top">
  132. <td><b>Guest kernel</b></td>
  133. <td colspan="3">$KERNELVERSION</td>
  134. </tr>
  135. <tr valign="top">
  136. <td><b>strongSwan</b></td>
  137. <td colspan="3">$SWANVERSION</td>
  138. </tr>
  139. <tr valign="top">
  140. <td><b>Date</b></td>
  141. <td colspan="3">$TESTDATE</td>
  142. </tr>
  143. <tr>
  144. <td width="100">&nbsp;</td>
  145. <td width="300">&nbsp;</td>
  146. <td width=" 80">&nbsp;</td>
  147. <td >&nbsp;</td>
  148. </tr>
  149. @EOF
  150. )
  151. cat > $INDEX <<@EOF
  152. <html>
  153. <head>
  154. <title>strongSwan KVM Tests</title>
  155. </head>
  156. <body>
  157. <h2>strongSwan KVM Tests</h2>
  158. $ENVIRONMENT_HEADER
  159. @EOF
  160. cat > $TESTRESULTSHTML <<@EOF
  161. <html>
  162. <head>
  163. <title>strongSwan KVM Tests - All Tests</title>
  164. </head>
  165. <body>
  166. <div><a href="index.html">strongSwan KVM Tests</a> / All Tests</div>
  167. <h2>All Tests</h2>
  168. $ENVIRONMENT_HEADER
  169. <tr align="left">
  170. <th>Number</th>
  171. <th>Test</th>
  172. <th align="right">Time [s]</th>
  173. <th>Result</th>
  174. </tr>
  175. @EOF
  176. echo "Guest kernel : $KERNELVERSION"
  177. echo "strongSwan : $SWANVERSION"
  178. echo "Date : $TESTDATE"
  179. echo
  180. ##############################################################################
  181. # trap CTRL-C to properly terminate a long run
  182. #
  183. function abort_tests()
  184. {
  185. echo -n "...aborting..." > /dev/tty
  186. aborted=YES
  187. }
  188. trap abort_tests INT
  189. ##############################################################################
  190. # enter specific test directory
  191. #
  192. if [ $# -gt 0 ]
  193. then
  194. TESTS=$(printf "%s\n" $* | sort -u)
  195. else
  196. TESTS=$(ls $DEFAULTTESTSDIR)
  197. fi
  198. for SUBDIR in $TESTS
  199. do
  200. SUBTESTS="`basename $SUBDIR`"
  201. if [ $SUBTESTS = $SUBDIR ]
  202. then
  203. SUBTESTS="`ls $DEFAULTTESTSDIR/$SUBDIR`"
  204. else
  205. if [[ $SUBTESTS == *'*'* ]]
  206. then
  207. SUBTESTS="`basename -a $DEFAULTTESTSDIR/$SUBDIR`"
  208. fi
  209. SUBDIR="`dirname $SUBDIR`"
  210. fi
  211. if [ ! -d $TODAYDIR/$SUBDIR ]
  212. then
  213. mkdir $TODAYDIR/$SUBDIR
  214. if [ $testnumber == 0 ]
  215. then
  216. FIRST="<b>Category</b>"
  217. else
  218. FIRST="&nbsp;"
  219. fi
  220. if [ $subdir_cnt != 0 ]
  221. then
  222. echo " <td align=\"right\">$subdir_cnt</td>" >> $INDEX
  223. echo " <td>&nbsp;</td>" >> $INDEX
  224. echo " </tr>" >> $INDEX
  225. subdir_cnt="0"
  226. fi
  227. echo " <tr>" >> $INDEX
  228. echo " <td>$FIRST</td>">> $INDEX
  229. echo " <td><a href=\"$SUBDIR/index.html\">$SUBDIR</a></td>" >> $INDEX
  230. SUBTESTSINDEX=$TODAYDIR/$SUBDIR/index.html
  231. cat > $SUBTESTSINDEX <<@EOF
  232. <html>
  233. <head>
  234. <title>strongSwan $SUBDIR Tests</title>
  235. </head>
  236. <body>
  237. <div><a href="../index.html">strongSwan KVM Tests</a> / $SUBDIR</div>
  238. <h2>strongSwan $SUBDIR Tests</h2>
  239. <table border="0" cellspacing="2" cellpadding="2">
  240. <tr valign="top">
  241. <td><b>Guest kernel</b></td>
  242. <td colspan="3">$KERNELVERSION</td>
  243. </tr>
  244. <tr valign="top">
  245. <td><b>strongSwan</b></td>
  246. <td colspan="3">$SWANVERSION</td>
  247. </tr>
  248. <tr valign="top">
  249. <td><b>Date</b></td>
  250. <td colspan="3">$TESTDATE</td>
  251. </tr>
  252. <tr>
  253. <td width="100">&nbsp;</td>
  254. <td width="300">&nbsp;</td>
  255. <td width=" 50">&nbsp;</td>
  256. <td >&nbsp;</td>
  257. </tr>
  258. <tr align="left">
  259. <th>Number</th>
  260. <th>Test</th>
  261. <th colspan="2">Result</th>
  262. </tr>
  263. @EOF
  264. fi
  265. for name in $SUBTESTS
  266. do
  267. let "testnumber += 1"
  268. let "subdir_cnt += 1"
  269. testname=$SUBDIR/$name
  270. log_action " $testnumber $testname:"
  271. teststart=$(date +%s)
  272. if [ ! -d $DEFAULTTESTSDIR/${testname} ]
  273. then
  274. echo "is missing..skipped"
  275. continue
  276. fi
  277. [ -f $DEFAULTTESTSDIR/${testname}/description.txt ] || die "!! File 'description.txt' is missing"
  278. [ -f $DEFAULTTESTSDIR/${testname}/test.conf ] || die "!! File 'test.conf' is missing"
  279. [ -f $DEFAULTTESTSDIR/${testname}/pretest.dat ] || die "!! File 'pretest.dat' is missing"
  280. [ -f $DEFAULTTESTSDIR/${testname}/posttest.dat ] || die "!! File 'posttest.dat' is missing"
  281. [ -f $DEFAULTTESTSDIR/${testname}/evaltest.dat ] || die "!! File 'evaltest.dat' is missing"
  282. TESTRESULTDIR=$TODAYDIR/$testname
  283. mkdir -p $TESTRESULTDIR
  284. CONSOLE_LOG=$TESTRESULTDIR/console.log
  285. touch $CONSOLE_LOG
  286. TESTDIR=$TESTSDIR/${testname}
  287. ##########################################################################
  288. # copy test specific configurations to hosts and clear log files
  289. #
  290. DBDIR=/etc/db.d
  291. $DIR/scripts/load-testconfig $testname
  292. unset RADIUSHOSTS
  293. unset DBHOSTS
  294. unset IPV6
  295. unset SWANCTL
  296. source $TESTDIR/test.conf
  297. ##########################################################################
  298. # run tcpdump in the background
  299. #
  300. if [ "$TCPDUMPHOSTS" != "" ]
  301. then
  302. echo -e "TCPDUMP\n" >> $CONSOLE_LOG 2>&1
  303. for host_iface in $TCPDUMPHOSTS
  304. do
  305. host=`echo $host_iface | awk -F ":" '{print $1}'`
  306. iface=`echo $host_iface | awk -F ":" '{if ($2 != "") { print $2 } else { printf("eth0") }}'`
  307. tcpdump_cmd="tcpdump -l $TCPDUMP_IM -i $iface not port ssh and not port domain >/tmp/tcpdump.log 2>/tmp/tcpdump.err.log &"
  308. echo "$(print_time)${host}# $tcpdump_cmd" >> $CONSOLE_LOG
  309. ssh $SSHCONF root@`eval echo \\\$ipv4_$host '$tcpdump_cmd'`
  310. eval TDUP_${host}="true"
  311. done
  312. fi
  313. ##########################################################################
  314. # create database directory in RAM
  315. #
  316. for host in $DBHOSTS
  317. do
  318. eval HOSTLOGIN=root@\$ipv4_${host}
  319. ssh $SSHCONF $HOSTLOGIN "mkdir -p $DBDIR; mount -t ramfs -o size=5m ramfs $DBDIR" >/dev/null 2>&1
  320. ssh $SSHCONF $HOSTLOGIN "chgrp www-data $DBDIR; chmod g+w $DBDIR" >/dev/null 2>&1
  321. done
  322. ##########################################################################
  323. # flush conntrack table on all hosts
  324. #
  325. for host in $STRONGSWANHOSTS
  326. do
  327. ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'conntrack -F' >/dev/null 2>&1
  328. done
  329. ##########################################################################
  330. # remove leak detective log on all hosts
  331. #
  332. export LEAK_DETECTIVE_LOG=/var/log/leak-detective.log
  333. for host in $STRONGSWANHOSTS
  334. do
  335. ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'rm -f $LEAK_DETECTIVE_LOG' >/dev/null 2>&1
  336. done
  337. ##########################################################################
  338. # flush IPsec state on all hosts
  339. #
  340. for host in $STRONGSWANHOSTS
  341. do
  342. ssh $SSHCONF root@`eval echo \\\$ipv4_$host` 'ip xfrm state flush; ip xfrm policy flush' >/dev/null 2>&1
  343. done
  344. ##########################################################################
  345. # execute pre-test commands
  346. #
  347. echo -n "pre.."
  348. echo -e "\nPRE-TEST\n" >> $CONSOLE_LOG 2>&1
  349. eval `awk -F "::" '{
  350. if ($1 !~ /^#.*/ && $2 != "")
  351. {
  352. printf("echo \"$(print_time)%s# %s\"; ", $1, $2)
  353. printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
  354. printf("echo;\n")
  355. }
  356. }' $TESTDIR/pretest.dat` >> $CONSOLE_LOG 2>&1
  357. ##########################################################################
  358. # stop tcpdump
  359. #
  360. function stop_tcpdump {
  361. # wait for packets to get processed, but don't wait longer than 1s
  362. eval ssh $SSHCONF root@\$ipv4_${1} "\"i=100; while [ \\\$i -gt 0 ]; do pkill -USR1 tcpdump; tail -1 /tmp/tcpdump.err.log | perl -n -e '/(\\d+).*?(\\d+)/; exit (\\\$1 == \\\$2)' || break; sleep 0.01; i=\\\$((\\\$i-1)); done;\""
  363. echo "$(print_time)${1}# killall tcpdump" >> $CONSOLE_LOG
  364. eval ssh $SSHCONF root@\$ipv4_${1} "\"killall tcpdump; while true; do killall -q -0 tcpdump || break; sleep 0.01; done;\""
  365. eval TDUP_${1}="false"
  366. echo "" >> $CONSOLE_LOG
  367. }
  368. ##########################################################################
  369. # get and evaluate test results
  370. #
  371. echo -n "test.."
  372. echo -e "\nTEST\n" >> $CONSOLE_LOG 2>&1
  373. STATUS="passed"
  374. eval `awk -F "::" '{
  375. host=$1
  376. command=$2
  377. pattern=$3
  378. hit=$4
  379. if (host ~ /^#.*/ || command == "")
  380. {
  381. next
  382. }
  383. printf("cmd_err=\044(tempfile -p test -s err); ")
  384. printf("cmd_out=\044(tempfile -p test -s out); ")
  385. if (command == "tcpdump")
  386. {
  387. printf("if [ \044TDUP_%s == \"true\" ]; then stop_tcpdump %s; fi; \n", host, host)
  388. printf("ssh \044SSHCONF root@\044ipv4_%s cat /tmp/tcpdump.log > \044cmd_out; ", host)
  389. }
  390. else
  391. {
  392. printf("ssh \044SSHCONF root@\044ipv4_%s %s >\044cmd_out 2>\044cmd_err; ", host, command)
  393. }
  394. printf("cmd_res=\044(cat \044cmd_out | grep \"%s\"); ", pattern)
  395. printf("cmd_exit=\044?; ")
  396. printf("cmd_fail=0; ")
  397. if (hit ~ /^[0-9]+$/)
  398. {
  399. printf("if [ \044(echo \"\044cmd_res\" | wc -l) -ne %d ] ", hit)
  400. }
  401. else
  402. {
  403. printf("if [ \044cmd_exit -eq 0 -a \"%s\" = \"NO\" ] ", hit)
  404. printf("|| [ \044cmd_exit -ne 0 -a \"%s\" = \"YES\" ] ", hit)
  405. }
  406. printf("; then STATUS=\"failed\"; cmd_fail=1; fi; \n")
  407. printf("if [ \044cmd_fail -ne 0 ]; then echo \"~~~~~~~ FAIL ~~~~~~~\"; fi; \n")
  408. if (command == "tcpdump")
  409. {
  410. printf("echo \"$(print_time)%s# cat /tmp/tcpdump.log | grep \047%s\047 [%s]\"; ", host, pattern, hit)
  411. }
  412. else
  413. {
  414. printf("echo \"$(print_time)%s# %s | grep \047%s\047 [%s]\"; ", host, command, pattern, hit)
  415. }
  416. printf("if [ -n \"\044cmd_res\" ]; then echo \"\044cmd_res\"; fi; \n")
  417. printf("cat \044cmd_err; \n")
  418. printf("if [ \044cmd_fail -ne 0 ]; then \n")
  419. printf("if [ -s \044cmd_out ]; then echo \"~~ output ~~~~~~~~~~\"; \n")
  420. printf("if [ \"\044verbose\" == \"YES\" ]; then cat \044cmd_out;\n")
  421. printf("else cat \044cmd_out | head; fi; fi; \n")
  422. printf("echo \"~~~~~~~~~~~~~~~~~~~~\"; fi; \n")
  423. printf("rm -f -- \044cmd_out \044cmd_err; \n")
  424. printf("echo; ")
  425. }' $TESTDIR/evaltest.dat` >> $CONSOLE_LOG 2>&1
  426. ##########################################################################
  427. # log statusall and listall output
  428. # get copies of ipsec.conf, ipsec.secrets
  429. # create index.html for the given test case
  430. cat > $TESTRESULTDIR/index.html <<@EOF
  431. <html>
  432. <head>
  433. <title>Test $testname</title>
  434. </head>
  435. <body>
  436. <table border="0" cellpadding="0" cellspacing="0" width="600">
  437. <tr><td>
  438. <div><a href="../../index.html">strongSwan KVM Tests</a> / <a href="../index.html">$SUBDIR</a> / $name</div>
  439. <h2>Test $testname</h2>
  440. <h3>Description</h3>
  441. @EOF
  442. cat $TESTDIR/description.txt >> $TESTRESULTDIR/index.html
  443. cat >> $TESTRESULTDIR/index.html <<@EOF
  444. <ul>
  445. <li><a href="console.log">console.log</a></li>
  446. </ul>
  447. <img src="../../images/$DIAGRAM" alt="$VIRTHOSTS">
  448. @EOF
  449. IPTABLES_CMD_V4="echo -e '=== filter table ==='; iptables -v -n -L; echo -e '\n=== nat table ==='; iptables -v -n -t nat -L; echo -e '\n=== mangle table ==='; iptables -v -n -t mangle -L"
  450. IPTABLES_CMD_V6="echo -e '=== filter table ==='; ip6tables -v -n -L; echo -e '\n=== nat table ==='; ip6tables -v -n -t nat -L; echo -e '\n=== mangle table ==='; ip6tables -v -n -t mangle -L"
  451. if [ -n "$IPV6" ]
  452. then
  453. IPROUTE_CMD="ip -6 route list table $SOURCEIP_ROUTING_TABLE"
  454. IPROUTE_DSP=$IPROUTE_CMD
  455. IPTABLES_CMD="$IPTABLES_CMD_V6"
  456. IPTABLES_DSP="ip6tables -L"
  457. IPTABLES_SAVE_CMD="ip6tables-save"
  458. IPTABLES_SAVE_DSP="ip6tables-save"
  459. else
  460. IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE"
  461. IPROUTE_DSP=$IPROUTE_CMD
  462. IPTABLES_CMD="$IPTABLES_CMD_V4"
  463. IPTABLES_DSP="iptables -L"
  464. IPTABLES_SAVE_CMD="iptables-save"
  465. IPTABLES_SAVE_DSP="iptables-save"
  466. fi
  467. if [ $name = "net2net-ip4-in-ip6-ikev2" -o $name = "net2net-ip6-in-ip4-ikev2" ]
  468. then
  469. IPROUTE_CMD="ip route list table $SOURCEIP_ROUTING_TABLE; echo; ip -6 route list table $SOURCEIP_ROUTING_TABLE"
  470. IPROUTE_DSP="ip (-6) route list table $SOURCEIP_ROUTING_TABLE"
  471. IPTABLES_CMD="$IPTABLES_CMD_V4; echo; $IPTABLES_CMD_V6"
  472. IPTABLES_DSP="iptables -L ; ip6tables -L"
  473. IPTABLES_SAVE_CMD="iptables-save; echo; ip6tables-save"
  474. IPTABLES_SAVE_DSP="iptables-save ; ip6tables-save"
  475. fi
  476. for host in $DBHOSTS
  477. do
  478. eval HOSTLOGIN=root@\$ipv4_${host}
  479. scp $SSHCONF $HOSTLOGIN:/etc/db.d/ipsec.sql \
  480. $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
  481. done
  482. for host in $IPSECHOSTS
  483. do
  484. eval HOSTLOGIN=root@\$ipv4_${host}
  485. scp $SSHCONF $HOSTLOGIN:/etc/strongswan.conf \
  486. $TESTRESULTDIR/${host}.strongswan.conf > /dev/null 2>&1
  487. if [ -n "$SWANCTL" ]
  488. then
  489. scp $SSHCONF $HOSTLOGIN:/etc/swanctl/swanctl.conf \
  490. $TESTRESULTDIR/${host}.swanctl.conf > /dev/null 2>&1
  491. for subsys in conns algs certs pools authorities sas pols
  492. do
  493. ssh $SSHCONF $HOSTLOGIN swanctl --list-$subsys \
  494. > $TESTRESULTDIR/${host}.swanctl.$subsys 2>/dev/null
  495. done
  496. ssh $SSHCONF $HOSTLOGIN swanctl --stats \
  497. > $TESTRESULTDIR/${host}.swanctl.stats 2>/dev/null
  498. echo "" >> $TESTRESULTDIR/${host}.swanctl.sas
  499. cat $TESTRESULTDIR/${host}.swanctl.pols >> \
  500. $TESTRESULTDIR/${host}.swanctl.sas
  501. cat $TESTRESULTDIR/${host}.swanctl.algs >> \
  502. $TESTRESULTDIR/${host}.swanctl.stats
  503. else
  504. for file in ipsec.conf ipsec.secrets
  505. do
  506. scp $SSHCONF $HOSTLOGIN:/etc/$file \
  507. $TESTRESULTDIR/${host}.$file > /dev/null 2>&1
  508. done
  509. for command in statusall listall
  510. do
  511. ssh $SSHCONF $HOSTLOGIN ipsec $command \
  512. > $TESTRESULTDIR/${host}.$command 2>/dev/null
  513. done
  514. fi
  515. if (! [ -f $TESTRESULTDIR/${host}.ipsec.sql ] ) then
  516. scp $SSHCONF $HOSTLOGIN:/etc/ipsec.d/ipsec.sql \
  517. $TESTRESULTDIR/${host}.ipsec.sql > /dev/null 2>&1
  518. fi
  519. ssh $SSHCONF $HOSTLOGIN ip -s xfrm policy \
  520. > $TESTRESULTDIR/${host}.ip.policy 2>/dev/null
  521. ssh $SSHCONF $HOSTLOGIN ip -s xfrm state \
  522. > $TESTRESULTDIR/${host}.ip.state 2>/dev/null
  523. ssh $SSHCONF $HOSTLOGIN $IPROUTE_CMD \
  524. > $TESTRESULTDIR/${host}.ip.route 2>/dev/null
  525. ssh $SSHCONF $HOSTLOGIN $IPTABLES_CMD \
  526. > $TESTRESULTDIR/${host}.iptables 2>/dev/null
  527. ssh $SSHCONF $HOSTLOGIN $IPTABLES_SAVE_CMD \
  528. > $TESTRESULTDIR/${host}.iptables-save 2>/dev/null
  529. chmod a+r $TESTRESULTDIR/*
  530. if [ -n "$SWANCTL" ]
  531. then
  532. cat >> $TESTRESULTDIR/index.html <<@EOF
  533. <h3>$host</h3>
  534. <table border="0" cellspacing="0" width="600">
  535. <tr>
  536. <td valign="top">
  537. <ul>
  538. <li><a href="$host.swanctl.conf">swanctl.conf</a></li>
  539. <li><a href="$host.swanctl.conns">swanctl --list-conns</a></li>
  540. <li><a href="$host.swanctl.certs">swanctl --list-certs</a></li>
  541. <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
  542. <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
  543. </ul>
  544. </td>
  545. <td valign="top">
  546. <ul>
  547. <li><a href="$host.swanctl.sas">swanctl --list-sas|--list-pols</a></li>
  548. <li><a href="$host.swanctl.pools">swanctl --list-pools</a></li>
  549. <li><a href="$host.swanctl.authorities">swanctl --list-authorities</a></li>
  550. <li><a href="$host.swanctl.stats">swanctl --stats|--list-algs</a></li>
  551. <li><a href="$host.auth.log">auth.log</a></li>
  552. <li><a href="$host.daemon.log">daemon.log</a></li>
  553. </ul>
  554. </td>
  555. <td valign="top">
  556. <ul>
  557. <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
  558. <li><a href="$host.ip.state">ip -s xfrm state</a></li>
  559. <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
  560. <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
  561. <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
  562. </ul>
  563. &nbsp;
  564. </td>
  565. </tr>
  566. </table>
  567. @EOF
  568. else
  569. cat >> $TESTRESULTDIR/index.html <<@EOF
  570. <h3>$host</h3>
  571. <table border="0" cellspacing="0" width="600">
  572. <tr>
  573. <td valign="top">
  574. <ul>
  575. <li><a href="$host.ipsec.conf">ipsec.conf</a></li>
  576. <li><a href="$host.ipsec.secrets">ipsec.secrets</a></li>
  577. <li><a href="$host.ipsec.sql">ipsec.sql</a></li>
  578. <li><a href="$host.strongswan.conf">strongswan.conf</a></li>
  579. </ul>
  580. </td>
  581. <td valign="top">
  582. <ul>
  583. <li><a href="$host.statusall">ipsec statusall</a></li>
  584. <li><a href="$host.listall">ipsec listall</a></li>
  585. <li><a href="$host.auth.log">auth.log</a></li>
  586. <li><a href="$host.daemon.log">daemon.log</a></li>
  587. </ul>
  588. </td>
  589. <td valign="top">
  590. <ul>
  591. <li><a href="$host.ip.policy">ip -s xfrm policy</a></li>
  592. <li><a href="$host.ip.state">ip -s xfrm state</a></li>
  593. <li><a href="$host.ip.route">$IPROUTE_DSP</a></li>
  594. <li><a href="$host.iptables">$IPTABLES_DSP</a></li>
  595. <li><a href="$host.iptables-save">$IPTABLES_SAVE_DSP</a></li>
  596. </ul>
  597. </td>
  598. </tr>
  599. </table>
  600. @EOF
  601. fi
  602. done
  603. for host in $RADIUSHOSTS
  604. do
  605. eval HOSTLOGIN=root@\$ipv4_${host}
  606. RADIUS_DIR=/etc/freeradius/3.0
  607. RADIUS_EAP_FILE=mods-enabled/eap
  608. RADIUS_EAP_NAME=eap
  609. if [ "$BASEIMGSUITE" == "jessie" ]
  610. then
  611. RADIUS_DIR=/etc/freeradius
  612. RADIUS_EAP_FILE=eap.conf
  613. RADIUS_EAP_NAME=eap.conf
  614. fi
  615. for file in clients.conf radiusd.conf proxy.conf users sites-enabled/default sites-enabled/inner-tunnel $RADIUS_EAP_FILE
  616. do
  617. scp $SSHCONF $HOSTLOGIN:$RADIUS_DIR/$file \
  618. $TESTRESULTDIR/${host}.$(basename $file) > /dev/null 2>&1
  619. done
  620. scp $SSHCONF $HOSTLOGIN:/var/log/freeradius/radius.log \
  621. $TESTRESULTDIR/${host}.radius.log > /dev/null 2>&1
  622. chmod a+r $TESTRESULTDIR/*
  623. cat >> $TESTRESULTDIR/index.html <<@EOF
  624. <h3>$host</h3>
  625. <table border="0" cellspacing="0" width="600">
  626. <tr>
  627. <td valign="top">
  628. <ul>
  629. <li><a href="$host.clients.conf">clients.conf</a></li>
  630. <li><a href="$host.radiusd.conf">radiusd.conf</a></li>
  631. <li><a href="$host.$RADIUS_EAP_NAME">$RADIUS_EAP_NAME</a></li>
  632. </ul>
  633. </td>
  634. <td valign="top">
  635. <ul>
  636. <li><a href="$host.default">sites-enabled/default</a></li>
  637. <li><a href="$host.inner-tunnel">sites-enabled/inner-tunnel</a></li>
  638. <li><a href="$host.radius.log">radius.log</a></li>
  639. </ul>
  640. </td>
  641. <td valign="top">
  642. <ul>
  643. <li><a href="$host.proxy.conf">proxy.conf</a></li>
  644. <li><a href="$host.users">users</a></li>
  645. </ul>
  646. </td>
  647. </tr>
  648. </table>
  649. @EOF
  650. done
  651. cat >> $TESTRESULTDIR/index.html <<@EOF
  652. <h3>tcpdump</h3>
  653. <ul>
  654. @EOF
  655. for host in $TCPDUMPHOSTS
  656. do
  657. cat >> $TESTRESULTDIR/index.html <<@EOF
  658. <li><a href="$host.tcpdump.log">$host tcpdump.log</a></li>
  659. @EOF
  660. done
  661. cat >> $TESTRESULTDIR/index.html <<@EOF
  662. </ul>
  663. @EOF
  664. cat >> $TESTRESULTDIR/index.html <<@EOF
  665. </td></tr>
  666. </table>
  667. </body>
  668. </html>
  669. @EOF
  670. ##########################################################################
  671. # execute post-test commands
  672. #
  673. echo -n "post"
  674. echo -e "\nPOST-TEST\n" >> $CONSOLE_LOG 2>&1
  675. eval `awk -F "::" '{
  676. if ($1 !~ /^#.*/ && $2 != "")
  677. {
  678. printf("echo \"$(print_time)%s# %s\"; ", $1, $2)
  679. printf("ssh \044SSHCONF root@\044ipv4_%s \"%s\"; ", $1, $2)
  680. printf("echo;\n")
  681. }
  682. }' $TESTDIR/posttest.dat` >> $CONSOLE_LOG 2>&1
  683. ##########################################################################
  684. # check that IPsec state was cleaned up properly
  685. #
  686. for host in $IPSECHOSTS
  687. do
  688. eval HOSTLOGIN=root@\$ipv4_${host}
  689. IPSECSTATE=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm state'`
  690. # ignore IPv4/v6 states created with IPComp SAs
  691. IPSECSTATEISSUE=`echo "$IPSECSTATE" | grep 'proto.*spi' | grep -v 'proto 4'`
  692. IPSECPOLICY=`ssh $SSHCONF $HOSTLOGIN 'ip xfrm policy'`
  693. if [ -n "$IPSECSTATEISSUE" -o -n "$IPSECPOLICY" ]
  694. then
  695. echo -e "\n$host# ip xfrm state [NO]" >> $CONSOLE_LOG
  696. echo "$IPSECSTATE" >> $CONSOLE_LOG
  697. echo -e "\n$host# ip xfrm policy [NO]" >> $CONSOLE_LOG
  698. echo "$IPSECPOLICY" >> $CONSOLE_LOG
  699. STATUS="failed"
  700. fi
  701. done
  702. ##########################################################################
  703. # make sure there were no leaks
  704. #
  705. for host in $STRONGSWANHOSTS
  706. do
  707. eval HOSTLOGIN=root@\$ipv4_${host}
  708. LEAKS=`ssh $SSHCONF $HOSTLOGIN 'cat $LEAK_DETECTIVE_LOG 2>/dev/null | grep -v "No leaks detected.*"'`
  709. if [ -n "$LEAKS" ]
  710. then
  711. echo -e "\n$host# cat $LEAK_DETECTIVE_LOG [NO]" >> $CONSOLE_LOG
  712. echo "$LEAKS" >> $CONSOLE_LOG
  713. echo "<<< $host $LEAK_DETECTIVE_LOG >>>" >> $CONSOLE_LOG
  714. STATUS="failed"
  715. fi
  716. done
  717. ##########################################################################
  718. # get a copy of /var/log/auth.log
  719. #
  720. for host in $IPSECHOSTS
  721. do
  722. eval HOSTLOGIN=root@\$ipv4_${host}
  723. ssh $SSHCONF $HOSTLOGIN "grep -s -E 'charon|last message repeated|imcv|pt-tls-client' \
  724. /var/log/auth.log" >> $TESTRESULTDIR/${host}.auth.log
  725. done
  726. ##########################################################################
  727. # get a copy of /var/log/daemon.log
  728. #
  729. for host in $IPSECHOSTS
  730. do
  731. eval HOSTLOGIN=root@\$ipv4_${host}
  732. ssh $SSHCONF $HOSTLOGIN "grep -s -E 'systemd|swanctl|charon|last message repeated|imcv' \
  733. /var/log/daemon.log" >> $TESTRESULTDIR/${host}.daemon.log
  734. done
  735. ##########################################################################
  736. # stop tcpdump if necessary
  737. #
  738. for host in $TCPDUMPHOSTS
  739. do
  740. if [ "`eval echo \\\$TDUP_${host}`" = "true" ]
  741. then
  742. stop_tcpdump $host
  743. fi
  744. eval HOSTLOGIN=root@\$ipv4_${host}
  745. scp $SSHCONF $HOSTLOGIN:/tmp/tcpdump.log \
  746. $TESTRESULTDIR/${host}.tcpdump.log > /dev/null 2>&1
  747. done
  748. ##########################################################################
  749. # remove database directory if needed
  750. #
  751. for host in $DBHOSTS
  752. do
  753. eval HOSTLOGIN=root@\$ipv4_${host}
  754. ssh $SSHCONF $HOSTLOGIN "umount $DBDIR; rm -r $DBDIR" > /dev/null 2>&1
  755. done
  756. ##########################################################################
  757. # copy default host config back if necessary
  758. #
  759. $DIR/scripts/restore-defaults $testname
  760. ##########################################################################
  761. # set counters
  762. #
  763. if [ $STATUS = "failed" ]
  764. then
  765. let "failed_cnt += 1"
  766. else
  767. let "passed_cnt += 1"
  768. fi
  769. ##########################################################################
  770. # write test status to html file
  771. #
  772. testend=$(date +%s)
  773. let "testend -= teststart"
  774. let "timetotal += testend"
  775. if [ $STATUS = "passed" ]
  776. then
  777. COLOR="green"
  778. log_status 0
  779. else
  780. COLOR="red"
  781. log_status 1
  782. fi
  783. cat >> $TESTRESULTSHTML << @EOF
  784. <tr>
  785. <td>$testnumber</td>
  786. <td><a href="$testname/index.html">$testname</a></td>
  787. <td align="right">$testend</td>
  788. <td><a href="$testname/console.log"><font color="$COLOR">$STATUS</font></a></td>
  789. </tr>
  790. @EOF
  791. cat >> $SUBTESTSINDEX << @EOF
  792. <tr>
  793. <td>$testnumber</td>
  794. <td><a href="$name/index.html">$name</a></td>
  795. <td><a href="$name/console.log"><font color="$COLOR">$STATUS</font></a></td>
  796. <td>&nbsp;</td>
  797. </tr>
  798. @EOF
  799. ##########################################################################
  800. # remove any charon.pid files that still may exist
  801. #
  802. for host in $IPSECHOSTS
  803. do
  804. eval HOSTLOGIN=root@\$ipv4_${host}
  805. ssh $SSHCONF $HOSTLOGIN 'if [ -f /var/run/charon.pid ]; then rm /var/run/charon.pid; echo " removed charon.pid on `hostname`"; fi'
  806. done
  807. if [ -n "$aborted" ]
  808. then
  809. break 2
  810. fi
  811. done
  812. done
  813. ##############################################################################
  814. # finish the results html file
  815. #
  816. cat >> $TESTRESULTSHTML << @EOF
  817. <tr>
  818. <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
  819. </tr>
  820. <tr>
  821. <td><b>Passed</b></td><td><b><font color="green">$passed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
  822. </tr>
  823. <tr>
  824. <td><b>Failed</b></td><td><b><font color="red">$failed_cnt</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
  825. </tr>
  826. <tr>
  827. <td><b>Time [s]</b></td><td><b><font color="blue">$timetotal</font></b></td><td>&nbsp;</td><td>&nbsp;</td>
  828. </tr>
  829. </table>
  830. </body>
  831. </html>
  832. @EOF
  833. if [ $subdir_cnt != 0 ]
  834. then
  835. cat >> $INDEX << @EOF
  836. <td align="right">$subdir_cnt</td>
  837. <td>&nbsp;</td>
  838. </tr>
  839. @EOF
  840. fi
  841. let "all_cnt = $passed_cnt + $failed_cnt"
  842. cat >> $INDEX << @EOF
  843. <tr>
  844. <td>&nbsp;</td>
  845. <td><a href="all.html"><b>all</b></a></td>
  846. <td align="right"><b>$all_cnt</b></td>
  847. <td>&nbsp;</td>
  848. </tr>
  849. <tr>
  850. <td><b>Failed</b></td>
  851. <td>&nbsp;</td>
  852. <td align="right"><b><font color="red">$failed_cnt</font></b></td>
  853. <td>&nbsp;</td>
  854. </tr>
  855. </table>
  856. </body>
  857. </html>
  858. @EOF
  859. echo
  860. echo_ok "Passed : $passed_cnt"
  861. echo_failed "Failed : $failed_cnt"
  862. echo
  863. echo "The results are available in $TODAYDIR"
  864. echo "or via the link http://$ipv4_winnetou/testresults/$TESTDATE"
  865. ENDDATE=`date +%Y%m%d-%H%M-%S`
  866. echo
  867. echo "Finished : $ENDDATE"