]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Support more dnstap transport types (DoT, DoH)
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 29 Jun 2021 14:47:21 +0000 (16:47 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 29 Jun 2021 14:49:52 +0000 (16:49 +0200)
pdns/dnsdist-lua-actions.cc
pdns/dnstap.cc
pdns/dnstap.hh

index 3d4d213c4b47cc519c202241b47f51d4a0786f07..e8d7f25f5eabbc8974f5427ec9bf74ef7788c985 100644 (file)
@@ -1043,6 +1043,28 @@ private:
   bool d_hasV6;
 };
 
+static DnstapMessage::ProtocolType ProtocolToDNSTap(DNSQuestion::Protocol protocol)
+{
+  DnstapMessage::ProtocolType result;
+  switch (protocol) {
+  default:
+  case DNSQuestion::Protocol::DoUDP:
+  case DNSQuestion::Protocol::DNSCryptUDP:
+    result = DnstapMessage::ProtocolType::DoUDP;
+    break;
+  case DNSQuestion::Protocol::DoTCP:
+  case DNSQuestion::Protocol::DNSCryptTCP:
+    result = DnstapMessage::ProtocolType::DoTCP;
+    break;
+  case DNSQuestion::Protocol::DoT:
+    result = DnstapMessage::ProtocolType::DoT;
+    break;
+  case DNSQuestion::Protocol::DoH:
+    result = DnstapMessage::ProtocolType::DoH;
+    break;
+  }
+  return result;
+}
 
 class DnstapLogAction : public DNSAction, public boost::noncopyable
 {
@@ -1056,7 +1078,8 @@ public:
     static thread_local std::string data;
     data.clear();
 
-    DnstapMessage message(data, !dq->getHeader()->qr ? DnstapMessage::MessageType::client_query : DnstapMessage::MessageType::client_response, d_identity, dq->remote, dq->local, dq->overTCP(), reinterpret_cast<const char*>(dq->getData().data()), dq->getData().size(), dq->queryTime, nullptr);
+    DnstapMessage::ProtocolType protocol = ProtocolToDNSTap(dq->getProtocol());
+    DnstapMessage message(data, !dq->getHeader()->qr ? DnstapMessage::MessageType::client_query : DnstapMessage::MessageType::client_response, d_identity, dq->remote, dq->local, protocol, reinterpret_cast<const char*>(dq->getData().data()), dq->getData().size(), dq->queryTime, nullptr);
     {
       if (d_alterFunc) {
         std::lock_guard<std::mutex> lock(g_luamutex);
@@ -1189,7 +1212,8 @@ public:
     gettime(&now, true);
     data.clear();
 
-    DnstapMessage message(data, DnstapMessage::MessageType::client_response, d_identity, dr->remote, dr->local, dr->overTCP(), reinterpret_cast<const char*>(dr->getData().data()), dr->getData().size(), dr->queryTime, &now);
+    DnstapMessage::ProtocolType protocol = ProtocolToDNSTap(dr->getProtocol());
+    DnstapMessage message(data, DnstapMessage::MessageType::client_response, d_identity, dr->remote, dr->local, protocol, reinterpret_cast<const char*>(dr->getData().data()), dr->getData().size(), dr->queryTime, &now);
     {
       if (d_alterFunc) {
         std::lock_guard<std::mutex> lock(g_luamutex);
index 954f2d0bf25f4653b41da112d2402b8131fbb734..86f933a6e1737c588077bceebe929cd6936d6609 100644 (file)
@@ -17,15 +17,11 @@ namespace DnstapSocketFamilyTypes {
   enum : protozero::pbf_tag_type { inet = 1, inet6 = 2 };
 }
 
-namespace DnstapSocketFamilyProtocol {
-  enum : protozero::pbf_tag_type { udp = 1, tcp = 2 };
-}
-
 namespace DnstapMessageFields {
   enum : protozero::pbf_tag_type { type = 1, socket_family = 2, socket_protocol = 3, query_address = 4, response_address = 5, query_port = 6, response_port = 7, query_time_sec = 8, query_time_nsec = 9, query_message = 10, query_zone = 11, response_time_sec = 12, response_time_nsec = 13, response_message = 14 };
 }
 
-DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType type, 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, boost::optional<const DNSName&> auth): d_buffer(buffer)
+DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType type, const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, DnstapMessage::ProtocolType protocol, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime, boost::optional<const DNSName&> auth): d_buffer(buffer)
 {
   protozero::pbf_writer pbf{d_buffer};
 
@@ -37,7 +33,7 @@ DnstapMessage::DnstapMessage(std::string& buffer, DnstapMessage::MessageType typ
   protozero::pbf_writer pbf_message{pbf, DnstapBaseFields::message};
 
   pbf_message.add_enum(DnstapMessageFields::type, static_cast<protozero::pbf_tag_type>(type));
-  pbf_message.add_enum(DnstapMessageFields::socket_protocol, isTCP ? DnstapSocketFamilyProtocol::tcp : DnstapSocketFamilyProtocol::udp);
+  pbf_message.add_enum(DnstapMessageFields::socket_protocol, static_cast<protozero::pbf_tag_type>(protocol));
 
   if (requestor != nullptr) {
     pbf_message.add_enum(DnstapMessageFields::socket_family, requestor->sin4.sin_family == AF_INET ? DnstapSocketFamilyTypes::inet : DnstapSocketFamilyTypes::inet6);
index 3d3fe71bb4552615db7b53c11089c78536834c05..f4c7ee6ad959ae6e161c8673eba75a4980fd1089 100644 (file)
@@ -34,8 +34,9 @@ class DnstapMessage
 {
 public:
   enum class MessageType : uint32_t { auth_query = 1, auth_response = 2, resolver_query = 3, resolver_response = 4, client_query = 5, client_response = 6, forwarder_query = 7, forwarded_response = 8, stub_query = 9, stub_response = 10, tool_query = 11, tool_response = 12 };
+  enum class ProtocolType : uint32_t { DoUDP = 1, DoTCP = 2, DoT = 3, DoH = 4 };
 
-  DnstapMessage(std::string& buffer, MessageType type, 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, boost::optional<const DNSName&> auth=boost::none);
+  DnstapMessage(std::string& buffer, MessageType type, const std::string& identity, const ComboAddress* requestor, const ComboAddress* responder, ProtocolType protocol, const char* packet, const size_t len, const struct timespec* queryTime, const struct timespec* responseTime, boost::optional<const DNSName&> auth=boost::none);
 
   void setExtra(const std::string& extra);