Remove building with NOCRYPTO option
[minix.git] / external / bsd / bind / dist / bin / tests / system / reclimit / ans2 / ans.pl
blob82bb8749f5b29e79effacea1dc147dd4ff79609d
1 #!/usr/bin/env perl
3 # Copyright (C) 2014 Internet Systems Consortium, Inc. ("ISC")
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
17 use strict;
18 use warnings;
20 use IO::File;
21 use Getopt::Long;
22 use Net::DNS::Nameserver;
24 my $pidf = new IO::File "ans.pid", "w" or die "cannot open pid file: $!";
25 print $pidf "$$\n" or die "cannot write pid file: $!";
26 $pidf->close or die "cannot close pid file: $!";
27 sub rmpid { unlink "ans.pid"; exit 1; };
29 $SIG{INT} = \&rmpid;
30 $SIG{TERM} = \&rmpid;
32 my $count = 0;
33 my $send_response = 0;
35 sub getlimit {
36 if ( -e "ans.limit") {
37 open(FH, "<", "ans.limit");
38 my $line = <FH>;
39 chomp $line;
40 close FH;
41 if ($line =~ /^\d+$/) {
42 return $line;
46 return 0;
49 my $localaddr = "10.53.0.2";
50 my $localport = 5300;
51 my $verbose = 0;
52 my $limit = getlimit();
54 sub reply_handler {
55 my ($qname, $qclass, $qtype, $peerhost, $query, $conn) = @_;
56 my ($rcode, @ans, @auth, @add);
58 print ("request: $qname/$qtype\n");
59 STDOUT->flush();
61 $count += 1;
63 if ($qname eq "count" ) {
64 if ($qtype eq "TXT") {
65 my ($ttl, $rdata) = (0, "$count");
66 my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata");
67 push @ans, $rr;
68 print ("\tcount: $count\n");
70 $rcode = "NOERROR";
71 } elsif ($qname eq "reset" ) {
72 $count = 0;
73 $send_response = 0;
74 $limit = getlimit();
75 $rcode = "NOERROR";
76 print ("\tlimit: $limit\n");
77 } elsif ($qname eq "direct.example.org" ) {
78 if ($qtype eq "A") {
79 my ($ttl, $rdata) = (3600, $localaddr);
80 my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata");
81 push @ans, $rr;
83 $rcode = "NOERROR";
84 } elsif ($qname eq "indirect.example.org") {
85 if (! $send_response) {
86 my $rr = new Net::DNS::RR("indirect.example.org 86400 $qclass NS ns1.1.example.org");
87 push @auth, $rr;
88 } elsif ($qtype eq "A") {
89 my ($ttl, $rdata) = (3600, $localaddr);
90 my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata");
91 push @ans, $rr;
93 $rcode = "NOERROR";
94 } elsif ($qname =~ /^ns1\.(\d+)\.example\.org$/) {
95 my $next = $1 + 1;
96 if ($limit == 0 || (! $send_response && $next <= $limit)) {
97 my $rr = new Net::DNS::RR("$1.example.org 86400 $qclass NS ns1.$next.example.org");
98 push @auth, $rr;
99 } else {
100 $send_response = 1;
101 if ($qtype eq "A") {
102 my ($ttl, $rdata) = (3600, $localaddr);
103 my $rr = new Net::DNS::RR("$qname $ttl $qclass $qtype $rdata");
104 print("\tresponse: $qname $ttl $qclass $qtype $rdata\n");
105 push @ans, $rr;
108 $rcode = "NOERROR";
109 } else {
110 $rcode = "NXDOMAIN";
113 # mark the answer as authoritive (by setting the 'aa' flag
114 return ($rcode, \@ans, \@auth, \@add, { aa => 1 });
117 GetOptions(
118 'port=i' => \$localport,
119 'verbose!' => \$verbose,
122 my $ns = Net::DNS::Nameserver->new(
123 LocalAddr => $localaddr,
124 LocalPort => $localport,
125 ReplyHandler => \&reply_handler,
126 Verbose => $verbose,
129 $ns->main_loop;