From: Otto Moerbeek Date: Fri, 8 Mar 2019 09:34:54 +0000 (+0100) Subject: Use separate class for recursor dnstap messages. X-Git-Tag: dnsdist-1.4.0-beta1~13^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=522253b0f5d85d0fbb624d25b33749247c423686;p=thirdparty%2Fpdns.git Use separate class for recursor dnstap messages. --- diff --git a/pdns/dnstap.cc b/pdns/dnstap.cc index 488e621659..f52ce2912b 100644 --- a/pdns/dnstap.cc +++ b/pdns/dnstap.cc @@ -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(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) { diff --git a/pdns/dnstap.hh b/pdns/dnstap.hh index 59dd3c752f..d00bd0bca8 100644 --- a/pdns/dnstap.hh +++ b/pdns/dnstap.hh @@ -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; diff --git a/pdns/lwres.cc b/pdns/lwres.cc index 5c5b802565..05e5709f15 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -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(&*packet.begin()), packet.size(), &ts, nullptr, true); + DnstapMessage message(SyncRes::s_serverID, nullptr, &ip, doTCP, reinterpret_cast(&*packet.begin()), packet.size(), &ts, nullptr); std::string str; message.serialize(str); @@ -111,7 +111,7 @@ static void logFstreamResponse(const std::shared_ptr(&*packet.begin()), packet.size(), &ts1, &ts2, true); + RecDnstapMessage message(SyncRes::s_serverID, nullptr, &ip, doTCP, static_cast(&*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 index 0000000000..217bcc9cf8 --- /dev/null +++ b/pdns/rec-dnstap.hh @@ -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(packet); + dnstap::Message* message = proto_message.mutable_message(); + message->set_type(!dh->qr ? dnstap::Message_Type_RESOLVER_QUERY : dnstap::Message_Type_RESOLVER_RESPONSE); + } +}; diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index ffbffa6316..6c37f2604b 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -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 index 0000000000..4011f47abe --- /dev/null +++ b/pdns/recursordist/rec-dnstap.hh @@ -0,0 +1 @@ +../rec-dnstap.hh \ No newline at end of file