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