]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Use protozero for outgoing queries Protocol Buffer operations
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 8 Dec 2020 18:32:22 +0000 (19:32 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 5 Jan 2021 09:25:41 +0000 (10:25 +0100)
15 files changed:
m4/pdns_check_dnstap.m4
pdns/lwres.cc
pdns/pdns_recursor.cc
pdns/protozero.hh
pdns/rec-lua-conf.cc
pdns/recpacketcache.cc
pdns/recpacketcache.hh
pdns/recursordist/Makefile.am
pdns/recursordist/configure.ac
pdns/recursordist/m4/pdns_with_protobuf.m4 [deleted symlink]
pdns/recursordist/rec-protozero.hh
pdns/resolve-context.hh
pdns/syncres.cc
pdns/syncres.hh
pdns/version.cc

index cd6dc49f469568aa48d871920a2c2d56b6cba3b0..1be83c676f1e7c6f89e0e54ed1193e51fc644bde 100644 (file)
@@ -1,5 +1,4 @@
 AC_DEFUN([PDNS_CHECK_DNSTAP], [
-  AC_REQUIRE([PDNS_WITH_PROTOBUF])
   AC_MSG_CHECKING([whether we will have dnstap])
   AC_ARG_ENABLE([dnstap],
     AS_HELP_STRING([--enable-dnstap],[enable dnstap support @<:@default=$1@:>@]),
@@ -28,8 +27,5 @@ AC_DEFUN([PDNS_CHECK_DNSTAP], [
     AS_IF([test x"$FSTRM_LIBS" = "x"], [
       AC_MSG_ERROR([dnstap requested but libfstrm was not found])
     ])
-    AS_IF([test "x$PROTOBUF_LIBS" = "x" -o x"$PROTOC" = "x"], [
-      AC_MSG_ERROR([dnstap requested but protobuf was not found])
-    ])
   ])
 ])
index fca41db91ac8c486713a8d53893410c270a92979..b9e1c0a0b8d6ae903fdb24e0763ac2a0aab52475 100644 (file)
@@ -49,8 +49,7 @@
 #include "ednssubnet.hh"
 #include "query-local-address.hh"
 
-#ifdef HAVE_PROTOBUF
-
+#include "rec-protozero.hh"
 #include "uuid-utils.hh"
 
 #ifdef HAVE_FSTRM
@@ -121,7 +120,7 @@ static void logFstreamResponse(const std::shared_ptr<std::vector<std::unique_ptr
 
 #endif // HAVE_FSTRM
 
-static void logOutgoingQuery(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<RecProtoBufMessage>& message, boost::optional<const boost::uuids::uuid&> initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, size_t bytes, boost::optional<Netmask>& srcmask)
+static void logOutgoingQuery(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<const boost::uuids::uuid&> initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, size_t bytes, boost::optional<Netmask>& srcmask)
 {
   if (!outgoingLoggers) {
     return;
@@ -139,29 +138,37 @@ static void logOutgoingQuery(const std::shared_ptr<std::vector<std::unique_ptr<R
     return;
   }
 
-  message = RecProtoBufMessage(DNSProtoBufMessage::OutgoingQuery, uuid, nullptr, &ip, domain, type, QClass::IN, qid, doTCP, bytes);
-  message->setServerIdentity(SyncRes::s_serverID);
+  static thread_local std::string buffer;
+  buffer.clear();
+  pdns::ProtoZero::Message m{buffer};
+  m.setType(3);
+  m.setMessageIdentity(uuid);
+  m.setSocketFamily(ip.sin4.sin_family);
+  m.setSocketProtocol(doTCP);
+  m.setTo(ip);
+  m.setInBytes(bytes);
+  m.setTime();
+  m.setId(qid);
+  m.setQuestion(domain, type, QClass::IN);
+  m.setToPort(ip.getPort());
+  m.setServerIdentity(SyncRes::s_serverID);
 
   if (initialRequestId) {
-    message->setInitialRequestID(*initialRequestId);
+    m.setInitialRequestID(*initialRequestId);
   }
 
   if (srcmask) {
-    message->setEDNSSubnet(*srcmask);
+    m.setEDNSSubnet(*srcmask, 128);
   }
 
-//  cerr <<message.toDebugString()<<endl;
-  std::string str;
-  message->serialize(str);
-
   for (auto& logger : *outgoingLoggers) {
     if (logger->logQueries()) {
-      logger->queueData(str);
+      logger->queueData(buffer);
     }
   }
 }
 
-static void logIncomingResponse(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<RecProtoBufMessage>& message, boost::optional<const boost::uuids::uuid&> initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, boost::optional<Netmask>& srcmask, size_t bytes, int rcode, const std::vector<DNSRecord>& records, const struct timeval& queryTime, const std::set<uint16_t>& exportTypes)
+static void logIncomingResponse(const std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>>& outgoingLoggers, boost::optional<const boost::uuids::uuid&> initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, boost::optional<Netmask>& srcmask, size_t bytes, int rcode, const std::vector<DNSRecord>& records, const struct timeval& queryTime, const std::set<uint16_t>& exportTypes)
 {
   if (!outgoingLoggers) {
     return;
@@ -179,44 +186,49 @@ static void logIncomingResponse(const std::shared_ptr<std::vector<std::unique_pt
     return;
   }
 
-  if (!message) {
-    message = RecProtoBufMessage(DNSProtoBufMessage::IncomingResponse, uuid, nullptr, &ip, domain, type, QClass::IN, qid, doTCP, bytes);
-    message->setServerIdentity(SyncRes::s_serverID);
-
-    if (initialRequestId) {
-      message->setInitialRequestID(*initialRequestId);
-    }
+  static thread_local std::string buffer;
+  buffer.clear();
+  pdns::ProtoZero::RecMessage m{buffer};
+  m.setType(4);
+  m.setMessageIdentity(uuid);
+  m.setSocketFamily(ip.sin4.sin_family);
+  m.setSocketProtocol(doTCP);
+  m.setTo(ip);
+  m.setInBytes(bytes);
+  m.setTime();
+  m.setId(qid);
+  m.setQuestion(domain, type, QClass::IN);
+  m.setToPort(ip.getPort());
+  m.setServerIdentity(SyncRes::s_serverID);
 
-    if (srcmask) {
-      message->setEDNSSubnet(*srcmask);
-    }
+  if (initialRequestId) {
+    m.setInitialRequestID(*initialRequestId);
   }
-  else {
-    message->updateTime();
-    message->setType(DNSProtoBufMessage::IncomingResponse);
-    message->setBytes(bytes);
+
+  if (srcmask) {
+    m.setEDNSSubnet(*srcmask, 128);
   }
 
-  message->setQueryTime(queryTime.tv_sec, queryTime.tv_usec);
+  m.startResponse();
+  m.setQueryTime(queryTime.tv_sec, queryTime.tv_usec);
   if (rcode == -1) {
-    message->setNetworkErrorResponseCode();
+    m.setNetworkErrorResponseCode();
   }
   else {
-    message->setResponseCode(rcode);
+    m.setResponseCode(rcode);
   }
-  message->addRRs(records, exportTypes);
 
-//  cerr <<message.toDebugString()<<endl;
-  std::string str;
-  message->serialize(str);
+  for (const auto& record : records) {
+    m.addRR(record, exportTypes, false);
+  }
+  m.commitResponse();
 
   for (auto& logger : *outgoingLoggers) {
     if (logger->logResponses()) {
-      logger->queueData(str);
+      logger->queueData(buffer);
     }
   }
 }
-#endif /* HAVE_PROTOBUF */
 
 /** lwr is only filled out in case 1 was returned, and even when returning 1 for 'success', lwr might contain DNS errors
     Never throws! 
@@ -273,16 +285,14 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int
   dt.set();
   *now=dt.getTimeval();
 
-#ifdef HAVE_PROTOBUF
   boost::uuids::uuid uuid;
   const struct timeval queryTime = *now;
-  boost::optional<RecProtoBufMessage> pbMessage = boost::none;
 
   if (outgoingLoggers) {
     uuid = getUniqueID();
-    logOutgoingQuery(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, vpacket.size(), srcmask);
+    logOutgoingQuery(outgoingLoggers, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, vpacket.size(), srcmask);
   }
-#endif /* HAVE_PROTOBUF */
+
 #ifdef HAVE_FSTRM
   if (isEnabledForQueries(fstrmLoggers)) {
     logFstreamQuery(fstrmLoggers, queryTime, ip, doTCP, context ? context->d_auth : boost::none, vpacket);
@@ -361,11 +371,9 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int
   *now=dt.getTimeval();
 
   if (ret != LWResult::Result::Success) { // includes 'timeout'
-#ifdef HAVE_PROTOBUF
       if (outgoingLoggers) {
-        logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, 0, -1, {}, queryTime, exportTypes);
+        logIncomingResponse(outgoingLoggers, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, 0, -1, {}, queryTime, exportTypes);
       }
-#endif
     return ret;
   }
 
@@ -386,11 +394,9 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int
     lwr->d_rcode=mdp.d_header.rcode;
     
     if(mdp.d_header.rcode == RCode::FormErr && mdp.d_qname.empty() && mdp.d_qtype == 0 && mdp.d_qclass == 0) {
-#ifdef HAVE_PROTOBUF
       if(outgoingLoggers) {
-        logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
+        logIncomingResponse(outgoingLoggers, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
       }
-#endif
       lwr->d_validpacket = true;
       return LWResult::Result::Success; // this is "success", the error is set in lwr->d_rcode
     }
@@ -432,11 +438,9 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int
       }
     }
         
-#ifdef HAVE_PROTOBUF
     if(outgoingLoggers) {
-      logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
+      logIncomingResponse(outgoingLoggers, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
     }
-#endif
 
     lwr->d_validpacket = true;
     return LWResult::Result::Success;
@@ -450,11 +454,9 @@ LWResult::Result asyncresolve(const ComboAddress& ip, const DNSName& domain, int
     lwr->d_validpacket = false;
     g_stats.serverParseError++;
 
-#ifdef HAVE_PROTOBUF
     if(outgoingLoggers) {
-      logIncomingResponse(outgoingLoggers, pbMessage, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
+      logIncomingResponse(outgoingLoggers, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, srcmask, len, lwr->d_rcode, lwr->d_records, queryTime, exportTypes);
     }
-#endif
 
     return LWResult::Result::Success; // success - oddly enough
   }
index 71b67b572dbc6b5ff1e349390fa18453f7eb0be1..11f426c80c64cfd5522ff354854d7db70e883f10 100644 (file)
@@ -98,7 +98,6 @@
 #endif /* NOD_ENABLED */
 #include "query-local-address.hh"
 
-#include "rec-protobuf.hh"
 #include "rec-snmp.hh"
 
 #ifdef HAVE_SYSTEMD
 
 #include "namespaces.hh"
 
-#ifdef HAVE_PROTOBUF
 #include "uuid-utils.hh"
 #include "rec-protozero.hh"
-#endif /* HAVE_PROTOBUF */
 
 #include "xpf.hh"
 
@@ -120,12 +117,10 @@ static thread_local std::shared_ptr<RecursorLua4> t_pdl;
 static thread_local unsigned int t_id = 0;
 static thread_local std::shared_ptr<Regex> t_traceRegex;
 static thread_local std::unique_ptr<tcpClientCounts_t> t_tcpClientCounts;
-#ifdef HAVE_PROTOBUF
 static thread_local std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> t_protobufServers{nullptr};
 static thread_local uint64_t t_protobufServersGeneration;
 static thread_local std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> t_outgoingProtobufServers{nullptr};
 static thread_local uint64_t t_outgoingProtobufServersGeneration;
-#endif /* HAVE_PROTOBUF */
 
 #ifdef HAVE_FSTRM
 static thread_local std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> t_frameStreamServers{nullptr};
@@ -330,13 +325,11 @@ struct DNSComboWriter {
      d_local holds our own. */
   ComboAddress d_local;
   ComboAddress d_destination;
-#ifdef HAVE_PROTOBUF
   boost::uuids::uuid d_uuid;
   string d_requestorId;
   string d_deviceId;
   string d_deviceName;
   struct timeval d_kernelTimestamp{0,0};
-#endif
   std::string d_query;
   std::unordered_set<std::string> d_policyTags;
   std::string d_routingTag;
@@ -883,7 +876,6 @@ catch(...)
   return "Exception making error message for exception";
 }
 
-#ifdef HAVE_PROTOBUF
 static void protobufLogQuery(uint8_t maskV4, uint8_t maskV6, const boost::uuids::uuid& uniqueId, const ComboAddress& remote, const ComboAddress& local, const Netmask& ednssubnet, bool tcp, uint16_t id, size_t len, const DNSName& qname, uint16_t qtype, uint16_t qclass, const std::unordered_set<std::string>& policyTags, const std::string& requestorId, const std::string& deviceId, const std::string& deviceName)
 {
   if (!t_protobufServers) {
@@ -924,7 +916,6 @@ static void protobufLogResponse(pdns::ProtoZero::RecMessage& message)
     server->queueData(msg);
   }
 }
-#endif
 
 /**
  * Chases the CNAME provided by the PolicyCustom RPZ policy.
@@ -1050,7 +1041,6 @@ static PolicyResult handlePolicyHit(const DNSFilterEngine::Policy& appliedPolicy
   return PolicyResult::NoAction;
 }
 
-#ifdef HAVE_PROTOBUF
 static std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> startProtobufServers(const ProtobufExportConfig& config)
 {
   auto result = std::make_shared<std::vector<std::unique_ptr<RemoteLogger>>>();
@@ -1203,7 +1193,6 @@ static bool checkFrameStreamExport(LocalStateHolder<LuaConfigItems>& luaconfsLoc
   return true;
 }
 #endif /* HAVE_FSTRM */
-#endif /* HAVE_PROTOBUF */
 
 #ifdef NOD_ENABLED
 static bool nodCheckNewDomain(const DNSName& dname)
@@ -1434,7 +1423,6 @@ static void startDoResolve(void *p)
     // Used to tell syncres later on if we should apply NSDNAME and NSIP RPZ triggers for this query
     bool wantsRPZ(true);
     RecursorPacketCache::OptPBData pbDataForCache;
-#ifdef HAVE_PROTOBUF
     pdns::ProtoZero::RecMessage pbMessage;
     if (checkProtobufExport(luaconfsLocal)) {
       pbMessage.reserve(128, 128); // It's a bit of a guess...
@@ -1443,7 +1431,6 @@ static void startDoResolve(void *p)
 
       // RRSets added below
     }
-#endif /* HAVE_PROTOBUF */
 
 #ifdef HAVE_FSTRM
     checkFrameStreamExport(luaconfsLocal);
@@ -1501,10 +1488,8 @@ static void startDoResolve(void *p)
     }
     sr.setDNSSECValidationRequested(g_dnssecmode == DNSSECMode::ValidateAll || g_dnssecmode==DNSSECMode::ValidateForLog || ((dc->d_mdp.d_header.ad || DNSSECOK) && g_dnssecmode==DNSSECMode::Process));
 
-#ifdef HAVE_PROTOBUF
     sr.setInitialRequestId(dc->d_uuid);
     sr.setOutgoingProtobufServers(t_outgoingProtobufServers);
-#endif
 #ifdef HAVE_FSTRM
     sr.setFrameStreamServers(t_frameStreamServers);
 #endif
@@ -1528,11 +1513,9 @@ static void startDoResolve(void *p)
     dq.currentRecords = &ret;
     dq.dh = &dc->d_mdp.d_header;
     dq.data = dc->d_data;
-#ifdef HAVE_PROTOBUF
     dq.requestorId = dc->d_requestorId;
     dq.deviceId = dc->d_deviceId;
     dq.deviceName = dc->d_deviceName;
-#endif
     dq.proxyProtocolValues = &dc->d_proxyProtocolValues;
     dq.extendedErrorCode = &dc->d_extendedErrorCode;
     dq.extendedErrorExtra = &dc->d_extendedErrorExtra;
@@ -1844,11 +1827,9 @@ static void startDoResolve(void *p)
        }
 #endif /* NOD ENABLED */
 
-#ifdef HAVE_PROTOBUF
         if (t_protobufServers) {
           pbMessage.addRR(*i, luaconfsLocal->protobufExportConfig.exportTypes, udr);
         }
-#endif
       }
       if(needCommit)
        pw.commit();
@@ -1965,7 +1946,6 @@ static void startDoResolve(void *p)
       }
     }
 #endif /* NOD_ENABLED */
-#ifdef HAVE_PROTOBUF
     if (t_protobufServers && !(luaconfsLocal->protobufExportConfig.taggedOnly && appliedPolicy.getName().empty() && dc->d_policyTags.empty())) {
       // Start constructing embedded DNSResponse object
       pbMessage.setResponseCode(pw.getHeader()->rcode);
@@ -2025,7 +2005,7 @@ static void startDoResolve(void *p)
         protobufLogResponse(pbMessage);
       }
     }
-#endif /* HAVE_PROTOBUF */
+
     if(!dc->d_tcp) {
       struct msghdr msgh;
       struct iovec iov;
@@ -2476,14 +2456,13 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
       string deviceId;
       string deviceName;
       bool logQuery = false;
-#ifdef HAVE_PROTOBUF
+
       auto luaconfsLocal = g_luaconfs.getLocal();
       if (checkProtobufExport(luaconfsLocal)) {
         needECS = true;
       }
       logQuery = t_protobufServers && luaconfsLocal->protobufExportConfig.logQueries;
       dc->d_logResponse = t_protobufServers && luaconfsLocal->protobufExportConfig.logResponses;
-#endif /* HAVE_PROTOBUF */
 
 #ifdef HAVE_FSTRM
       checkFrameStreamExport(luaconfsLocal);
@@ -2527,7 +2506,6 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
 
       const struct dnsheader* dh = reinterpret_cast<const struct dnsheader*>(&conn->data[0]);
 
-#ifdef HAVE_PROTOBUF
       if(t_protobufServers || t_outgoingProtobufServers) {
         dc->d_requestorId = requestorId;
         dc->d_deviceId = deviceId;
@@ -2548,7 +2526,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
           }
         }
       }
-#endif
+
       if (t_pdl) {
         if (t_pdl->ipfilter(dc->d_source, dc->d_destination, *dh)) {
           if (!g_quiet) {
@@ -2711,7 +2689,6 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
   string routingTag;
   bool logQuery = false;
   bool logResponse = false;
-#ifdef HAVE_PROTOBUF
   boost::uuids::uuid uniqueId;
   auto luaconfsLocal = g_luaconfs.getLocal();
   if (checkProtobufExport(luaconfsLocal)) {
@@ -2722,7 +2699,6 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
   }
   logQuery = t_protobufServers && luaconfsLocal->protobufExportConfig.logQueries;
   logResponse = t_protobufServers && luaconfsLocal->protobufExportConfig.logResponses;
-#endif
 #ifdef HAVE_FSTRM
   checkFrameStreamExport(luaconfsLocal);
 #endif
@@ -2796,13 +2772,12 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
 
     bool cacheHit = false;
     RecursorPacketCache::OptPBData pbData{boost::none};
-#ifdef HAVE_PROTOBUF
+
     if (t_protobufServers) {
       if (logQuery && !(luaconfsLocal->protobufExportConfig.taggedOnly && policyTags.empty())) {
         protobufLogQuery(luaconfsLocal->protobufMaskV4, luaconfsLocal->protobufMaskV6, uniqueId, source, destination, ednssubnet.source, false, dh->id, question.size(), qname, qtype, qclass, policyTags, requestorId, deviceId, deviceName);
       }
     }
-#endif /* HAVE_PROTOBUF */
 
     /* It might seem like a good idea to skip the packet cache lookup if we know that the answer is not cacheable,
        but it means that the hash would not be computed. If some script decides at a later time to mark back the answer
@@ -2823,8 +2798,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
           t_bogusqueryring->push_back(make_pair(qname, qtype));
       }
 
-#ifdef HAVE_PROTOBUF
-      if(t_protobufServers && logResponse && !(luaconfsLocal->protobufExportConfig.taggedOnly && pbData && !pbData->d_tagged)) { // XXX
+      if (t_protobufServers && logResponse && !(luaconfsLocal->protobufExportConfig.taggedOnly && pbData && !pbData->d_tagged)) { // XXX
         pdns::ProtoZero::RecMessage pbMessage(pbData ? pbData->d_message : "", pbData ? pbData->d_response : "", 64, 10); // The extra bytes we are going to add
         if (pbData) {
           // We take the inmutable string from the cache and are appending a few values
@@ -2863,7 +2837,7 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
 #endif
         protobufLogResponse(pbMessage);
       }
-#endif /* HAVE_PROTOBUF */
+
       if(!g_quiet)
         g_log<<Logger::Notice<<t_id<< " question answered from packet cache tag="<<ctag<<" from "<<source.toStringWithPort()<<(source != fromaddr ? " (via "+fromaddr.toStringWithPort()+")" : "")<<endl;
 
@@ -2935,7 +2909,6 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
   dc->d_followCNAMERecords = followCNAMEs;
   dc->d_rcode = rcode;
   dc->d_logResponse = logResponse;
-#ifdef HAVE_PROTOBUF
   if (t_protobufServers || t_outgoingProtobufServers) {
     dc->d_uuid = std::move(uniqueId);
   }
@@ -2943,7 +2916,6 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
   dc->d_deviceId = deviceId;
   dc->d_deviceName = deviceName;
   dc->d_kernelTimestamp = tv;
-#endif
   dc->d_proxyProtocolValues = std::move(proxyProtocolValues);
   dc->d_routingTag = std::move(routingTag);
   dc->d_extendedErrorCode = extendedErrorCode;
@@ -4996,9 +4968,6 @@ static int serviceMain(int argc, char*argv[])
     }
   }
 
-#ifdef HAVE_PROTOBUF
-  google::protobuf::ShutdownProtobufLibrary();
-#endif /* HAVE_PROTOBUF */
   return ret;
 }
 
@@ -5076,12 +5045,10 @@ try
   MT=std::unique_ptr<MTasker<PacketID,string> >(new MTasker<PacketID,string>(::arg().asNum("stack-size")));
   threadInfo.mt = MT.get();
 
-#ifdef HAVE_PROTOBUF
   /* start protobuf export threads if needed */
   auto luaconfsLocal = g_luaconfs.getLocal();
   checkProtobufExport(luaconfsLocal);
   checkOutgoingProtobufExport(luaconfsLocal);
-#endif /* HAVE_PROTOBUF */
 #ifdef HAVE_FSTRM
   checkFrameStreamExport(luaconfsLocal);
 #endif
index 7a767af1be93c5b45d3b38616777f90769f78169..7d4f49ed305a860101ffa3299d5c298800e3f918 100644 (file)
@@ -127,11 +127,9 @@ namespace pdns {
         }
       }
 
