]> git.ipfire.org Git - thirdparty/pdns.git/blob - modules/pipebackend/backend-v5.pl
dnsdist: Handle EAGAIN when reading from the non-blocking TCP pipe
[thirdparty/pdns.git] / modules / pipebackend / backend-v5.pl
1 #!/usr/bin/perl -w
2 # sample PowerDNS Coprocess backend with edns-client-subnet support
3 #
4
5 use strict;
6
7
8 $|=1; # no buffering
9
10 my $line=<>;
11 chomp($line);
12
13 unless($line eq "HELO\t5" ) {
14 print "FAIL\n";
15 print STDERR "Received unexpected '$line', wrong ABI version?\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
27 if ($arr[0] eq "CMD") {
28 print $arr[1],"\n";
29 print "END\n";
30 next;
31 }
32
33 if(@arr < 8) {
34 print "LOG PowerDNS sent unparseable line\n";
35 print "FAIL\n";
36 next;
37 }
38
39 my ($type,$qname,$qclass,$qtype,$id,$ip,$localip,$ednsip)=split(/\t/);
40 my $bits=21;
41 my $auth = 1;
42
43 if(($qtype eq "SOA" || $qtype eq "ANY") && $qname eq "example.com") {
44 print STDERR "$$ Sent SOA records\n";
45 print "DATA $bits $auth $qname $qclass SOA 3600 -1 ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600\n";
46 }
47 if(($qtype eq "NS" || $qtype eq "ANY") && $qname eq "example.com") {
48 print STDERR "$$ Sent NS records\n";
49 print "DATA $bits $auth $qname $qclass NS 3600 -1 ns1.example.com\n";
50 print "DATA $bits $auth $qname $qclass NS 3600 -1 ns2.example.com\n";
51 }
52 if(($qtype eq "TXT" || $qtype eq "ANY") && $qname eq "example.com") {
53 print STDERR "$$ Sent TXT records\n";
54 print "DATA $bits $auth $qname $qclass TXT 3600 -1 \"hallo allemaal!\"\n";
55 }
56 if(($qtype eq "A" || $qtype eq "ANY") && $qname eq "webserver.example.com") {
57 print STDERR "$$ Sent A records\n";
58 print "DATA $bits $auth $qname $qclass A 3600 -1 1.2.3.4\n";
59 print "DATA $bits $auth $qname $qclass A 3600 -1 1.2.3.5\n";
60 print "DATA $bits $auth $qname $qclass A 3600 -1 1.2.3.6\n";
61 }
62 if(($qtype eq "CNAME" || $qtype eq "ANY") && $qname eq "www.example.com") {
63 print STDERR "$$ Sent CNAME records\n";
64 print "DATA $bits $auth $qname $qclass CNAME 3600 -1 webserver.example.com\n";
65 }
66 if(($qtype eq "MX" || $qtype eq "ANY") && $qname eq "example.com") {
67 print STDERR "$$ Sent MX records\n";
68 print "DATA $bits $auth $qname $qclass MX 3600 -1 25 smtp.powerdns.com\n";
69 }
70
71 print STDERR "$$ End of data\n";
72 print "END\n";
73 }
74