DIGOPTS="-p ${PORT} +tries=3 +time=5"
+# Check whether the SOA record for the name provided in $1 can be resolved by
+# ns1. Return 0 if resolution succeeds as expected; return 1 otherwise.
+resolution_succeeds() {
+ _ret=0
+ $DIG $DIGOPTS +tcp @10.53.0.1 ${1} SOA > dig.out.test$n || _ret=1
+ grep "status: NOERROR" dig.out.test$n > /dev/null || _ret=1
+ return $_ret
+}
+
+# Check whether the SOA record for the name provided in $1 can be resolved by
+# ns1. Return 0 if resolution fails as expected; return 1 otherwise. Note that
+# both a SERVFAIL response and timing out mean resolution failed, so the exit
+# code of dig does not influence the result (the exit code for a SERVFAIL
+# response is 0 while the exit code for not getting a response at all is not 0).
+resolution_fails() {
+ _servfail=0
+ _timeout=0
+ $DIG $DIGOPTS +tcp @10.53.0.1 ${1} SOA > dig.out.test$n
+ grep "status: SERVFAIL" dig.out.test$n > /dev/null && _servfail=1
+ grep "connection timed out" dig.out.test$n > /dev/null && _timeout=1
+ if [ $_servfail -eq 1 ] || [ $_timeout -eq 1 ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
status=0
n=0
n=`expr $n + 1`
echo_i "checking recursive lookup to drop edns server succeeds ($n)"
ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 dropedns soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds dropedns. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1`
echo_i "checking recursive lookup to drop edns + no tcp server succeeds ($n)"
ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 dropedns-notcp soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds dropedns-notcp. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1`
echo_i "checking recursive lookup to plain dns server succeeds ($n)"
ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 plain soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds plain. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1`
echo_i "checking recursive lookup to plain dns + no tcp server succeeds ($n)"
ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 plain-notcp soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds plain-notcp. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1`
n=`expr $n + 1`
echo_i "checking recursive lookup to edns 512 server succeeds ($n)"
ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 edns512 soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds edns512. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1`
echo_i "checking recursive lookup to edns 512 + no tcp server succeeds ($n)"
ret=0
-$DIG $DIGOPTS +tcp @10.53.0.1 edns512-notcp soa > dig.out.test$n || ret=1
-grep "status: NOERROR" dig.out.test$n > /dev/null || ret=1
+resolution_succeeds edns512-notcp. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
n=`expr $n + 1`
echo_i "checking recursive lookup to edns 512 + no tcp + trust anchor fails ($n)"
ret=0
- $DIG $DIGOPTS +tcp @10.53.0.1 edns512-notcp soa > dig.out.test$n
- grep "status: SERVFAIL" dig.out.test$n > /dev/null ||
- grep "connection timed out;" dig.out.test$n > /dev/null || ret=1
+ resolution_fails edns512-notcp. || ret=1
if [ $ret != 0 ]; then echo_i "failed"; fi
status=`expr $status + $ret`
else