Performing recursive lookup within Lua

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Performing recursive lookup within Lua

David Coulson
I have a pretty simple use case - I'm are doing 1:1 NAT for a /16 and need to manipulate A and PTR records to make sure DNS aligns with NAT.

Modifying A records was easy with Lua & powerdns recursor, however PTR is causing some issues.

I’m using this code:

        if (dq.qtype ==pdns.PTR and endswith(dq.qname:toString(),""))
                print("PTR mapping for "..dq.qname:toString())
                local newptr=string.gsub(dq.qname:toString(), ".232.10.i", ".51.10.i")
                dq:addAnswer(pdns.CNAME, newptr)
                dq.rcode = 0
                dq:addAnswer(pdns.TXT, "\"Source PTR "..newptr.."\"", 3600)

                return true;

So basically if we do a DNS lookup for 10.232.x.y it returns the PTR for 10.51.x.y - Simple right?

The issue is that powerdns returns both the CNAME and the PTR, so our upstream DNS server ends up with in it’s cache which conflicts with other 10.51/16 records (which is why we're doing NAT in the first place).

;; ANSWER SECTION: 3590 IN CNAME 1190 IN PTR 3590 IN TXT "Source PTR"

Is there an easy way to get PowerDNS to just return the PTR record, or can I do a query for the 10.51.x.y PTR inside Lua and just respond with that record?

If there is a better way to accomplish what I’m intending, I’m open to suggestions!

Pdns-users mailing list
[hidden email]