From: bert hubert Date: Mon, 21 Dec 2015 19:45:01 +0000 (+0000) Subject: it turns out, we could not simply compare DNSNames in Lua. Now we can, but it is... X-Git-Tag: dnsdist-1.0.0-alpha1~45^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F3060%2Fhead;p=thirdparty%2Fpdns.git it turns out, we could not simply compare DNSNames in Lua. Now we can, but it is ugly. --- diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index d4352c60f7..a4232c563b 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -158,7 +158,11 @@ RecursorLua4::RecursorLua4(const std::string& fname) { d_lw = new LuaContext; d_lw->writeFunction("newDN", [](const std::string& dom){ return DNSName(dom); }); - d_lw->registerFunction("isPartOf", &DNSName::isPartOf); + d_lw->registerFunction("isPartOf", &DNSName::isPartOf); + d_lw->registerFunction("equal", + [](const DNSName& lhs, const std::string& rhs) { return lhs==DNSName(rhs); }); + d_lw->registerFunction("__eq", &DNSName::operator==); + d_lw->registerFunction("toString", [](const ComboAddress& ca) { return ca.toString(); }); d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); }); d_lw->writeFunction("newNMG", []() { return NetmaskGroup(); }); diff --git a/pdns/powerdns-example-script.lua b/pdns/powerdns-example-script.lua index 7c4ce2e96b..cda9e81c20 100644 --- a/pdns/powerdns-example-script.lua +++ b/pdns/powerdns-example-script.lua @@ -9,11 +9,26 @@ dropset:add("123.cn") malwareset = newDS() malwareset:add("nl") +magic2 = newDN("www.magic2.com") + -- shows the various ways of blocking, dropping, changing questions -- return false to say you did not take over the question, but we'll still listen to 'variable' -- to selectively disable the cache function preresolve(dq) print("Got question for "..dq.qname:toString()) + + -- note that the comparisons below are CaSe InSensiTivE and you don't have to worry about trailing dots + if(dq.qname:equal("magic.com")) + then + print("Magic!") + else + print("not magic..") + end + + if(dq.qname:__eq(magic2)) -- we hope to improve this syntax + then + print("Faster magic") -- compares against existing DNSName + end -- sadly, dq.qname == magic2 won't work yet if blockset:check(dq.qname) then dq.variable = true -- disable packet cache in any case