+++ /dev/null
-#!/usr/bin/perl -w
-
-# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
-#
-# SPDX-License-Identifier: MPL-2.0
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, you can obtain one at https://mozilla.org/MPL/2.0/.
-#
-# See the COPYRIGHT file distributed with this work for additional
-# information regarding copyright ownership.
-
-use IO::File;
-use IO::Socket;
-use Net::DNS;
-use Net::DNS::Packet;
-
-my $localport = int($ENV{'PORT'});
-if (!$localport) { $localport = 5300; }
-
-my $sock = IO::Socket::INET->new(LocalAddr => "10.53.0.7",
- LocalPort => $localport, Proto => "udp") 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;
-
-STDOUT->autoflush(1);
-
-print "Net::DNS::VERSION => $Net::DNS::VERSION\n";
-
-for (;;) {
- $sock->recv($buf, 512);
-
- print "**** request from " , $sock->peerhost, " port ", $sock->peerport, "\n";
-
- my $packet;
-
- if ($Net::DNS::VERSION > 0.68) {
- $packet = new Net::DNS::Packet(\$buf, 0);
- $@ and die $@;
- } else {
- my $err;
- ($packet, $err) = new Net::DNS::Packet(\$buf, 0);
- $err and die $err;
- }
-
- print "REQUEST:\n";
- $packet->print;
-
- $packet->header->qr(1);
- $packet->header->opcode(5);
-
- my @questions = $packet->question;
- my $qname = $questions[0]->qname;
- my $qtype = $questions[0]->qtype;
- $packet->push("update", rr_del("$qname SOA"));
-
- print "RESPONSE:\n";
- $packet->print;
-
- $sock->send($packet->data);
-}
--- /dev/null
+# Copyright (C) Internet Systems Consortium, Inc. ("ISC")
+#
+# SPDX-License-Identifier: MPL-2.0
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, you can obtain one at https://mozilla.org/MPL/2.0/.
+#
+# See the COPYRIGHT file distributed with this work for additional
+# information regarding copyright ownership.
+
+from typing import AsyncGenerator
+
+import dns.opcode
+import dns.rcode
+
+from isctest.asyncserver import (
+ AsyncDnsServer,
+ DnsResponseSend,
+ ResponseHandler,
+ QueryContext,
+)
+
+
+class ReplyUpdateHandler(ResponseHandler):
+ async def get_responses(
+ self, qctx: QueryContext
+ ) -> AsyncGenerator[DnsResponseSend, None]:
+ qctx.response.set_opcode(dns.opcode.UPDATE)
+ yield DnsResponseSend(qctx.response)
+
+
+def main() -> None:
+ server = AsyncDnsServer(default_aa=True, default_rcode=dns.rcode.NOERROR)
+ server.install_response_handler(ReplyUpdateHandler())
+ server.run()
+
+
+if __name__ == "__main__":
+ main()
HAS_PYYAML=0
$PYTHON -c "import yaml" 2>/dev/null && HAS_PYYAML=1
-#
-# test whether ans7/ans.pl will be able to send a UPDATE response.
-# if it can't, we will log that below.
-#
-if "$PERL" -e 'use Net::DNS; use Net::DNS::Packet; my $p = new Net::DNS::Packet; $p->header->opcode(5);' >/dev/null 2>&1; then
- checkupdate=1
-else
- checkupdate=0
-fi
-
-if [ -x "$NSLOOKUP" -a $checkupdate -eq 1 ]; then
-
- n=$((n + 1))
- echo_i "check nslookup handles UPDATE response ($n)"
- ret=0
- "$NSLOOKUP" -q=CNAME -timeout=1 "-port=$PORT" foo.bar 10.53.0.7 >nslookup.out.test$n 2>&1 && ret=1
- grep "Opcode mismatch" nslookup.out.test$n >/dev/null || ret=1
- if [ $ret -ne 0 ]; then echo_i "failed"; fi
- status=$((status + ret))
-
-fi
-
-if [ -x "$HOST" -a $checkupdate -eq 1 ]; then
-
- n=$((n + 1))
- echo_i "check host handles UPDATE response ($n)"
- ret=0
- "$HOST" -W 1 -t CNAME -p $PORT foo.bar 10.53.0.7 >host.out.test$n 2>&1 && ret=1
- grep "Opcode mismatch" host.out.test$n >/dev/null || ret=1
- if [ $ret -ne 0 ]; then echo_i "failed"; fi
- status=$((status + ret))
-
-fi
-
-if [ -x "$NSUPDATE" -a $checkupdate -eq 1 ]; then
-
- n=$((n + 1))
- echo_i "check nsupdate handles UPDATE response to QUERY ($n)"
- ret=0
- res=0
- $NSUPDATE <<EOF >nsupdate.out.test$n 2>&1 || res=$?
+n=$((n + 1))
+echo_i "check nslookup handles UPDATE response ($n)"
+ret=0
+"$NSLOOKUP" -q=CNAME -timeout=1 "-port=$PORT" foo.bar 10.53.0.7 >nslookup.out.test$n 2>&1 && ret=1
+grep "Opcode mismatch" nslookup.out.test$n >/dev/null || ret=1
+if [ $ret -ne 0 ]; then echo_i "failed"; fi
+status=$((status + ret))
+
+n=$((n + 1))
+echo_i "check host handles UPDATE response ($n)"
+ret=0
+"$HOST" -W 1 -t CNAME -p $PORT foo.bar 10.53.0.7 >host.out.test$n 2>&1 && ret=1
+grep "Opcode mismatch" host.out.test$n >/dev/null || ret=1
+if [ $ret -ne 0 ]; then echo_i "failed"; fi
+status=$((status + ret))
+
+n=$((n + 1))
+echo_i "check nsupdate handles UPDATE response to QUERY ($n)"
+ret=0
+res=0
+$NSUPDATE <<EOF >nsupdate.out.test$n 2>&1 || res=$?
server 10.53.0.7 ${PORT}
add x.example.com 300 in a 1.2.3.4
send
EOF
- test $res -eq 1 || ret=1
- grep "invalid OPCODE in response to SOA query" nsupdate.out.test$n >/dev/null || ret=1
- if [ $ret -ne 0 ]; then echo_i "failed"; fi
- status=$((status + ret))
-
-fi
+test $res -eq 1 || ret=1
+grep "invalid OPCODE in response to SOA query" nsupdate.out.test$n >/dev/null || ret=1
+if [ $ret -ne 0 ]; then echo_i "failed"; fi
+status=$((status + ret))
if [ -x "$DIG" ]; then
-
- if [ $checkupdate -eq 1 ]; then
-
- n=$((n + 1))
- echo_i "check dig handles UPDATE response ($n)"
- ret=0
- dig_with_opts @10.53.0.7 +tries=1 +timeout=1 cname foo.bar >dig.out.test$n 2>&1 && ret=1
- grep "Opcode mismatch" dig.out.test$n >/dev/null || ret=1
- if [ $ret -ne 0 ]; then echo_i "failed"; fi
- status=$((status + ret))
- else
- echo_i "Skipped UPDATE handling test"
- fi
+ n=$((n + 1))
+ echo_i "check dig handles UPDATE response ($n)"
+ ret=0
+ dig_with_opts @10.53.0.7 +tries=1 +timeout=1 cname foo.bar >dig.out.test$n 2>&1 && ret=1
+ grep "Opcode mismatch" dig.out.test$n >/dev/null || ret=1
+ if [ $ret -ne 0 ]; then echo_i "failed"; fi
+ status=$((status + ret))
n=$((n + 1))
echo_i "checking dig short form works ($n)"