-      void setInitialRequesId(const std::string& id)
+      void setInitialRequestID(const boost::uuids::uuid& uniqueId)
       {
-        if (!id.empty()) {
-          d_message.add_string(16, id);
-        }
+        d_message.add_bytes(16, reinterpret_cast<const char*>(uniqueId.begin()), uniqueId.size());
       }
 
       void setDeviceId(const std::string& id)
@@ -178,6 +176,12 @@ namespace pdns {
         d_response.add_uint32(1, rcode);
       }
 
+      void setNetworkErrorResponseCode()
+      {
+        /* special code meaning 'network error', like a timeout */
+        d_response.add_uint32(1, 65536);
+      }
+
       void setAppliedPolicy(const std::string& policy)
       {
         d_response.add_string(3, policy);
index 7532c8a487a649223fc91d3ff4ee7adf2bc786cf..fa6a4c13bddb7c728172740a3a1ba7487a0e7598 100644 (file)
@@ -109,7 +109,6 @@ static void parseRPZParameters(rpzOptions_t& have, std::shared_ptr<DNSFilterEngi
   }
 }
 
-#if HAVE_PROTOBUF
 typedef std::unordered_map<std::string, boost::variant<bool, uint64_t, std::string, std::vector<std::pair<int,std::string> > > > protobufOptions_t;
 
 static void parseProtobufOptions(boost::optional<protobufOptions_t> vars, ProtobufExportConfig& config)
