Skip to content

Commit

Permalink
Merge pull request PowerDNS#3726 from ahupowerdns/getca-netmasks
Browse files Browse the repository at this point in the history
implement getCA() for faster & native IP address extraction in Lua sc…
  • Loading branch information
ahupowerdns committed Apr 18, 2016
2 parents 0a8ea76 + 7d5f094 commit 7510711
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/markdown/recursor/scripting.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ IP addresses are passed to Lua in native format. They can be matched against net
```
nmg = newNMG()
nmg:addMask("127.0.0.0/8")
nmg:addMask({"213.244.168.0/24", "130.161.0.0/16"})
nmg:addMasks({"213.244.168.0/24", "130.161.0.0/16"})
nmg:addMasks(dofile("bad.ips")) -- contains return {"ip1","ip2"..}
if nmg:match(dq.remote) then
print("Intercepting query from ", dq.remote)
Expand Down
16 changes: 16 additions & 0 deletions pdns/lua-recursor4.cc
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ RecursorLua4::RecursorLua4(const std::string& fname)
nmg.addMask(mask);
});

d_lw->registerFunction<void(NetmaskGroup::*)(const vector<pair<unsigned int, std::string>>&)>("addMasks", [](NetmaskGroup&nmg, const vector<pair<unsigned int, std::string>>& masks)
{
for(const auto& mask: masks)
nmg.addMask(mask.second);
});


d_lw->registerFunction("match", (bool (NetmaskGroup::*)(const ComboAddress&) const)&NetmaskGroup::match);
d_lw->registerFunction<string(DNSName::*)()>("toString", [](const DNSName&dn ) { return dn.toString(); });
d_lw->registerFunction<string(DNSName::*)()>("toStringNoDot", [](const DNSName&dn ) { return dn.toStringNoDot(); });
Expand Down Expand Up @@ -313,6 +320,15 @@ RecursorLua4::RecursorLua4(const std::string& fname)


d_lw->registerFunction<string(DNSRecord::*)()>("getContent", [](const DNSRecord& dr) { return dr.d_content->getZoneRepresentation(); });
d_lw->registerFunction<boost::optional<ComboAddress>(DNSRecord::*)()>("getCA", [](const DNSRecord& dr) {
boost::optional<ComboAddress> ret;

if(auto rec = std::dynamic_pointer_cast<ARecordContent>(dr.d_content))
ret=rec->getCA(53);
else if(auto rec = std::dynamic_pointer_cast<AAAARecordContent>(dr.d_content))
ret=rec->getCA(53);
return ret;
});


d_lw->registerFunction<void(DNSRecord::*)(const std::string&)>("changeContent", [](DNSRecord& dr, const std::string& newContent) { dr.d_content = shared_ptr<DNSRecordContent>(DNSRecordContent::mastermake(dr.d_type, 1, newContent)); });
Expand Down

0 comments on commit 7510711

Please sign in to comment.