1be771a7bSCy Schubert# #-- stat_values.test --# 2be771a7bSCy Schubert# source the master var file when it's there 3be771a7bSCy Schubert[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master 4be771a7bSCy Schubert# use .tpkg.var.test for in test variable passing 5be771a7bSCy Schubert[ -f .tpkg.var.test ] && source .tpkg.var.test 6be771a7bSCy Schubert. ../common.sh 7be771a7bSCy Schubert 8be771a7bSCy SchubertPRE="../.." 9be771a7bSCy Schubert 10be771a7bSCy Schubert# Individual thread stats. 11be771a7bSCy SchubertSTATS_IGNORE_THREAD="\ 12be771a7bSCy Schubert^thread" 13be771a7bSCy Schubert 14be771a7bSCy Schubert# Histogram stats. 15be771a7bSCy SchubertSTATS_IGNORE_HISTOGRAM="\ 16be771a7bSCy Schubert^histogram" 17be771a7bSCy Schubert 18be771a7bSCy Schubert# Time dependent stats. 19be771a7bSCy SchubertSTATS_IGNORE_TIME_SPECIFIC="\ 20be771a7bSCy Schubert^total.recursion.time.avg= 21be771a7bSCy Schubert^total.recursion.time.median= 22be771a7bSCy Schubert^time.now= 23be771a7bSCy Schubert^time.up= 24be771a7bSCy Schubert^time.elapsed=" 25be771a7bSCy Schubert 26be771a7bSCy Schubert# Usage dependent stats. 27be771a7bSCy SchubertSTATS_IGNORE_USAGE_SPECIFIC="\ 28be771a7bSCy Schubert^total.requestlist.avg= 29be771a7bSCy Schubert^total.requestlist.max= 30be771a7bSCy Schubert^total.requestlist.overwritten= 31be771a7bSCy Schubert^total.requestlist.exceeded= 32be771a7bSCy Schubert^total.requestlist.current.all= 33be771a7bSCy Schubert^total.requestlist.current.user= 34be771a7bSCy Schubert^total.tcpusage= 35be771a7bSCy Schubert^mem\." 36be771a7bSCy Schubert 37be771a7bSCy Schubert# Stats to ignore by default. 38be771a7bSCy SchubertSTATS_IGNORE_DEFAULT="\ 39be771a7bSCy Schubert$STATS_IGNORE_THREAD 40be771a7bSCy Schubert$STATS_IGNORE_HISTOGRAM 41be771a7bSCy Schubert$STATS_IGNORE_TIME_SPECIFIC 42be771a7bSCy Schubert$STATS_IGNORE_USAGE_SPECIFIC" 43be771a7bSCy Schubert 44be771a7bSCy Schubert# Various files to be used while testing. 45be771a7bSCy SchubertSTATS_FILE=stats.$$ 46be771a7bSCy SchubertEXPECTED_STATS_FILE=expected_stats.$$ 47be771a7bSCy SchubertIGNORE_REGEX_FILE=ignore_regex.$$ 48be771a7bSCy SchubertFILTERED_STATS_FILE=filtered_stats.$$ 49be771a7bSCy SchubertFOUND_STATS_FILE=found_stats.$$ 50be771a7bSCy SchubertREST_STATS_FILE=rest_stats.$$ 51be771a7bSCy Schubert 52be771a7bSCy SchubertDEBUG=0 53be771a7bSCy Schubert 54be771a7bSCy Schubertif dig -h 2>&1 | grep "cookie" >/dev/null; then 55be771a7bSCy Schubert nocookie="+nocookie" 56be771a7bSCy Schubertelse 57be771a7bSCy Schubert nocookie="" 58be771a7bSCy Schubertfi 59be771a7bSCy Schubert 60be771a7bSCy Schubert# Write stats to $STATS_FILE. 61be771a7bSCy Schubert# Call this when you want to get stats from unbound. 62be771a7bSCy Schubertget_stats () { 63be771a7bSCy Schubert echo "> Getting stats" 64be771a7bSCy Schubert echo "$PRE/unbound-control -c ub.conf stats" 65be771a7bSCy Schubert $PRE/unbound-control -c ub.conf stats > $STATS_FILE 66be771a7bSCy Schubert if test $? -ne 0; then 67be771a7bSCy Schubert echo "wrong exit value after success" 68be771a7bSCy Schubert exit 1 69be771a7bSCy Schubert fi 70be771a7bSCy Schubert} 71be771a7bSCy Schubert 72be771a7bSCy Schubert# Set the expected stat values by writing to $EXPECTED_STATS_FILE. 73be771a7bSCy Schubert# sort is used for proper diff later. 74be771a7bSCy Schubertset_expected_stats () { 75be771a7bSCy Schubert echo "$1" | sort > $EXPECTED_STATS_FILE 76be771a7bSCy Schubert} 77be771a7bSCy Schubert 78be771a7bSCy Schubert# Set the regex to ignore stats by writing to $IGNORE_REGEX_FILE. 79be771a7bSCy Schubertset_ignore_regex_stats () { 80be771a7bSCy Schubert echo "$1" > $IGNORE_REGEX_FILE 81be771a7bSCy Schubert} 82be771a7bSCy Schubert 83be771a7bSCy Schubert# Filter the stats by removing any matched regex from $IGNORE_REGEX_FILE, 84be771a7bSCy Schubert# sorts and writes the left over stats to $FILTERED_STATS_FILE. 85be771a7bSCy Schubertfilter_stats () { 86be771a7bSCy Schubert grep -v -f $IGNORE_REGEX_FILE $STATS_FILE | sort > $FILTERED_STATS_FILE 87be771a7bSCy Schubert} 88be771a7bSCy Schubert 89be771a7bSCy Schubert# Check that the stats in $FILTERED_STATS_FILE include the expected stats in 90be771a7bSCy Schubert# $EXPECTED_STATS_FILE. 91be771a7bSCy Schubertcheck_expected_stats () { 92be771a7bSCy Schubert echo "> Checking expected stats" 93be771a7bSCy Schubert grep -F -x -f $EXPECTED_STATS_FILE $FILTERED_STATS_FILE > $FOUND_STATS_FILE 94be771a7bSCy Schubert if test $DEBUG -ne 0; then 95be771a7bSCy Schubert echo "Found:" 96be771a7bSCy Schubert cat $FOUND_STATS_FILE 97be771a7bSCy Schubert fi 98be771a7bSCy Schubert if diff $EXPECTED_STATS_FILE $FOUND_STATS_FILE; then 99be771a7bSCy Schubert echo "OK" 100be771a7bSCy Schubert else 101be771a7bSCy Schubert echo "! bad expected stats:" 102be771a7bSCy Schubert cat $FILTERED_STATS_FILE 103be771a7bSCy Schubert end 1 104be771a7bSCy Schubert fi 105be771a7bSCy Schubert} 106be771a7bSCy Schubert 107be771a7bSCy Schubert# Check that the rest (unspecified) stats are all 0 (no surprises). 108be771a7bSCy Schubertcheck_rest_stats () { 109be771a7bSCy Schubert echo "> Checking rest stats" 110be771a7bSCy Schubert grep -F -x -v -f $EXPECTED_STATS_FILE $FILTERED_STATS_FILE > $REST_STATS_FILE 111be771a7bSCy Schubert if test $DEBUG -ne 0; then 112be771a7bSCy Schubert echo "Rest:" 113be771a7bSCy Schubert cat $REST_STATS_FILE 114be771a7bSCy Schubert fi 115be771a7bSCy Schubert if grep -v "=0$" $REST_STATS_FILE; then 116be771a7bSCy Schubert echo "! bad rest stats" 117be771a7bSCy Schubert end 1 118be771a7bSCy Schubert else 119be771a7bSCy Schubert echo "OK" 120be771a7bSCy Schubert fi 121be771a7bSCy Schubert} 122be771a7bSCy Schubert 123be771a7bSCy Schubert# Main function to check stats by: 124be771a7bSCy Schubert# - Getting stats from unbound 125be771a7bSCy Schubert# - Filtering out the stats we are not interested in 126be771a7bSCy Schubert# - Checking that the expected stats are part of the filtered stats 127be771a7bSCy Schubert# - The rest of the stats have 0 values. 128be771a7bSCy Schubertcheck_stats () { 129be771a7bSCy Schubert set_expected_stats "$1" 130be771a7bSCy Schubert if test $DEBUG -ne 0; then 131be771a7bSCy Schubert echo "Expected:" 132be771a7bSCy Schubert cat $EXPECTED_STATS_FILE 133be771a7bSCy Schubert fi 134be771a7bSCy Schubert get_stats 135be771a7bSCy Schubert filter_stats 136be771a7bSCy Schubert if test $DEBUG -ne 0; then 137be771a7bSCy Schubert echo "Filtered:" 138be771a7bSCy Schubert cat $FILTERED_STATS_FILE 139be771a7bSCy Schubert fi 140be771a7bSCy Schubert check_expected_stats 141be771a7bSCy Schubert check_rest_stats 142be771a7bSCy Schubert} 143be771a7bSCy Schubert 144be771a7bSCy Schubert# Convenient function to set an option through unbound-control. 145be771a7bSCy Schubertset_ub_option () { 146be771a7bSCy Schubert name=$1 147be771a7bSCy Schubert value=$2 148be771a7bSCy Schubert echo "$PRE/unbound-control -c ub.conf set_option $name: $value" 149be771a7bSCy Schubert $PRE/unbound-control -c ub.conf set_option $name: $value 150be771a7bSCy Schubert if test $? -ne 0; then 151be771a7bSCy Schubert echo "wrong exit value after success" 152be771a7bSCy Schubert exit 1 153be771a7bSCy Schubert fi 154be771a7bSCy Schubert} 155be771a7bSCy Schubert 156be771a7bSCy Schubert# Convenient function to kill current Unbound and bring up one with an alternate configuration. 157be771a7bSCy Schubertbring_up_alternate_configuration () { 158be771a7bSCy Schubert conf_file=$1 159be771a7bSCy Schubert kill_pid $UNBOUND_PID # kill current Unbound 160be771a7bSCy Schubert echo "" 161be771a7bSCy Schubert cat unbound.log 162be771a7bSCy Schubert echo "" 163be771a7bSCy Schubert $PRE/unbound -d -c $conf_file >unbound.log 2>&1 & 164be771a7bSCy Schubert UNBOUND_PID=$! 165be771a7bSCy Schubert echo "UNBOUND_PID=$UNBOUND_PID" >> .tpkg.var.test 166be771a7bSCy Schubert wait_unbound_up unbound.log 167be771a7bSCy Schubert} 168be771a7bSCy Schubert 169be771a7bSCy Schubert# Convenient function to exit the test. 170be771a7bSCy Schubertend () { 171be771a7bSCy Schubert echo "> cat logfiles" 172be771a7bSCy Schubert cat fwd.log 173be771a7bSCy Schubert cat unbound.log 174be771a7bSCy Schubert if test $1 -eq 1; then 175be771a7bSCy Schubert echo "Not OK" 176be771a7bSCy Schubert else 177be771a7bSCy Schubert echo "> OK" 178be771a7bSCy Schubert fi 179be771a7bSCy Schubert exit $1 180be771a7bSCy Schubert} 181be771a7bSCy Schubert 182be771a7bSCy Schubert# Ignore all run specific stats. 183be771a7bSCy Schubertset_ignore_regex_stats "$STATS_IGNORE_DEFAULT" 184be771a7bSCy Schubert 185be771a7bSCy Schubert# Check if the server is up. 186be771a7bSCy Schubertecho "> dig 1ttl.example.com." 187be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT 1ttl.example.com. | tee outfile 188be771a7bSCy Schubertecho "> check answer" 189be771a7bSCy Schubertif grep "1.1.1.1" outfile; then 190be771a7bSCy Schubert echo "OK" 191be771a7bSCy Schubertelse 192be771a7bSCy Schubert end 1 193be771a7bSCy Schubertfi 194be771a7bSCy Schubert 195be771a7bSCy Schubert 196be771a7bSCy Schubertteststep "Check initial stats based on first query." 197be771a7bSCy Schubertcheck_stats "\ 198be771a7bSCy Schuberttotal.num.queries=1 199be771a7bSCy Schuberttotal.num.cachemiss=1 200be771a7bSCy Schuberttotal.num.recursivereplies=1 201be771a7bSCy Schubertnum.query.type.A=1 202be771a7bSCy Schubertnum.query.class.IN=1 203be771a7bSCy Schubertnum.query.opcode.QUERY=1 204be771a7bSCy Schubertnum.query.flags.RD=1 205be771a7bSCy Schubertnum.query.flags.AD=1 206be771a7bSCy Schubertnum.query.edns.present=1 207be771a7bSCy Schubertnum.query.udpout=1 208be771a7bSCy Schubertmsg.cache.count=1 209be771a7bSCy Schubertrrset.cache.count=1 210be771a7bSCy Schubertinfra.cache.count=1 211be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 212be771a7bSCy Schubert 213be771a7bSCy Schubert 214be771a7bSCy Schubertteststep "Check stat reset." 215be771a7bSCy Schubertcheck_stats "\ 216be771a7bSCy Schubertmsg.cache.count=1 217be771a7bSCy Schubertrrset.cache.count=1 218be771a7bSCy Schubertinfra.cache.count=1" 219be771a7bSCy Schubert 220be771a7bSCy Schubert 221be771a7bSCy Schubertteststep "Enable serve-expired and check." 222be771a7bSCy Schubertset_ub_option serve-expired yes 223be771a7bSCy Schubertsleep 2 # make sure the TTL has expired. 224be771a7bSCy Schubertecho "> dig 1ttl.example.com." 225be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT 1ttl.example.com. | tee outfile 226be771a7bSCy Schubertecho "> check answer" 227be771a7bSCy Schubertif grep "1.1.1.1" outfile; then 228be771a7bSCy Schubert echo "OK" 229be771a7bSCy Schubertelse 230be771a7bSCy Schubert end 1 231be771a7bSCy Schubertfi 232be771a7bSCy Schubertcheck_stats "\ 233be771a7bSCy Schuberttotal.num.queries=1 234be771a7bSCy Schuberttotal.num.expired=1 235be771a7bSCy Schuberttotal.num.cachehits=1 236be771a7bSCy Schuberttotal.num.prefetch=1 237be771a7bSCy Schubertnum.answer.rcode.NOERROR=1 238be771a7bSCy Schubertnum.query.class.IN=1 239be771a7bSCy Schubertnum.query.edns.present=1 240be771a7bSCy Schubertnum.query.flags.AD=1 241be771a7bSCy Schubertnum.query.flags.RD=1 242be771a7bSCy Schubertnum.query.opcode.QUERY=1 243be771a7bSCy Schubertnum.query.type.A=1 244be771a7bSCy Schubertnum.query.udpout=1 245be771a7bSCy Schubertmsg.cache.count=1 246be771a7bSCy Schubertrrset.cache.count=1 247be771a7bSCy Schubertinfra.cache.count=1" 248be771a7bSCy Schubert 249be771a7bSCy Schubert 250be771a7bSCy Schubertteststep "Enable serve-expired-client-timeout and check." 251be771a7bSCy Schubertset_ub_option serve-expired-client-timeout 1 252be771a7bSCy Schubertecho "> dig servfail.expired." 253be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT servfail.expired. | tee outfile 254be771a7bSCy Schubertecho "> check answer" 255be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 256be771a7bSCy Schubert echo "OK" 257be771a7bSCy Schubertelse 258be771a7bSCy Schubert end 1 259be771a7bSCy Schubertfi 260be771a7bSCy Schubertcheck_stats "\ 261be771a7bSCy Schuberttotal.num.queries=1 262be771a7bSCy Schuberttotal.num.cachemiss=1 263be771a7bSCy Schuberttotal.num.recursivereplies=1 264be771a7bSCy Schubertnum.query.type.A=1 265be771a7bSCy Schubertnum.query.class.IN=1 266be771a7bSCy Schubertnum.query.opcode.QUERY=1 267be771a7bSCy Schubertnum.query.flags.RD=1 268be771a7bSCy Schubertnum.query.flags.AD=1 269be771a7bSCy Schubertnum.query.edns.present=1 270be771a7bSCy Schubertnum.query.udpout=1 271be771a7bSCy Schubertmsg.cache.count=2 272be771a7bSCy Schubertrrset.cache.count=2 273be771a7bSCy Schubertinfra.cache.count=2 274be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 275be771a7bSCy Schubertkill_pid $FWD_EXPIRED_PID # kill the expired forwarder to force a servfail from upstream. 276be771a7bSCy Schubertsleep 2 # make sure the TTL has expired. 277be771a7bSCy Schubertecho "> dig servfail.expired." 278be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT servfail.expired. | tee outfile 279be771a7bSCy Schubertecho "> check answer" 280be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 281be771a7bSCy Schubert echo "OK" 282be771a7bSCy Schubertelse 283be771a7bSCy Schubert end 1 284be771a7bSCy Schubertfi 285be771a7bSCy Schubertsleep 1 # make sure the outgoing UDP (and no edns1xx0 retry because not a smaller buffer size) are accounted for. 286be771a7bSCy Schubertcheck_stats "\ 287be771a7bSCy Schuberttotal.num.queries=1 288be771a7bSCy Schuberttotal.num.expired=1 289be771a7bSCy Schuberttotal.num.recursivereplies=1 290be771a7bSCy Schubertnum.answer.rcode.NOERROR=1 291be771a7bSCy Schubertnum.query.class.IN=1 292be771a7bSCy Schubertnum.query.edns.present=1 293be771a7bSCy Schubertnum.query.flags.AD=1 294be771a7bSCy Schubertnum.query.flags.RD=1 295be771a7bSCy Schubertnum.query.opcode.QUERY=1 296be771a7bSCy Schubertnum.query.type.A=1 297be771a7bSCy Schubertnum.query.udpout=1 298be771a7bSCy Schuberttotal.num.cachemiss=1 299be771a7bSCy Schubertmsg.cache.count=2 300be771a7bSCy Schubertrrset.cache.count=2 301be771a7bSCy Schubertinfra.cache.count=2" 302be771a7bSCy Schubert 303be771a7bSCy Schubert 304be771a7bSCy Schubert# Disable serve-expired 305be771a7bSCy Schubertset_ub_option serve-expired no 306be771a7bSCy Schubert 307be771a7bSCy Schubert 308be771a7bSCy Schubertteststep "Check REFUSED; try without RD flag." 309be771a7bSCy Schubertecho "> dig somethingelse.example.com." 310be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT +nordflag somethingelse.example.com. | tee outfile 311be771a7bSCy Schubertecho "> check answer" 312be771a7bSCy Schubertif grep "REFUSED" outfile; then 313be771a7bSCy Schubert echo "OK" 314be771a7bSCy Schubertelse 315be771a7bSCy Schubert end 1 316be771a7bSCy Schubertfi 317be771a7bSCy Schubertcheck_stats "\ 318be771a7bSCy Schubertnum.answer.rcode.REFUSED=1 319be771a7bSCy Schuberttotal.num.cachehits=1 320be771a7bSCy Schubertnum.query.class.IN=1 321be771a7bSCy Schubertnum.query.edns.present=1 322be771a7bSCy Schubertnum.query.flags.AD=1 323be771a7bSCy Schubertnum.query.opcode.QUERY=1 324be771a7bSCy Schubertnum.query.type.A=1 325be771a7bSCy Schuberttotal.num.queries=1 326be771a7bSCy Schubertmsg.cache.count=2 327be771a7bSCy Schubertrrset.cache.count=2 328be771a7bSCy Schubertinfra.cache.count=2" 329be771a7bSCy Schubert 330be771a7bSCy Schubert 331be771a7bSCy Schubertteststep "Check the AD flag." 332be771a7bSCy Schubertecho "> dig www.example.com." 333be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT +noadflag www.example.com. | tee outfile 334be771a7bSCy Schubertecho "> check answer" 335be771a7bSCy Schubertif grep "10.20.30.40" outfile; then 336be771a7bSCy Schubert echo "OK" 337be771a7bSCy Schubertelse 338be771a7bSCy Schubert end 1 339be771a7bSCy Schubertfi 340be771a7bSCy Schubertcheck_stats "\ 341be771a7bSCy Schubertnum.query.flags.AD=0 342be771a7bSCy Schuberttotal.num.cachemiss=1 343be771a7bSCy Schubertnum.answer.rcode.NOERROR=1 344be771a7bSCy Schubertnum.query.class.IN=1 345be771a7bSCy Schubertnum.query.edns.present=1 346be771a7bSCy Schubertnum.query.flags.RD=1 347be771a7bSCy Schubertnum.query.opcode.QUERY=1 348be771a7bSCy Schubertnum.query.type.A=1 349be771a7bSCy Schubertnum.query.udpout=1 350be771a7bSCy Schuberttotal.num.queries=1 351be771a7bSCy Schuberttotal.num.recursivereplies=1 352be771a7bSCy Schubertmsg.cache.count=3 353be771a7bSCy Schubertrrset.cache.count=3 354be771a7bSCy Schubertinfra.cache.count=2" 355be771a7bSCy Schubert 356be771a7bSCy Schubert 357be771a7bSCy Schubertteststep "Check local zone." 358be771a7bSCy Schubertecho "> dig www.local.zone." 359be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT www.local.zone. | tee outfile 360be771a7bSCy Schubertecho "> check answer" 361be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 362be771a7bSCy Schubert echo "OK" 363be771a7bSCy Schubertelse 364be771a7bSCy Schubert end 1 365be771a7bSCy Schubertfi 366be771a7bSCy Schubertcheck_stats "\ 367be771a7bSCy Schubertnum.answer.rcode.NOERROR=1 368be771a7bSCy Schuberttotal.num.cachehits=1 369be771a7bSCy Schubertnum.query.class.IN=1 370be771a7bSCy Schubertnum.query.edns.present=1 371be771a7bSCy Schubertnum.query.flags.AD=1 372be771a7bSCy Schubertnum.query.flags.RD=1 373be771a7bSCy Schubertnum.query.opcode.QUERY=1 374be771a7bSCy Schubertnum.query.type.A=1 375be771a7bSCy Schuberttotal.num.queries=1 376be771a7bSCy Schubertmsg.cache.count=3 377be771a7bSCy Schubertrrset.cache.count=3 378be771a7bSCy Schubertinfra.cache.count=2" 379be771a7bSCy Schubert 380be771a7bSCy Schubert 381be771a7bSCy Schubertteststep "Check NXDOMAIN (with local data)." 382be771a7bSCy Schubertecho "> dig mail.local.zone." 383be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT mail.local.zone. | tee outfile 384be771a7bSCy Schubertecho "> check answer" 385be771a7bSCy Schubertif grep "NXDOMAIN" outfile; then 386be771a7bSCy Schubert echo "OK" 387be771a7bSCy Schubertelse 388be771a7bSCy Schubert end 1 389be771a7bSCy Schubertfi 390be771a7bSCy Schubertcheck_stats "\ 391be771a7bSCy Schubertnum.answer.rcode.NXDOMAIN=1 392be771a7bSCy Schuberttotal.num.cachehits=1 393be771a7bSCy Schubertnum.query.class.IN=1 394be771a7bSCy Schubertnum.query.edns.present=1 395be771a7bSCy Schubertnum.query.flags.AD=1 396be771a7bSCy Schubertnum.query.flags.RD=1 397be771a7bSCy Schubertnum.query.opcode.QUERY=1 398be771a7bSCy Schubertnum.query.type.A=1 399be771a7bSCy Schuberttotal.num.queries=1 400be771a7bSCy Schubertmsg.cache.count=3 401be771a7bSCy Schubertrrset.cache.count=3 402be771a7bSCy Schubertinfra.cache.count=2" 403be771a7bSCy Schubert 404be771a7bSCy Schubert 405be771a7bSCy Schubertteststep "Check CHAOS." 406be771a7bSCy Schubertecho "> dig id.server. ch txt" 407be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT id.server. ch txt | tee outfile 408be771a7bSCy Schubertecho "> check answer" 409be771a7bSCy Schubertif grep "stat_values" outfile; then 410be771a7bSCy Schubert echo "OK" 411be771a7bSCy Schubertelse 412be771a7bSCy Schubert end 1 413be771a7bSCy Schubertfi 414be771a7bSCy Schubertcheck_stats "\ 415be771a7bSCy Schubertnum.query.class.CH=1 416be771a7bSCy Schuberttotal.num.cachehits=1 417be771a7bSCy Schubertnum.answer.rcode.NOERROR=1 418be771a7bSCy Schubertnum.query.edns.present=1 419be771a7bSCy Schubertnum.query.flags.AD=1 420be771a7bSCy Schubertnum.query.flags.RD=1 421be771a7bSCy Schubertnum.query.opcode.QUERY=1 422be771a7bSCy Schubertnum.query.type.TXT=1 423be771a7bSCy Schuberttotal.num.queries=1 424be771a7bSCy Schubertmsg.cache.count=3 425be771a7bSCy Schubertrrset.cache.count=3 426be771a7bSCy Schubertinfra.cache.count=2" 427be771a7bSCy Schubert 428be771a7bSCy Schubert 429be771a7bSCy Schubertteststep "Check dns-error-reporting." 430be771a7bSCy Schubertecho "> dig www.bogusdnssec." 431be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT www.bogusdnssec. | tee outfile 432be771a7bSCy Schubertecho "> check answer" 433be771a7bSCy Schubertif grep "SERVFAIL" outfile; then 434be771a7bSCy Schubert echo "OK" 435be771a7bSCy Schubertelse 436be771a7bSCy Schubert end 1 437be771a7bSCy Schubertfi 438be771a7bSCy Schubertcheck_stats "\ 439be771a7bSCy Schubertinfra.cache.count=4 440be771a7bSCy Schubertkey.cache.count=1 441be771a7bSCy Schubertmsg.cache.count=7 442be771a7bSCy Schubertnum.answer.bogus=1 443be771a7bSCy Schubertnum.answer.rcode.SERVFAIL=1 444be771a7bSCy Schubertnum.query.class.IN=1 445be771a7bSCy Schubertnum.query.edns.present=1 446be771a7bSCy Schubertnum.query.flags.AD=1 447be771a7bSCy Schubertnum.query.flags.RD=1 448be771a7bSCy Schubertnum.query.opcode.QUERY=1 449be771a7bSCy Schubertnum.query.type.A=1 450be771a7bSCy Schubertnum.query.udpout=9 451*b2efd602SCy Schubertnum.valops=6 452*b2efd602SCy Schubertrrset.cache.count=5 453be771a7bSCy Schuberttotal.num.cachemiss=1 454be771a7bSCy Schuberttotal.num.dns_error_reports=1 455be771a7bSCy Schuberttotal.num.queries=1 456be771a7bSCy Schuberttotal.num.recursivereplies=1" 457be771a7bSCy Schubert 458be771a7bSCy Schubert 459be771a7bSCy Schubert### 460be771a7bSCy Schubert# 461be771a7bSCy Schubert# Bring the discard-timeout, wait-limit configured Unbound up 462be771a7bSCy Schubert# 463be771a7bSCy Schubertbring_up_alternate_configuration ub_discard_wait_limit.conf 464be771a7bSCy Schubert# 465be771a7bSCy Schubert### 466be771a7bSCy Schubert 467be771a7bSCy Schubert 468be771a7bSCy Schubertteststep "Check discard-timeout and wait-limit" 469be771a7bSCy Schubertecho "> dig www.unresponsive" 470be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT +retry=2 +timeout=1 www.unresponsive. | tee outfile 471be771a7bSCy Schubertecho "> check answer" 472be771a7bSCy Schubertif grep "no servers could be reached" outfile; then 473be771a7bSCy Schubert echo "OK" 474be771a7bSCy Schubertelse 475be771a7bSCy Schubert end 1 476be771a7bSCy Schubertfi 477be771a7bSCy Schubertcheck_stats "\ 478be771a7bSCy Schubertinfra.cache.count=1 479be771a7bSCy Schubertmsg.cache.count=1 480be771a7bSCy Schubertnum.query.class.IN=3 481be771a7bSCy Schubertnum.query.edns.present=3 482be771a7bSCy Schubertnum.query.flags.AD=3 483be771a7bSCy Schubertnum.query.flags.RD=3 484be771a7bSCy Schubertnum.query.opcode.QUERY=3 485be771a7bSCy Schubertnum.query.type.A=3 486be771a7bSCy Schubertnum.query.udpout=1 487be771a7bSCy Schuberttotal.num.cachemiss=3 488be771a7bSCy Schuberttotal.num.queries=3 489be771a7bSCy Schuberttotal.num.queries_discard_timeout=2 490be771a7bSCy Schuberttotal.num.queries_wait_limit=1" 491be771a7bSCy Schubert 492be771a7bSCy Schubert 493be771a7bSCy Schubert### 494be771a7bSCy Schubert# 495be771a7bSCy Schubert# Bring the downstream DNS Cookies configured Unbound up 496be771a7bSCy Schubert# 497be771a7bSCy Schubertbring_up_alternate_configuration ub_downstream_cookies.conf 498be771a7bSCy Schubert# 499be771a7bSCy Schubert### 500be771a7bSCy Schubert 501be771a7bSCy Schubert 502be771a7bSCy Schubertteststep "Get a DNS Cookie." 503be771a7bSCy Schubertecho "> dig www.local.zone +tcp $nocookie +ednsopt=10:0102030405060708" 504be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT +tcp $nocookie +ednsopt=10:0102030405060708 +retry=0 +time=1 www.local.zone. | tee outfile 505be771a7bSCy Schubertecho "> check answer" 506be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 507be771a7bSCy Schubert echo "OK" 508be771a7bSCy Schubertelse 509be771a7bSCy Schubert end 1 510be771a7bSCy Schubertfi 511be771a7bSCy Schubert# Save valid cookie 512be771a7bSCy Schubertvalid_cookie=`grep "COOKIE: " outfile | cut -d ' ' -f 3` 513be771a7bSCy Schubertinvalid_cookie=`echo $valid_cookie | tr '0' '4'` 514be771a7bSCy Schubertcheck_stats "\ 515be771a7bSCy Schuberttotal.num.queries=1 516be771a7bSCy Schuberttotal.num.queries_cookie_client=1 517be771a7bSCy Schuberttotal.num.cachehits=1 518be771a7bSCy Schubertnum.query.type.A=1 519be771a7bSCy Schubertnum.query.class.IN=1 520be771a7bSCy Schubertnum.query.opcode.QUERY=1 521be771a7bSCy Schubertnum.query.flags.RD=1 522be771a7bSCy Schubertnum.query.flags.AD=1 523be771a7bSCy Schubertnum.query.edns.present=1 524be771a7bSCy Schubertnum.query.tcp=1 525be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 526be771a7bSCy Schubert 527be771a7bSCy Schubert 528be771a7bSCy Schubertteststep "Present the valid DNS Cookie." 529be771a7bSCy Schubertecho "> dig www.local.zone $nocookie +ednsopt=10:valid_cookie" 530be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT $nocookie +ednsopt=10:$valid_cookie +retry=0 +time=1 www.local.zone. | tee outfile 531be771a7bSCy Schubertecho "> check answer" 532be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 533be771a7bSCy Schubert echo "OK" 534be771a7bSCy Schubertelse 535be771a7bSCy Schubert end 1 536be771a7bSCy Schubertfi 537be771a7bSCy Schubertcheck_stats "\ 538be771a7bSCy Schuberttotal.num.queries=1 539be771a7bSCy Schuberttotal.num.queries_cookie_valid=1 540be771a7bSCy Schuberttotal.num.cachehits=1 541be771a7bSCy Schubertnum.query.type.A=1 542be771a7bSCy Schubertnum.query.class.IN=1 543be771a7bSCy Schubertnum.query.opcode.QUERY=1 544be771a7bSCy Schubertnum.query.flags.RD=1 545be771a7bSCy Schubertnum.query.flags.AD=1 546be771a7bSCy Schubertnum.query.edns.present=1 547be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 548be771a7bSCy Schubert 549be771a7bSCy Schubert 550be771a7bSCy Schubertteststep "Present an invalid DNS Cookie." 551be771a7bSCy Schubertecho "> dig www.local.zone $nocookie +ednsopt=10:invalid_cookie" 552be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT $nocookie +ednsopt=10:$invalid_cookie +retry=0 +time=1 www.local.zone. | tee outfile 553be771a7bSCy Schubertecho "> check answer" 554be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 555be771a7bSCy Schubert end 1 556be771a7bSCy Schubertelse 557be771a7bSCy Schubert echo "OK" 558be771a7bSCy Schubertfi 559be771a7bSCy Schubert# A lot of stats are missing since BADCOOKIE error response is before 560be771a7bSCy Schubert# those stat calculations. 561be771a7bSCy Schubert# BADCOOKIE is an extended error code; we record YXRRSET below. 562be771a7bSCy Schubertcheck_stats "\ 563be771a7bSCy Schuberttotal.num.queries=1 564be771a7bSCy Schuberttotal.num.queries_cookie_invalid=1 565be771a7bSCy Schuberttotal.num.cachehits=1 566be771a7bSCy Schubertnum.answer.rcode.YXRRSET=1" 567be771a7bSCy Schubert 568be771a7bSCy Schubert 569be771a7bSCy Schubertteststep "Present no DNS Cookie." 570be771a7bSCy Schubertecho "> dig www.local.zone +ignore" 571be771a7bSCy Schubertdig @127.0.0.1 -p $UNBOUND_PORT +ignore $nocookie +retry=0 +time=1 www.local.zone. | tee outfile 572be771a7bSCy Schubertecho "> check answer" 573be771a7bSCy Schubertif grep "192.0.2.1" outfile; then 574be771a7bSCy Schubert end 1 575be771a7bSCy Schubertelse 576be771a7bSCy Schubert echo "OK" 577be771a7bSCy Schubertfi 578be771a7bSCy Schubert# A lot of stats are missing since REFUSED error response because of no DNS 579be771a7bSCy Schubert# Cookie is before those stat calculations. 580be771a7bSCy Schubertcheck_stats "\ 581be771a7bSCy Schuberttotal.num.queries=1 582be771a7bSCy Schuberttotal.num.cachehits=1 583be771a7bSCy Schubertnum.answer.rcode.REFUSED=1" 584be771a7bSCy Schubert 585be771a7bSCy Schubertif test x$USE_CACHEDB = "x1"; then 586be771a7bSCy Schubert 587be771a7bSCy Schubert 588be771a7bSCy Schubert### 589be771a7bSCy Schubert# 590be771a7bSCy Schubert# Bring the cachedb configured Unbound up 591be771a7bSCy Schubert# 592be771a7bSCy Schubertbring_up_alternate_configuration ub_cachedb.conf 593be771a7bSCy Schubert# 594be771a7bSCy Schubert### 595be771a7bSCy Schubert 596be771a7bSCy Schubert 597be771a7bSCy Schubertteststep "Check cachedb cache miss." 598be771a7bSCy Schubertecho "> dig www.example.com." 599be771a7bSCy Schubertdig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile 600be771a7bSCy Schubertecho "> check answer" 601be771a7bSCy Schubertif grep "10.20.30.40" outfile; then 602be771a7bSCy Schubert echo "OK" 603be771a7bSCy Schubertelse 604be771a7bSCy Schubert end 1 605be771a7bSCy Schubertfi 606be771a7bSCy Schubertcheck_stats "\ 607be771a7bSCy Schuberttotal.num.queries=1 608be771a7bSCy Schuberttotal.num.cachemiss=1 609be771a7bSCy Schuberttotal.num.cachehits=0 610be771a7bSCy Schuberttotal.num.recursivereplies=1 611be771a7bSCy Schubertnum.query.type.A=1 612be771a7bSCy Schubertnum.query.class.IN=1 613be771a7bSCy Schubertnum.query.opcode.QUERY=1 614be771a7bSCy Schubertnum.query.flags.RD=1 615be771a7bSCy Schubertnum.query.flags.AD=1 616be771a7bSCy Schubertnum.query.edns.present=1 617be771a7bSCy Schubertnum.query.udpout=1 618be771a7bSCy Schubertnum.query.cachedb=0 619be771a7bSCy Schubertmsg.cache.count=1 620be771a7bSCy Schubertrrset.cache.count=1 621be771a7bSCy Schubertinfra.cache.count=1 622be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 623be771a7bSCy Schubert 624be771a7bSCy Schubert 625be771a7bSCy Schubertteststep "Check cachedb cache hit." 626be771a7bSCy Schubertecho "> dig www.example.com." 627be771a7bSCy Schubertdig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile 628be771a7bSCy Schubertecho "> check answer" 629be771a7bSCy Schubertif grep "10.20.30.40" outfile; then 630be771a7bSCy Schubert echo "OK" 631be771a7bSCy Schubertelse 632be771a7bSCy Schubert end 1 633be771a7bSCy Schubertfi 634be771a7bSCy Schubertcheck_stats "\ 635be771a7bSCy Schuberttotal.num.queries=1 636be771a7bSCy Schuberttotal.num.cachemiss=1 637be771a7bSCy Schuberttotal.num.cachehits=0 638be771a7bSCy Schuberttotal.num.recursivereplies=1 639be771a7bSCy Schubertnum.query.type.A=1 640be771a7bSCy Schubertnum.query.class.IN=1 641be771a7bSCy Schubertnum.query.opcode.QUERY=1 642be771a7bSCy Schubertnum.query.flags.RD=1 643be771a7bSCy Schubertnum.query.flags.AD=1 644be771a7bSCy Schubertnum.query.edns.present=1 645be771a7bSCy Schubertnum.query.udpout=0 646be771a7bSCy Schubertnum.query.cachedb=1 647be771a7bSCy Schubertmsg.cache.count=1 648be771a7bSCy Schubertrrset.cache.count=1 649be771a7bSCy Schubertinfra.cache.count=1 650be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 651be771a7bSCy Schubert 652be771a7bSCy Schubert 653be771a7bSCy Schubertteststep "Check cachedb cache hit with stat reset." 654be771a7bSCy Schubertecho "> dig www.example.com." 655be771a7bSCy Schubertdig @127.0.0.1 +ednsopt=65534 -p $UNBOUND_PORT www.example.com. | tee outfile 656be771a7bSCy Schubertecho "> check answer" 657be771a7bSCy Schubertif grep "10.20.30.40" outfile; then 658be771a7bSCy Schubert echo "OK" 659be771a7bSCy Schubertelse 660be771a7bSCy Schubert end 1 661be771a7bSCy Schubertfi 662be771a7bSCy Schubertcheck_stats "\ 663be771a7bSCy Schuberttotal.num.queries=1 664be771a7bSCy Schuberttotal.num.cachemiss=1 665be771a7bSCy Schuberttotal.num.cachehits=0 666be771a7bSCy Schuberttotal.num.recursivereplies=1 667be771a7bSCy Schubertnum.query.type.A=1 668be771a7bSCy Schubertnum.query.class.IN=1 669be771a7bSCy Schubertnum.query.opcode.QUERY=1 670be771a7bSCy Schubertnum.query.flags.RD=1 671be771a7bSCy Schubertnum.query.flags.AD=1 672be771a7bSCy Schubertnum.query.edns.present=1 673be771a7bSCy Schubertnum.query.cachedb=1 674be771a7bSCy Schubertmsg.cache.count=1 675be771a7bSCy Schubertrrset.cache.count=1 676be771a7bSCy Schubertinfra.cache.count=1 677be771a7bSCy Schubertnum.answer.rcode.NOERROR=1" 678be771a7bSCy Schubert 679be771a7bSCy Schubertfi # USE_CACHEDB 680be771a7bSCy Schubert 681be771a7bSCy Schubertend 0 682