From: Remi Gacogne Date: Wed, 15 Dec 2021 09:54:07 +0000 (+0100) Subject: dnsdist: Use an alias for the DOHUnit unique pointer X-Git-Tag: auth-4.7.0-alpha1~122^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f46a693ffc6a9e7614f787726b210731fe10a8d;p=thirdparty%2Fpdns.git dnsdist: Use an alias for the DOHUnit unique pointer --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 964eb4b43d..c57fcd363a 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -630,7 +630,7 @@ void responderThread(std::shared_ptr dss) /* read the potential DOHUnit state as soon as possible, but don't use it until we have confirmed that we own this state by updating usageIndicator */ - auto du = std::unique_ptr(ids->du, DOHUnit::release); + auto du = DOHUnitUniquePtr(ids->du, DOHUnit::release); /* setting age to 0 to prevent the maintainer thread from cleaning this IDS while we process the response. */ @@ -1524,13 +1524,13 @@ static void processUDPQuery(ClientState& cs, LocalHolders& holders, const struct unsigned int idOffset = (ss->idOffset++) % ss->idStates.size(); IDState* ids = &ss->idStates[idOffset]; ids->age = 0; - std::unique_ptr du(nullptr, DOHUnit::release); + DOHUnitUniquePtr du(nullptr, DOHUnit::release); /* that means that the state was in use, possibly with an allocated DOHUnit that we will need to handle, but we can't touch it before confirming that we now own this state */ if (ids->isInUse()) { - du = std::unique_ptr(ids->du, DOHUnit::release); + du = DOHUnitUniquePtr(ids->du, DOHUnit::release); } /* we atomically replace the value, we now own this state */ @@ -1886,7 +1886,7 @@ static void healthChecksThread() continue; } ids.du = nullptr; - handleDOHTimeout(std::unique_ptr(oldDU, DOHUnit::release)); + handleDOHTimeout(DOHUnitUniquePtr(oldDU, DOHUnit::release)); oldDU = nullptr; ids.age = 0; dss->reuseds++; diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index c8611879f7..92396fc5fd 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -225,7 +225,7 @@ struct DOHServerConfig /* This internal function sends back the object to the main thread to send a reply. The caller should NOT release or touch the unit after calling this function */ -static void sendDoHUnitToTheMainThread(std::unique_ptr&& du, const char* description) +static void sendDoHUnitToTheMainThread(DOHUnitUniquePtr&& du, const char* description) { auto ptr = du.release(); ptr->get(); @@ -249,7 +249,7 @@ static void sendDoHUnitToTheMainThread(std::unique_ptr&& oldDU) +void handleDOHTimeout(DOHUnitUniquePtr&& oldDU) { if (oldDU == nullptr) { return; @@ -415,7 +415,7 @@ static void handleResponse(DOHFrontend& df, st_h2o_req_t* req, uint16_t statusCo class DoHTCPCrossQuerySender : public TCPQuerySender { public: - DoHTCPCrossQuerySender(std::unique_ptr&& du_): du(std::move(du_)) + DoHTCPCrossQuerySender(DOHUnitUniquePtr&& du_): du(std::move(du_)) { } @@ -490,13 +490,13 @@ public: } private: - std::unique_ptr du; + DOHUnitUniquePtr du; }; class DoHCrossProtocolQuery : public CrossProtocolQuery { public: - DoHCrossProtocolQuery(std::unique_ptr&& du_): du(std::move(du_)) + DoHCrossProtocolQuery(DOHUnitUniquePtr&& du_): du(std::move(du_)) { query = InternalQuery(std::move(du->query), std::move(du->ids)); /* we _could_ remove it from the query buffer and put in query's d_proxyProtocolPayload, @@ -522,13 +522,13 @@ public: } private: - std::unique_ptr du; + DOHUnitUniquePtr du; }; /* We are not in the main DoH thread but in the DoH 'client' thread. */ -static void processDOHQuery(std::unique_ptr&& du) +static void processDOHQuery(DOHUnitUniquePtr&& du) { uint16_t queryId = 0; ComboAddress remote; @@ -676,7 +676,7 @@ static void processDOHQuery(std::unique_ptr&& du) to handle it because it's about to be overwritten. */ ++du->downstream->reuseds; ++g_stats.downstreamTimeouts; - handleDOHTimeout(std::unique_ptr(oldDU, DOHUnit::release)); + handleDOHTimeout(DOHUnitUniquePtr(oldDU, DOHUnit::release)); } ids->origFD = 0; @@ -1239,7 +1239,7 @@ static void dnsdistclient(int qsock) continue; } - std::unique_ptr du(ptr, DOHUnit::release); + DOHUnitUniquePtr du(ptr, DOHUnit::release); /* we are not in the main DoH thread anymore, so there is a real risk of a race condition where h2o kills the query while we are processing it, so we can't touch the content of du->req until we are back into the @@ -1306,7 +1306,7 @@ static void on_dnsdist(h2o_socket_t *listener, const char *err) return; } - std::unique_ptr du(ptr, DOHUnit::release); + DOHUnitUniquePtr du(ptr, DOHUnit::release); if (!du->req) { // it got killed in flight du->self = nullptr; continue; @@ -1634,7 +1634,7 @@ void dohThread(ClientState* cs) } } -void handleUDPResponseForDoH(std::unique_ptr&& du, PacketBuffer&& udpResponse, IDState&& state) +void handleUDPResponseForDoH(DOHUnitUniquePtr&& du, PacketBuffer&& udpResponse, IDState&& state) { du->response = std::move(udpResponse); du->ids = std::move(state); diff --git a/pdns/doh.hh b/pdns/doh.hh index 65fc6d604a..6004379bf2 100644 --- a/pdns/doh.hh +++ b/pdns/doh.hh @@ -260,4 +260,6 @@ void handleUDPResponseForDoH(std::unique_ptr&&, Pack #endif /* HAVE_DNS_OVER_HTTPS */ -void handleDOHTimeout(std::unique_ptr&& oldDU); +using DOHUnitUniquePtr = std::unique_ptr; + +void handleDOHTimeout(DOHUnitUniquePtr&& oldDU);