]> granicus.if.org Git - pdns/commitdiff
move recursor to LuaWrapper based new API for blocking, changing etc of queries....
authorbert hubert <bert.hubert@netherlabs.nl>
Fri, 18 Dec 2015 08:14:05 +0000 (09:14 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Fri, 18 Dec 2015 08:14:05 +0000 (09:14 +0100)
build-scripts/dist-recursor
pdns/Makefile-recursor
pdns/Makefile.am
pdns/lua-pdns.hh
pdns/lua-recursor.cc
pdns/lua-recursor4.cc
pdns/lua-recursor4.hh
pdns/pdns_recursor.cc
pdns/syncres.hh

index ae6450129ad334466d9f9f0f3e70d91cbe789ad9..1d547c89f9887d8fd717195892061da6e8370df4 100755 (executable)
@@ -32,7 +32,7 @@ rcpgenerator.hh lock.hh dnswriter.hh  dnsrecords.hh dnsparser.hh utility.hh \
 recursor_cache.hh rec_channel.hh qtype.hh misc.hh dns.hh syncres.hh \
 sstuff.hh mtasker.hh mtasker.cc lwres.hh logger.hh pdnsexception.hh \
 mplexer.hh pubsuffix.hh mbedtlscompat.hh \
-dns_random.hh lua-pdns.hh lua-recursor.hh namespaces.hh \
+dns_random.hh lua-recursor4.hh namespaces.hh \
 recpacketcache.hh base32.hh cachecleaner.hh json.hh version.hh \
 ws-recursor.hh ws-api.hh secpoll-recursor.hh \
 responsestats.hh webserver.hh dnsname.hh dnspacket.hh ednssubnet.hh \
@@ -41,11 +41,11 @@ dnsseckeeper.hh statbag.hh ueberbackend.hh sha.hh dnsbackend.hh comment.hh \
 validate.hh validate-recursor.hh sortlist.hh rec-lua-conf.hh sholder.hh"
 
 CFILES="syncres.cc iputils.cc  misc.cc unix_utility.cc qtype.cc \
-logger.cc arguments.cc  lwres.cc pdns_recursor.cc lua-iputils.cc \
+logger.cc arguments.cc  lwres.cc pdns_recursor.cc \
 recursor_cache.cc  dnsparser.cc dnswriter.cc  dnsrecords.cc  rcpgenerator.cc  \
 base64.cc  zoneparser-tng.cc  rec_channel.cc rec_channel_rec.cc rec_control.cc \
 selectmplexer.cc epollmplexer.cc kqueuemplexer.cc portsmplexer.cc pdns_hw.cc \
-sillyrecords.cc pubsuffix.cc lua-pdns.cc lua-recursor.cc randomhelper.cc \
+sillyrecords.cc pubsuffix.cc lua-recursor4.cc randomhelper.cc \
 devpollmplexer.cc recpacketcache.cc dns.cc reczones.cc base32.cc nsecrecords.cc \
 dnslabeltext.cc json.cc ws-recursor.cc ws-api.cc version.cc dns_random.cc \
 responsestats.cc webserver.cc rec-carbon.cc secpoll-recursor.cc dnsname.cc \
index d32a8a80462609007d1e3a06e0a8d7ea14504796..e1edefa2f5c96ff9e67328b3ed6401074c6fff42 100644 (file)
@@ -27,10 +27,10 @@ ext/mbedtls/library/ripemd160.o ext/mbedtls/library/rsa.o \
 ext/mbedtls/library/bignum.o ext/mbedtls/library/oid.o ext/mbedtls/library/asn1parse.o  \
 ext/mbedtls/library/ctr_drbg.o ext/mbedtls/library/entropy.o ext/mbedtls/library/entropy_poll.o\
 ext/mbedtls/library/timing.o \
-lua-pdns.o lua-recursor.o randomhelper.o recpacketcache.o dns.o \
+lua-recursor4.o randomhelper.o recpacketcache.o dns.o \
 reczones.o base32.o nsecrecords.o json.o ws-recursor.o ws-api.o \
 version.o responsestats.o webserver.o ext/yahttp/yahttp/reqresp.o ext/yahttp/yahttp/router.o \
-rec-carbon.o secpoll-recursor.o lua-iputils.o iputils.o dnsname.o \
+rec-carbon.o secpoll-recursor.o iputils.o dnsname.o \
 rpzloader.o filterpo.o resolver.o ixfr.o dnssecinfra.o gss_context.o \
 ednssubnet.o validate.o validate-recursor.o mbedtlssigners.o \
 rec-lua-conf.o sortlist.o
index 8be5817b31c6cd54f78f1bc59cf79cfd037c8e5b..cc34b6bec61f7d4983b1c92e520816f40965d9d7 100644 (file)
@@ -1105,9 +1105,7 @@ pdns_recursor_SOURCES = \
        ixfr.cc ixfr.hh \
        json.cc json.hh \
        logger.cc \
-       lua-pdns.cc lua-pdns.hh lua-iputils.cc \
-       lua-recursor.cc lua-recursor.hh \
-       lua-recursor4.cc lua-recursor4.hh \     
+       lua-recursor4.cc lua-recursor4.hh \
        lwres.cc lwres.hh \
        mbedtlscompat.hh \
        mbedtlssigners.cc \
index 0b71b18264772166e7b18f3a68ca9bd88cbbf6c6..5d1f5796da4adf3c9f2469c626d3edf7ad8f2090 100644 (file)
@@ -31,8 +31,7 @@ protected: // FIXME?
   bool d_failed;
   bool d_variable;  
 };
