PowerDNS didnt get answer from pipe backend

1.2k views Asked by At

I'm trying to write own pipe-backend for powerdns, but can't get it work properly. I'm starting pdn_server with my backend and try to test it with command:

# nslookup example.com 127.0.0.1

and

# dig @127.0.0.1 example.com

First problem is that first query to backend comes with type 'SOA'(backend abi version 2):

Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0

I though 'Ok, lets start from SOA' and try to write part of code. In debug I can see that backend started, did receive query and send answer to pdns. But seems like something goes wrong and pdns didn't get it. Can't figure out whats a problem. Source code and debug is following:

#!/usr/bin/python

from sys import stdin, stdout, stderr

data = stdin.readline()
stdout.write("OK\tCC DNS Backend\n")
stdout.flush()

stderr.write("$$$ Main loop started...\n")

while True:
    line = stdin.readline().strip()

    kind, qname, qclass, qtype, id, ip, mask = line.split('\t')

    if kind == 'Q':
        stderr.write('$$$ Got request ' + qname + '\n')
        if qtype != 'SOA':
            r = "DATA\t'+qname+'\t'+qtype+'\t'+qclass+'\t'+'127.0.0.1\n"
            stderr.write(r)
            stdout.write(r)
        else:
            stderr.write("$$$ Sending SOA\n")
            r = "DATA\texample.com\tIN\tSOA\t86400\t1\tahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600\n"
            stdout.write(r)
            stderr.write(r)

        stdout.write("END\n")
        stderr.write("END\n")

Debug:

Dec 05 15:36:43 Done launching threads, ready to distribute questions
Dec 05 15:36:49 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
$$$ Main loop started...
Dec 05 15:36:49 Backend launched with banner: OK    CC DNS Backend
$$$ Main loop started...
Dec 05 15:36:49 Backend launched with banner: OK    CC DNS Backend
Dec 05 15:36:54 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
Dec 05 15:36:59 Query: 'Q   example.com IN  SOA -1  127.0.0.1   0.0.0.0'
$$$ Got request example.com
$$$ Sending SOA
DATA    example.com IN  SOA 86400   1   ahu.example.com ns1.example.com 2008080300 1800 3600 604800 3600
END
1

There are 1 answers

0
dtoch On

The problem was in buffered input-output of python. Mailing list users gave the answer - change line:

#!/usr/bin/python

to

#!/usr/bin/python -u

'-u' disable buffering.