From: Remi Gacogne Date: Mon, 31 Jul 2023 09:46:16 +0000 (+0200) Subject: dnsdist: Get rid of the reference counter for DOHUnit X-Git-Tag: rec-5.0.0-alpha1~19^2~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9c784123eb64bdfbcc48d6c660480cb29179ce8c;p=thirdparty%2Fpdns.git dnsdist: Get rid of the reference counter for DOHUnit It is no longer needed since we now rely on moving the unique pointer around. --- diff --git a/pdns/dnsdist-idstate.hh b/pdns/dnsdist-idstate.hh index b61984249e..cf5442fea0 100644 --- a/pdns/dnsdist-idstate.hh +++ b/pdns/dnsdist-idstate.hh @@ -99,12 +99,7 @@ struct InternalQueryState std::string d_requestorID; }; - static void DeleterPlaceHolder(DOHUnit*) - { - } - - InternalQueryState() : - du(std::unique_ptr(nullptr, DeleterPlaceHolder)) + InternalQueryState() { origDest.sin4.sin_family = 0; } @@ -130,7 +125,7 @@ struct InternalQueryState std::unique_ptr d_protoBufData{nullptr}; boost::optional tempFailureTTL{boost::none}; // 8 ClientState* cs{nullptr}; // 8 - std::unique_ptr du; // 8 + std::unique_ptr du{nullptr}; // 8 uint32_t cacheKey{0}; // 4 uint32_t cacheKeyNoECS{0}; // 4 // DoH-only */ diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index 3a05d1c2a7..eeb0af4808 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -163,7 +163,6 @@ public: private: h2o_accept_ctx_t d_h2o_accept_ctx; - std::atomic d_refcnt{1}; time_t d_ticketsKeyNextRotation{0}; std::atomic_flag d_rotatingTicketsKey; }; @@ -176,14 +175,14 @@ struct DOHServerConfig { #ifndef USE_SINGLE_ACCEPTOR_THREAD { - auto [sender, receiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverBlocking, internalPipeBufferSize); + auto [sender, receiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverBlocking, internalPipeBufferSize); d_querySender = std::move(sender); d_queryReceiver = std::move(receiver); } #endif /* USE_SINGLE_ACCEPTOR_THREAD */ { - auto [sender, receiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, internalPipeBufferSize); + auto [sender, receiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, internalPipeBufferSize); d_responseSender = std::move(sender); d_responseReceiver = std::move(receiver); } @@ -209,11 +208,11 @@ struct DOHServerConfig ClientState* cs{nullptr}; std::shared_ptr df{nullptr}; #ifndef USE_SINGLE_ACCEPTOR_THREAD - pdns::channel::Sender d_querySender; - pdns::channel::Receiver d_queryReceiver; + pdns::channel::Sender d_querySender; + pdns::channel::Receiver d_queryReceiver; #endif /* USE_SINGLE_ACCEPTOR_THREAD */ - pdns::channel::Sender d_responseSender; - pdns::channel::Receiver d_responseReceiver; + pdns::channel::Sender d_responseSender; + pdns::channel::Receiver d_responseReceiver; }; /* This internal function sends back the object to the main thread to send a reply. @@ -839,7 +838,7 @@ static void doh_dispatch_query(DOHServerConfig* dsc, h2o_handler_t* self, h2o_re /* we are doing quite some copies here, sorry about that, but we can't keep accessing the req object once we are in a different thread because the request might get killed by h2o at pretty much any time */ - auto du = std::unique_ptr(new DOHUnit(std::move(query), std::move(path), std::string(req->authority.base, req->authority.len)), DOHUnit::release); + auto du = std::make_unique(std::move(query), std::move(path), std::string(req->authority.base, req->authority.len)); du->dsc = dsc; du->req = req; du->ids.origDest = local; @@ -870,7 +869,7 @@ static void doh_dispatch_query(DOHServerConfig* dsc, h2o_handler_t* self, h2o_re *(du->self) = du.get(); #ifdef USE_SINGLE_ACCEPTOR_THREAD - processDOHQuery(DOHUnitUniquePtr(du.release(), DOHUnit::release), true); + processDOHQuery(du, true); #else /* USE_SINGLE_ACCEPTOR_THREAD */ try { if (!dsc->d_querySender.send(std::move(du))) { @@ -1232,13 +1231,13 @@ void DOHUnit::setHTTPResponse(uint16_t statusCode, PacketBuffer&& body_, const s /* query has been parsed by h2o, which called doh_handler() in the main DoH thread. In order not to block for long, doh_handler() called doh_dispatch_query() which allocated a DOHUnit object and passed it to us */ -static void dnsdistclient(pdns::channel::Receiver&& receiver) +static void dnsdistclient(pdns::channel::Receiver&& receiver) { setThreadName("dnsdist/doh-cli"); for(;;) { try { - auto tmp = receiver.receive(DOHUnit::release); + auto tmp = receiver.receive(); if (!tmp) { continue; } @@ -1281,9 +1280,9 @@ static void on_dnsdist(h2o_socket_t *listener, const char *err) memory and likely coming up too late after the client has gone away */ auto* dsc = static_cast(listener->data); while (true) { - std::unique_ptr du{nullptr, DOHUnit::release}; + std::unique_ptr du{nullptr}; try { - auto tmp = dsc->d_responseReceiver.receive(DOHUnit::release); + auto tmp = dsc->d_responseReceiver.receive(); if (!tmp) { return; } diff --git a/pdns/doh.hh b/pdns/doh.hh index b38c7bbf30..6f3816c300 100644 --- a/pdns/doh.hh +++ b/pdns/doh.hh @@ -180,18 +180,6 @@ struct DOHFrontend #ifndef HAVE_DNS_OVER_HTTPS struct DOHUnit { - static void release(DOHUnit*) - { - } - - void get() - { - } - - void release() - { - } - size_t proxyProtocolPayloadSize{0}; uint16_t status_code{200}; }; @@ -215,29 +203,6 @@ struct DOHUnit DOHUnit(const DOHUnit&) = delete; DOHUnit& operator=(const DOHUnit&) = delete; - void get() - { - ++d_refcnt; - } - - void release() - { - if (--d_refcnt == 0) { - if (self) { - *self = nullptr; - } - - delete this; - } - } - - static void release(DOHUnit* ptr) - { - if (ptr) { - ptr->release(); - } - } - InternalQueryState ids; std::string sni; std::string path; @@ -251,8 +216,7 @@ struct DOHUnit st_h2o_req_t* req{nullptr}; DOHUnit** self{nullptr}; DOHServerConfig* dsc{nullptr}; - pdns::channel::Sender* responseSender{nullptr}; - std::atomic d_refcnt{1}; + pdns::channel::Sender* responseSender{nullptr}; size_t query_at{0}; size_t proxyProtocolPayloadSize{0}; int rsock{-1}; @@ -277,7 +241,7 @@ struct DOHUnit void setHTTPResponse(uint16_t statusCode, PacketBuffer&& body, const std::string& contentType=""); }; -void handleUDPResponseForDoH(std::unique_ptr&&, PacketBuffer&& response, InternalQueryState&& state); +void handleUDPResponseForDoH(std::unique_ptr&&, PacketBuffer&& response, InternalQueryState&& state); struct CrossProtocolQuery; struct DNSQuestion; @@ -287,6 +251,6 @@ std::unique_ptr getDoHCrossProtocolQueryFromDQ(DNSQuestion& #endif /* HAVE_LIBH2OEVLOOP */ #endif /* HAVE_DNS_OVER_HTTPS */ -using DOHUnitUniquePtr = std::unique_ptr; +using DOHUnitUniquePtr = std::unique_ptr; void handleDOHTimeout(DOHUnitUniquePtr&& oldDU);