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(),".232.10.in-addr.arpa."))
        then
                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.followupFunction="followCNAMERecords"
                dq:addAnswer(pdns.TXT, "\"Source PTR "..newptr.."\"", 3600)

                return true;
        end

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 y.x.15.10.in-addr.arpa 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:
23.10.232.10.in-addr.arpa. 3590 IN CNAME 23.10.51.10.in-addr.arpa.
23.10.51.10.in-addr.arpa. 1190 IN PTR server.domain.com.
23.10.232.10.in-addr.arpa. 3590 IN TXT "Source PTR 23.10.51.10.in-addr.arpa."

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!

Thanks=
David
_______________________________________________
Pdns-users mailing list
[hidden email]
http://mailman.powerdns.com/mailman/listinfo/pdns-users