]> granicus.if.org Git - pdns/commitdiff
Move UUID generators to a common function, fix boost 1.69.0 warning
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 18 Jan 2019 10:08:20 +0000 (11:08 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 18 Jan 2019 10:08:20 +0000 (11:08 +0100)
20 files changed:
pdns/Makefile.am
pdns/dnsdist-lua-actions.cc
pdns/dnsdist-lua-rules.cc
pdns/dnsdist-protobuf.cc
pdns/dnsdist.cc
pdns/dnsdist.hh
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/uuid-utils.cc [new symlink]
pdns/dnsdistdist/uuid-utils.hh [new symlink]
pdns/dnspcap2protobuf.cc
pdns/dnstap.hh
pdns/lwres.cc
pdns/pdns_recursor.cc
pdns/protobuf.hh
pdns/recursordist/Makefile.am
pdns/recursordist/uuid-utils.cc [new symlink]
pdns/recursordist/uuid-utils.hh [new symlink]
pdns/syncres.hh
pdns/uuid-utils.cc [new file with mode: 0644]
pdns/uuid-utils.hh [new file with mode: 0644]

index 73f73791dceb7e5906b37a85423128d32beeb405..36f1877c97567c53eb9ad05013249e3f98e0dc3b 100644 (file)
@@ -1219,7 +1219,8 @@ dnspcap2protobuf_SOURCES = \
        sillyrecords.cc \
        statbag.cc \
        unix_utility.cc \
-       utility.hh
+       utility.hh \
+       uuid-utils.hh uuid-utils.cc
 
 nodist_dnspcap2protobuf_SOURCES=dnsmessage.pb.cc dnsmessage.pb.h
 
index 5cb2dc3e8e4f5fca2662b1afc559635ff68b70ec..43fa9aa3c1918ffd1b30927b3aa810242a74a9dd 100644 (file)
@@ -758,7 +758,7 @@ public:
   {
 #ifdef HAVE_PROTOBUF
     if (!dq->uniqueId) {
-      dq->uniqueId = t_uuidGenerator();
+      dq->uniqueId = getUniqueID();
     }
 
     DNSDistProtoBufMessage message(*dq);
@@ -878,7 +878,7 @@ public:
   {
 #ifdef HAVE_PROTOBUF
     if (!dr->uniqueId) {
-      dr->uniqueId = t_uuidGenerator();
+      dr->uniqueId = getUniqueID();
     }
 
     DNSDistProtoBufMessage message(*dr, d_includeCNAME);
index c209d10a500822b1af30299a89b5b9df4ebc67ea..9d83032bf95a95ee5dbca728de4bcfd3f6ba6dd9 100644 (file)
@@ -61,11 +61,10 @@ std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var)
 static boost::uuids::uuid makeRuleID(std::string& id)
 {
   if (id.empty()) {
-    return t_uuidGenerator();
+    return getUniqueID();
   }
 
-  boost::uuids::string_generator gen;
-  return gen(id);
+  return getUniqueID(id);
 }
 
 void parseRuleParams(boost::optional<luaruleparams_t> params, boost::uuids::uuid& uuid, uint64_t& creationOrder)
@@ -128,8 +127,7 @@ static void rmRule(GlobalStateHolder<vector<T> > *someRulActions, boost::variant
   setLuaSideEffect();
   auto rules = someRulActions->getCopy();
   if (auto str = boost::get<std::string>(&id)) {
-    boost::uuids::string_generator gen;
-    const auto uuid = gen(*str);
+    const auto uuid = getUniqueID(*str);
     if (rules.erase(std::remove_if(rules.begin(),
                                     rules.end(),
                                     [uuid](const T& a) { return a.d_id == uuid; }),
index 26c67b6b28e2557918220c0dc53c987f9c5e4ea7..fcf2fd6508b02efb7039aec57ec76d0455ed2cb1 100644 (file)
 #ifdef HAVE_PROTOBUF
 #include "dnsmessage.pb.h"
 
-DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSQuestion& dq): DNSProtoBufMessage(Query, dq.uniqueId ? *dq.uniqueId : t_uuidGenerator(), dq.remote, dq.local, *dq.qname, dq.qtype, dq.qclass, dq.dh->id, dq.tcp, dq.len)
+DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSQuestion& dq): DNSProtoBufMessage(Query, dq.uniqueId ? *dq.uniqueId : getUniqueID(), dq.remote, dq.local, *dq.qname, dq.qtype, dq.qclass, dq.dh->id, dq.tcp, dq.len)
 {
   setQueryTime(dq.queryTime->tv_sec, dq.queryTime->tv_nsec / 1000);
 };
 
-DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSResponse& dr, bool includeCNAME): DNSProtoBufMessage(Response, dr.uniqueId ? *dr.uniqueId : t_uuidGenerator(), dr.remote, dr.local, *dr.qname, dr.qtype, dr.qclass, dr.dh->id, dr.tcp, dr.len)
+DNSDistProtoBufMessage::DNSDistProtoBufMessage(const DNSResponse& dr, bool includeCNAME): DNSProtoBufMessage(Response, dr.uniqueId ? *dr.uniqueId : getUniqueID(), dr.remote, dr.local, *dr.qname, dr.qtype, dr.qclass, dr.dh->id, dr.tcp, dr.len)
 {
   setQueryTime(dr.queryTime->tv_sec, dr.queryTime->tv_nsec / 1000);
   setResponseCode(dr.dh->rcode);
index 6ce43ff7c5b8730b94a2720e95c59aafabea26d1..65e5c2fb78db14c96d09df97cb2eb8bd1c589a1d 100644 (file)
@@ -64,8 +64,6 @@
 #include "sstuff.hh"
 #include "threadname.hh"
 
-thread_local boost::uuids::random_generator t_uuidGenerator;
-
 /* Known sins:
 
    Receiver is currently single threaded
@@ -702,7 +700,7 @@ void DownstreamState::setWeight(int newWeight)
 DownstreamState::DownstreamState(const ComboAddress& remote_, const ComboAddress& sourceAddr_, unsigned int sourceItf_, size_t numberOfSockets): remote(remote_), sourceAddr(sourceAddr_), sourceItf(sourceItf_)
 {
   pthread_rwlock_init(&d_lock, nullptr);
-  id = t_uuidGenerator();
+  id = getUniqueID();
   threadStarted.clear();
 
   mplexer = std::unique_ptr<FDMultiplexer>(FDMultiplexer::getMultiplexerSilent());
index bbeeb0bcba60ad59bacac72e93cd91fe5686f49a..8340716b85bacdad3d921fdd804281d2591a7b3e 100644 (file)
 #include "mplexer.hh"
 #include "sholder.hh"
 #include "tcpiohandler.hh"
-
-#include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
-#include <boost/uuid/uuid_io.hpp>
+#include "uuid-utils.hh"
 
 void carbonDumpThread();
 uint64_t uptimeOfProcess(const std::string& str);
@@ -59,8 +56,6 @@ extern uint16_t g_ECSSourcePrefixV4;
 extern uint16_t g_ECSSourcePrefixV6;
 extern bool g_ECSOverride;
 
-extern thread_local boost::uuids::random_generator t_uuidGenerator;
-
 typedef std::unordered_map<string, string> QTag;
 
 struct DNSQuestion
index 9f422a86cdac138ee7dcf8018533a99c021bb05f..7d5bec38706db67f822b113fae4372a904ba6a0d 100644 (file)
@@ -142,6 +142,7 @@ dnsdist_SOURCES = \
        statnode.cc statnode.hh \
        tcpiohandler.cc tcpiohandler.hh \
        threadname.hh threadname.cc \
+       uuid-utils.hh uuid-utils.cc \
        xpf.cc xpf.hh \
        ext/luawrapper/include/LuaContext.hpp \
        ext/json11/json11.cpp \
diff --git a/pdns/dnsdistdist/uuid-utils.cc b/pdns/dnsdistdist/uuid-utils.cc
new file mode 120000 (symlink)
index 0000000..e09cb82
--- /dev/null
@@ -0,0 +1 @@
+../uuid-utils.cc
\ No newline at end of file
diff --git a/pdns/dnsdistdist/uuid-utils.hh b/pdns/dnsdistdist/uuid-utils.hh
new file mode 120000 (symlink)
index 0000000..f05d869
--- /dev/null
@@ -0,0 +1 @@
+../uuid-utils.hh
\ No newline at end of file
index 441927c32ab49a9e4ed762b48511b6469e3f09dc..9d0f19ad75174a14ff1ba3d2ae1423d764809957 100644 (file)
@@ -23,7 +23,6 @@
 #include "config.h"
 #endif
 #include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
 
 #include "iputils.hh"
 #include "misc.hh"
@@ -32,6 +31,7 @@
 #include "dnspcap.hh"
 #include "dnsparser.hh"
 #include "protobuf.hh"
+#include "uuid-utils.hh"
 
 #include "statbag.hh"
 StatBag S;
@@ -75,7 +75,6 @@ try {
     ind=atoi(argv[3]);
 
   std::map<uint16_t,std::pair<boost::uuids::uuid,struct timeval> > ids;
-  boost::uuids::random_generator uuidGenerator;
   try {
     while (pr.getUDPPacket()) {
       const dnsheader* dh=(dnsheader*)pr.d_payload;
@@ -104,7 +103,7 @@ try {
       if (!dh->qr) {
         queryTime.tv_sec = pr.d_pheader.ts.tv_sec;
         queryTime.tv_usec = pr.d_pheader.ts.tv_usec;
-        uniqueId = uuidGenerator();
+        uniqueId = getUniqueID();
         ids[dh->id] = std::make_pair(uniqueId, queryTime);
       }
       else {
@@ -115,7 +114,7 @@ try {
           hasQueryTime = true;
         }
         else {
-          uniqueId = uuidGenerator();
+          uniqueId = getUniqueID();
         }
       }
 
index e25df4f104cef8d06ff4ab89ac5370fb8bc76b0c..d00bd0bca81c5c74477a0b66858bab47d68295f3 100644 (file)
@@ -31,7 +31,6 @@
 
 #ifdef HAVE_PROTOBUF
 #include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
 #include "dnstap.pb.h"
 #endif /* HAVE_PROTOBUF */
 
@@ -48,4 +47,4 @@ public:
 protected:
   dnstap::Dnstap proto_message;
 #endif /* HAVE_PROTOBUF */
-};
\ No newline at end of file
+};
index d4765b0b7bfe6f62e73c5325008d16e373292735..794838924ae0106d532b81d3e79d31ed6ff45c26 100644 (file)
@@ -50,6 +50,8 @@
 
 #ifdef HAVE_PROTOBUF
 
+#include "uuid-utils.hh"
+
 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)
@@ -160,7 +162,7 @@ int asyncresolve(const ComboAddress& ip, const DNSName& domain, int type, bool d
   const struct timeval queryTime = *now;
 
   if (outgoingLoggers) {
-    uuid = (*t_uuidGenerator)();
+    uuid = getUniqueID();
     logOutgoingQuery(outgoingLoggers, context ? context->d_initialRequestId : boost::none, uuid, ip, domain, type, qid, doTCP, vpacket.size(), srcmask);
   }
 #endif
index ca40f1bb9248eb3ec18dd95ec1c2845327eaa684..e8208a859849691aca47db6d4b1cdfa010c49c50 100644 (file)
 
 #include "namespaces.hh"
 
+#ifdef HAVE_PROTOBUF
+#include "uuid-utils.hh"
+#endif
+
 #include "xpf.hh"
 
 typedef map<ComboAddress, uint32_t, ComboAddress::addressOnlyLessThan> tcpClientCounts_t;
@@ -124,9 +128,6 @@ thread_local FDMultiplexer* t_fdm{nullptr};
 thread_local std::unique_ptr<addrringbuf_t> t_remotes, t_servfailremotes, t_largeanswerremotes, t_bogusremotes;
 thread_local std::unique_ptr<boost::circular_buffer<pair<DNSName, uint16_t> > > t_queryring, t_servfailqueryring, t_bogusqueryring;
 thread_local std::shared_ptr<NetmaskGroup> t_allowFrom;
-#ifdef HAVE_PROTOBUF
-thread_local std::unique_ptr<boost::uuids::random_generator> t_uuidGenerator;
-#endif
 #ifdef NOD_ENABLED
 thread_local std::shared_ptr<nod::NODDB> t_nodDBp;
 thread_local std::shared_ptr<nod::UniqueResponseDB> t_udrDBp;
@@ -1942,7 +1943,7 @@ static void handleRunningTCPQuestion(int fd, FDMultiplexer::funcparam_t& var)
       if(t_protobufServers || t_outgoingProtobufServers) {
         dc->d_requestorId = requestorId;
         dc->d_deviceId = deviceId;
-        dc->d_uuid = (*t_uuidGenerator)();
+        dc->d_uuid = getUniqueID();
       }
 
       if(t_protobufServers) {
@@ -2077,10 +2078,10 @@ static string* doProcessUDPQuestion(const std::string& question, const ComboAddr
   boost::uuids::uuid uniqueId;
   auto luaconfsLocal = g_luaconfs.getLocal();
   if (checkProtobufExport(luaconfsLocal)) {
-    uniqueId = (*t_uuidGenerator)();
+    uniqueId = getUniqueID();
     needECS = true;
   } else if (checkOutgoingProtobufExport(luaconfsLocal)) {
-    uniqueId = (*t_uuidGenerator)();
+    uniqueId = getUniqueID();
   }
   logQuery = t_protobufServers && luaconfsLocal->protobufExportConfig.logQueries;
   bool logResponse = t_protobufServers && luaconfsLocal->protobufExportConfig.logResponses;
@@ -3932,9 +3933,6 @@ try
 
   t_packetCache = std::unique_ptr<RecursorPacketCache>(new RecursorPacketCache());
 
-#ifdef HAVE_PROTOBUF
-  t_uuidGenerator = std::unique_ptr<boost::uuids::random_generator>(new boost::uuids::random_generator());
-#endif
   g_log<<Logger::Warning<<"Done priming cache with root hints"<<endl;
 
 #ifdef NOD_ENABLED
index fc070acb982866ce3911c79cb3b0d8bacc4b6261..c52af41621b97019c0bdd11eb7ab3522a583cab2 100644 (file)
@@ -31,7 +31,6 @@
 
 #ifdef HAVE_PROTOBUF
 #include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
 #include "dnsmessage.pb.h"
 #endif /* HAVE_PROTOBUF */
 
index 022cc6cb3fb2c782e99b40a0cf66589e0d2e7e67..c640a9990947bdc72e974ba70afbfe190f153fb1 100644 (file)
@@ -362,6 +362,10 @@ testrunner_LDADD += $(PROTOBUF_LIBS)
 testrunner$(OBJEXT): dnsmessage.pb.cc
 
 endif
+
+pdns_recursor_SOURCES += \
+       uuid-utils.hh uuid-utils.cc
+
 endif
 
 rec_control_SOURCES = \
diff --git a/pdns/recursordist/uuid-utils.cc b/pdns/recursordist/uuid-utils.cc
new file mode 120000 (symlink)
index 0000000..e09cb82
--- /dev/null
@@ -0,0 +1 @@
+../uuid-utils.cc
\ No newline at end of file
diff --git a/pdns/recursordist/uuid-utils.hh b/pdns/recursordist/uuid-utils.hh
new file mode 120000 (symlink)
index 0000000..f05d869
--- /dev/null
@@ -0,0 +1 @@
+../uuid-utils.hh
\ No newline at end of file
index 78b08e24db882c7a979053dac719c1cf9a357404..75eaee04d74d1629d2dc631eb7adb368957519ac 100644 (file)
@@ -56,7 +56,6 @@
 
 #ifdef HAVE_PROTOBUF
 #include <boost/uuid/uuid.hpp>
-#include <boost/uuid/uuid_generators.hpp>
 #endif
 
 class RecursorLua4;
@@ -1016,7 +1015,3 @@ void doCarbonDump(void*);
 void primeHints(void);
 
 extern __thread struct timeval g_now;
-
-#ifdef HAVE_PROTOBUF
-extern thread_local std::unique_ptr<boost::uuids::random_generator> t_uuidGenerator;
-#endif
diff --git a/pdns/uuid-utils.cc b/pdns/uuid-utils.cc
new file mode 100644 (file)
index 0000000..12340ae
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * 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.
+ */
+
+#include "uuid-utils.hh"
+
+// see https://github.com/boostorg/random/issues/49
+#if BOOST_VERSION == 106900
+#ifndef BOOST_PENDING_INTEGER_LOG2_HPP
+#define BOOST_PENDING_INTEGER_LOG2_HPP
+#include <boost/integer/integer_log2.hpp>
+#endif /* BOOST_PENDING_INTEGER_LOG2_HPP */
+#endif /* BOOST_VERSION */
+
+#include <boost/uuid/uuid_generators.hpp>
+
+thread_local boost::uuids::random_generator t_uuidGenerator;
+
+boost::uuids::uuid getUniqueID()
+{
+  return t_uuidGenerator();
+}
+
+boost::uuids::uuid getUniqueID(const std::string& str)
+{
+  boost::uuids::string_generator gen;
+  return gen(str);
+}
+
diff --git a/pdns/uuid-utils.hh b/pdns/uuid-utils.hh
new file mode 100644 (file)
index 0000000..3aa7844
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * 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
+
+#include <boost/uuid/uuid.hpp>
+#include <boost/uuid/uuid_io.hpp>
+
+boost::uuids::uuid getUniqueID();
+boost::uuids::uuid getUniqueID(const std::string& str);