1# #-- dnstap_reconnect.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 10; fi 34if grep "www.example.com" tap.log; then echo "yes it is in tap.log"; 35else 36 echo "information not in tap.log" 37 echo "failed" 38 echo "> cat logfiles" 39 cat tap.log 40 cat tap.errlog 41 cat fwd.log 42 cat unbound.log 43 echo "Not OK" 44 exit 1 45fi 46 47echo "" 48echo "> test disconnect from the upstream server" 49 50kill_pid $DNSTAP_SOCKET_PID 51dig @127.0.0.1 -p $UNBOUND_PORT down.example.net. 52 53# bring log socket back up 54$PRE/unbound-dnstap-socket -u dnstap.socket -l -vvvv 2>tap2.errlog >tap2.log & 55if test $? -ne 0; then 56 echo "could not start (again) unbound-dnstap-socket server" 57 exit 1 58fi 59DNSTAP_SOCKET_PID=$! 60echo "DNSTAP_SOCKET_PID=$DNSTAP_SOCKET_PID" >> .tpkg.var.test 61# wait for the server to go up and make the dnstap.socket file 62wait_server_up "tap2.errlog" "creating unix socket" 63 64dig @127.0.0.1 -p $UNBOUND_PORT up.example.net. 65sleep 2 66dig @127.0.0.1 -p $UNBOUND_PORT up2.example.net. 67 68for x in down up up2; do 69 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 70 if grep "$x.example.net" tap2.log >/dev/null; then :; else sleep 1; fi 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 10; fi 73 if grep "$x.example.net" tap2.log; then echo "yes it is in tap2.log"; 74 else 75 echo "$x.example.net. information not in tap2.log" 76 echo "failed" 77 echo "> cat logfiles" 78 cat tap.log 79 cat tap.errlog 80 echo "> tap2 logfiles" 81 cat tap2.log 82 cat tap2.errlog 83 cat fwd.log 84 cat unbound.log 85 echo "Not OK" 86 exit 1 87 fi 88done 89 90echo "> cat logfiles" 91cat tap.log 92cat tap.errlog 93echo "> tap2 logfiles" 94cat tap2.log 95cat tap2.errlog 96cat fwd.log 97echo "> OK" 98exit 0 99