1#!/bin/sh
2#
3# Copyright (C) 2013, 2014  Internet Systems Consortium, Inc. ("ISC")
4#
5# Permission to use, copy, modify, and/or distribute this software for any
6# purpose with or without fee is hereby granted, provided that the above
7# copyright notice and this permission notice appear in all copies.
8#
9# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11# AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15# PERFORMANCE OF THIS SOFTWARE.
16
17SYSTEMTESTTOP=..
18. $SYSTEMTESTTOP/conf.sh
19
20status=0
21n=0
22
23rm -f dig.out.*
24
25DIGOPTS="+tcp +short -p 5300 @10.53.0.2"
26DIGOPTS6="+tcp +short -p 5300 @fd92:7065:b8e:ffff::2"
27
28n=`expr $n + 1`
29echo "I:checking GeoIP country database by code ($n)"
30ret=0
31lret=0
32for i in 1 2 3 4 5 6 7; do
33    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
34    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
35    [ "$i" = "$j" ] || lret=1
36    [ $lret -eq 1 ] && break
37done
38[ $lret -eq 1 ] && ret=1
39[ $ret -eq 0 ] || echo "I:failed"
40status=`expr $status + $ret`
41
42echo "I:reloading server"
43cp -f ns2/named2.conf ns2/named.conf
44$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
45sleep 3
46
47n=`expr $n + 1`
48echo "I:checking GeoIP country database by three-letter code ($n)"
49ret=0
50lret=0
51for i in 1 2 3 4 5 6 7; do
52    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
53    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
54    [ "$i" = "$j" ] || lret=1
55    [ $lret -eq 1 ] && break
56done
57[ $lret -eq 1 ] && ret=1
58[ $ret -eq 0 ] || echo "I:failed"
59status=`expr $status + $ret`
60
61echo "I:reloading server"
62cp -f ns2/named3.conf ns2/named.conf
63$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
64sleep 3
65
66n=`expr $n + 1`
67echo "I:checking GeoIP country database by name ($n)"
68ret=0
69lret=0
70for i in 1 2 3 4 5 6 7; do
71    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
72    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
73    [ "$i" = "$j" ] || lret=1
74    [ $lret -eq 1 ] && break
75done
76[ $lret -eq 1 ] && ret=1
77[ $ret -eq 0 ] || echo "I:failed"
78status=`expr $status + $ret`
79
80echo "I:reloading server"
81cp -f ns2/named4.conf ns2/named.conf
82$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
83sleep 3
84
85n=`expr $n + 1`
86echo "I:checking GeoIP region code, no specified database ($n)"
87ret=0
88lret=0
89# skipping 2 on purpose here; it has the same region code as 1
90for i in 1 3 4 5 6 7; do
91    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
92    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
93    [ "$i" = "$j" ] || lret=1
94    [ $lret -eq 1 ] && break
95done
96[ $lret -eq 1 ] && ret=1
97[ $ret -eq 0 ] || echo "I:failed"
98status=`expr $status + $ret`
99
100echo "I:reloading server"
101cp -f ns2/named5.conf ns2/named.conf
102$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
103sleep 3
104
105n=`expr $n + 1`
106echo "I:checking GeoIP region database by region name and country code ($n)"
107ret=0
108lret=0
109for i in 1 2 3 4 5 6 7; do
110    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
111    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
112    [ "$i" = "$j" ] || lret=1
113    [ $lret -eq 1 ] && break
114done
115[ $lret -eq 1 ] && ret=1
116[ $ret -eq 0 ] || echo "I:failed"
117status=`expr $status + $ret`
118
119echo "I:reloading server"
120cp -f ns2/named6.conf ns2/named.conf
121$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
122sleep 3
123
124if $TESTSOCK6 fd92:7065:b8e:ffff::3
125then
126  n=`expr $n + 1`
127  echo "I:checking GeoIP city database by city name using IPv6 ($n)"
128  ret=0
129  $DIG +tcp +short -p 5300 @fd92:7065:b8e:ffff::1 -6 txt example -b fd92:7065:b8e:ffff::2 > dig.out.ns2.test$n || ret=1
130  [ $ret -eq 0 ] || echo "I:failed"
131  status=`expr $status + $ret`
132else
133  echo "I:IPv6 unavailable; skipping"
134fi
135
136n=`expr $n + 1`
137echo "I:checking GeoIP city database by city name ($n)"
138ret=0
139lret=0
140for i in 1 2 3 4 5 6 7; do
141    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
142    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
143    [ "$i" = "$j" ] || lret=1
144    [ $lret -eq 1 ] && break
145done
146[ $lret -eq 1 ] && ret=1
147[ $ret -eq 0 ] || echo "I:failed"
148status=`expr $status + $ret`
149
150echo "I:reloading server"
151cp -f ns2/named7.conf ns2/named.conf
152$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
153sleep 3
154
155n=`expr $n + 1`
156echo "I:checking GeoIP isp database ($n)"
157ret=0
158lret=0
159for i in 1 2 3 4 5 6 7; do
160    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
161    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
162    [ "$i" = "$j" ] || lret=1
163    [ $lret -eq 1 ] && break
164done
165[ $lret -eq 1 ] && ret=1
166[ $ret -eq 0 ] || echo "I:failed"
167status=`expr $status + $ret`
168
169echo "I:reloading server"
170cp -f ns2/named8.conf ns2/named.conf
171$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
172sleep 3
173
174n=`expr $n + 1`
175echo "I:checking GeoIP org database ($n)"
176ret=0
177lret=0
178for i in 1 2 3 4 5 6 7; do
179    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
180    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
181    [ "$i" = "$j" ] || lret=1
182    [ $lret -eq 1 ] && break
183done
184[ $lret -eq 1 ] && ret=1
185[ $ret -eq 0 ] || echo "I:failed"
186status=`expr $status + $ret`
187
188echo "I:reloading server"
189cp -f ns2/named9.conf ns2/named.conf
190$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
191sleep 3
192
193n=`expr $n + 1`
194echo "I:checking GeoIP asnum database ($n)"
195ret=0
196lret=0
197for i in 1 2 3 4 5 6 7; do
198    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
199    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
200    [ "$i" = "$j" ] || lret=1
201    [ $lret -eq 1 ] && break
202done
203[ $lret -eq 1 ] && ret=1
204[ $ret -eq 0 ] || echo "I:failed"
205status=`expr $status + $ret`
206
207echo "I:reloading server"
208cp -f ns2/named10.conf ns2/named.conf
209$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
210sleep 3
211
212n=`expr $n + 1`
213echo "I:checking GeoIP asnum database - ASNNNN only ($n)"
214ret=0
215lret=0
216for i in 1 2 3 4 5 6 7; do
217    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
218    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
219    [ "$i" = "$j" ] || lret=1
220    [ $lret -eq 1 ] && break
221done
222[ $lret -eq 1 ] && ret=1
223[ $ret -eq 0 ] || echo "I:failed"
224status=`expr $status + $ret`
225
226echo "I:reloading server"
227cp -f ns2/named11.conf ns2/named.conf
228$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
229sleep 3
230
231n=`expr $n + 1`
232echo "I:checking GeoIP domain database ($n)"
233ret=0
234lret=0
235for i in 1 2 3 4 5 6 7; do
236    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
237    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
238    [ "$i" = "$j" ] || lret=1
239    [ $lret -eq 1 ] && break
240done
241[ $lret -eq 1 ] && ret=1
242[ $ret -eq 0 ] || echo "I:failed"
243status=`expr $status + $ret`
244
245echo "I:reloading server"
246cp -f ns2/named12.conf ns2/named.conf
247$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
248sleep 3
249
250n=`expr $n + 1`
251echo "I:checking GeoIP netspeed database ($n)"
252ret=0
253lret=0
254for i in 1 2 3 4; do
255    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
256    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
257    [ "$i" = "$j" ] || lret=1
258    [ $lret -eq 1 ] && break
259done
260[ $lret -eq 1 ] && ret=1
261[ $ret -eq 0 ] || echo "I:failed"
262status=`expr $status + $ret`
263
264echo "I:reloading server"
265cp -f ns2/named13.conf ns2/named.conf
266$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
267sleep 3
268
269n=`expr $n + 1`
270echo "I:checking GeoIP blackhole ACL ($n)"
271ret=0
272$DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n || ret=1
273$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 status 2>&1 > rndc.out.ns2.test$n || ret=1
274[ $ret -eq 0 ] || echo "I:failed"
275status=`expr $status + $ret`
276
277echo "I:reloading server"
278cp -f ns2/named14.conf ns2/named.conf
279$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
280sleep 3
281
282n=`expr $n + 1`
283echo "I:checking GeoIP country database by code (using nested ACLs) ($n)"
284ret=0
285lret=0
286for i in 1 2 3 4 5 6 7; do
287    $DIG $DIGOPTS txt example -b 10.53.0.$i > dig.out.ns2.test$n.$i || lret=1
288    j=`cat dig.out.ns2.test$n.$i | tr -d '"'`
289    [ "$i" = "$j" ] || lret=1
290    [ $lret -eq 1 ] && break
291done
292[ $lret -eq 1 ] && ret=1
293[ $ret -eq 0 ] || echo "I:failed"
294status=`expr $status + $ret`
295
296n=`expr $n + 1`
297echo "I:reloading server with different geoip-directory ($n)"
298ret=0
299cp -f ns2/named15.conf ns2/named.conf
300$RNDC -c ../common/rndc.conf -s 10.53.0.2 -p 9953 reload 2>&1 | sed 's/^/I:ns2 /'
301sleep 3
302awk '/using "..\/data2" as GeoIP directory/ {m=1} ; { if (m>0) { print } }' ns2/named.run | grep "GeoIP City .* DB not available" > /dev/null || ret=1
303[ $ret -eq 0 ] || echo "I:failed"
304status=`expr $status + $ret`
305
306n=`expr $n + 1`
307echo "I:checking GeoIP v4/v6 when only IPv6 database is available ($n)"
308ret=0
309$DIG $DIGOPTS -4 txt example -b 10.53.0.2 > dig.out.ns2.test$n.1 || ret=1
310j=`cat dig.out.ns2.test$n.1 | tr -d '"'`
311[ "$j" = "bogus" ] || ret=1
312if $TESTSOCK6 fd92:7065:b8e:ffff::2; then
313    $DIG $DIGOPTS6 txt example -b fd92:7065:b8e:ffff::2 > dig.out.ns2.test$n.2 || ret=1
314    j=`cat dig.out.ns2.test$n.2 | tr -d '"'`
315    [ "$j" = "2" ] || ret=1
316fi
317[ $ret -eq 0 ] || echo "I:failed"
318status=`expr $status + $ret`
319
320echo "I:exit status: $status"
321exit $status
322