]> granicus.if.org Git - pdns/commitdiff
rec: Add the DNSSEC validation state to the DNSQuestion Lua object
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 2 Nov 2017 09:27:18 +0000 (10:27 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 2 Nov 2017 09:27:18 +0000 (10:27 +0100)
pdns/lua-recursor4.cc
pdns/lua-recursor4.hh
pdns/pdns_recursor.cc
pdns/recursordist/contrib/dns64.lua
pdns/recursordist/docs/lua-scripting/dq.rst

index bdfa7d54b120a913493aa97c556bf1c45891d69e..2d64a23980668da732fa3643931a5887b0a49aa5 100644 (file)
@@ -337,6 +337,7 @@ RecursorLua4::RecursorLua4(const std::string& fname)
   d_lw->registerMember<bool (DNSQuestion::*)>("isTcp", [](const DNSQuestion& dq) -> bool { return dq.isTcp; }, [](DNSQuestion& dq, bool newTcp) { (void) newTcp; });
   d_lw->registerMember<const ComboAddress (DNSQuestion::*)>("localaddr", [](const DNSQuestion& dq) -> const ComboAddress& { return dq.local; }, [](DNSQuestion& dq, const ComboAddress& newLocal) { (void) newLocal; });
   d_lw->registerMember<const ComboAddress (DNSQuestion::*)>("remoteaddr", [](const DNSQuestion& dq) -> const ComboAddress& { return dq.remote; }, [](DNSQuestion& dq, const ComboAddress& newRemote) { (void) newRemote; });
+  d_lw->registerMember<vState (DNSQuestion::*)>("validationState", [](const DNSQuestion& dq) -> vState { return dq.validationState; }, [](DNSQuestion& dq, vState newState) { (void) newState; });
 
   d_lw->registerMember<bool (DNSQuestion::*)>("variable", [](const DNSQuestion& dq) -> bool { return dq.variable; }, [](DNSQuestion& dq, bool newVariable) { dq.variable = newVariable; });
   d_lw->registerMember<bool (DNSQuestion::*)>("wantsRPZ", [](const DNSQuestion& dq) -> bool { return dq.wantsRPZ; }, [](DNSQuestion& dq, bool newWantsRPZ) { dq.wantsRPZ = newWantsRPZ; });
@@ -503,6 +504,14 @@ RecursorLua4::RecursorLua4(const std::string& fname)
 
   for(const auto& n : QType::names)
     pd.push_back({n.first, n.second});
+
+  pd.push_back({"validationstates", in_t{
+        {"Indeterminate", Indeterminate },
+        {"Bogus", Bogus },
+        {"Insecure", Insecure },
+        {"Secure", Secure },
+  }});
+
   pd.push_back({"now", &g_now});
   d_lw->registerMember("tv_sec", &timeval::tv_sec);
   d_lw->registerMember("tv_usec", &timeval::tv_usec);
index db6966adbdfc8f8dfb3dbb562aeafa180ec37374..f7ef48e7edd857bd2f2cde864535c4181c454089 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 #pragma once
-#include "iputils.hh"
-#include "dnsname.hh"
-#include "namespaces.hh"
-#include "dnsrecords.hh"
-#include "filterpo.hh"
-#include "ednsoptions.hh"
 
 #include <unordered_map>
 
 #include "config.h"
 #endif
 
+#include "iputils.hh"
+#include "dnsname.hh"
+#include "namespaces.hh"
+#include "dnsrecords.hh"
+#include "filterpo.hh"
+#include "ednsoptions.hh"
+#include "validate.hh"
+
 string GenUDPQueryResponse(const ComboAddress& dest, const string& query);
 unsigned int getRecursorThreadId();
 
@@ -72,6 +74,7 @@ public:
     std::unordered_map<std::string,bool>* discardedPolicies{nullptr};
     std::string requestorId;
     std::string deviceId;
+    vState validationState{Indeterminate};
     bool& variable;
     bool& wantsRPZ;
     unsigned int tag{0};
index 4b0e8ba83ea45a24dfb4ca6bf90a1b4f7b4422ad..e2286d9c4b102c06c559d2dc1209373d0bffe9c5 100644 (file)
@@ -904,6 +904,8 @@ static void startDoResolve(void *p)
         res = RCode::ServFail;
       }
 
+      dq.validationState = sr.getValidationState();
+
       // During lookup, an NSDNAME or NSIP trigger was hit in RPZ
       if (res == -2) { // XXX This block should be macro'd, it is repeated post-resolve.
         appliedPolicy = sr.d_appliedPolicy;
index 0ab8bb1ec6421897b397b80843a7a4f773227903..bf779a3c4766721eea6fc3a6fcb461abed2f658f 100644 (file)
@@ -6,6 +6,11 @@ function nodata ( dq )
     return false
   end  --  only AAAA records
 
+  -- don't fake AAAA records if DNSSEC validation failed
+  if dq.validationState == pdns.validationstates.Bogus then
+     return false
+  end
+
   dq.followupFunction = "getFakeAAAARecords"
   dq.followupPrefix = prefix
   dq.followupName = dq.qname
index cd7e6baa4e3cbcf8b6e8284022ea092c61457949..963d6ab93a4326530e5ecf8b7dcd2e0ff4464783 100644 (file)
@@ -124,6 +124,14 @@ The DNSQuestion object contains at least the following fields:
 
     The name of the callback function that is called when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>` when an answer is received.
 
+.. attribute:: DNSQuestion.validationState
+
+    .. versionadded:: 4.1.0
+
+    The result of the DNSSEC validation, accessible from the ``postresolve``, ``nxdomain`` and ``nodata`` hooks.
+    Possible states are ``pdns.validationstates.Indeterminate``, ``pdns.validationstates.Bogus``, ``pdns.validationstates.Insecure`` and ``pdns.validationstates.Secure``.
+    The result will always be ``pdns.validationstates.Indeterminate`` is validation is disabled or was not requested.
+
 It also supports the following methods:
 
 .. classmethod:: DNSQuestion:addAnswer(type, content, [ttl, name])