1#!/bin/sh 2# 3# Copyright (C) Internet Systems Consortium, Inc. ("ISC") 4# 5# This Source Code Form is subject to the terms of the Mozilla Public 6# License, v. 2.0. If a copy of the MPL was not distributed with this 7# file, you can obtain one at https://mozilla.org/MPL/2.0/. 8# 9# See the COPYRIGHT file distributed with this work for additional 10# information regarding copyright ownership. 11 12SYSTEMTESTTOP=.. 13. $SYSTEMTESTTOP/conf.sh 14 15status=0 16n=0 17 18DIGOPTS="@10.53.0.1 -p ${PORT}" 19RNDCCMD="$RNDC -c $SYSTEMTESTTOP/common/rndc.conf -p ${CONTROLPORT} -s" 20 21newtest() { 22 n=`expr $n + 1` 23 echo_i "${1} (${n})" 24 ret=0 25} 26 27test_add() { 28 host="$1" 29 type="$2" 30 ip="$3" 31 32 cat <<EOF > ns1/update.txt 33server 10.53.0.1 ${PORT} 34ttl 86400 35update add $host $type $ip 36send 37EOF 38 39 newtest "adding $host $type $ip" 40 $NSUPDATE ns1/update.txt > /dev/null 2>&1 || { 41 [ "$should_fail" ] || \ 42 echo_i "update failed for $host $type $ip" 43 return 1 44 } 45 46 out=`$DIG $DIGOPTS +noall +answer -t $type -q $host` 47 echo $out > added.a.out.$n 48 lines=`echo "$out" | grep "$ip" | wc -l` 49 [ $lines -eq 1 ] || { 50 [ "$should_fail" ] || \ 51 echo_i "dig output incorrect for $host $type $cmd: $out" 52 return 1 53 } 54 55 for i in 1 2 3 4 5 6 7 8 9 10 56 do 57 out=`$DIG $DIGOPTS +noall +answer -x $ip` 58 echo $out > added.ptr.out.$n 59 lines=`echo "$out" | grep "$host" | wc -l` 60 [ $lines -eq 1 ] && break; 61 $PERL -e 'select(undef, undef, undef, 0.1);' 62 done 63 [ $lines -eq 1 ] || { 64 [ "$should_fail" ] || \ 65 echo_i "dig reverse output incorrect for $host $type $cmd: $out" 66 return 1 67 } 68 69 return 0 70} 71 72test_del() { 73 host="$1" 74 type="$2" 75 76 ip=`$DIG $DIGOPTS +short $host $type` 77 78 cat <<EOF > ns1/update.txt 79server 10.53.0.1 ${PORT} 80update del $host $type 81send 82EOF 83 84 newtest "deleting $host $type (was $ip)" 85 $NSUPDATE ns1/update.txt > /dev/null 2>&1 || { 86 [ "$should_fail" ] || \ 87 echo_i "update failed deleting $host $type" 88 return 1 89 } 90 91 out=`$DIG $DIGOPTS +noall +answer -t $type -q $host` 92 echo $out > deleted.a.out.$n 93 lines=`echo "$out" | grep "$ip" | wc -l` 94 [ $lines -eq 0 ] || { 95 [ "$should_fail" ] || \ 96 echo_i "dig output incorrect for $host $type $cmd: $out" 97 return 1 98 } 99 100 for i in 1 2 3 4 5 6 7 8 9 10 101 do 102 out=`$DIG $DIGOPTS +noall +answer -x $ip` 103 echo $out > deleted.ptr.out.$n 104 lines=`echo "$out" | grep "$host" | wc -l` 105 [ $lines -eq 0 ] && break 106 $PERL -e 'select(undef, undef, undef, 0.1);' 107 done 108 [ $lines -eq 0 ] || { 109 [ "$should_fail" ] || \ 110 echo_i "dig reverse output incorrect for $host $type $cmd: $out" 111 return 1 112 } 113 114 return 0 115} 116 117test_add test1.ipv4.example.nil. A "10.53.0.10" || ret=1 118status=`expr $status + $ret` 119 120test_add test2.ipv4.example.nil. A "10.53.0.11" || ret=1 121status=`expr $status + $ret` 122 123test_add test3.ipv4.example.nil. A "10.53.0.12" || ret=1 124status=`expr $status + $ret` 125 126test_add test4.ipv6.example.nil. AAAA "2001:db8::1" || ret=1 127status=`expr $status + $ret` 128 129test_del test1.ipv4.example.nil. A || ret=1 130status=`expr $status + $ret` 131 132test_del test2.ipv4.example.nil. A || ret=1 133status=`expr $status + $ret` 134 135test_del test3.ipv4.example.nil. A || ret=1 136status=`expr $status + $ret` 137 138test_del test4.ipv6.example.nil. AAAA || ret=1 139status=`expr $status + $ret` 140 141newtest "checking parameter logging" 142grep "loading params for dyndb 'sample' from .*named.conf:" ns1/named.run > /dev/null || ret=1 143grep "loading params for dyndb 'sample2' from .*named.conf:" ns1/named.run > /dev/null || ret=1 144[ $ret -eq 1 ] && echo_i "failed" 145status=`expr $status + $ret` 146 147echo_i "checking dyndb still works after reload" 148$RNDCCMD 10.53.0.1 reload 2>&1 | sed 's/^/ns1 /' | cat_i 149 150test_add test5.ipv4.example.nil. A "10.53.0.10" || ret=1 151status=`expr $status + $ret` 152 153test_add test6.ipv6.example.nil. AAAA "2001:db8::1" || ret=1 154status=`expr $status + $ret` 155 156test_del test5.ipv4.example.nil. A || ret=1 157status=`expr $status + $ret` 158 159test_del test6.ipv6.example.nil. AAAA || ret=1 160status=`expr $status + $ret` 161 162echo_i "exit status: $status" 163[ $status -eq 0 ] || exit 1 164