Search code examples
luadnspowerdns

PowerDNS Scripting - Getting the DNS Query's Unique ID


I'm writing lua scripts for PowerDNS.

I wish to get some kind of a unique ID for each DNS query when my script intercepts a DNS query.

I'm intercepting the DNS queries with the "preresolve" and "postresolve" functions and they don't have any unique ID that will symbolize the current DNS query it's handling.

I saw that when using the function "ipfilter", I can use the GetID() function to get the DNS query ID. This ability is missing in the "preresolve" and "postresolve" functions.

Any ideas?


Solution

  • After upgrading from PDNS Recursor version 3.0 to 4.0 I found my answer.

    In version 4, 'preresolve' and 'postresolve' functions get the dq (DNSQuestion) object, the dq object contains two fields that can help with the query ID.

    One, you can use the original query ID by getting the value from

    dq:getDH():getID()
    

    Two, dq can contain a custom LUA object reference that is persistent throughout the lifetime of the dq object.

    local data={}
    data["domaindetails"]= dq.udpAnswer
    dq.data=data  
    

    Find more details in their Scripting manual: https://doc.powerdns.com/md/recursor/scripting/#the-dnsquestion-dq-object