From 4465e9413a75ba9576f6bfb55df95553504c37cd Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 15 Oct 2015 14:02:49 +0200 Subject: [PATCH] its a wip --- pdns/dumresp.cc | 17 +++++++++------ pdns/lua-pdns.cc | 4 +++- pdns/lua-pdns.hh | 3 ++- pdns/lua-recursor.cc | 51 +++++++++++++++++++++++++++++++++++++++++-- pdns/lua-recursor.hh | 2 +- pdns/misc.cc | 6 +++++ pdns/pdns_recursor.cc | 51 +++++++++++++++++++++++++++++++++++++++++++ pdns/sstuff.hh | 18 ++++++++++----- pdns/syncres.cc | 1 + 9 files changed, 136 insertions(+), 17 deletions(-) diff --git a/pdns/dumresp.cc b/pdns/dumresp.cc index 679dc1b95..02d08652f 100644 --- a/pdns/dumresp.cc +++ b/pdns/dumresp.cc @@ -10,18 +10,18 @@ StatBag S; int main(int argc, char** argv) try { - if(argc != 3) { - cerr<<"Syntax: dumresp local-address number-of-threads"<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/lua-pdns.cc b/pdns/lua-pdns.cc index 99f77504a..e7c07dccd 100644 --- a/pdns/lua-pdns.cc +++ b/pdns/lua-pdns.cc @@ -38,6 +38,7 @@ extern "C" { #include "logger.hh" #include "namespaces.hh" #include "dnsparser.hh" +#undef L bool netmaskMatchTable(lua_State* lua, const std::string& ip) { @@ -83,6 +84,8 @@ static bool getFromTable(lua_State *lua, const std::string &key, uint32_t& value return ret; } + + void pushResourceRecordsTable(lua_State* lua, const vector& records) { // make a table of tables @@ -363,7 +366,6 @@ bool PowerDNSLua::getFromTable(const std::string& key, uint32_t& value) return ::getFromTable(d_lua, key, value); } - PowerDNSLua::~PowerDNSLua() { lua_close(d_lua); diff --git a/pdns/lua-pdns.hh b/pdns/lua-pdns.hh index 86125d699..f5a6ba5c7 100644 --- a/pdns/lua-pdns.hh +++ b/pdns/lua-pdns.hh @@ -1,8 +1,8 @@ #ifndef PDNS_LUA_PDNS_HH #define PDNS_LUA_PDNS_HH + #include "dns.hh" #include "iputils.hh" - struct lua_State; class PowerDNSLua @@ -26,6 +26,7 @@ protected: // FIXME? bool passthrough(const string& func, const ComboAddress& remote,const ComboAddress& local, const string& query, const QType& qtype, vector& ret, int& res, bool* variable); bool getFromTable(const std::string& key, std::string& value); bool getFromTable(const std::string& key, uint32_t& value); + ComboAddress d_local; bool d_failed; bool d_variable; diff --git a/pdns/lua-recursor.cc b/pdns/lua-recursor.cc index 3c25a7f70..8aba70b28 100644 --- a/pdns/lua-recursor.cc +++ b/pdns/lua-recursor.cc @@ -66,7 +66,7 @@ extern "C" { #include "namespaces.hh" #include "rec_channel.hh" #include "dnsrecords.hh" - +#undef L static int getRegisteredNameLua(lua_State *L) { const char *name = luaL_checkstring(L, 1); string regname=getRegisteredName(DNSName(name)).toString(); // hnnggg @@ -107,6 +107,7 @@ int followCNAMERecords(vector& ret, const QType& qtype) } + int getFakeAAAARecords(const std::string& qname, const std::string& prefix, vector& ret) { int rcode=directResolve(qname, QType(QType::A), 1, ret); @@ -227,6 +228,21 @@ bool RecursorLua::ipfilter(const ComboAddress& remote, const ComboAddress& local return newres != -1; } +static bool getFromTable(lua_State *lua, const std::string &key, lua_CFunction& value) +{ + lua_pushstring(lua, key.c_str()); // 4 is now '1' + lua_gettable(lua, -2); // replace by the first entry of our table we hope + + bool ret=false; + + if(lua_isfunction(lua, -1)) { + value = lua_tocfunction(lua, -1); + ret=true; + } + lua_pop(lua, 1); + return ret; +} + bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, const ComboAddress& local, const DNSName& query, const QType& qtype, vector& ret, int& res, bool* variable) @@ -281,7 +297,38 @@ 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(); - if(tocall == "getFakeAAAARecords") { + cerr<<"tocall: "<> vec; + vec.push_back(make_unique(12)); +} + int writen2(int fd, const void *buf, size_t count) { const char *ptr = (char*)buf; diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index a0632736a..1aa506437 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -230,6 +230,57 @@ int arecvtcp(string& data, int len, Socket* sock, bool incompleteOkay) return ret; } +void handleUDPQueryResponse(int fd, FDMultiplexer::funcparam_t& var) +{ + cerr<<"In handle UDPQueryResponse"<(&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)<waitEvent(pident,&data, g_networkTimeoutMsec); + cerr<<"Got back: "<