xref: /netbsd-src/external/mpl/bind/dist/bin/tests/system/fetchlimit/tests.sh (revision ae082add65442546470c0ba499a860ee89eed305)
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
17DIGCMD="$DIG @10.53.0.3 -p ${PORT} +tcp +tries=1 +time=1"
18RNDCCMD="$RNDC -p ${CONTROLPORT} -s 10.53.0.3 -c ../common/rndc.conf"
19
20burst() {
21    num=${3:-20}
22    rm -f burst.input.$$
23    while [ $num -gt 0 ]; do
24        num=$((num-1))
25        echo "${num}${1}${2}.lamesub.example A" >> burst.input.$$
26    done
27    $PERL ../ditch.pl -p ${PORT} -s 10.53.0.3 burst.input.$$
28    rm -f burst.input.$$
29}
30
31stat() {
32    clients=`$RNDCCMD status | grep "recursive clients" |
33            sed 's;.*: \([^/][^/]*\)/.*;\1;'`
34    echo_i "clients: $clients"
35    [ "$clients" = "" ] && return 1
36    [ "$clients" -ge $1 ] || return 1
37    [ "$clients" -le $2 ] || return 1
38    return 0
39}
40
41status=0
42
43echo_i "checking recursing clients are dropped at the per-server limit"
44ret=0
45# make the server lame and restart
46$RNDCCMD flush
47touch ans4/norespond
48for try in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
49    burst a $try
50    # fetches-per-server is at 400, but at 20qps against a lame server,
51    # we'll reach 200 at the tenth second, and the quota should have been
52    # tuned to less than that by then.
53    [ $try -le 5 ] && low=$((try*10))
54    stat 20 200 || ret=1
55    [ $ret -eq 1 ] && break
56    sleep 1
57done
58if [ $ret != 0 ]; then echo_i "failed"; fi
59status=$((status+ret))
60
61echo_i "dumping ADB data"
62$RNDCCMD dumpdb -adb
63info=`grep '10.53.0.4' ns3/named_dump.db | sed 's/.*\(atr [.0-9]*\).*\(quota [0-9]*\).*/\1 \2/'`
64echo_i $info
65set -- $info
66quota=$5
67[ ${5:-200} -lt 200 ] || ret=1
68
69echo_i "checking servfail statistics"
70ret=0
71rm -f ns3/named.stats
72$RNDCCMD stats
73for try in 1 2 3 4 5; do
74    [ -f ns3/named.stats ] && break
75    sleep 1
76done
77sspill=`grep 'spilled due to server' ns3/named.stats | sed 's/\([0-9][0-9]*\) spilled.*/\1/'`
78[ -z "$sspill" ] && sspill=0
79fails=`grep 'queries resulted in SERVFAIL' ns3/named.stats | sed 's/\([0-9][0-9]*\) queries.*/\1/'`
80[ -z "$fails" ] && fails=0
81[ "$fails" -ge "$sspill" ] || ret=1
82if [ $ret != 0 ]; then echo_i "failed"; fi
83status=$((status+ret))
84
85echo_i "checking lame server recovery"
86ret=0
87rm -f ans4/norespond
88for try in 1 2 3 4 5; do
89    burst b $try
90    stat 0 200 || ret=1
91    [ $ret -eq 1 ] && break
92    sleep 1
93done
94
95echo_i "dumping ADB data"
96$RNDCCMD dumpdb -adb
97info=`grep '10.53.0.4' ns3/named_dump.db | sed 's/.*\(atr [.0-9]*\).*\(quota [0-9]*\).*/\1 \2/'`
98echo_i $info
99set -- $info
100[ ${5:-${quota}} -lt $quota ] || ret=1
101quota=$5
102
103for try in 1 2 3 4 5 6 7 8 9 10; do
104    burst c $try
105    stat 0 20 || ret=1
106    [ $ret -eq 1 ] && break
107    sleep 1
108done
109
110echo_i "dumping ADB data"
111$RNDCCMD dumpdb -adb
112info=`grep '10.53.0.4' ns3/named_dump.db | sed 's/.*\(atr [.0-9]*\).*\(quota [0-9]*\).*/\1 \2/'`
113echo_i $info
114set -- $info
115[ ${5:-${quota}} -gt $quota ] || ret=1
116quota=$5
117if [ $ret != 0 ]; then echo_i "failed"; fi
118status=$((status+ret))
119
120copy_setports ns3/named2.conf.in ns3/named.conf
121rndc_reconfig ns3 10.53.0.3
122
123echo_i "checking lame server clients are dropped at the per-domain limit"
124ret=0
125fail=0
126success=0
127touch ans4/norespond
128for try in 1 2 3 4 5; do
129    burst b $try 300
130    $DIGCMD a ${try}.example > dig.out.ns3.$try
131    grep "status: NOERROR" dig.out.ns3.$try > /dev/null 2>&1 && \
132            success=$((success+1))
133    grep "status: SERVFAIL" dig.out.ns3.$try > /dev/null 2>&1 && \
134            fail=$(($fail+1))
135    stat 30 50 || ret=1
136    [ $ret -eq 1 ] && break
137    $RNDCCMD recursing 2>&1 | sed 's/^/ns3 /' | cat_i
138    sleep 1
139done
140echo_i "$success successful valid queries, $fail SERVFAIL"
141if [ $ret != 0 ]; then echo_i "failed"; fi
142status=$((status+ret))
143
144echo_i "checking drop statistics"
145rm -f ns3/named.stats
146$RNDCCMD stats
147for try in 1 2 3 4 5; do
148    [ -f ns3/named.stats ] && break
149    sleep 1
150done
151zspill=`grep 'spilled due to zone' ns3/named.stats | sed 's/\([0-9][0-9]*\) spilled.*/\1/'`
152[ -z "$zspill" ] && zspill=0
153drops=`grep 'queries dropped' ns3/named.stats | sed 's/\([0-9][0-9]*\) queries.*/\1/'`
154[ -z "$drops" ] && drops=0
155[ "$drops" -ge "$zspill" ] || ret=1
156if [ $ret != 0 ]; then echo_i "failed"; fi
157status=$((status+ret))
158
159copy_setports ns3/named3.conf.in ns3/named.conf
160rndc_reconfig ns3 10.53.0.3
161
162echo_i "checking lame server clients are dropped below the hard limit"
163ret=0
164fail=0
165exceeded=0
166success=0
167touch ans4/norespond
168for try in 1 2 3 4 5; do
169    burst b $try 400
170    $DIGCMD +time=2 a ${try}.example > dig.out.ns3.$try
171    stat 100 400 || exceeded=$((exceeded + 1))
172    grep "status: NOERROR" dig.out.ns3.$try > /dev/null 2>&1 && \
173            success=$((success+1))
174    grep "status: SERVFAIL" dig.out.ns3.$try > /dev/null 2>&1 && \
175            fail=$(($fail+1))
176    sleep 1
177done
178echo_i "$success successful valid queries (expected 5)"
179[ "$success" -eq 5 ] || { echo_i "failed"; ret=1; }
180echo_i "$fail SERVFAIL responses (expected 0)"
181[ "$fail" -eq 0 ] || { echo_i "failed"; ret=1; }
182echo_i "clients count exceeded 400 on $exceeded trials (expected 0)"
183[ "$exceeded" -eq 0 ] || { echo_i "failed"; ret=1; }
184if [ $ret != 0 ]; then echo_i "failed"; fi
185status=$((status+ret))
186
187echo_i "checking drop statistics"
188rm -f ns3/named.stats
189$RNDCCMD stats
190for try in 1 2 3 4 5; do
191    [ -f ns3/named.stats ] && break
192    sleep 1
193done
194drops=`grep 'queries dropped due to recursive client limit' ns3/named.stats | sed 's/\([0-9][0-9]*\) queries.*/\1/'`
195[ "${drops:-0}" -ne 0 ] || ret=1
196if [ $ret != 0 ]; then echo_i "failed"; fi
197status=$((status+ret))
198
199echo_i "exit status: $status"
200[ $status -eq 0 ] || exit 1
201