1# #-- dnstap_tcp.test --# 2# source the master var file when it's there 3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master 4# use .tpkg.var.test for in test variable passing 5[ -f .tpkg.var.test ] && source .tpkg.var.test 6 7. ../common.sh 8PRE="../.." 9if grep "define USE_DNSTAP 1" $PRE/config.h; then echo test enabled; else echo test skipped; exit 0; fi 10 11# test if the server is up. 12echo "> dig www.example.com." 13dig @127.0.0.1 -p $UNBOUND_PORT www.example.com. | tee outfile 14echo "> check answer" 15if grep "10.20.30.40" outfile; then 16 echo "OK" 17else 18 echo "> cat logfiles" 19 cat tap.log 20 cat tap.errlog 21 cat fwd.log 22 cat unbound.log 23 echo "Not OK" 24 exit 1 25fi 26 27echo "> check tap.log for dnstap info" 28# see if it logged the information in tap.log 29# wait for a moment for filesystem to catch up. 30if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 31if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 32if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 33if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 34if grep "www.example.com" tap.log >/dev/null; then :; else sleep 1; fi 35if grep "www.example.com" tap.log >/dev/null; then :; else sleep 10; fi 36if grep "www.example.com" tap.log; then echo "yes it is in tap.log"; 37else 38 echo "information not in tap.log" 39 echo "failed" 40 echo "> cat logfiles" 41 cat tap.log 42 cat tap.errlog 43 cat fwd.log 44 cat unbound.log 45 echo "Not OK" 46 exit 1 47fi 48 49echo "" 50echo "> test disconnect from the upstream server" 51 52kill_pid $DNSTAP_SOCKET_PID 53dig @127.0.0.1 -p $UNBOUND_PORT down.example.net. 54 55# bring log socket back up 56$PRE/unbound-dnstap-socket -s "127.0.0.1@$TAP_PORT" -l -vvvv 2>tap2.errlog >tap2.log & 57if test $? -ne 0; then 58 echo "could not start (again) unbound-dnstap-socket server" 59 exit 1 60fi 61DNSTAP_SOCKET_PID=$! 62echo "DNSTAP_SOCKET_PID=$DNSTAP_SOCKET_PID" >> .tpkg.var.test 63# wait for the server to go up 64wait_server_up "tap2.errlog" "start of service" 65 66dig @127.0.0.1 -p $UNBOUND_PORT up.example.net. 67sleep 2 68dig @127.0.0.1 -p $UNBOUND_PORT up2.example.net. 69 70for x in down up up2; do 71 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 72 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 73 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 74 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 75 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 76 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 10; fi 77 if grep "$x.example.net" tap2.log; then echo "yes it is in tap2.log"; 78 else 79 echo "$x.example.net. information not in tap2.log" 80 echo "failed" 81 echo "> cat logfiles" 82 cat tap.log 83 cat tap.errlog 84 echo "> tap2 logfiles" 85 cat tap2.log 86 cat tap2.errlog 87 cat fwd.log 88 cat unbound.log 89 echo "Not OK" 90 exit 1 91 fi 92done 93 94echo "> OK" 95exit 0 96