Skip to content

Instantly share code, notes, and snippets.

@ahupowerdns
Last active November 11, 2016 19:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ahupowerdns/4f73a60836c5790a4037 to your computer and use it in GitHub Desktop.
-- load this and the previous snippet as 'lua-dns-script=macfilter.lua'
function macPrint(a)
return string.format("%02x:%02x:%02x:%02x:%02x:%02x", a:byte(1), a:byte(2), a:byte(3), a:byte(4), a:byte(5), a:byte(6))
end
function preresolve(dq)
print("Got question for "..dq.qname:toString().." from "..dq.remoteaddr:toString().." to "..dq.localaddr:toString())
local a=dq:getEDNSOption(65001)
if(a ~= nil) then
print("There is an EDNS option 65001 present: "..macPrint(a))
if(filter[dq.remoteaddr:toString()][macPrint(a)] and baddomains:check(dq.qname)) then
print("Wanted filtering")
dq:addAnswer(pdns.CNAME, "blockingserver.powerdns.com")
return true
end
-- an obvious enhancement is to implement a 'default' mac address describing the default
-- filtering an IP address wants
end
return false
end
@pdifeo
Copy link

pdifeo commented Nov 11, 2016

Hi,

I'm a PowerDNS newbie, and after many time of work on your script I realize that there is missing code after

dq:addAnswer(pdns.CNAME, "blockingserver.powerdns.com")

Maybe 2 lines of code must be inserted

dq.rcode = 0
dq.followupFunction="followCNAMERecords"

Please, tell me if this is correct or no.

Regards
Pasquale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment