From d61aa9451bb202ed2a88bb42cf8f85a969fe96c4 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 18 Jan 2019 11:08:20 +0100 Subject: [PATCH] Move UUID generators to a common function, fix boost 1.69.0 warning --- pdns/Makefile.am | 3 ++- pdns/dnsdist-lua-actions.cc | 4 +-- pdns/dnsdist-lua-rules.cc | 8 +++--- pdns/dnsdist-protobuf.cc | 4 +-- pdns/dnsdist.cc | 4 +-- pdns/dnsdist.hh | 7 +---- pdns/dnsdistdist/Makefile.am | 1 + pdns/dnsdistdist/uuid-utils.cc | 1 + pdns/dnsdistdist/uuid-utils.hh | 1 + pdns/dnspcap2protobuf.cc | 7 +++-- pdns/dnstap.hh | 3 +-- pdns/lwres.cc | 4 ++- pdns/pdns_recursor.cc | 16 +++++------ pdns/protobuf.hh | 1 - pdns/recursordist/Makefile.am | 4 +++ pdns/recursordist/uuid-utils.cc | 1 + pdns/recursordist/uuid-utils.hh | 1 + pdns/syncres.hh | 5 ---- pdns/uuid-utils.cc | 47 +++++++++++++++++++++++++++++++++ pdns/uuid-utils.hh | 28 ++++++++++++++++++++ 20 files changed, 109 insertions(+), 41 deletions(-) create mode 120000 pdns/dnsdistdist/uuid-utils.cc create mode 120000 pdns/dnsdistdist/uuid-utils.hh create mode 120000 pdns/recursordist/uuid-utils.cc create mode 120000 pdns/recursordist/uuid-utils.hh create mode 100644 pdns/uuid-utils.cc create mode 100644 pdns/uuid-utils.hh diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 73f73791dc..36f1877c97 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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 diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index 5cb2dc3e8e..43fa9aa3c1 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -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); diff --git a/pdns/dnsdist-lua-rules.cc b/pdns/dnsdist-lua-rules.cc index c209d10a50..9d83032bf9 100644 --- a/pdns/dnsdist-lua-rules.cc +++ b/pdns/dnsdist-lua-rules.cc @@ -61,11 +61,10 @@ std::shared_ptr 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 params, boost::uuids::uuid& uuid, uint64_t& creationOrder) @@ -128,8 +127,7 @@ static void rmRule(GlobalStateHolder > *someRulActions, boost::variant setLuaSideEffect(); auto rules = someRulActions->getCopy(); if (auto str = boost::get(&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; }), diff --git a/pdns/dnsdist-protobuf.cc b/pdns/dnsdist-protobuf.cc index 26c67b6b28..fcf2fd6508 100644 --- a/pdns/dnsdist-protobuf.cc +++ b/pdns/dnsdist-protobuf.cc @@ -28,12 +28,12 @@ #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); diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 6ce43ff7c5..65e5c2fb78 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -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::getMultiplexerSilent()); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index bbeeb0bcba..8340716b85 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -47,10 +47,7 @@ #include "mplexer.hh" #include "sholder.hh" #include "tcpiohandler.hh" - -#include -#include -#include +#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 QTag; struct DNSQuestion diff --git a/pdns/dnsdistdist/Makefile.am b/pdns/dnsdistdist/Makefile.am index 9f422a86cd..7d5bec3870 100644 --- a/pdns/dnsdistdist/Makefile.am +++ b/pdns/dnsdistdist/Makefile.am @@ -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 index 0000000000..e09cb82957 --- /dev/null +++ b/pdns/dnsdistdist/uuid-utils.cc @@ -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 index 0000000000..f05d869cf0 --- /dev/null +++ b/pdns/dnsdistdist/uuid-utils.hh @@ -0,0 +1 @@ +../uuid-utils.hh \ No newline at end of file diff --git a/pdns/dnspcap2protobuf.cc b/pdns/dnspcap2protobuf.cc index 441927c32a..9d0f19ad75 100644 --- a/pdns/dnspcap2protobuf.cc +++ b/pdns/dnspcap2protobuf.cc @@ -23,7 +23,6 @@ #include "config.h" #endif #include -#include #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 > 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(); } } diff --git a/pdns/dnstap.hh b/pdns/dnstap.hh index e25df4f104..d00bd0bca8 100644 --- a/pdns/dnstap.hh +++ b/pdns/dnstap.hh @@ -31,7 +31,6 @@ #ifdef HAVE_PROTOBUF #include -#include #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 +}; diff --git a/pdns/lwres.cc b/pdns/lwres.cc index d4765b0b7b..794838924a 100644 --- a/pdns/lwres.cc +++ b/pdns/lwres.cc @@ -50,6 +50,8 @@ #ifdef HAVE_PROTOBUF +#include "uuid-utils.hh" + static void logOutgoingQuery(const std::shared_ptr>>& outgoingLoggers, boost::optional initialRequestId, const boost::uuids::uuid& uuid, const ComboAddress& ip, const DNSName& domain, int type, uint16_t qid, bool doTCP, size_t bytes, boost::optional& 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 diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index ca40f1bb92..e8208a8598 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -102,6 +102,10 @@ #include "namespaces.hh" +#ifdef HAVE_PROTOBUF +#include "uuid-utils.hh" +#endif + #include "xpf.hh" typedef map tcpClientCounts_t; @@ -124,9 +128,6 @@ thread_local FDMultiplexer* t_fdm{nullptr}; thread_local std::unique_ptr t_remotes, t_servfailremotes, t_largeanswerremotes, t_bogusremotes; thread_local std::unique_ptr > > t_queryring, t_servfailqueryring, t_bogusqueryring; thread_local std::shared_ptr t_allowFrom; -#ifdef HAVE_PROTOBUF -thread_local std::unique_ptr t_uuidGenerator; -#endif #ifdef NOD_ENABLED thread_local std::shared_ptr t_nodDBp; thread_local std::shared_ptr 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(new RecursorPacketCache()); -#ifdef HAVE_PROTOBUF - t_uuidGenerator = std::unique_ptr(new boost::uuids::random_generator()); -#endif g_log< -#include #include "dnsmessage.pb.h" #endif /* HAVE_PROTOBUF */ diff --git a/pdns/recursordist/Makefile.am b/pdns/recursordist/Makefile.am index 022cc6cb3f..c640a99909 100644 --- a/pdns/recursordist/Makefile.am +++ b/pdns/recursordist/Makefile.am @@ -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 index 0000000000..e09cb82957 --- /dev/null +++ b/pdns/recursordist/uuid-utils.cc @@ -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 index 0000000000..f05d869cf0 --- /dev/null +++ b/pdns/recursordist/uuid-utils.hh @@ -0,0 +1 @@ +../uuid-utils.hh \ No newline at end of file diff --git a/pdns/syncres.hh b/pdns/syncres.hh index 78b08e24db..75eaee04d7 100644 --- a/pdns/syncres.hh +++ b/pdns/syncres.hh @@ -56,7 +56,6 @@ #ifdef HAVE_PROTOBUF #include -#include #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 t_uuidGenerator; -#endif diff --git a/pdns/uuid-utils.cc b/pdns/uuid-utils.cc new file mode 100644 index 0000000000..12340aefce --- /dev/null +++ b/pdns/uuid-utils.cc @@ -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 +#endif /* BOOST_PENDING_INTEGER_LOG2_HPP */ +#endif /* BOOST_VERSION */ + +#include + +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 index 0000000000..3aa7844b3a --- /dev/null +++ b/pdns/uuid-utils.hh @@ -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 +#include + +boost::uuids::uuid getUniqueID(); +boost::uuids::uuid getUniqueID(const std::string& str); -- 2.47.2