]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add NOD and UDR to Protobuf Logs
authorNeil Cook <neil.cook@noware.co.uk>
Fri, 19 Oct 2018 11:18:47 +0000 (11:18 +0000)
committerNeil Cook <neil.cook@noware.co.uk>
Wed, 24 Oct 2018 12:43:24 +0000 (12:43 +0000)
- Add newly observed domain flag to DNS Message protobuf definition
- Add unique dns response flag to RRs in DNS Message Response definition
- Utility methods to manipulate new flags in Protobuf messages

pdns/dnsmessage.proto
pdns/rec-protobuf.cc
pdns/rec-protobuf.hh

index 12ece21db3cbdab124488744bb6fc0932d80de2e..a460b51f3cd09ca2f404252dcdad0f0a7ccf06e2 100644 (file)
@@ -70,6 +70,7 @@ message PBDNSMessage {
       optional uint32 class = 3;
       optional uint32 ttl = 4;
       optional bytes rdata = 5;
+      optional bool  udr = 6;                   // True if this is the first time this RR has been seen for this question
     }
     optional uint32 rcode = 1;
     repeated DNSRR rrs = 2;
@@ -85,4 +86,5 @@ message PBDNSMessage {
   optional string requestorId = 15;             // Username of the requestor
   optional bytes initialRequestId = 16;         // UUID of the incoming query that initiated this outgoing query or incoming response
   optional bytes deviceId = 17;                // Device ID of the requestor (could be mac address IP address or e.g. IMEI)
+  optional bool  newlyObservedDomain = 18;      // True if the domain has not been seen before
 }
index 530e81bdbf9753f94da3c5426a2376d7902734f4..f12d793510cad3b47100825553b34773f86b9032 100644 (file)
@@ -2,7 +2,32 @@
 #include "config.h"
 #include "rec-protobuf.hh"
 
+#ifdef NOD_ENABLED
+void RecProtoBufMessage::setNOD(bool nod)
+{
+#ifdef HAVE_PROTOBUF
+  d_message.set_newlyobserveddomain(nod);
+#endif /* HAVE_PROTOBUF */  
+}
+
+void RecProtoBufMessage::clearUDR() 
+{
+#ifdef HAVE_PROTOBUF
+  auto response = d_message.mutable_response();
+  const int count = response->rrs_size();
+  for (int idx = 0; idx < count; idx++) {
+    auto rr = response->mutable_rrs(idx);
+    rr->set_udr(false);
+  }
+#endif /* HAVE_PROTOBUF */
+}
+#endif /* NOD_ENABLED */
+
+#ifdef NOD_ENABLED
+void RecProtoBufMessage::addRR(const DNSRecord& record, const std::set<uint16_t>& exportTypes, bool udr)
+#else
 void RecProtoBufMessage::addRR(const DNSRecord& record, const std::set<uint16_t>& exportTypes)
+#endif /* NOD_ENABLED */
 {
 #ifdef HAVE_PROTOBUF
   PBDNSMessage_DNSResponse* response = d_message.mutable_response();
@@ -27,6 +52,9 @@ void RecProtoBufMessage::addRR(const DNSRecord& record, const std::set<uint16_t>
   pbRR->set_type(record.d_type);
   pbRR->set_class_(record.d_class);
   pbRR->set_ttl(record.d_ttl);
+#ifdef NOD_ENABLED
+  pbRR->set_udr(udr);
+#endif
 
   switch(record.d_type) {
   case QType::A:
index c8d0e6880f4a71816b79a8a1909eaf354adef3f7..34386283d60ebdbed631de1194a3eb0796bc4532 100644 (file)
@@ -43,7 +43,13 @@ public:
 #endif /* HAVE_PROTOBUF */
 
   void addRRs(const std::vector<DNSRecord>& records, const std::set<uint16_t>& exportTypes);
+#ifdef NOD_ENABLED
+  void setNOD(bool nod);
+  void addRR(const DNSRecord& record, const std::set<uint16_t>& exportTypes, bool udr=false);
+  void clearUDR();
+#else
   void addRR(const DNSRecord& record, const std::set<uint16_t>& exportTypes);
+#endif /* NOD_ENABLED */
   void setAppliedPolicy(const std::string& policy);
   void setAppliedPolicyType(const DNSFilterEngine::PolicyType& policyType);
   void setPolicyTags(const std::vector<std::string>& policyTags);