diff options
Diffstat (limited to 'bin/tests/system/ixfr')
-rw-r--r-- | bin/tests/system/ixfr/ans2/ans.pl | 157 | ||||
-rw-r--r-- | bin/tests/system/ixfr/clean.sh | 21 | ||||
-rw-r--r-- | bin/tests/system/ixfr/prereq.sh | 26 | ||||
-rw-r--r-- | bin/tests/system/ixfr/setup.sh | 43 | ||||
-rw-r--r-- | bin/tests/system/ixfr/tests.sh | 132 |
5 files changed, 379 insertions, 0 deletions
diff --git a/bin/tests/system/ixfr/ans2/ans.pl b/bin/tests/system/ixfr/ans2/ans.pl new file mode 100644 index 0000000..ef67955 --- /dev/null +++ b/bin/tests/system/ixfr/ans2/ans.pl @@ -0,0 +1,157 @@ +#!/usr/bin/perl +# +# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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.6 2007/09/24 04:13:25 marka 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 open pid file: $!"; +print $pidf "$$\n" or die "cannot write pid file: $!"; +$pidf->close or die "cannot close pid file: $!";; +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 0000000..530f458 --- /dev/null +++ b/bin/tests/system/ixfr/clean.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# +# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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.6 2007/09/26 03:22:43 marka Exp $ + +rm -f ns1/named.conf ns1/myftp.db +rm -f */named.memstats diff --git a/bin/tests/system/ixfr/prereq.sh b/bin/tests/system/ixfr/prereq.sh new file mode 100644 index 0000000..aaf349b --- /dev/null +++ b/bin/tests/system/ixfr/prereq.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# +# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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: prereq.sh,v 1.5 2007/06/19 23:47:03 tbox Exp $ + +if $PERL -e 'use Net::DNS;' 2>/dev/null +then + : +else + echo "I:This test requires the Net::DNS library." >&2 + exit 1 +fi diff --git a/bin/tests/system/ixfr/setup.sh b/bin/tests/system/ixfr/setup.sh new file mode 100644 index 0000000..6e5b8e4 --- /dev/null +++ b/bin/tests/system/ixfr/setup.sh @@ -0,0 +1,43 @@ +#!/bin/sh +# +# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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.4 2007/06/19 23:47:03 tbox Exp $ + +rm -f ns1/*.db ns1/*.jnl + +cat <<EOF >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 0000000..109f01e --- /dev/null +++ b/bin/tests/system/ixfr/tests.sh @@ -0,0 +1,132 @@ +#!/bin/sh +# +# Copyright (C) 2004, 2007 Internet Systems Consortium, Inc. ("ISC") +# Copyright (C) 2001 Internet Software Consortium. +# +# Permission to use, copy, modify, and/or 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 ISC DISCLAIMS ALL WARRANTIES WITH +# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +# AND FITNESS. IN NO EVENT SHALL ISC 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.5 2007/06/19 23:47:03 tbox Exp $ + +SYSTEMTESTTOP=.. +. $SYSTEMTESTTOP/conf.sh + +status=0 + +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 <<EOF +/SOA/ +nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 +/AXFR/ +nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 +nil. 300 NS ns.nil. +nil. 300 TXT "initial AXFR" +a.nil. 60 A 10.0.0.61 +b.nil. 60 A 10.0.0.62 +nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 +EOF + +sleep 1 + +# Initially, ns1 is not authoritative for anything (see setup.sh). +# Now that ans is up and running with the right data, we make it +# a slave for nil. + +cat <<EOF >>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 <<EOF +/SOA/ +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +/IXFR/ +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +nil. 300 SOA ns.nil. root.nil. 1 300 300 604800 300 +a.nil. 60 A 10.0.0.61 +nil. 300 TXT "initial AXFR" +nil. 300 SOA ns.nil. root.nil. 2 300 300 604800 300 +nil. 300 TXT "successful IXFR" +a.nil. 60 A 10.0.1.61 +nil. 300 SOA ns.nil. root.nil. 2 300 300 604800 300 +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +EOF + +sleep 1 + +$RNDCCMD refresh nil + +sleep 2 + +$DIGCMD nil. TXT | grep 'successful IXFR' >/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 <<EOF +/SOA/ +nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 +/IXFR/ +nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +nil. 300 TXT "delete-nonexistent-txt-record" +nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 +nil. 300 TXT "this-txt-record-would-be-added" +nil. 300 SOA ns.nil. root.nil. 4 300 300 604800 300 +/AXFR/ +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +nil. 300 NS ns.nil. +nil. 300 TXT "fallback AXFR" +nil. 300 SOA ns.nil. root.nil. 3 300 300 604800 300 +EOF + +sleep 1 + +$RNDCCMD refresh nil + +sleep 2 + +$DIGCMD nil. TXT | grep 'fallback AXFR' >/dev/null || { + echo "I:failed" + status=1 +} + +echo "I:exit status: $status" +exit $status |