]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Use separate class for recursor dnstap messages.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 8 Mar 2019 09:34:54 +0000 (10:34 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 8 Mar 2019 09:34:54 +0000 (10:34 +0100)
pdns/dnstap.cc
pdns/dnstap.hh
pdns/lwres.cc
pdns/rec-dnstap.hh [new file with mode: 0644]
pdns/recursordist/Makefile.am
pdns/recursordist/rec-dnstap.hh [new symlink]

index 488e6216591438ce9bdafffde99a60c7ee32c9b9..f52ce2912b12f378139a97d92ec55fbdaed0d0bb 100644 (file)
@@ -2,7 +2,7 @@
 #include "gettime.hh"
 #include "dnstap.hh"
 
-DnstapMessage::DnstapMessage(const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, bool isTCP, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime, bool recursor)
+DnstapMessage::DnstapMessage(const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, bool isTCP, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime)
 {
 #ifdef HAVE_PROTOBUF
   const struct dnsheader* dh = reinterpret_cast<const struct dnsheader*>(packet);
@@ -13,11 +13,7 @@ DnstapMessage::DnstapMessage(const std::string& identity, const ComboAddress* re
 
   dnstap::Message* message = proto_message.mutable_message();
 
-  if (recursor) {
-    message->set_type(!dh->qr ? dnstap::Message_Type_RESOLVER_QUERY : dnstap::Message_Type_RESOLVER_RESPONSE);
-  } else {
-    message->set_type(!dh->qr ? dnstap::Message_Type_CLIENT_QUERY : dnstap::Message_Type_CLIENT_RESPONSE);
-  }
+  message->set_type(!dh->qr ? dnstap::Message_Type_CLIENT_QUERY : dnstap::Message_Type_CLIENT_RESPONSE);
   message->set_socket_protocol(isTCP ? dnstap::TCP : dnstap::UDP);
 
   if (requestor != nullptr) {
index 59dd3c752f2b8d3b5bc0c91e0b58fd44b79dae86..d00bd0bca81c5c74477a0b66858bab47d68295f3 100644 (file)
@@ -37,7 +37,7 @@
 class DnstapMessage
 {
 public:
-  DnstapMessage(const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, bool isTCP, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime, bool recursor = false);
+  DnstapMessage(const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, bool isTCP, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime);
   void serialize(std::string& data) const;
   std::string toDebugString() const;
 
index 5c5b80256554be4c4fdc6ee587589d3fdeb57f14..05e5709f150dc1457ce283a387966cf90ddcaee5 100644 (file)
@@ -53,7 +53,7 @@
 #include "uuid-utils.hh"
 
 #ifdef HAVE_FSTRM
-#include "dnstap.hh"
+#include "rec-dnstap.hh"
 #include "fstrm_logger.hh"
 bool g_syslog;
 
@@ -79,7 +79,7 @@ static void logFstreamQuery(const std::shared_ptr<std::vector<std::unique_ptr<Re
 
   struct timespec ts;
   TIMEVAL_TO_TIMESPEC(&queryTime, &ts);
-  DnstapMessage message(SyncRes::s_serverID, nullptr, &ip, doTCP, reinterpret_cast<const char*>(&*packet.begin()), packet.size(), &ts, nullptr, true);
+  DnstapMessage message(SyncRes::s_serverID, nullptr, &ip, doTCP, reinterpret_cast<const char*>(&*packet.begin()), packet.size(), &ts, nullptr);
   std::string str;
   message.serialize(str);
 
@@ -111,7 +111,7 @@ static void logFstreamResponse(const std::shared_ptr<std::vector<std::unique_ptr
   struct timespec ts1, ts2;
   TIMEVAL_TO_TIMESPEC(&queryTime, &ts1);
   TIMEVAL_TO_TIMESPEC(&replyTime, &ts2);
-  DnstapMessage message(SyncRes::s_serverID, nullptr, &ip, doTCP, static_cast<const char*>(&*packet.begin()), packet.size(), &ts1, &ts2, true);
+  RecDnstapMessage message(SyncRes::s_serverID, nullptr, &ip, doTCP, static_cast<const char*>(&*packet.begin()), packet.size(), &ts1, &ts2);
   std::string str;
   message.serialize(str);
 
diff --git a/pdns/rec-dnstap.hh b/pdns/rec-dnstap.hh
new file mode 100644 (file)
index 0000000..217bcc9
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+
+#ifdef HAVE_FSTRM
+#include "dnstap.hh"
+#endif /* HAVE_FSTRM */
+
+class RecDnstapMessage : public DnstapMessage
+{
+public:
+  RecDnstapMessage(const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, bool isTCP, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime)
+      : DnstapMessage(identity, requestor, responder, isTCP, packet, len, queryTime, responseTime) {
+    const struct dnsheader* dh = reinterpret_cast<const struct dnsheader*>(packet);
+    dnstap::Message* message = proto_message.mutable_message();
+    message->set_type(!dh->qr ? dnstap::Message_Type_RESOLVER_QUERY : dnstap::Message_Type_RESOLVER_RESPONSE);
+  }
+};
index ffbffa631682bb8d7223dff4de50777cc6fea5aa..6c37f2604b8664c97cb316eb3a12f79f44250df1 100644 (file)
@@ -370,7 +370,7 @@ nodist_testrunner_SOURCES = dnsmessage.pb.cc dnsmessage.pb.h
 
 if FSTRM
 BUILT_SOURCES += dnstap.pb.cc
-pdns_recursor.$(OBJEXT): dnstap.pb.cc  dnsmessage.pb.cc
+pdns_recursor.$(OBJEXT): dnstap.pb.cc dnsmessage.pb.cc
 testrunner$(OBJEXT): dnstap.pb.cc dnsmessage.pb.cc
 nodist_pdns_recursor_SOURCES += dnstap.pb.cc dnstap.pb.h
 nodist_testrunner_SOURCES += dnstap.pb.cc dnstap.pb.h
@@ -390,7 +390,7 @@ endif
 
 if FSTRM
 pdns_recursor_SOURCES += \
-       dnstap.cc dnstap.hh fstrm_logger.cc fstrm_logger.hh
+       dnstap.cc dnstap.hh fstrm_logger.cc fstrm_logger.hh rec-dnstap.hh
 
 pdns_recursor_LDADD += \
        $(FSTRM_LIBS)
diff --git a/pdns/recursordist/rec-dnstap.hh b/pdns/recursordist/rec-dnstap.hh
new file mode 120000 (symlink)
index 0000000..4011f47
--- /dev/null
@@ -0,0 +1 @@
+../rec-dnstap.hh
\ No newline at end of file