12116Sjkh# #-- padding.pre--#
22116Sjkh# source the master var file when it's there
32116Sjkh[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
42116Sjkh# use .tpkg.var.test for in test variable passing
52116Sjkh[ -f .tpkg.var.test ] && source .tpkg.var.test
62116Sjkh
72116SjkhPRE="../.."
82116Sjkh. ../common.sh
92116Sjkhif grep "define USE_DNSTAP 1" $PRE/config.h; then echo test enabled; else skip_test "test skipped"; fi
102116Sjkh
112116Sjkhget_random_port 5
122116SjkhUNBOUND_PORT=$RND_PORT
132116SjkhUPSTREAM_PORT=$(($RND_PORT + 1))
142116SjkhFWD_PORT=$(($RND_PORT + 2))
152116SjkhCONTROL_PORT=$(($RND_PORT + 3))
162116SjkhCONTROL_PORT2=$(($RND_PORT + 4))
172116Sjkhecho "UNBOUND_PORT=$UNBOUND_PORT" >> .tpkg.var.test
182116Sjkhecho "UPSTREAM_PORT=$UPSTREAM_PORT" >> .tpkg.var.test
192116Sjkhecho "FWD_PORT=$FWD_PORT" >> .tpkg.var.test
202116Sjkhecho "CONTROL_PORT=$CONTROL_PORT" >> .tpkg.var.test
212116Sjkhecho "CONTROL_PORT2=$CONTROL_PORT2" >> .tpkg.var.test
222116Sjkh
232116Sjkh# start ldns-testnd
242116Sjkhget_ldns_testns
252116Sjkh$LDNS_TESTNS -p $FWD_PORT padding.testns >fwd.log 2>&1 &
262116SjkhFWD_PID=$!
272116Sjkhecho "FWD_PID=$FWD_PID" >> .tpkg.var.test
282116Sjkh
292116Sjkh# start the dnstap log server
3050476Speter# the -vvvv flag prints protocol and connection information from the
312116Sjkh# unbound-dnstap-socket server.
32121502Sdes# the -l flag prints the DNS info in the DNSTAP packet in multiline output.
332116Sjkh# stderr is the '-vvvv' server logs and errors.
342116Sjkh# stdout is the one-line packet logs (or with -l, multiline).
352116Sjkh$PRE/unbound-dnstap-socket -u dnstap.socket -l -vvvv 2>tap.errlog >tap.log &
366794Sjkhif test $? -ne 0; then
37121502Sdes        echo "could not start unbound-dnstap-socket server"
38121502Sdes        exit 1
396794Sjkhfi
4084881SbdeDNSTAP_SOCKET_PID=$!
4184881Sbdeecho "DNSTAP_SOCKET_PID=$DNSTAP_SOCKET_PID" >> .tpkg.var.test
422116Sjkh# wait for the server to go up and make the dnstap.socket file
4384306Sruwait_server_up "tap.errlog" "creating unix socket"
442116Sjkhif test ! -S dnstap.socket; then 
452116Sjkh        echo "the dnstap.socket file does not exist!"
466794Sjkhfi
476794Sjkh
48121502Sdes# make config file
49121502Sdessed -e 's/@PORT\@/'$UNBOUND_PORT'/' -e 's/@TOPORT\@/'$UPSTREAM_PORT'/' -e 's/@CONTROL_PORT\@/'$CONTROL_PORT'/' < padding.conf > ub.conf
502116Sjkh# start unbound in the background
512116Sjkh$PRE/unbound -d -c ub.conf >unbound.log 2>&1 &
52121502Sdes#$PRE/unbound -d -c ub.conf 2>&1 | tee unbound.log &
53121502SdesUNBOUND_PID=$!
54131421Sruecho "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test
55121502Sdes
566794Sjkh# make upstream config file
572116Sjkhsed -e 's/@PORT\@/'$UPSTREAM_PORT'/' -e 's/@TOPORT\@/'$FWD_PORT'/' -e 's/@CONTROL_PORT2\@/'$CONTROL_PORT2'/' < padding.conf2 > ub2.conf
582116Sjkh# start upstream unbound in the background
592116Sjkh$PRE/unbound -d -c ub2.conf >unbound2.log 2>&1 &
60121502Sdes#$PRE/unbound -d -c ub2.conf 2>&1 | tee unbound2.log &
61121502SdesUPSTREAM_PID=$!
62131421Sruecho "UPSTREAM_PID=$UPSTREAM_PID" >> .tpkg.var.test
63121502Sdes
646794Sjkhwait_ldns_testns_up fwd.log
652116Sjkhwait_unbound_up unbound.log
662116Sjkhwait_unbound_up unbound2.log
672116Sjkh
682116Sjkhcat .tpkg.var.test
692116Sjkh
702116Sjkh