From: bert hubert Date: Sun, 18 Oct 2015 10:59:31 +0000 (+0200) Subject: first stab at generic asynchronous lookup engine for Lua, with known crasher bugs... X-Git-Tag: dnsdist-1.0.0-alpha1~262^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fba1e944b2037043d683bea39a63f9b797fdad6a;p=thirdparty%2Fpdns.git first stab at generic asynchronous lookup engine for Lua, with known crasher bugs (see lua-recursor.cc 'PLAIN WRONG') --- diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 8203f0419b..75c2bfc13f 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -109,6 +109,7 @@ EXTRA_PROGRAMS = \ dnstcpbench \ dnswasher \ dumresp \ + kvresp \ notify \ nproxy \ nsec3dig \ @@ -532,6 +533,14 @@ dumresp_SOURCES = \ unix_utility.cc \ qtype.cc +kvresp_SOURCES = \ + dnslabeltext.cc dnsname.cc dnsname.hh \ + kvresp.cc \ + logger.cc \ + misc.cc misc.hh \ + statbag.cc \ + unix_utility.cc \ + qtype.cc saxfr_SOURCES = \ base32.cc \ diff --git a/pdns/dumresp.cc b/pdns/dumresp.cc index 02d08652fd..864f774de1 100644 --- a/pdns/dumresp.cc +++ b/pdns/dumresp.cc @@ -40,12 +40,10 @@ try if(len < 0) unixDie("recvfrom"); cout<<"Had packet: "<qr) continue; dh->qr=1; dh->ad=0; - */ if(sendto(s.getHandle(), buffer, len, 0, (struct sockaddr*)&rem, socklen) < 0) unixDie("sendto"); diff --git a/pdns/kv-example-script.lua b/pdns/kv-example-script.lua new file mode 100644 index 0000000000..f55fbb98c8 --- /dev/null +++ b/pdns/kv-example-script.lua @@ -0,0 +1,45 @@ + +--[[ +This implements a two-step domain filtering solution where the status of an IP address +and a domain name need to be looked up. +To do so, we use the udpQuestionResponse answers which generically allows us to do asynchronous +lookups via UDP. +Such lookups can be slow, they won't block PowerDNS while we wait for them. + +To benefit from this hook, return: "udpQueryResponse", UDP-server, data +from preresolve (or other hooks). +The 'data' third return value should be a table with the query in there, plus the callback +that needs to be called once the data is in. + +We'll add more parameters, like 'timeout' and perhaps 'protocol' as we improve this feature +over time. +--]] + +function preresolve ( remoteip, domain, qtype ) + print ("preresolve handler called for: "..remoteip.. ", local: ".. getlocaladdress()..", ".. domain..", ".. qtype) + return "udpQueryResponse", "127.0.0.1:5555", {query="IP "..remoteip, callback="getipdetails"} +end + +function getipdetails(remoteip, domain, qtype, data) + print("In getipdetails, got ".. data.response.. " from '"..remoteip.."', for '"..remoteip.."'") + data.ipstatus=data.response + data.query="DOMAIN "..domain + data.callback="getdomaindetails" + return "udpQueryResponse", "127.0.0.1:5555", data +end + +function getdomaindetails(remoteip, domain, qtype, data) + print("In getipdetails, got ".. data.response.. " from '"..remoteip.."', for '"..domain.."'") + print("So status of domain is "..data.response.." and status of IP is "..data.ipstatus) + if(data.ipstatus=="1" and data.response=="1") + then + print("IP wants filtering and domain is of the filtered kind") + return 0,{{qtype=pdns.CNAME, content="www.blocked.com", ttl=3602}, + {qname="www.webserver.com", qtype=pdns.A, content="1.2.3.4", ttl=3602}} + else + return pdns.PASS, {} + end +end + + + diff --git a/pdns/kvresp.cc b/pdns/kvresp.cc new file mode 100644 index 0000000000..89ddeaebb6 --- /dev/null +++ b/pdns/kvresp.cc @@ -0,0 +1,56 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "iputils.hh" +#include "sstuff.hh" +#include "statbag.hh" + +StatBag S; + +int main(int argc, char** argv) +try +{ + if(argc != 3) { + cerr<<"Syntax: dumresp local-address local-port"< parts; + stringtok(parts, query); + if(parts.size()<2) + continue; + string response; + if(parts[0]=="DOMAIN") + response= (parts[1].find("xxx") != string::npos) ? "1" : "0"; + else if(parts[0]=="IP") + response= (parts[1]=="127.0.0.1") ? "1" : "0"; + else + response= "???"; + + cout<<"Our reply: "<& ret, int& res, bool* variable) { @@ -289,7 +273,7 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co throw runtime_error(error); return false; } - + loop:; if(variable) *variable |= d_variable; @@ -297,36 +281,37 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co string tocall = lua_tostring(d_lua,1); lua_remove(d_lua, 1); // the name ret.clear(); - cerr<<"tocall: "<(&var); + PacketID pident=*any_cast(&var); char resp[512]; int ret=recv(fd, resp, sizeof(resp), 0); t_fdm->removeReadFD(fd); if(ret >= 0) { string data(resp, ret); - cerr<<"Reporting what we got ('"<sendEvent(*pident, &data)<sendEvent(pident, &data); } else { - cerr<<"Had some kind of error: "<sendEvent(pident, &empty); + // cerr<<"Had some kind of error: "<waitEvent(pident,&data, g_networkTimeoutMsec); - cerr<<"Got back: "<