c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt#!/bin/sh
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt#
675d004f498f4a3a3fd7433deaef230ffddbc263Tinderbox User# Copyright (C) 2014-2017 Internet Systems Consortium, Inc. ("ISC")
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan HuntSYSTEMTESTTOP=..
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt. $SYSTEMTESTTOP/conf.sh
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan HuntDIGOPTS="-p 5300"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=0
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=0
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset() {
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień cp $1 ns3/named.conf
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 reconfig 2>&1 | sed 's/^/I:ns3 /'
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień $RNDC -c ../common/rndc.conf -s 10.53.0.3 -p 9953 flush | sed 's/^/I: ns3 /'
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień}
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_sends_aaaa_queries() {
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień if grep "started AAAA fetch" ns3/named.run >/dev/null; then
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień return 0
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień else
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień return 1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień fi
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień}
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień# Check whether the number of queries ans2 received from ns3 (this value is
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień# read from dig output stored in file $1) is as expected. The expected query
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień# count is variable:
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień# - if ns3 sends AAAA queries, the query count should equal $2,
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień# - if ns3 does not send AAAA queries, the query count should equal $3.
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńcheck_query_count() {
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień count=`sed 's/[^0-9]//g;' $1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień expected_count_with_aaaa=$2
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień expected_count_without_aaaa=$3
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień if ns3_sends_aaaa_queries; then
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień expected_count=$expected_count_with_aaaa
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień else
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień expected_count=$expected_count_without_aaaa
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień fi
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień if [ $count -ne $expected_count ]; then
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień echo "I: count ($count) != $expected_count"
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień fi
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień}
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: set max-recursion-depth=12"
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt excessive-depth lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntecho "1000" > ans2/ans.limit
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect1.example.org > dig.out.1.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntgrep "status: SERVFAIL" dig.out.1.test$n > /dev/null || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńcheck_query_count dig.out.2.test$n 26 14
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt permissible lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntecho "12" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named1.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect2.example.org > dig.out.1.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntgrep "status: NOERROR" dig.out.1.test$n > /dev/null || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńcheck_query_count dig.out.2.test$n 49 26
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: set max-recursion-depth=5"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt excessive-depth lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntecho "12" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named2.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect3.example.org > dig.out.1.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntgrep "status: SERVFAIL" dig.out.1.test$n > /dev/null || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńcheck_query_count dig.out.2.test$n 12 7
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt permissible lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntecho "5" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named2.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect4.example.org > dig.out.1.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntgrep "status: NOERROR" dig.out.1.test$n > /dev/null || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńcheck_query_count dig.out.2.test$n 21 12
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: set max-recursion-depth=100, max-recursion-queries=50"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt excessive-queries lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntecho "13" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named3.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect5.example.org > dig.out.1.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńif ns3_sends_aaaa_queries; then
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn grep "status: SERVFAIL" dig.out.1.test$n > /dev/null || ret=1
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburnfi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunteval count=`cat dig.out.2.test$n`
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn[ $count -le 50 ] || { ret=1; echo "I: count ($count) !<= 50"; }
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt permissible lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntecho "12" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named3.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect6.example.org > dig.out.1.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntgrep "status: NOERROR" dig.out.1.test$n > /dev/null || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunteval count=`cat dig.out.2.test$n`
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn[ $count -le 50 ] || { ret=1; echo "I: count ($count) !<= 50"; }
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: set max-recursion-depth=100, max-recursion-queries=40"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt excessive-queries lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntecho "10" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named4.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect7.example.org > dig.out.1.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńif ns3_sends_aaaa_queries; then
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn grep "status: SERVFAIL" dig.out.1.test$n > /dev/null || ret=1
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburnfi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunteval count=`cat dig.out.2.test$n`
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn[ $count -le 40 ] || { ret=1; echo "I: count ($count) !<= 40"; }
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntn=`expr $n + 1`
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńecho "I: attempt permissible lookup ($n)"
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntret=0
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntecho "9" > ans2/ans.limit
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named4.conf
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
012ce6857e612b25ab2c2052eb505a0944c15107Mark Andrews$DIG $DIGOPTS @10.53.0.3 indirect8.example.org > dig.out.1.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntgrep "status: NOERROR" dig.out.1.test$n > /dev/null || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunteval count=`cat dig.out.2.test$n`
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn[ $count -le 40 ] || { ret=1; echo "I: count ($count) !<= 40"; }
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntstatus=`expr $status + $ret`
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntn=`expr $n + 1`
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntecho "I: attempting NS explosion ($n)"
05e448935cb2d6ab08c24257f6536362d3496512Evan Huntret=0
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępieńns3_reset ns3/named4.conf
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień$DIG $DIGOPTS @10.53.0.2 reset > /dev/null || ret=1
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt$DIG $DIGOPTS +short @10.53.0.3 ns1.1.example.net > dig.out.1.test$n || ret=1
2d517e233ff3b3fcd272eb5b2e2d3db6d31a1681Michał Kępień$DIG $DIGOPTS +short @10.53.0.2 count txt > dig.out.2.test$n || ret=1
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunteval count=`cat dig.out.2.test$n`
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt[ $count -lt 50 ] || ret=1
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunt$DIG $DIGOPTS +short @10.53.0.7 count txt > dig.out.3.test$n || ret=1
05e448935cb2d6ab08c24257f6536362d3496512Evan Hunteval count=`cat dig.out.3.test$n`
9effea437d7973c9ed981ab2e14b219182d86ee7Curtis Blackburn[ $count -lt 50 ] || { ret=1; echo "I: count ($count) !<= 50"; }
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntif [ $ret != 0 ]; then echo "I:failed"; fi
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntstatus=`expr $status + $ret`
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Hunt
c4f54e5bd1cd09f601252627b5b26768ab797742Evan Huntecho "I:exit status: $status"
3635d8f9104e70e141a8f191a0e6c1502ceed2f3Mark Andrews[ $status -eq 0 ] || exit 1