@@ -168,7 +167,6 @@ static void parseProtobufOptions(boost::optional<protobufOptions_t> vars, Protob
     }
   }
 }
-#endif /* HAVE_PROTOBUF */
 
 #ifdef HAVE_FSTRM
 typedef std::unordered_map<std::string, boost::variant<bool, uint64_t, std::string, std::vector<std::pair<int,std::string> > > > frameStreamOptions_t;
@@ -487,7 +485,6 @@ void loadRecursorLuaConfig(const std::string& fname, luaConfigDelayedThreads& de
       updateTrustAnchorsFromFile(fnamearg, lci.dsAnchors);
     });
 
-#if HAVE_PROTOBUF
   Lua.writeFunction("setProtobufMasks", [&lci](const uint8_t maskV4, uint8_t maskV6) {
       lci.protobufMaskV4 = maskV4;
       lci.protobufMaskV6 = maskV6;
@@ -556,7 +553,6 @@ void loadRecursorLuaConfig(const std::string& fname, luaConfigDelayedThreads& de
         g_log<<Logger::Error<<"Only one outgoingProtobufServer() directive can be configured, we already have "<<lci.outgoingProtobufExportConfig.servers.at(0).toString()<<endl;
       }
     });
-#endif
 
 #ifdef HAVE_FSTRM
   Lua.writeFunction("dnstapFrameStreamServer", [&lci](boost::variant<const std::string, const std::unordered_map<int, std::string>> servers, boost::optional<frameStreamOptions_t> vars) {
index a938c12cd54232819f45af8ad0054cf5dfd0decd..bbccffd26d04bd61c242b4f47f52d4218c9bcdb7 100644 (file)
@@ -71,7 +71,7 @@ bool RecursorPacketCache::checkResponseMatches(std::pair<packetCache_t::index<Ha
 
       d_hits++;
       moveCacheItemToBack<SequencedTag>(d_packetCache, iter);
-#ifdef HAVE_PROTOBUF
+
       if (pbdata != nullptr) {
         if (iter->d_pbdata) {
           *pbdata = iter->d_pbdata;
@@ -79,7 +79,7 @@ bool RecursorPacketCache::checkResponseMatches(std::pair<packetCache_t::index<Ha
           *pbdata = boost::none;
         }
       }
-#endif
+
       return true;
     }
     else {
@@ -158,11 +158,10 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
     iter->d_ttd = now + ttl;
     iter->d_creation = now;
     iter->d_vstate = valState;
-#ifdef HAVE_PROTOBUF
+
     if (pbdata) {
       iter->d_pbdata = std::move(*pbdata);
     }
-#endif
 
     break;
   }
@@ -176,11 +175,11 @@ void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash,
     e.d_creation = now;
     e.d_tag = tag;
     e.d_vstate = valState;
-#ifdef HAVE_PROTOBUF
+
     if (pbdata) {
       e.d_pbdata = std::move(*pbdata);
     }
-#endif
+
     d_packetCache.insert(e);
   }
 }
index 75400b14b4826dc81cfa45cf0dff185a7e9a4a5e..aae60d954962146b7c5c40e2e75e2a4b03db422d 100644 (file)
@@ -38,8 +38,6 @@
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
-#include "rec-protobuf.hh"
-
 
 using namespace ::boost::multi_index;
 
@@ -86,9 +84,7 @@ private:
     DNSName d_name;
     mutable std::string d_packet; // "I know what I am doing"
     mutable std::string d_query;
-#ifdef HAVE_PROTOBUF
     mutable OptPBData d_pbdata;
-#endif
     mutable time_t d_ttd;
     mutable time_t d_creation; // so we can 'age' our packets
     uint32_t d_qhash;
index 16ea652280f78610862e22f5972e5d487ce67929..8f7f0ac05a5381f05ad1ca174e0517c94804400f 100644 (file)
@@ -143,7 +143,6 @@ pdns_recursor_SOURCES = \
        pdns_recursor.cc \
        pdnsexception.hh \
        pollmplexer.cc \
-       protobuf.cc protobuf.hh \
        protozero.cc protozero.hh \
        proxy-protocol.cc proxy-protocol.hh \
        pubsuffix.hh pubsuffix.cc \
@@ -153,7 +152,6 @@ pdns_recursor_SOURCES = \
        rcpgenerator.cc rcpgenerator.hh \
        rec-carbon.cc \
        rec-lua-conf.hh rec-lua-conf.cc \
-       rec-protobuf.cc rec-protobuf.hh \
        rec-protozero.cc rec-protozero.hh \
        rec-snmp.hh rec-snmp.cc \
        rec_channel.cc rec_channel.hh rec_metrics.hh \
@@ -257,11 +255,9 @@ testrunner_SOURCES = \
        opensslsigners.cc opensslsigners.hh \
        pdnsexception.hh \
        pollmplexer.cc \
-       protobuf.cc protobuf.hh \
        qtype.cc qtype.hh \
        query-local-address.hh query-local-address.cc \
        rcpgenerator.cc \
-       rec-protobuf.cc rec-protobuf.hh \
        recpacketcache.cc recpacketcache.hh \
        recursor_cache.cc recursor_cache.hh \
        resolver.hh resolver.cc \
@@ -394,24 +390,6 @@ testrunner_SOURCES += \
        portsmplexer.cc
 endif
 
-if HAVE_PROTOBUF
-if HAVE_PROTOC
-dnsmessage.pb.cc: dnsmessage.proto
-       $(AM_V_GEN)$(PROTOC) --cpp_out=./ $<
-
-BUILT_SOURCES += dnsmessage.pb.cc
-pdns_recursor_LDADD += $(PROTOBUF_LIBS)
-nodist_pdns_recursor_SOURCES = dnsmessage.pb.cc dnsmessage.pb.h
-nodist_testrunner_SOURCES = dnsmessage.pb.cc dnsmessage.pb.h
-
-pdns_recursor.$(OBJEXT): dnsmessage.pb.cc
-testrunner$(OBJEXT): dnsmessage.pb.cc
-
-testrunner_LDADD += $(PROTOBUF_LIBS)
-
-endif
-endif
-
 if FSTRM
 pdns_recursor_SOURCES += \
        dnstap.cc dnstap.hh
index f5f525ad5ea5ed394fe58eef6b3d9f38b0844528..950b3d48d50c9068fe9e99ca2ce0d2dd8ac4761d 100644 (file)
@@ -42,8 +42,6 @@ PTHREAD_SET_NAME
 
 PDNS_CHECK_CLOCK_GETTIME
 
-PDNS_WITH_PROTOBUF
-
 BOOST_REQUIRE([1.42])
 
 # Check against flat_set header that requires boost >= 1.48
@@ -206,10 +204,9 @@ AS_IF([test "x$LIBDECAF_LIBS" != "x" || test "x$libcrypto_ed448" = "xyes"],
   [AC_MSG_NOTICE([ed448: yes])],
   [AC_MSG_NOTICE([ed448: no])]
 )
-AS_IF([test "x$PROTOBUF_LIBS" != "x" -a x"$PROTOC" != "x"],
-  [AC_MSG_NOTICE([Protobuf: yes])],
-  [AC_MSG_NOTICE([Protobuf: no])]
-)
+
+AC_MSG_NOTICE([Protobuf: yes])
+
 AS_IF([test "x$NET_SNMP_LIBS" != "x"],
   [AC_MSG_NOTICE([SNMP: yes])],
   [AC_MSG_NOTICE([SNMP: no])]
diff --git a/pdns/recursordist/m4/pdns_with_protobuf.m4 b/pdns/recursordist/m4/pdns_with_protobuf.m4
deleted file mode 120000 (symlink)
index bdfe381..0000000
+++ /dev/null
@@ -1 +0,0 @@
-../../../m4/pdns_with_protobuf.m4
\ No newline at end of file
index 74f208651f23769523a30d4ef18f91028c494f8e..42eba70ad20993181005347ef7c2f8eff194c45c 100644 (file)
@@ -33,6 +33,12 @@ namespace pdns {
       {
         d_response = protozero::pbf_writer(d_rspbuf);
       }
+
+      RecMessage(std::string& buffer): Message(buffer)
+      {
+        d_response = protozero::pbf_writer(buffer);
+      }
+
       // Start a new messagebuf, containing separate data for the response part
       RecMessage(std::string::size_type sz1, std::string::size_type sz2): RecMessage()
       {
index 7ad9bf553b05f2e23044115d0a4bc2fd6f1d2d3a..5782961249ef32658645efd0fc75133544bcd20f 100644 (file)
@@ -2,10 +2,8 @@
 
 #include "config.h"
 
-#ifdef HAVE_PROTOBUF
 #include <boost/uuid/uuid.hpp>
 #include <boost/optional.hpp>
-#endif
 
 struct ResolveContext {
   ResolveContext()
@@ -15,9 +13,7 @@ struct ResolveContext {
   ResolveContext(const ResolveContext& ctx) = delete;
   ResolveContext & operator=(const ResolveContext&) = delete;
   
-#ifdef HAVE_PROTOBUF
   boost::optional<const boost::uuids::uuid&> d_initialRequestId;
-#endif
 #ifdef HAVE_FSTRM
   boost::optional<const DNSName&> d_auth;
 #endif
index 87d26e4e7dca4a19728fceebab8c03f65b50e972..cfc8ad56f2eb2392637405799784be3548b3e6b1 100644 (file)
@@ -574,9 +574,7 @@ LWResult::Result SyncRes::asyncresolveWrapper(const ComboAddress& ip, bool ednsM
   int EDNSLevel = 0;
   auto luaconfsLocal = g_luaconfs.getLocal();
   ResolveContext ctx;
-#ifdef HAVE_PROTOBUF
   ctx.d_initialRequestId = d_initialRequestId;
-#endif
 #ifdef HAVE_FSTRM
   ctx.d_auth = auth;
 #endif
index 8581459b8aa504df30d13c86d8aca6b1c2cf7643..f1a32128655ada023ff5d480a6baf4a93cf6a205 100644 (file)
 #include "config.h"
 #endif
 
-#ifdef HAVE_PROTOBUF
 #include <boost/uuid/uuid.hpp>
 #ifdef HAVE_FSTRM
 #include "fstrm_logger.hh"
 #endif /* HAVE_FSTRM */
-#endif
 
 extern GlobalStateHolder<SuffixMatchNode> g_dontThrottleNames;
 extern GlobalStateHolder<NetmaskGroup> g_dontThrottleNetmasks;
@@ -684,7 +682,6 @@ public:
 
   void setQuerySource(const ComboAddress& requestor, boost::optional<const EDNSSubnetOpts&> incomingECS);
 
-#ifdef HAVE_PROTOBUF
   void setInitialRequestId(boost::optional<const boost::uuids::uuid&> initialRequestId)
   {
     d_initialRequestId = initialRequestId;
@@ -694,7 +691,6 @@ public:
   {
     d_outgoingProtobufServers = servers;
   }
-#endif
 
 #ifdef HAVE_FSTRM
   void setFrameStreamServers(std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>>& servers)
@@ -875,9 +871,7 @@ private:
   boost::optional<Netmask> d_outgoingECSNetwork;
   std::shared_ptr<std::vector<std::unique_ptr<RemoteLogger>>> d_outgoingProtobufServers{nullptr};
   std::shared_ptr<std::vector<std::unique_ptr<FrameStreamLogger>>> d_frameStreamServers{nullptr};
-#ifdef HAVE_PROTOBUF
   boost::optional<const boost::uuids::uuid&> d_initialRequestId;
-#endif
   asyncresolve_t d_asyncResolve{nullptr};
   struct timeval d_now;
   string d_prefix;
index 2b7a513ec58b79ae9c934ed19df1c909a7b5c9e1..7b6d154753c57db81cf4a3dab442d86f1a51f0b7 100644 (file)
@@ -122,9 +122,7 @@ void showBuildConfiguration()
 #ifdef HAVE_P11KIT1
     "PKCS#11 " <<
 #endif
-#ifdef HAVE_PROTOBUF
 "protobuf " <<
-#endif
 #ifdef HAVE_FSTRM
 "dnstap-framestream " <<
 #endif