]> granicus.if.org Git - pdns/commitdiff
Recursor: Add DNSSEC validation statistics
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 30 Jun 2016 14:55:48 +0000 (16:55 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 5 Jul 2016 14:26:42 +0000 (16:26 +0200)
Closes #3916

docs/markdown/recursor/stats.md
pdns/rec_channel_rec.cc
pdns/syncres.hh
pdns/validate-recursor.cc

index cef77567bce664e106fab47b72668755eade7bb2..7030bf0432942835130d5cc60c59e3cb4efc3965 100644 (file)
@@ -26,6 +26,13 @@ The `rec_control get` command can be used to query the following statistics, eit
 * `client-parse-errors`: counts number of client packets that could not be parsed
 * `concurrent-queries`: shows the number of MThreads currently running
 * `dlg-only-drops`: number of records dropped because of delegation only setting
+* `dnssec-queries`: number of queries received with the DO and/or AD bit set
+* `dnssec-result-bogus`: number of DNSSEC validations that had the Bogus state
+* `dnssec-result-indeterminate`: number of DNSSEC validations that had the Indeterminate state
+* `dnssec-result-insecure`: number of DNSSEC validations that had the Insecure state
+* `dnssec-result-nta`: number of DNSSEC validations that had the NTA (negative trust anchor) state
+* `dnssec-result-secure`: number of DNSSEC validations that had the Secure state
+* `dnssec-validations`: number of DNSSEC validations performed
 * `dont-outqueries`: number of outgoing queries dropped because of 'dont-query' setting (since 3.3)
 * `edns-ping-matches`: number of servers that sent a valid EDNS PING response
 * `edns-ping-mismatches`: number of servers that sent an invalid EDNS PING response
index 3e0b7c40e25c504d3cdb2eb1cef9cba7dca46cc9..caeb01ade2386bd545c91aa022a5bc476b69b352 100644 (file)
@@ -846,6 +846,13 @@ RecursorControlParser::RecursorControlParser()
   addGetStat("memory-alloc-flux", boost::bind(&MallocTracer::getAllocFlux, g_mtracer, string()));
   addGetStat("memory-allocated", boost::bind(&MallocTracer::getTotAllocated, g_mtracer, string()));
 #endif
+
+  addGetStat("dnssec-validations", &g_stats.dnssecValidations);
+  addGetStat("dnssec-result-insecure", &g_stats.dnssecResults[Insecure]);
+  addGetStat("dnssec-result-secure", &g_stats.dnssecResults[Secure]);
+  addGetStat("dnssec-result-bogus", &g_stats.dnssecResults[Bogus]);
+  addGetStat("dnssec-result-indeterminate", &g_stats.dnssecResults[Indeterminate]);
+  addGetStat("dnssec-result-nta", &g_stats.dnssecResults[NTA]);
 }
 
 static void doExitGeneric(bool nicely)
index 564af638c3741ad05e02271dacee4477c1a85a2b..3287bb7acf881fb2c09698b62cb6228bc5292294 100644 (file)
@@ -23,6 +23,7 @@
 #include <boost/tuple/tuple_comparison.hpp>
 #include "mtasker.hh"
 #include "iputils.hh"
+#include "validate.hh"
 
 #include "filterpo.hh"
 
@@ -606,6 +607,8 @@ struct RecursorStats
   time_t startupTime;
   std::atomic<uint64_t> dnssecQueries;
   unsigned int maxMThreadStackUsage;
+  std::atomic<uint64_t> dnssecValidations; // should be the sum of all dnssecResult* stats
+  std::map<vState, std::atomic<uint64_t> > dnssecResults;
 };
 
 //! represents a running TCP/IP client session
index eae00a61d4e064cf787a77bffac2340a2cc6922f..94f3a8b51e83196ba11b20bf4a399438dc3469aa 100644 (file)
@@ -25,12 +25,19 @@ public:
   int d_queries{0};
 };
 
+inline vState increaseDNSSECStateCounter(const vState& state)
+{
+  g_stats.dnssecResults[state]++;
+  return state;
+}
 
 vState validateRecords(const vector<DNSRecord>& recs)
 {
   if(recs.empty())
     return Insecure; // can't secure nothing 
 
+  g_stats.dnssecValidations++;
+
   cspmap_t cspmap=harvestCSPFromRecs(recs);
   LOG("Got "<<cspmap.size()<<" RRSETs: "<<endl);
   int numsigs=0;
@@ -49,8 +56,10 @@ vState validateRecords(const vector<DNSRecord>& recs)
     for(const auto& csp : cspmap) {
       for(const auto& sig : csp.second.signatures) {
         state = getKeysFor(sro, sig->d_signer, keys); // XXX check validity here
-        if(state == NTA)
+        if(state == NTA) {
+          increaseDNSSECStateCounter(state);
           return Insecure;
+        }
         LOG("! state = "<<vStates[state]<<", now have "<<keys.size()<<" keys"<<endl);
         for(const auto& k : keys) {
           LOG("Key: "<<k.getZoneRepresentation()<< " {tag="<<k.getTag()<<"}"<<endl);
@@ -59,9 +68,8 @@ vState validateRecords(const vector<DNSRecord>& recs)
         // maybe not the right idea
       }
     }
-    if(state == Bogus) {
-      return state;
-    }
+    if(state == Bogus)
+      return increaseDNSSECStateCounter(state);
     validateWithKeySet(cspmap, validrrsets, keys);
   }
   else {
@@ -69,16 +77,16 @@ vState validateRecords(const vector<DNSRecord>& recs)
     state = getKeysFor(sro, recs.begin()->d_name, keys); // um WHAT DOES THIS MEAN - try first qname??
    
     LOG("! state = "<<vStates[state]<<", now have "<<keys.size()<<" keys "<<endl);
-    return state;
+    
+    return increaseDNSSECStateCounter(state);
   }
   
   LOG("Took "<<sro.d_queries<<" queries"<<endl);
-  if(validrrsets.size() == cspmap.size()) // shortcut - everything was ok
-    return Secure;
+  if(validrrsets.size() == cspmap.size())// shortcut - everything was ok
+    return increaseDNSSECStateCounter(Secure);
 
-  if(keys.empty()) {
-    return Insecure;
-  }
+  if(keys.empty())
+    return increaseDNSSECStateCounter(Insecure);
 
 #if 0
   cerr<<"! validated "<<validrrsets.size()<<" RRsets out of "<<cspmap.size()<<endl;
@@ -96,9 +104,9 @@ vState validateRecords(const vector<DNSRecord>& recs)
     LOG(csp.first.first<<"|"<<DNSRecordContent::NumberToType(csp.first.second)<<" with "<<csp.second.signatures.size()<<" signatures"<<endl);
     if(!csp.second.signatures.empty() && !validrrsets.count(csp.first)) {
       LOG("Lacks signature, must have one, signatures: "<<csp.second.signatures.size()<<", valid rrsets: "<<validrrsets.count(csp.first)<<endl);
-      return Bogus;
+      return increaseDNSSECStateCounter(Bogus);
     }
   }
   
-  return Insecure;
+  return increaseDNSSECStateCounter(Insecure);
 }