From 89485c1d7119644d2a11466ef22bb894dec0905f Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Thu, 10 May 2001 18:29:09 +0000 Subject: [PATCH] added incremental zone transfer test --- bin/tests/system/conf.sh.in | 4 +- bin/tests/system/ixfr/ans2/ans.pl | 157 ++++++++++++++++++++++++++++++ bin/tests/system/ixfr/clean.sh | 20 ++++ bin/tests/system/ixfr/setup.sh | 43 ++++++++ bin/tests/system/ixfr/tests.sh | 130 +++++++++++++++++++++++++ bin/tests/system/send.pl | 39 ++++++++ 6 files changed, 391 insertions(+), 2 deletions(-) create mode 100644 bin/tests/system/ixfr/ans2/ans.pl create mode 100644 bin/tests/system/ixfr/clean.sh create mode 100644 bin/tests/system/ixfr/setup.sh create mode 100644 bin/tests/system/ixfr/tests.sh create mode 100644 bin/tests/system/send.pl diff --git a/bin/tests/system/conf.sh.in b/bin/tests/system/conf.sh.in index 02eb2e06ec..fad4993b16 100644 --- a/bin/tests/system/conf.sh.in +++ b/bin/tests/system/conf.sh.in @@ -15,7 +15,7 @@ # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# $Id: conf.sh.in,v 1.21 2001/03/08 16:19:35 tale Exp $ +# $Id: conf.sh.in,v 1.22 2001/05/10 18:29:07 gson Exp $ # # Common configuration data for system tests, to be sourced into @@ -42,7 +42,7 @@ KEYSETTOOL=$TOP/bin/dnssec/dnssec-makekeyset # The "stress" test is not run by default since it creates enough # load on the machine to make it unusable to other users. -SUBDIRS="cacheclean dnssec forward glue limits lwresd notify nsupdate \ +SUBDIRS="cacheclean dnssec forward glue ixfr limits lwresd notify nsupdate \ resolver sortlist stub tkey unknown upforwd v6synth views xfer xferquota" # PERL will be an empty string if no perl interpreter was found. diff --git a/bin/tests/system/ixfr/ans2/ans.pl b/bin/tests/system/ixfr/ans2/ans.pl new file mode 100644 index 0000000000..d911f27fca --- /dev/null +++ b/bin/tests/system/ixfr/ans2/ans.pl @@ -0,0 +1,157 @@ +#!/usr/bin/perl +# +# Copyright (C) 2000, 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# $Id: ans.pl,v 1.1 2001/05/10 18:29:09 gson Exp $ + +# +# This is the name server from hell. It provides canned +# responses based on pattern matching the queries, and +# can be reprogrammed on-the-fly over a TCP connection. +# +# The server listens for control connections on port 5301. +# A control connection is a TCP stream of lines like +# +# /pattern/ +# name ttl type rdata +# name ttl type rdata +# ... +# /pattern/ +# name ttl type rdata +# name ttl type rdata +# ... +# +# There can be any number of patterns, each associated +# with any number of response RRs. Each pattern is a +# Perl regular expression. +# +# Each incoming query is converted into a string of the form +# "qname qtype" (the printable query domain name, space, +# printable query type) and matched against each pattern. +# +# The first pattern matching the query is selected, and +# the RR following the pattern line are sent in the +# answer section of the response. +# +# Each new control connection causes the current set of +# patterns and responses to be cleared before adding new +# ones. +# +# The server handles UDP and TCP queries. Zone transfer +# responses work, but must fit in a single 64 k message. +# + +use IO::File; +use IO::Socket; +use Net::DNS; +use Net::DNS::Packet; + +my $ctlsock = IO::Socket::INET->new(LocalAddr => "10.53.0.2", + LocalPort => 5301, Proto => "tcp", Listen => 5, Reuse => 1) or die "$!"; + +my $udpsock = IO::Socket::INET->new(LocalAddr => "10.53.0.2", + LocalPort => 5300, Proto => "udp", Reuse => 1) or die "$!"; + +my $tcpsock = IO::Socket::INET->new(LocalAddr => "10.53.0.2", + LocalPort => 5300, Proto => "tcp", Listen => 5, Reuse => 1) or die "$!"; + +my $pidf = new IO::File "ans.pid", "w" or die "cannot write pid file: $!"; +print $pidf "$$\n"; +$pidf->close; +sub rmpid { unlink "ans.pid"; exit 1; }; + +$SIG{INT} = \&rmpid; +$SIG{TERM} = \&rmpid; + +my @answers = (); + +sub handle { + my ($buf) = @_; + + my ($packet, $err) = new Net::DNS::Packet(\$buf, 0); + $err and die $err; + + $packet->header->qr(1); + $packet->header->aa(1); + + my @questions = $packet->question; + my $qname = $questions[0]->qname; + my $qtype = $questions[0]->qtype; + + my $r; + foreach $r (@rules) { + my $pattern = $r->{pattern}; + warn "match $qname $qtype == $pattern"; + if ("$qname $qtype" =~ /$pattern/) { + my $a; + foreach $a (@{$r->{answer}}) { + $packet->push("answer", $a); + } + last; + } + } + + # $packet->print; + + return $packet->data; +} + +for (;;) { + $rin = ''; + vec($rin, fileno($ctlsock), 1) = 1; + vec($rin, fileno($tcpsock), 1) = 1; + vec($rin, fileno($udpsock), 1) = 1; + + select($rout = $rin, undef, undef, undef); + + if (vec($rout, fileno($ctlsock), 1)) { + warn "ctl conn"; + my $conn = $ctlsock->accept; + @rules = (); + while (my $line = $conn->getline) { + chomp $line; + if ($line =~ m!^/(.*)/$!) { + $rule = { pattern => $1, answer => [] }; + push(@rules, $rule); + } else { + push(@{$rule->{answer}}, + new Net::DNS::RR($line)); + } + + } + $conn->close; + } elsif (vec($rout, fileno($udpsock), 1)) { + printf "UDP request\n"; + $udpsock->recv($buf, 512); + $response = handle($buf); + $udpsock->send($response); + } elsif (vec($rout, fileno($tcpsock), 1)) { + my $conn = $tcpsock->accept; + for (;;) { + printf "TCP request\n"; + my $n = $conn->sysread($lenbuf, 2); + last unless $n == 2; + my $len = unpack("n", $lenbuf); + $n = $conn->sysread($buf, $len); + last unless $n == $len; + $response = handle($buf); + $len = length($response); + $n = $conn->syswrite(pack("n", $len), 2); + $n = $conn->syswrite($response, $len); + } + $conn->close; + } +} diff --git a/bin/tests/system/ixfr/clean.sh b/bin/tests/system/ixfr/clean.sh new file mode 100644 index 0000000000..f43740dde8 --- /dev/null +++ b/bin/tests/system/ixfr/clean.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# $Id: clean.sh,v 1.1 2001/05/10 18:29:09 gson Exp $ + +rm -f ns1/named.conf diff --git a/bin/tests/system/ixfr/setup.sh b/bin/tests/system/ixfr/setup.sh new file mode 100644 index 0000000000..057d2556d2 --- /dev/null +++ b/bin/tests/system/ixfr/setup.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# $Id: setup.sh,v 1.1 2001/05/10 18:29:09 gson Exp $ + +rm -f ns1/*.db ns1/*.jnl + +cat <ns1/named.conf +options { + query-source address 10.53.0.1; + notify-source 10.53.0.1; + transfer-source 10.53.0.1; + port 5300; + pid-file "named.pid"; + listen-on { 10.53.0.1; }; + listen-on-v6 { none; }; + recursion no; + notify yes; +}; + +key rndc_key { + secret "1234abcd8765"; + algorithm hmac-md5; +}; + +controls { + inet 10.53.0.1 port 9953 allow { any; } keys { rndc_key; }; +}; +EOF diff --git a/bin/tests/system/ixfr/tests.sh b/bin/tests/system/ixfr/tests.sh new file mode 100644 index 0000000000..19e54f8592 --- /dev/null +++ b/bin/tests/system/ixfr/tests.sh @@ -0,0 +1,130 @@ +#!/bin/sh +# +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# $Id: tests.sh,v 1.1 2001/05/10 18:29:09 gson Exp $ + +SYSTEMTESTTOP=.. +. $SYSTEMTESTTOP/conf.sh + +DIGOPTS="+tcp +noadd +nosea +nostat +noquest +nocomm +nocmd" +DIGCMD="$DIG $DIGOPTS @10.53.0.1 -p 5300" +SENDCMD="$PERL ../send.pl 10.53.0.2 5301" +RNDCCMD="$RNDC -s 10.53.0.1 -p 9953 -c ../common/rndc.conf" + +echo "I:testing initial AXFR" + +$SENDCMD <>ns1/named.conf +zone "nil" { + type slave; + file "myftp.db"; + masters { 10.53.0.2; }; +}; +EOF + +$RNDCCMD reload + +sleep 2 + +$DIGCMD nil. TXT | grep 'initial AXFR' >/dev/null || { + echo "I:failed" + status=1 +} + +echo "I:testing successful IXFR" + +# We change the IP address of a.nil., and the TXT record at the apex. +# Then we do a SOA-only update. + +$SENDCMD </dev/null || { + echo "I:failed" + status=1 +} + +echo "I:testing AXFR fallback after IXFR failure" + +# Provide a broken IXFR response and a working fallback AXFR response + +$SENDCMD </dev/null || { + echo "I:failed" + status=1 +} + +echo "I:exit status: $status" +exit $status diff --git a/bin/tests/system/send.pl b/bin/tests/system/send.pl new file mode 100644 index 0000000000..5e006f3d1a --- /dev/null +++ b/bin/tests/system/send.pl @@ -0,0 +1,39 @@ +#!/usr/bin/perl +# +# Copyright (C) 2000, 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, +# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING +# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION +# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +# $Id: send.pl,v 1.1 2001/05/10 18:29:08 gson Exp $ + +# +# Send a file to a given address and port using TCP. Used for +# configuring the test server in ixfr/ans2/ans.pl. +# + +use IO::File; +use IO::Socket; + +@ARGV == 2 or die "usage: send.pl host port [file ...]\n"; + +my $host = shift @ARGV; +my $port = shift @ARGV; + +my $sock = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, + Proto => "tcp",) or die "$!"; +while (<>) { + $sock->syswrite($_, length $_); +} + +$sock->close;