3 # Copyright (C) 2004, 2007, 2009, 2010, 2012 Internet Systems Consortium, Inc. ("ISC")
4 # Copyright (C) 2000, 2001 Internet Software Consortium.
6 # Permission to use, copy, modify, and/or distribute this software for any
7 # purpose with or without fee is hereby granted, provided that the above
8 # copyright notice and this permission notice appear in all copies.
10 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 # PERFORMANCE OF THIS SOFTWARE.
18 # Id: ans.pl,v 1.15 2010/05/19 09:33:50 tbox Exp
29 my $sock = IO
::Socket
::INET
->new(LocalAddr
=> "10.53.0.2",
30 LocalPort
=> 5300, Proto
=> "udp") or die "$!";
32 my $pidf = new IO
::File
"ans.pid", "w" or die "cannot open pid file: $!";
33 print $pidf "$$\n" or die "cannot write pid file: $!";
34 $pidf->close or die "cannot close pid file: $!";
35 sub rmpid
{ unlink "ans.pid"; exit 1; };
41 $sock->recv($buf, 512);
43 print "**** request from " , $sock->peerhost, " port ", $sock->peerport, "\n";
47 if ($Net::DNS
::VERSION
> 0.68) {
48 $packet = new Net
::DNS
::Packet
(\
$buf, 0);
52 ($packet, $err) = new Net
::DNS
::Packet
(\
$buf, 0);
59 $packet->header->qr(1);
61 my @questions = $packet->question;
62 my $qname = $questions[0]->qname;
63 my $qtype = $questions[0]->qtype;
65 if ($qname eq "cname1.example.com") {
66 # Data for the "cname + other data / 1" test
67 $packet->push("answer", new Net
::DNS
::RR
("cname1.example.com 300 CNAME cname1.example.com"));
68 $packet->push("answer", new Net
::DNS
::RR
("cname1.example.com 300 A 1.2.3.4"));
69 } elsif ($qname eq "cname2.example.com") {
70 # Data for the "cname + other data / 2" test: same RRs in opposite order
71 $packet->push("answer", new Net
::DNS
::RR
("cname2.example.com 300 A 1.2.3.4"));
72 $packet->push("answer", new Net
::DNS
::RR
("cname2.example.com 300 CNAME cname2.example.com"));
73 } elsif ($qname eq "www.example.org" || $qname eq "www.example.net" ||
74 $qname eq "badcname.example.org" ||
75 $qname eq "goodcname.example.org" ||
76 $qname eq "foo.baddname.example.org" ||
77 $qname eq "foo.gooddname.example.org") {
78 # Data for address/alias filtering.
79 $packet->header->aa(1);
81 $packet->push("answer",
82 new Net
::DNS
::RR
($qname .
84 } elsif ($qtype eq "AAAA") {
85 $packet->push("answer",
86 new Net
::DNS
::RR
($qname .
87 " 300 AAAA 2001:db8:beef::1"));
89 } elsif ($qname eq "badcname.example.net" ||
90 $qname eq "goodcname.example.net") {
91 # Data for CNAME/DNAME filtering. We need to make one-level
92 # delegation to avoid automatic acceptance for subdomain aliases
93 $packet->push("authority", new Net
::DNS
::RR
("example.net 300 NS ns.example.net"));
94 $packet->push("additional", new Net
::DNS
::RR
("ns.example.net 300 A 10.53.0.3"));
95 } elsif ($qname =~ /^nodata\.example\.net$/i) {
96 $packet->header->aa(1);
97 } elsif ($qname =~ /^nxdomain\.example\.net$/i) {
98 $packet->header->aa(1);
99 $packet->header->rcode(NXDOMAIN
);
100 } elsif ($qname =~ /sub\.example\.org/) {
101 # Data for CNAME/DNAME filtering. The final answers are
102 # expected to be accepted regardless of the filter setting.
103 $packet->push("authority", new Net
::DNS
::RR
("sub.example.org 300 NS ns.sub.example.org"));
104 $packet->push("additional", new Net
::DNS
::RR
("ns.sub.example.org 300 A 10.53.0.3"));
105 } elsif ($qname =~ /\.broken/) {
106 # Delegation to broken TLD.
107 $packet->push("authority", new Net
::DNS
::RR
("broken 300 NS ns.broken"));
108 $packet->push("additional", new Net
::DNS
::RR
("ns.broken 300 A 10.53.0.4"));
110 # Data for the "bogus referrals" test
111 $packet->push("authority", new Net
::DNS
::RR
("below.www.example.com 300 NS ns.below.www.example.com"));
112 $packet->push("additional", new Net
::DNS
::RR
("ns.below.www.example.com 300 A 10.53.0.3"));
115 $sock->send($packet->data);