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 14SYSTEMTESTTOP=.. 15. $SYSTEMTESTTOP/conf.sh 16 17DIGOPTS="+tcp +noadd +nosea +nostat +noquest +nocomm +nocmd" 18DIGCMD="$DIG $DIGOPTS -p ${PORT}" 19RNDCCMD="$RNDC -p ${CONTROLPORT} -c ../common/rndc.conf" 20 21status=0 22 23ret=0 24n=1 25stats=0 26rndc_stats() { 27 _ns=$1 28 _ip=$2 29 30 $RNDCCMD -s $_ip stats > /dev/null 2>&1 || return 1 31 [ -f "${_ns}/named.stats" ] || return 1 32 33 last_stats=named.stats.$_ns-$stats-$n 34 mv ${_ns}/named.stats $last_stats 35 stats=$((stats+1)) 36} 37 38echo_i "fetching a.example from ns2's initial configuration ($n)" 39$DIGCMD +noauth a.example. @10.53.0.2 any > dig.out.ns2.1 || ret=1 40if [ $ret != 0 ]; then echo_i "failed"; fi 41status=`expr $status + $ret` 42n=`expr $n + 1` 43 44ret=0 45echo_i "dumping initial stats for ns2 ($n)" 46rndc_stats ns2 10.53.0.2 || ret=1 47if [ $ret != 0 ]; then echo_i "failed"; fi 48status=`expr $status + $ret` 49n=`expr $n + 1` 50 51ret=0 52echo_i "verifying adb records in named.stats ($n)" 53grep "ADB stats" $last_stats > /dev/null || ret=1 54if [ $ret != 0 ]; then echo_i "failed"; fi 55status=`expr $status + $ret` 56n=`expr $n + 1` 57 58echo_i "checking for 1 entry in adb hash table in named.stats ($n)" 59grep "1 Addresses in hash table" $last_stats > /dev/null || ret=1 60if [ $ret != 0 ]; then echo_i "failed"; fi 61status=`expr $status + $ret` 62n=`expr $n + 1` 63 64ret=0 65echo_i "verifying cache statistics in named.stats ($n)" 66grep "Cache Statistics" $last_stats > /dev/null || ret=1 67if [ $ret != 0 ]; then echo_i "failed"; fi 68status=`expr $status + $ret` 69n=`expr $n + 1` 70 71ret=0 72echo_i "checking for 2 entries in adb hash table in named.stats ($n)" 73$DIGCMD a.example.info. @10.53.0.2 any > /dev/null 2>&1 74rndc_stats ns2 10.53.0.2 || ret=1 75grep "2 Addresses in hash table" $last_stats > /dev/null || ret=1 76if [ $ret != 0 ]; then echo_i "failed"; fi 77status=`expr $status + $ret` 78n=`expr $n + 1` 79 80ret=0 81echo_i "dumping initial stats for ns3 ($n)" 82rndc_stats ns3 10.53.0.3 || ret=1 83if [ ! "$CYGWIN" ]; then 84 nsock0nstat=`grep "UDP/IPv4 sockets active" $last_stats | awk '{print $1}'` 85 [ 0 -ne ${nsock0nstat:-0} ] || ret=1 86fi 87if [ $ret != 0 ]; then echo_i "failed"; fi 88status=`expr $status + $ret` 89n=`expr $n + 1` 90 91echo_i "sending queries to ns3" 92$DIGCMD +tries=2 +time=1 +recurse @10.53.0.3 foo.info. any > /dev/null 2>&1 93 94ret=0 95echo_i "dumping updated stats for ns3 ($n)" 96getstats() { 97 rndc_stats ns3 10.53.0.3 || return 1 98 grep "2 recursing clients" $last_stats > /dev/null || return 1 99} 100retry_quiet 5 getstats || ret=1 101if [ $ret != 0 ]; then echo_i "failed"; fi 102status=`expr $status + $ret` 103n=`expr $n + 1` 104 105ret=0 106echo_i "verifying recursing clients output in named.stats ($n)" 107grep "2 recursing clients" $last_stats > /dev/null || ret=1 108if [ $ret != 0 ]; then echo_i "failed"; fi 109status=`expr $status + $ret` 110n=`expr $n + 1` 111 112ret=0 113echo_i "verifying active fetches output in named.stats ($n)" 114grep "1 active fetches" $last_stats > /dev/null || ret=1 115if [ $ret != 0 ]; then echo_i "failed"; fi 116status=`expr $status + $ret` 117n=`expr $n + 1` 118 119if [ ! "$CYGWIN" ]; then 120 ret=0 121 echo_i "verifying active sockets output in named.stats ($n)" 122 nsock1nstat=`grep "UDP/IPv4 sockets active" $last_stats | awk '{print $1}'` 123 [ `expr ${nsock1nstat:-0} - ${nsock0nstat:-0}` -eq 1 ] || ret=1 124 if [ $ret != 0 ]; then echo_i "failed"; fi 125 status=`expr $status + $ret` 126 n=`expr $n + 1` 127fi 128 129# there should be 1 UDP and no TCP queries. As the TCP counter is zero 130# no status line is emitted. 131ret=0 132echo_i "verifying queries in progress in named.stats ($n)" 133grep "1 UDP queries in progress" $last_stats > /dev/null || ret=1 134grep "TCP queries in progress" $last_stats > /dev/null && ret=1 135if [ $ret != 0 ]; then echo_i "failed"; fi 136status=`expr $status + $ret` 137n=`expr $n + 1` 138 139ret=0 140echo_i "verifying bucket size output ($n)" 141grep "bucket size" $last_stats > /dev/null || ret=1 142if [ $ret != 0 ]; then echo_i "failed"; fi 143status=`expr $status + $ret` 144n=`expr $n + 1` 145 146ret=0 147echo_i "checking priming queries are counted ($n)" 148grep "priming queries" $last_stats > /dev/null || ret=1 149if [ $ret != 0 ]; then echo_i "failed"; fi 150status=`expr $status + $ret` 151n=`expr $n + 1` 152 153ret=0 154echo_i "checking that zones with slash are properly shown in XML output ($n)" 155if $FEATURETEST --have-libxml2 && [ -x ${CURL} ] ; then 156 ${CURL} http://10.53.0.1:${EXTRAPORT1}/xml/v3/zones > curl.out.${n} 2>/dev/null || ret=1 157 grep '<zone name="32/1.0.0.127-in-addr.example" rdataclass="IN">' curl.out.${n} > /dev/null || ret=1 158else 159 echo_i "skipping test as libxml2 and/or curl was not found" 160fi 161if [ $ret != 0 ]; then echo_i "failed"; fi 162status=`expr $status + $ret` 163n=`expr $n + 1` 164 165ret=0 166echo_i "checking that zones return their type ($n)" 167if $FEATURETEST --have-libxml2 && [ -x ${CURL} ] ; then 168 ${CURL} http://10.53.0.1:${EXTRAPORT1}/xml/v3/zones > curl.out.${n} 2>/dev/null || ret=1 169 grep '<zone name="32/1.0.0.127-in-addr.example" rdataclass="IN"><type>master</type>' curl.out.${n} > /dev/null || ret=1 170else 171 echo_i "skipping test as libxml2 and/or curl was not found" 172fi 173if [ $ret != 0 ]; then echo_i "failed"; fi 174status=`expr $status + $ret` 175n=`expr $n + 1` 176 177ret=0 178echo_i "checking bind9.xsl vs xml ($n)" 179if $FEATURETEST --have-libxml2 && [ -x "${CURL}" ] && [ -x "${XSLTPROC}" ] ; then 180 $DIGCMD +notcp +recurse @10.53.0.3 soa . > /dev/null 2>&1 181 $DIGCMD +notcp +recurse @10.53.0.3 soa example > /dev/null 2>&1 182 ${CURL} http://10.53.0.3:${EXTRAPORT1}/xml/v3 > curl.out.${n}.xml 2>/dev/null || ret=1 183 ${CURL} http://10.53.0.3:${EXTRAPORT1}/bind9.xsl > curl.out.${n}.xsl 2>/dev/null || ret=1 184 ${XSLTPROC} curl.out.${n}.xsl - < curl.out.${n}.xml > xsltproc.out.${n} 2>/dev/null || ret=1 185 cp curl.out.${n}.xml stats.xml.out || ret=1 186 187 # 188 # grep for expected sections. 189 # 190 grep "<h1>ISC Bind 9 Configuration and Statistics</h1>" xsltproc.out.${n} >/dev/null || ret=1 191 grep "<h2>Server Status</h2>" xsltproc.out.${n} >/dev/null || ret=1 192 grep "<h2>Incoming Requests by DNS Opcode</h2>" xsltproc.out.${n} >/dev/null || ret=1 193 grep "<h3>Incoming Queries by Query Type</h3>" xsltproc.out.${n} >/dev/null || ret=1 194 grep "<h2>Outgoing Queries per view</h2>" xsltproc.out.${n} >/dev/null || ret=1 195 grep "<h3>View " xsltproc.out.${n} >/dev/null || ret=1 196 grep "<h2>Server Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1 197 grep "<h2>Zone Maintenance Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1 198 grep "<h2>Resolver Statistics (Common)</h2>" xsltproc.out.${n} >/dev/null || ret=1 199 grep "<h3>Resolver Statistics for View " xsltproc.out.${n} >/dev/null || ret=1 200 grep "<h3>ADB Statistics for View " xsltproc.out.${n} >/dev/null || ret=1 201 grep "<h3>Cache Statistics for View " xsltproc.out.${n} >/dev/null || ret=1 202 # grep "<h3>Cache DB RRsets for View " xsltproc.out.${n} >/dev/null || ret=1 203 grep "<h2>Traffic Size Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1 204 grep "<h4>UDP Requests Received</h4>" xsltproc.out.${n} >/dev/null || ret=1 205 grep "<h4>UDP Responses Sent</h4>" xsltproc.out.${n} >/dev/null || ret=1 206 grep "<h4>TCP Requests Received</h4>" xsltproc.out.${n} >/dev/null || ret=1 207 grep "<h4>TCP Responses Sent</h4>" xsltproc.out.${n} >/dev/null || ret=1 208 grep "<h2>Socket I/O Statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1 209 grep "<h3>Zones for View " xsltproc.out.${n} >/dev/null || ret=1 210 grep "<h2>Received QTYPES per view/zone</h2>" xsltproc.out.${n} >/dev/null || ret=1 211 grep "<h3>View _default" xsltproc.out.${n} >/dev/null || ret=1 212 grep "<h4>Zone example" xsltproc.out.${n} >/dev/null || ret=1 213 grep "<h2>Response Codes per view/zone</h2>" xsltproc.out.${n} >/dev/null || ret=1 214 grep "<h3>View _default" xsltproc.out.${n} >/dev/null || ret=1 215 grep "<h4>Zone example" xsltproc.out.${n} >/dev/null || ret=1 216 # grep "<h2>Glue cache statistics</h2>" xsltproc.out.${n} >/dev/null || ret=1 217 grep "<h3>View _default" xsltproc.out.${n} >/dev/null || ret=1 218 grep "<h4>Zone example" xsltproc.out.${n} >/dev/null || ret=1 219 grep "<h2>Network Status</h2>" xsltproc.out.${n} >/dev/null || ret=1 220 grep "<h2>Task Manager Configuration</h2>" xsltproc.out.${n} >/dev/null || ret=1 221 grep "<h2>Tasks</h2>" xsltproc.out.${n} >/dev/null || ret=1 222 grep "<h2>Memory Usage Summary</h2>" xsltproc.out.${n} >/dev/null || ret=1 223 grep "<h2>Memory Contexts</h2>" xsltproc.out.${n} >/dev/null || ret=1 224else 225 echo_i "skipping test as libxml2 and/or curl and/or xsltproc was not found" 226fi 227if [ $ret != 0 ]; then echo_i "failed"; fi 228status=`expr $status + $ret` 229n=`expr $n + 1` 230 231ret=0 232echo_i "checking bind9.xml socket statistics ($n)" 233if $FEATURETEST --have-libxml2 && [ -x "${CURL}" ] && [ -x "${XSLTPROC}" ] ; then 234 # Socket statistics (expect no errors) 235 grep "<counter name=\"TCP4AcceptFail\">0</counter>" stats.xml.out >/dev/null || ret=1 236 grep "<counter name=\"TCP4BindFail\">0</counter>" stats.xml.out >/dev/null || ret=1 237 grep "<counter name=\"TCP4ConnFail\">0</counter>" stats.xml.out >/dev/null || ret=1 238 grep "<counter name=\"TCP4OpenFail\">0</counter>" stats.xml.out >/dev/null || ret=1 239 grep "<counter name=\"TCP4RecvErr\">0</counter>" stats.xml.out >/dev/null || ret=1 240 grep "<counter name=\"TCP4SendErr\">0</counter>" stats.xml.out >/dev/null || ret=1 241 242 grep "<counter name=\"TCP6AcceptFail\">0</counter>" stats.xml.out >/dev/null || ret=1 243 grep "<counter name=\"TCP6BindFail\">0</counter>" stats.xml.out >/dev/null || ret=1 244 grep "<counter name=\"TCP6ConnFail\">0</counter>" stats.xml.out >/dev/null || ret=1 245 grep "<counter name=\"TCP6OpenFail\">0</counter>" stats.xml.out >/dev/null || ret=1 246 grep "<counter name=\"TCP6RecvErr\">0</counter>" stats.xml.out >/dev/null || ret=1 247 grep "<counter name=\"TCP6SendErr\">0</counter>" stats.xml.out >/dev/null || ret=1 248else 249 echo_i "skipping test as libxml2 and/or curl and/or xsltproc was not found" 250fi 251if [ $ret != 0 ]; then echo_i "failed"; fi 252status=`expr $status + $ret` 253n=`expr $n + 1` 254 255echo_i "Check that 'zone-statistics full;' is processed by 'rndc reconfig' ($n)" 256ret=0 257# off by default 258rndc_stats ns2 10.53.0.2 || ret=1 259sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' > /dev/null && ret=0 260# turn on 261copy_setports ns2/named2.conf.in ns2/named.conf 262rndc_reconfig ns2 10.53.0.2 263rndc_stats ns2 10.53.0.2 || ret=1 264sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' > /dev/null || ret=1 265# turn off 266copy_setports ns2/named.conf.in ns2/named.conf 267rndc_reconfig ns2 10.53.0.2 268rndc_stats ns2 10.53.0.2 || ret=1 269sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' > /dev/null && ret=0 270# turn on 271copy_setports ns2/named2.conf.in ns2/named.conf 272rndc_reconfig ns2 10.53.0.2 273rndc_stats ns2 10.53.0.2 || ret=1 274sed -n '/Per Zone Query Statistics/,/^++/p' $last_stats | grep -F '[example]' > /dev/null || ret=1 275if [ $ret != 0 ]; then echo_i "failed"; fi 276status=`expr $status + $ret` 277n=`expr $n + 1` 278 279echo_i "exit status: $status" 280[ $status -eq 0 ] || exit 1 281