]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/pipebackend/backend.pl
dnsdist: Handle EAGAIN when reading from the non-blocking TCP pipe
[thirdparty/pdns.git] / modules / pipebackend / backend.pl
1 #!/usr/bin/perl -w
2 # sample PowerDNS Coprocess backend
3 #
4
5 use strict;
6
7
8 $|=1; # no buffering
9
10 my $line=<>;
11 chomp($line);
12
13 unless($line eq "HELO\t1") {
14 print "FAIL\n";
15 print STDERR "Received '$line'\n";
16 <>;
17 exit;
18 }
19 print "OK Sample backend firing up\n"; # print our banner
20
21 while(<>)
22 {
23 print STDERR "$$ Received: $_";
24 chomp();
25 my @arr=split(/\t/);
26 if(@arr<6) {
27 print "LOG PowerDNS sent unparseable line\n";
28 print "FAIL\n";
29 next;
30 }
31
32 # note! the qname is what PowerDNS asks the backend. It need not be what the internet asked PowerDNS!
33 my ($type,$qname,$qclass,$qtype,$id,$ip)=split(/\t/);
34
35 if(($qtype eq "SOA" || $qtype eq "ANY") && $qname eq "example.com") {
36 print STDERR "$$ Sent SOA records\n";
37 print "DATA $qname $qclass SOA 3600 -1 ns1.example.com ahu.example.com 2008080300 1800 3600 604800 3600\n";
38 }
39 if(($qtype eq "NS" || $qtype eq "ANY") && $qname eq "example.com") {
40 print STDERR "$$ Sent NS records\n";
41 print "DATA $qname $qclass NS 3600 -1 ns1.example.com\n";
42 print "DATA $qname $qclass NS 3600 -1 ns2.example.com\n";
43 }
44 if(($qtype eq "TXT" || $qtype eq "ANY") && $qname eq "example.com") {
45 print STDERR "$$ Sent NS records\n";
46 print "DATA $qname $qclass TXT 3600 -1 \"hallo allemaal!\"\n";
47 }
48 if(($qtype eq "A" || $qtype eq "ANY") && $qname eq "webserver.example.com") {
49 print STDERR "$$ Sent A records\n";
50 print "DATA $qname $qclass A 3600 -1 1.2.3.4\n";
51 print "DATA $qname $qclass A 3600 -1 1.2.3.5\n";
52 print "DATA $qname $qclass A 3600 -1 1.2.3.6\n";
53 }
54 elsif(($qtype eq "CNAME" || $qtype eq "ANY") && $qname eq "www.example.com") {
55 print STDERR "$$ Sent CNAME records\n";
56 print "DATA $qname $qclass CNAME 3600 -1 webserver.example.com\n";
57 }
58
59
60 print STDERR "$$ End of data\n";
61 print "END\n";
62 }
63