From: Neil Cook Date: Fri, 19 Oct 2018 11:18:47 +0000 (+0000) Subject: Add NOD and UDR to Protobuf Logs X-Git-Tag: dnsdist-1.3.3~16^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d6399006fc16d3a38fbe8affcdcbd87c4cc4c82e;p=thirdparty%2Fpdns.git Add NOD and UDR to Protobuf Logs - 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 --- diff --git a/pdns/dnsmessage.proto b/pdns/dnsmessage.proto index 12ece21db3..a460b51f3c 100644 --- a/pdns/dnsmessage.proto +++ b/pdns/dnsmessage.proto @@ -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 } diff --git a/pdns/rec-protobuf.cc b/pdns/rec-protobuf.cc index 530e81bdbf..f12d793510 100644 --- a/pdns/rec-protobuf.cc +++ b/pdns/rec-protobuf.cc @@ -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& exportTypes, bool udr) +#else void RecProtoBufMessage::addRR(const DNSRecord& record, const std::set& 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 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: diff --git a/pdns/rec-protobuf.hh b/pdns/rec-protobuf.hh index c8d0e6880f..34386283d6 100644 --- a/pdns/rec-protobuf.hh +++ b/pdns/rec-protobuf.hh @@ -43,7 +43,13 @@ public: #endif /* HAVE_PROTOBUF */ void addRRs(const std::vector& records, const std::set& exportTypes); +#ifdef NOD_ENABLED + void setNOD(bool nod); + void addRR(const DNSRecord& record, const std::set& exportTypes, bool udr=false); + void clearUDR(); +#else void addRR(const DNSRecord& record, const std::set& exportTypes); +#endif /* NOD_ENABLED */ void setAppliedPolicy(const std::string& policy); void setAppliedPolicyType(const DNSFilterEngine::PolicyType& policyType); void setPolicyTags(const std::vector& policyTags);