tests.sh revision 225146b2c8c7de8dcff979841b56b15aef8aded2
609b8d08176469485edce25f3c2f50365bbd3819Mark Andrews# Copyright (C) 2011-2013 Internet Systems Consortium, Inc. ("ISC")
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# Permission to use, copy, modify, and/or distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews#
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews# PERFORMANCE OF THIS SOFTWARE.
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User# $Id$
f97d56e757b9a293ffbaa915ca4d792ae84ba85aTinderbox User
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# test response policy zones (RPZ)
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsSYSTEMTESTTOP=..
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews. $SYSTEMTESTTOP/conf.sh
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverns=10.53.0
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntns1=$ns.1 # root, defining the others
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntns2=$ns.2 # authoritative server whose records are rewritten
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntns3=$ns.3 # main rewriting resolver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntns4=$ns.4 # another authoritative server that is rewritten
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntns5=$ns.5 # another rewriting resolver
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryverHAVE_CORE=
94315060c2b0d9deafabe72d6a0482405fd9d377Evan HuntSAVE_RESULTS=
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark AndrewsUSAGE="$0: [-x]"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewswhile getopts "x" c; do
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews case $c in
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews x) set -x;;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews *) echo "$USAGE" 1>&2; exit 1;;
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews esac
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsdone
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsshift `expr $OPTIND - 1 || true`
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsif test "$#" -ne 0; then
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews echo "$USAGE" 1>&2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews exit 1
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsfi
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# really quit on control-C
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewstrap 'exit 1' 1 2 15
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
94315060c2b0d9deafabe72d6a0482405fd9d377Evan HuntTS='%H:%M:%S '
94315060c2b0d9deafabe72d6a0482405fd9d377Evan HuntTS=
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntcomment () {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if test -n "$TS"; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt date "+I:${TS}$*"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fi
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon SchryverRNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p 9953 -s"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverdigcmd () {
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if test "$1" = TCP; then
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt shift
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt fi
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt # Default to +noauth and @$ns3
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt # Also default to -bX where X is the @value so that OS X will choose
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt # the right IP source address.
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt digcmd_args=`echo "+noadd +time=1 +tries=1 -p 5300 $*" | \
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt sed -e "/@/!s/.*/& @$ns3/" \
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt -e '/-b/!s/@\([^ ]*\)/@\1 -b\1/' \
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt -e '/+n?o?auth/!s/.*/+noauth &/'`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver #echo I:dig $digcmd_args 1>&2
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver $DIG $digcmd_args
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# set DIGNM=file name for dig output
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryverGROUP_NM=
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryverTEST_NUM=0
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvermake_dignm () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver TEST_NUM=`expr $TEST_NUM + 1`
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver DIGNM=dig.out$GROUP_NM-$TEST_NUM
88112d5fcb6b9e1d0f80105a9d2a6f09440c2401Mark Andrews while test -f $DIGNM; do
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver TEST_NUM="$TEST_NUM+"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver DIGNM=dig.out$GROUP_NM-$TEST_NUM
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver done
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewssetret () {
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews ret=1
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt status=`expr $status + 1`
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews echo "$*"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# (re)load the reponse policy zones with the rules in the file $TEST_FILE
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverload_db () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if test -n "$TEST_FILE"; then
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if $NSUPDATE -v $TEST_FILE; then :
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt $RNDCCMD $ns3 sync
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt else
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver echo "I:failed to update policy zone with $TEST_FILE"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt $RNDCCMD $ns3 sync
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver exit 1
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt fi
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fi
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverrestart () {
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver # try to ensure that the server really has stopped
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver # and won't mess with ns$1/name.pid
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -z "$HAVE_CORE" -a -f ns$1/named.pid; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver $RNDCCMD $ns$1 halt >/dev/null 2>&1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -f ns$1/named.pid; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver sleep 1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver PID=`cat ns$1/named.pid 2>/dev/null`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -n "$PID"; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver echo "I:killing ns$1 server $PID"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver kill -9 $PID
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver rm -f ns$1/*.jnl
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -f ns$1/base.db; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver for NM in ns$1/bl*.db; do
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver cp -f ns$1/base.db $NM
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver done
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver $PERL $SYSTEMTESTTOP/start.pl --noclean --restart . ns$1
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver load_db
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver# $1=server and irrelevant args $2=error message
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverckalive () {
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver CKALIVE_NS=`expr "$1" : '.*@ns\([1-9]\).*'`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -z "$CKALIVE_NS"; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver CKALIVE_NS=3
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver eval CKALIVE_IP=\$ns$CKALIVE_NS
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver $RNDCCMD $CKALIVE_IP status >/dev/null 2>&1 && return 0
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver HAVE_CORE=yes
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver setret "$2"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver # restart the server to avoid stalling waiting for it to stop
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver restart $CKALIVE_NS
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver return 1
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntckstats () {
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt HOST=$1
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt LABEL="$2"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt NSDIR="$3"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt EXPECTED="$4"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt $RNDCCMD $HOST stats
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt NEW_CNT=0`sed -n -e 's/[ ]*\([0-9]*\).response policy.*/\1/p' \
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt $NSDIR/named.stats | tail -1`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt eval "OLD_CNT=0\$${NSDIR}_CNT"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt GOT=`expr $NEW_CNT - $OLD_CNT`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if test "$GOT" -ne "$EXPECTED"; then
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt setret "I:wrong $LABEL $NSDIR statistics of $GOT instead of $EXPECTED"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fi
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt eval "${NSDIR}_CNT=$NEW_CNT"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt}
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# $1=message $2=optional test file name
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstart_group () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ret=0
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt test -n "$1" && date "+I:${TS}checking $1"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver TEST_FILE=$2
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if test -n "$TEST_FILE"; then
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver GROUP_NM="-$TEST_FILE"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver load_db
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver else
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver GROUP_NM=
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fi
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver TEST_NUM=0
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverend_group () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver if test -n "$TEST_FILE"; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt # remove the previous set of test rules
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver sed -e 's/[ ]add[ ]/ delete /' $TEST_FILE | $NSUPDATE
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver TEST_FILE=
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ckalive $ns3 "I:failed; ns3 server crashed and restarted"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver GROUP_NM=
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntclean_result () {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if test -z "$SAVE_RESULTS"; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt rm -f $*
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fi
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt}
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# $1=dig args $2=other dig output file
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverckresult () {
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver #ckalive "$1" "I:server crashed by 'dig $1'" || return 1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if $PERL $SYSTEMTESTTOP/digcomp.pl $DIGNM $2 >/dev/null; then
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt NEED_TCP=`echo "$1" | sed -n -e 's/[Tt][Cc][Pp].*/TCP/p'`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt RESULT_TCP=`sed -n -e 's/.*Truncated, retrying in TCP.*/TCP/p' $DIGNM`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if test "$NEED_TCP" != "$RESULT_TCP"; then
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt setret "I:'dig $1' wrong; no or unexpected truncation in $DIGNM"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt return 1
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt fi
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt clean_result ${DIGNM}*
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver return 0
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fi
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver setret "I:'dig $1' wrong; diff $DIGNM $2"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver return 1
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# check only that the server does not crash
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# $1=target domain $2=optional query type
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernocrash () {
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver digcmd $* >/dev/null
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ckalive "$*" "I:server crashed by 'dig $*'"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver}
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# check rewrite to NXDOMAIN
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# $1=target domain $2=optional query type
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnxdomain () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver make_dignm
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver digcmd $* \
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver | sed -e 's/^[a-z].* IN CNAME /;xxx &/' \
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver -e 's/^[a-z].* IN RRSIG /;xxx &/' \
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver >$DIGNM
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ckresult "$*" proto.nxdomain
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# check rewrite to NODATA
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews# $1=target domain $2=optional query type
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnodata () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver make_dignm
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver digcmd $* \
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver | sed -e 's/^[a-z].* IN CNAME /;xxx &/' >$DIGNM
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ckresult "$*" proto.nodata
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# check rewrite to an address
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# modify the output so that it is easily compared, but save the original line
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver# $1=IPv4 address $2=digcmd args $3=optional TTL
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ADDR=$1
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver make_dignm
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver digcmd $2 >$DIGNM
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver #ckalive "$2" "I:server crashed by 'dig $2'" || return 1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ADDR_ESC=`echo "$ADDR" | sed -e 's/\./\\\\./g'`
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt ADDR_TTL=`sed -n -e "s/^[-.a-z0-9]\{1,\} *\([0-9]*\) IN AA* ${ADDR_ESC}\$/\1/p" $DIGNM`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -z "$ADDR_TTL"; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver setret "I:'dig $2' wrong; no address $ADDR record in $DIGNM"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver return 1
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver if test -n "$3" && test "$ADDR_TTL" -ne "$3"; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver setret "I:'dig $2' wrong; TTL=$ADDR_TTL instead of $3 in $DIGNM"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver return 1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt clean_result ${DIGNM}*
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt# Check that a response is not rewritten
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt# Use $ns1 instead of the authority for most test domains, $ns2 to prevent
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt# spurious differences for `dig +norecurse`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt# $1=optional "TCP" remaining args for dig
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver make_dignm
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver digcmd $* >$DIGNM
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt digcmd $* @$ns1 >${DIGNM}_OK
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt ckresult "$*" ${DIGNM}_OK && clean_result ${DIGNM}_OK
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# check against a 'here document'
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverhere () {
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver make_dignm
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver sed -e 's/^[ ]*//' >${DIGNM}_OK
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver digcmd $* >$DIGNM
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ckresult "$*" ${DIGNM}_OK
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews}
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt# check dropped response
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan HuntDROPPED='^;; connection timed out; no servers could be reached'
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntdrop () {
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt make_dignm
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt digcmd $* >$DIGNM
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt if grep "$DROPPED" $DIGNM >/dev/null; then
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt clean_result ${DIGNM}*
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt return 0
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt fi
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt setret "I:'dig $1' wrong; response in $DIGNM"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt return 1
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt}
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# make prototype files to check against rewritten results
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverdigcmd nonexistent @$ns2 >proto.nxdomain
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverdigcmd txt-only.tld2 @$ns2 >proto.nodata
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsstatus=0
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstart_group "QNAME rewrites" test1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange . # 1 do not crash or rewrite root
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a0-1.tld2 # 2
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernodata a3-1.tld2 # 3
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnodata a3-2.tld2 # 4 nodata at DNAME itself
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange sub.a3-2.tld2 # 5 miss where DNAME might work
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernxdomain a4-2.tld2 # 6 rewrite based on CNAME target
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernxdomain a4-2-cname.tld2 # 7
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernodata a4-3-cname.tld2 # 8
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 12.12.12.12 a4-1.sub1.tld2 # 9 A replacement
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 12.12.12.12 a4-1.sub2.tld2 # 10 A replacement with wildcard
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 12.12.12.12 nxc1.sub1.tld2 # 11 replace NXDOMAIN with CNAME
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 12.12.12.12 nxc2.sub1.tld2 # 12 replace NXDOMAIN with CNAME chain
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 127.4.4.1 a4-4.tld2 # 13 prefer 1st conflicting QNAME zone
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a6-1.tld2 # 14
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 127.6.2.1 a6-2.tld2 # 15
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 56.56.56.56 a3-6.tld2 # 16 wildcard CNAME
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 57.57.57.57 a3-7.sub1.tld2 # 17 wildcard CNAME
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 127.0.0.16 a4-5-cname3.tld2 # 18 CNAME chain
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 127.0.0.17 a4-6-cname3.tld2 # 19 stop short in CNAME chain
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange a5-2.tld2 +norecurse # 20 check that RD=1 is required
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange a5-3.tld2 +norecurse # 21
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange a5-4.tld2 +norecurse # 22
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange sub.a5-4.tld2 +norecurse # 23
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain c1.crash2.tld3 # 24 assert in rbtdb.c
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a0-1.tld2 +dnssec # 25 simple DO=1 without signatures
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnxdomain a0-1.tld2s +nodnssec # 26 simple DO=0 with signatures
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a0-1.tld2s +dnssec # 27 simple DO=1 with signatures
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a0-1s-cname.tld2s +dnssec # 28 DNSSEC too early in CNAME chain
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a0-1-scname.tld2 +dnssec # 29 DNSSEC on target in CNAME chain
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange a0-1.tld2s srv +auth +dnssec # 30 no write for DNSSEC and no record
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnxdomain a0-1.tld2s srv +nodnssec # 31
9fa2a0deed3b880f3bf04d4f615c13a0d67cc0ceMark Andrewsdrop a3-8.tld2 any # 32 drop
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnochange tcp a3-9.tld2 # 33 tcp-only
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunthere x.servfail <<'EOF' # 34 qname-wait-recurse yes
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt ;; status: SERVFAIL, x
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan HuntEOF
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntaddr 35.35.35.35 "x.servfail @$ns5" # 35 qname-wait-recurse no
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverend_group
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntckstats $ns3 test1 ns3 22
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntckstats $ns5 test1 ns5 1
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstart_group "IP rewrites" test2
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernodata a3-1.tld2 # 1 NODATA
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a3-2.tld2 # 2 no policy record so no change
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a4-1.tld2 # 3 obsolete PASSTHRU record style
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a4-2.tld2 # 4
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a4-2.tld2 -taaaa # 5 no A => no policy rewrite
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a4-2.tld2 -ttxt # 6 no A => no policy rewrite
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a4-2.tld2 -tany # 7 no A => no policy rewrite
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernodata a4-3.tld2 # 8
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a3-1.tld2 -taaaa # 9 IPv6 policy
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a4-1-aaaa.tld2 -taaaa # 10
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 127.0.0.1 a5-1-2.tld2 # 11 prefer smallest policy address
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 127.0.0.1 a5-3.tld2 # 12 prefer first conflicting IP zone
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntnochange a5-4.tld2 +norecurse # 13 check that RD=1 is required for #14
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntaddr 14.14.14.14 a5-4.tld2 # 14 prefer QNAME to IP
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernochange a4-4.tld2 # 15 PASSTHRU
75c622f53bdda9d2f69f05e06eaf7be01fc09a33Evan Huntnxdomain c2.crash2.tld3 # 16 assert in rbtdb.c
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntaddr 127.0.0.17 "a4-4.tld2 -b $ns1" # 17 client-IP address trigger
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsnxdomain a7-1.tld2 # 18 slave policy zone (RT34450)
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewscp ns2/blv2.tld2.db.in ns2/bl.tld2.db
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews$RNDCCMD 10.53.0.2 reload bl.tld2
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsgoodsoa="rpz.tld2. hostmaster.ns.tld2. 2 3600 1200 604800 60"
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsfor i in 0 1 2 3 4 5 6 7 8 9 10
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsdo
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews soa=`$DIG -p 5300 +short soa bl.tld2 @10.53.0.3 -b10.53.0.3`
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews test "$soa" = "$goodsoa" && break
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews sleep 1
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsdone
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsnochange a7-1.tld2 # 19 PASSTHRU
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewssleep 1 # ensure that a clock tick has occured so that the reload takes effect
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewscp ns2/blv3.tld2.db.in ns2/bl.tld2.db
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsgoodsoa="rpz.tld2. hostmaster.ns.tld2. 3 3600 1200 604800 60"
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews$RNDCCMD 10.53.0.2 reload bl.tld2
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsfor i in 0 1 2 3 4 5 6 7 8 9 10
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsdo
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews soa=`$DIG -p 5300 +short soa bl.tld2 @10.53.0.3 -b10.53.0.3`
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews test "$soa" = "$goodsoa" && break
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrews sleep 1
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsdone
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsnxdomain a7-1.tld2 # 20 slave policy zone (RT34450)
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverend_group
df0892aea6bfd20a01c3abf2b756625d23830390Mark Andrewsckstats $ns3 test2 ns3 12
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# check that IP addresses for previous group were deleted from the radix tree
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstart_group "radix tree deletions"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a3-1.tld2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a3-2.tld2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-1.tld2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-2.tld2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-2.tld2 -taaaa
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-2.tld2 -ttxt
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-2.tld2 -tany
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-3.tld2
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a3-1.tld2 -tAAAA
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsnochange a4-1-aaaa.tld2 -tAAAA
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernochange a5-1-2.tld2
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverend_group
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntckstats $ns3 'radix tree deletions' ns3 0
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsif ./rpz nsdname; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt # these tests assume "min-ns-dots 0"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver start_group "NSDNAME rewrites" test3
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt nochange a3-1.tld2 # 1
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver nochange a3-1.tld2 +dnssec # 2 this once caused problems
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nxdomain a3-1.sub1.tld2 # 3 NXDOMAIN *.sub1.tld2 by NSDNAME
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nxdomain a3-1.subsub.sub1.tld2
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nxdomain a3-1.subsub.sub1.tld2 -tany
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver addr 12.12.12.12 a4-2.subsub.sub2.tld2 # 6 walled garden for *.sub2.tld2
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nochange a3-2.tld2. # 7 exempt rewrite by name
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nochange a0-1.tld2. # 8 exempt rewrite by address block
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver addr 12.12.12.12 a4-1.tld2 # 9 prefer QNAME policy to NSDNAME
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver addr 127.0.0.1 a3-1.sub3.tld2 # 10 prefer policy for largest NSDNAME
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver addr 127.0.0.2 a3-1.subsub.sub3.tld2
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nxdomain xxx.crash1.tld2 # 12 dns_db_detachnode() crash
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver end_group
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt ckstats $ns3 test3 ns3 7
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewselse
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt echo "I:NSDNAME not checked; named configured with --disable-rpz-nsdname"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsfi
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsif ./rpz nsip; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt # these tests assume "min-ns-dots 0"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver start_group "NSIP rewrites" test4
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt nxdomain a3-1.tld2 # 1 NXDOMAIN for all of tld2
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nochange a3-2.tld2. # 2 exempt rewrite by name
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nochange a0-1.tld2. # 3 exempt rewrite by address block
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nochange a3-1.tld4 # 4 different NS IP address
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver end_group
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt start_group "walled garden NSIP rewrites" test4a
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt addr 41.41.41.41 a3-1.tld2 # 1 walled garden for all of tld2
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt addr 2041::41 'a3-1.tld2 AAAA' # 2 walled garden for all of tld2
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt here a3-1.tld2 TXT <<'EOF' # 3 text message for all of tld2
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt ;; status: NOERROR, x
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt a3-1.tld2. x IN TXT "NSIP walled garden"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan HuntEOF
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt end_group
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt ckstats $ns3 test4 ns3 4
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewselse
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt echo "I:NSIP not checked; named configured with --disable-rpz-nsip"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsfi
76db58eb818dc4839fa816df6a1a1ecb2c7a6bd0Evan Hunt
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# policies in ./test5 overridden by response-policy{} in ns3/named.conf
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver# and in ns5/named.conf
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverstart_group "policy overrides" test5
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryveraddr 127.0.0.1 a3-1.tld2 # 1 bl-given
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernochange a3-2.tld2 # 2 bl-passthru
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernochange a3-3.tld2 # 3 bl-no-op obsolete for passthru
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryvernochange a3-4.tld2 # 4 bl-disabled
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnodata a3-5.tld2 # 5 bl-nodata zone recursive-only no
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnodata a3-5.tld2 +norecurse # 6 bl-nodata zone recursive-only no
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnodata a3-5.tld2 # 7 bl-nodata not needed
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnxdomain a3-5.tld2 +norecurse @$ns5 # 8 bl-nodata global recursive-only no
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnxdomain a3-5.tld2s @$ns5 # 9 bl-nodata global break-dnssec
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnxdomain a3-5.tld2s +dnssec @$ns5 # 10 bl-nodata global break-dnssec
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryvernxdomain a3-6.tld2 # 11 bl-nxdomain
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverhere a3-7.tld2 -tany <<'EOF'
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver ;; status: NOERROR, x
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver a3-7.tld2. x IN CNAME txt-only.tld2.
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver txt-only.tld2. x IN TXT "txt-only-tld2"
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon SchryverEOF
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 58.58.58.58 a3-8.tld2 # 13 bl_wildcname
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 59.59.59.59 a3-9.sub9.tld2 # 14 bl_wildcname
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 12.12.12.12 a3-15.tld2 # 15 bl-garden via CNAME to a12.tld2
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 127.0.0.16 a3-16.tld2 100 # 16 bl max-policy-ttl 100
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryveraddr 17.17.17.17 "a3-17.tld2 @$ns5" 90 # 17 ns5 bl max-policy-ttl 90
9fa2a0deed3b880f3bf04d4f615c13a0d67cc0ceMark Andrewsdrop a3-18.tld2 any # 18 bl-drop
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntnxdomain TCP a3-19.tld2 # 19 bl-tcp-only
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverend_group
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntckstats $ns3 test5 ns3 12
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntckstats $ns5 test5 ns5 4
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver# check that miscellaneous bugs are still absent
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntstart_group "crashes" test6
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverfor Q in RRSIG SIG ANY 'ANY +dnssec'; do
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nocrash a3-1.tld2 -t$Q
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nocrash a3-2.tld2 -t$Q
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nocrash a3-5.tld2 -t$Q
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nocrash www.redirect -t$Q
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryver nocrash www.credirect -t$Q
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverdone
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt# This is not a bug, because any data leaked by writing 24.4.3.2.10.rpz-ip
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt# (or whatever) is available by publishing "foo A 10.2.3.4" and then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt# resolving foo.
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt# nxdomain 32.3.2.1.127.rpz-ip
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverend_group
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Huntckstats $ns3 bugs ns3 8
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt
475b1ed9cced1f92ce34bc2e59b3065dae48f366Mark Andrews
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver# superficial test for major performance bugs
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon SchryverQPERF=`sh qperf.sh`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverif test -n "$QPERF"; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver perf () {
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt date "+I:${TS}checking performance $1"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt # Dry run to prime everything
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt comment "before dry run $1"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt $QPERF -c -1 -l30 -d ns5/requests -s $ns5 -p 5300 >/dev/null
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt comment "before real test $1"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt PFILE="ns5/$2.perf"
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt $RNDCCMD $ns5 notrace
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt $QPERF -c -1 -l30 -d ns5/requests -s $ns5 -p 5300 >$PFILE
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt comment "after test $1"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt X=`sed -n -e 's/.*Returned *\([^ ]*:\) *\([0-9]*\) .*/\1\2/p' $PFILE \
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt | tr '\n' ' '`
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if test "$X" != "$3"; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt setret "I:wrong results '$X' in $PFILE"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver ckalive $ns5 "I:failed; server #5 crashed"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver }
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver trim () {
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver sed -n -e 's/.*Queries per second: *\([0-9]*\).*/\1/p' ns5/$1.perf
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver }
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt # get qps with rpz
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt perf 'with RPZ' rpz 'NOERROR:2900 NXDOMAIN:100 '
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt RPZ=`trim rpz`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt # turn off rpz and measure qps again
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt echo "# RPZ off" >ns5/rpz-switch
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt RNDCCMD_OUT=`$RNDCCMD $ns5 reload`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt perf 'without RPZ' norpz 'NOERROR:3000 '
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver NORPZ=`trim norpz`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt PERCENT=`expr \( "$RPZ" \* 100 + \( $NORPZ / 2 \) \) / $NORPZ`
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt echo "I:$RPZ qps with RPZ is $PERCENT% of $NORPZ qps without RPZ"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt MIN_PERCENT=30
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if test "$PERCENT" -lt $MIN_PERCENT; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt setret "I:$RPZ qps with rpz or $PERCENT% is below $MIN_PERCENT% of $NORPZ qps"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt fi
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt if test "$PERCENT" -ge 100; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt setret "I:$RPZ qps with RPZ or $PERCENT% of $NORPZ qps without RPZ is too high"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver fi
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
421d4a06479e61fbdc35087f3c4abc9fe65ad72aEvan Hunt ckstats $ns5 performance ns5 200
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverelse
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver echo "I:performance not checked; queryperf not available"
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryverfi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver# restart the main test RPZ server to see if that creates a core file
9fee08f655527a5dd849b171daeeee1dbbccca76Vernon Schryverif test -z "$HAVE_CORE"; then
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver $PERL $SYSTEMTESTTOP/stop.pl . ns3
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver restart 3
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver HAVE_CORE=`find ns* -name '*core*' -print`
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver test -z "$HAVE_CORE" || setret "I:found $HAVE_CORE; memory leak?"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsfi
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrews
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt# look for complaints from lib/dns/rpz.c and bin/name/query.c
94315060c2b0d9deafabe72d6a0482405fd9d377Evan HuntEMSGS=`egrep -l 'invalid rpz|rpz.*failed' ns*/named.run`
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntif test -n "$EMSGS"; then
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt setret "I:error messages in $EMSGS starting with:"
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Hunt egrep 'invalid rpz|rpz.*failed' ns*/named.run | sed -e '10,$d' -e 's/^/I: /'
94315060c2b0d9deafabe72d6a0482405fd9d377Evan Huntfi
afaa290bb6acc504e93a0adbf20b6dd6c64e6d63Vernon Schryver
225146b2c8c7de8dcff979841b56b15aef8aded2Mark Andrewsecho "I:checking that ttl values are not zeroed when qtype is '*'"
225146b2c8c7de8dcff979841b56b15aef8aded2Mark Andrews$DIG +noall +answer -p 5300 @$ns3 any a3-2.tld2 > dig.out.any
225146b2c8c7de8dcff979841b56b15aef8aded2Mark Andrewsttl=`awk '/a3-2 tld2 text/ {print $2}' dig.out.any`
225146b2c8c7de8dcff979841b56b15aef8aded2Mark Andrewsif test ${ttl:=0} -eq 0; then setret I:failed; fi
225146b2c8c7de8dcff979841b56b15aef8aded2Mark Andrews
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsecho "I:exit status: $status"
87708bde16713bc02ff2598f4a82f98c699a2f2dMark Andrewsexit $status