This appendix lists several of the available backends in more detail
Questions come in over a filedescriptor, by default standard input. Answers are sent out over another filedescriptor, standard output by default.
PowerDNS sends out 'HELO\t1', indicating that it wants to speak the protocol as defined in this document, version 1. A PowerDNS CoProcess must then send out a banner, prefixed by 'OK\t', indicating it launched successfully. If it does not support the indicated version, it should respond with FAIL, but not exit. Suggested behaviour is to try and read a further line, and wait to be terminated.
Questions come in three forms and are prefixed by a tag indicating the kind:
Regular queries
List requests, which mean that an entire zone should be listed
Check if the coprocess is functioning
type qname qclass qtype id ip-addressFields are tab separated, and terminated with a single \n. Type is the tag above, qname is the domain the question is about. qclass is always 'IN' currently, denoting an INternet question. qtype is the kind of information desired, the record type, like A, CNAME or AAAA. id can be specified to help your backend find an answer if the id is already known from an earlier query. You can ignore it. ip-address is the ip-address of the nameserver asking the question.
Each answer starts with a tag, possibly followed by a TAB and more data.
Indicating a succesful line of DATA
Indicating the end of an answer - no further data
Indicating a lookup failure. Also serves as 'END'. No further data.
For specifying things that should be logged. Can only be sent after a query and before an END line. After the tab, the message to be logged
DATA qname qclass qtype ttl id contentA sample dialogue may look like this:
Q www.ds9a.nl IN CNAME -1 213.244.168.210 DATA www.ds9a.nl IN CNAME 3600 1 ws1.ds9a.nl Q ws1.ds9a.nl IN CNAME -1 213.244.168.210 END Q wd1.ds9a.nl IN A -1 213.244.168.210 DATA ws1.ds9a.nl IN A 3600 1 1.2.3.4 DATA ws1.ds9a.nl IN A 3600 1 1.2.3.5 DATA ws1.ds9a.nl IN A 3600 1 1.2.3.6 ENDThis would correspond to a remote webserver 213.244.168.210 wanting to resolve the IP address of www.ds9a.nl, and PowerDNS traversing the CNAMEs to find the IP addresses of ws1.ds9a.nl Another dialogue might be:
Q ds9a.nl IN SOA -1 213.244.168.210 DATA ds9a.nl IN SOA 86400 1 ahu.ds9a.nl ... END AXFR 1 DATA ds9a.nl IN SOA 86400 1 ahu.ds9a.nl ... DATA ds9a.nl IN NS 86400 1 ns1.ds9a.nl DATA ds9a.nl IN NS 86400 1 ns2.ds9a.nl DATA ns1.ds9a.nl IN A 86400 1 213.244.168.210 DATA ns2.ds9a.nl IN A 86400 1 63.123.33.135 . . ENDThis is a typical zone transfer.
#!/usr/bin/perl -w # sample PowerDNS Coprocess backend # use strict; $|=1; # no buffering my $line=<>; chomp($line); unless($line eq "HELO\t1") { print "FAIL\n"; print STDERR "Recevied '$line'\n"; <<>;; exit; } print "OK Sample backend firing up\n"; # print our banner while(<>) { # print STDERR "$$ Received: $_"; chomp(); my @arr=split(/\t/); if(@arr<6) { print "LOG PowerDNS sent unparseable line\n"; print "FAIL\n"; next; } my ($type,$qname,$qclass,$qtype,$id,$ip)=split(/\t/); if($qtype eq "A" && $qname eq "webserver.example.com") { # print STDERR "$$ Sent A records\n"; print "DATA $qname $qclass $qtype 3600 -1 1.2.3.4\n"; print "DATA $qname $qclass $qtype 3600 -1 1.2.3.5\n"; print "DATA $qname $qclass $qtype 3600 -1 1.2.3.6\n"; } elsif($qtype eq "CNAME" && $qname eq "www.example.com") { # print STDERR "$$ Sent CNAME records\n"; print "DATA $qname $qclass CNAME 3600 -1 webserver.example.com\n"; } elsif($qtype eq "MBOXFW") { # print STDERR "$$ Sent MBOXFW records\n"; print "DATA $qname $qclass MBOXFW 3600 -1 powerdns\@example.com\n"; } # print STDERR "$$ End of data\n"; print "END\n"; }