0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt# Ad hoc name server
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntmy $sock = IO::Socket::INET->new(LocalAddr => "10.53.0.4",
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntmy $pidf = new IO::File "ans.pid", "w" or die "cannot open pid file: $!";
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Huntprint $pidf "$$\n" or die "cannot write pid file: $!";
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt print "**** request from " , $sock->peerhost, " port ", $sock->peerport, "\n";
03958ad4b9fd6b2d6f1fbf20e85d8ff2a1f9d069Mark Andrews $@ and die $@;
03958ad4b9fd6b2d6f1fbf20e85d8ff2a1f9d069Mark Andrews ($packet, $err) = new Net::DNS::Packet(\$buf, 0);
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt print "REQUEST:\n";
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # Data for the "cname + other data / 1" test
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("answer", new Net::DNS::RR("cname1.example.com 300 CNAME cname1.example.com"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("answer", new Net::DNS::RR("cname1.example.com 300 A 1.2.3.4"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # Data for the "cname + other data / 2" test: same RRs in opposite order
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("answer", new Net::DNS::RR("cname2.example.com 300 A 1.2.3.4"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("answer", new Net::DNS::RR("cname2.example.com 300 CNAME cname2.example.com"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt } elsif ($qname eq "www.example.org" || $qname eq "www.example.net" ||
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # Data for address/alias filtering.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt " 300 A 192.0.2.1"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt " 300 AAAA 2001:db8:beef::1"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # Data for CNAME/DNAME filtering. We need to make one-level
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # delegation to avoid automatic acceptance for subdomain aliases
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("authority", new Net::DNS::RR("example.net 300 NS ns.example.net"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("additional", new Net::DNS::RR("ns.example.net 300 A 10.53.0.3"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # Data for CNAME/DNAME filtering. The final answers are
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # expected to be accepted regardless of the filter setting.
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("authority", new Net::DNS::RR("sub.example.org 300 NS ns.sub.example.org"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("additional", new Net::DNS::RR("ns.sub.example.org 300 A 10.53.0.3"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt # Data for the "bogus referrals" test
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("authority", new Net::DNS::RR("below.www.example.com 300 NS ns.below.www.example.com"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt $packet->push("additional", new Net::DNS::RR("ns.below.www.example.com 300 A 10.53.0.3"));
dd2a0a6d2dec1c23787351e51b434a838dec5603Evan Hunt print "RESPONSE:\n";