From: Nicki Křížek Date: Fri, 28 Nov 2025 10:19:24 +0000 (+0100) Subject: Replace digdelv/ans7 with AsyncDnsServer X-Git-Tag: v9.21.18~32^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c50a7d2de198a83692d144e5b5b7e4394e1563a9;p=thirdparty%2Fbind9.git Replace digdelv/ans7 with AsyncDnsServer ans7 server always replies with an UPDATE opcode in the message. --- diff --git a/bin/tests/system/digdelv/ans7/ans.pl b/bin/tests/system/digdelv/ans7/ans.pl deleted file mode 100755 index a7aa60eb9da..00000000000 --- a/bin/tests/system/digdelv/ans7/ans.pl +++ /dev/null @@ -1,68 +0,0 @@ -#!/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); -} diff --git a/bin/tests/system/digdelv/ans7/ans.py b/bin/tests/system/digdelv/ans7/ans.py new file mode 100644 index 00000000000..77e71415907 --- /dev/null +++ b/bin/tests/system/digdelv/ans7/ans.py @@ -0,0 +1,40 @@ +# 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() diff --git a/bin/tests/system/digdelv/tests.sh b/bin/tests/system/digdelv/tests.sh index aa49344ee67..ec356dc7f40 100644 --- a/bin/tests/system/digdelv/tests.sh +++ b/bin/tests/system/digdelv/tests.sh @@ -71,72 +71,44 @@ NOSPLIT="$(sed /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 <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 <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)"