-// enum for policy decisions, used by both auth and recursor. Not all values supported everywhere.
-namespace PolicyDecision { enum returnTypes { PASS=-1, DROP=-2, TRUNCATE=-3 }; };
+
 void pushResourceRecordsTable(lua_State* lua, const vector<DNSRecord>& records);
 void popResourceRecordsTable(lua_State *lua, const DNSName &query, vector<DNSRecord>& ret);
 void pushSyslogSecurityLevelTable(lua_State *lua);
index 5064dbc3033583aa4914c2c24d73446d49f766fe..6510a39e8c1d05b35409740dc2f0dfd3b25f9f02 100644 (file)
@@ -291,7 +291,6 @@ bool RecursorLua::passthrough(const string& func, const ComboAddress& remote, co
       auto table = getLuaTable(d_lua, -1);
       lua_pop(d_lua, 2);
       string answer = GenUDPQueryResponse(ComboAddress(dest), uquery);
-
       lua_getglobal(d_lua,  callback.c_str());
       
       lua_pushstring(d_lua,  remote.toString().c_str() );
index 59b2dc17ecad50c46e539703194a27fc96058ff7..3d688af642cfdfcaa1b91f4f40e6a64f6ff61a07 100644 (file)
@@ -6,10 +6,6 @@
 #include "dnsparser.hh"
 #include "syncres.hh"
 
-namespace {
-  enum class PolicyDecision { PASS=-1, DROP=-2, TRUNCATE=-3 };
-}
-
 static int followCNAMERecords(vector<DNSRecord>& ret, const QType& qtype)
 {
   vector<DNSRecord> resolved;
@@ -122,7 +118,15 @@ 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("toString", &ComboAddress::toString);  
+  d_lw->registerFunction<string(ComboAddress::*)()>("toString", [](const ComboAddress& ca) { return ca.toString(); });
+  d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); });
+  d_lw->writeFunction("newNMG", []() { return NetmaskGroup(); });
+  d_lw->registerFunction<void(NetmaskGroup::*)(const std::string&mask)>("addMask", [](NetmaskGroup&nmg, const std::string& mask)
+                        {
+                          nmg.addMask(mask);
+                        });
+
+  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->registerMember("qname", &DNSQuestion::qname);
   d_lw->registerMember("qtype", &DNSQuestion::qtype);
@@ -185,8 +189,10 @@ RecursorLua4::RecursorLua4(const std::string& fname)
   d_nodata = d_lw->readVariable<boost::optional<luacall_t>>("nodata").get_value_or(0);
   d_nxdomain = d_lw->readVariable<boost::optional<luacall_t>>("nxdomain").get_value_or(0);
   d_postresolve = d_lw->readVariable<boost::optional<luacall_t>>("postresolve").get_value_or(0);
-  
-  //  d_ipfilter = d_lw->readVariable<boost::optional<ipfilter_t>>("ipfilter").get_value_or(0);
+  d_preoutquery = d_lw->readVariable<boost::optional<luacall_t>>("preoutquery").get_value_or(0);
+
+  d_ipfilter = d_lw->readVariable<boost::optional<ipfilter_t>>("ipfilter").get_value_or(0);
+
 }
 
 bool RecursorLua4::preresolve(const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable)
