Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-- 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

This comment has been minimized.

Copy link

@pdifeo 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