2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

use new packet for response; rename variable to request and response

This commit is contained in:
Mark Andrews
2018-10-31 16:14:43 +11:00
parent 5794c78159
commit 280d0ca507

View File

@@ -44,39 +44,42 @@ $SIG{TERM} = \&rmpid;
sub handleUDP { sub handleUDP {
my ($buf) = @_; my ($buf) = @_;
my $packet; my $request;
if ($Net::DNS::VERSION > 0.68) { if ($Net::DNS::VERSION > 0.68) {
$packet = new Net::DNS::Packet(\$buf, 0); $request = new Net::DNS::Packet(\$buf, 0);
$@ and die $@; $@ and die $@;
} else { } else {
my $err; my $err;
($packet, $err) = new Net::DNS::Packet(\$buf, 0); ($request, $err) = new Net::DNS::Packet(\$buf, 0);
$err and die $err; $err and die $err;
} }
my @questions = $packet->question; my @questions = $request->question;
my $qname = $questions[0]->qname; my $qname = $questions[0]->qname;
my $qtype = $questions[0]->qtype; my $qtype = $questions[0]->qtype;
my $qclass = $questions[0]->qclass; my $qclass = $questions[0]->qclass;
my $id = $packet->header->id; my $id = $request->header->id;
$packet->header->qr(1); my $response = new Net::DNS::Packet($qname, $qtype, $qclass);
$packet->header->aa(1); $response->header->qr(1);
$packet->header->tc(0); $response->header->aa(1);
$response->header->tc(0);
$response->header->id($id);
# Responses to queries for no-questions/NS and ns.no-questions/A are # Responses to queries for no-questions/NS and ns.no-questions/A are
# _not_ malformed or truncated. # _not_ malformed or truncated.
if ($qname eq "no-questions" && $qtype eq "NS") { if ($qname eq "no-questions" && $qtype eq "NS") {
$packet->push("answer", new Net::DNS::RR($qname . " 300 NS ns.no-questions")); $response->push("answer", new Net::DNS::RR($qname . " 300 NS ns.no-questions"));
$packet->push("additional", new Net::DNS::RR("ns.no-questions. 300 A 10.53.0.8")); $response->push("additional", new Net::DNS::RR("ns.no-questions. 300 A 10.53.0.8"));
return $packet->data; return $response->data;
} elsif ($qname eq "ns.no-questions") { } elsif ($qname eq "ns.no-questions") {
$packet->push("answer", new Net::DNS::RR($qname . " 300 A 10.53.0.8")); $response->push("answer", new Net::DNS::RR($qname . " 300 A 10.53.0.8"))
return $packet->data; if ($qtype eq "A");
return $response->data;
} elsif ($qname =~ /\.formerr-to-all$/) { } elsif ($qname =~ /\.formerr-to-all$/) {
$packet->header->rcode("FORMERR"); $response->header->rcode("FORMERR");
return $packet->data; return $response->data;
} }
# don't use Net::DNS to construct the header only reply as early # don't use Net::DNS to construct the header only reply as early
@@ -110,14 +113,14 @@ sub handleTCP {
my $id = $request->header->id; my $id = $request->header->id;
my @results = (); my @results = ();
my $packet = new Net::DNS::Packet($qname, $qtype, $qclass); my $response = new Net::DNS::Packet($qname, $qtype, $qclass);
$packet->header->qr(1); $response->header->qr(1);
$packet->header->aa(1); $response->header->aa(1);
$packet->header->id($id); $response->header->id($id);
$packet->push("answer", new Net::DNS::RR("$qname 300 A 1.2.3.4")); $response->push("answer", new Net::DNS::RR("$qname 300 A 1.2.3.4"));
push(@results, $packet->data); push(@results, $response->data);
return \@results; return \@results;
} }