@@ -211,13 +217,14 @@ bool RecursorLua4::postresolve(const ComboAddress& remote,const ComboAddress& lo
 
 bool RecursorLua4::preoutquery(const ComboAddress& ns, const ComboAddress& requestor, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret)
 {
-  return genhook(d_postresolve, ns, requestor, query, qtype, res, ret, 0);
+  return genhook(d_preoutquery, ns, requestor, query, qtype, res, ret, 0);
 }
 
 bool RecursorLua4::ipfilter(const ComboAddress& remote, const ComboAddress& local, const struct dnsheader& dh)
 {
   if(d_ipfilter)
-    return d_ipfilter(remote, local);
+    return d_ipfilter({remote}, {local});
+  return false; // don't block
 }
 
 bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable)
@@ -233,11 +240,11 @@ bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const Com
   dq->records = res;
 
   bool handled=func(dq);
-  if(variable) *variable = dq->variable; // could still be set to indicate this *name* is variable
+  if(variable) *variable |= dq->variable; // could still be set to indicate this *name* is variable
 
   if(handled) {
     ret=dq->rcode;
-    
+  loop:;
     if(!dq->followupFunction.empty()) {
       if(dq->followupFunction=="followCNAMERecords") {
        ret = followCNAMERecords(dq->records, qtype);
@@ -248,11 +255,18 @@ bool RecursorLua4::genhook(luacall_t& func, const ComboAddress& remote,const Com
       else if(dq->followupFunction=="getFakePTRRecords") {
        ret=getFakePTRRecords(dq->followupName, dq->followupPrefix, dq->records);
       }
+      else if(dq->followupFunction=="udpQueryResponse") {
+       dq->udpAnswer = GenUDPQueryResponse(dq->udpQueryDest, dq->udpQuery);
+       auto func = d_lw->readVariable<boost::optional<luacall_t>>(dq->udpCallback).get_value_or(0);
+       if(!func) {
+         L<<Logger::Error<<"Attempted callback for Lua UDP Query/Response which could not be found"<<endl;
+         return false;
+       }
+       goto loop;
+      }
+      
     }
     res=dq->records;
-
-    
-
   }
 
 
index f10032f670ae5e13cf1149d335e4eb5b4b8139ea..f8c574c5dc2f33d1c3bb7e824e17ddda159765d0 100644 (file)
@@ -3,6 +3,7 @@
 #include "dnsname.hh"
 #include "namespaces.hh"
 #include "dnsrecords.hh"
+string GenUDPQueryResponse(const ComboAddress& dest, const string& query);
 
 class LuaContext;
 class RecursorLua4 : public boost::noncopyable
@@ -35,15 +36,20 @@ private:
     
     string followupFunction;
     string followupPrefix;
+
+    string udpQuery;
+    ComboAddress udpQueryDest;
+    string udpAnswer;
+    string udpCallback;
+    
     DNSName followupName;
   };
 
-
   LuaContext* d_lw;
   typedef std::function<bool(std::shared_ptr<DNSQuestion>)> luacall_t;
   luacall_t d_preresolve, d_nxdomain, d_nodata, d_postresolve, d_preoutquery, d_postoutquery;
   bool genhook(luacall_t& func, const ComboAddress& remote,const ComboAddress& local, const DNSName& query, const QType& qtype, vector<DNSRecord>& res, int& ret, bool* variable);
-  typedef std::function<bool(const ComboAddress&, const ComboAddress&)> ipfilter_t;
+  typedef std::function<bool(ComboAddress,ComboAddress)> ipfilter_t;
   ipfilter_t d_ipfilter;
 };
 
index df26a74a31401d153cd9cd7654a5f02d4b144818..40211d404aaa73b60b7ae00183d29d537bc66755 100644 (file)
@@ -72,7 +72,6 @@ extern SortList g_sortlist;
 #include "iputils.hh"
 #include "mplexer.hh"
 #include "config.h"
-#include "lua-recursor.hh"
 #include "lua-recursor4.hh"
 #include "version.hh"
 #include "responsestats.hh"
index 2b18b02ea3359a10cc2de69ccc812dd6d77db240..0f3de7b828e6dbf10b11a31fcd481fe647c1ca13 100644 (file)
@@ -676,4 +676,6 @@ void doCarbonDump(void*);
 boost::optional<Netmask> getEDNSSubnetMask(const ComboAddress& local, const DNSName&dn, const ComboAddress& rem);
 void  parseEDNSSubnetWhitelist(const std::string& wlist);
 
+// enum for policy decisions, used by both auth and recursor. Not all values supported everywhere.
+namespace PolicyDecision { enum returnTypes { PASS=-1, DROP=-2, TRUNCATE=-3 }; };
 #endif