From 004a0fc4dac391cb0576bce6569db96c1f275067 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 3 May 2024 15:47:54 +0200 Subject: [PATCH] dnsdist: Log the correct amount of bytes sent for DoH w/ nghttp2 (cherry picked from commit 35ffb61530571618ae601c0b598dd18aa2a76790) --- pdns/dnsdist-tcp.cc | 8 ++++---- pdns/dnsdistdist/dnsdist-nghttp2-in.cc | 3 ++- pdns/dnsdistdist/dnsdist-tcp-upstream.hh | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index e3eb68e115..4e05e31cbe 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -195,7 +195,7 @@ static IOState sendQueuedResponses(std::shared_ptr& return IOState::Done; } -void IncomingTCPConnectionState::handleResponseSent(TCPResponse& currentResponse) +void IncomingTCPConnectionState::handleResponseSent(TCPResponse& currentResponse, size_t sentBytes) { if (currentResponse.d_idstate.qtype == QType::AXFR || currentResponse.d_idstate.qtype == QType::IXFR) { return; @@ -207,7 +207,7 @@ void IncomingTCPConnectionState::handleResponseSent(TCPResponse& currentResponse if (!currentResponse.d_idstate.selfGenerated && backend) { const auto& ids = currentResponse.d_idstate; double udiff = ids.queryRealTime.udiff(); - vinfolog("Got answer from %s, relayed to %s (%s, %d bytes), took %f us", backend->d_config.remote.toStringWithPort(), ids.origRemote.toStringWithPort(), getProtocol().toString(), currentResponse.d_buffer.size(), udiff); + vinfolog("Got answer from %s, relayed to %s (%s, %d bytes), took %f us", backend->d_config.remote.toStringWithPort(), ids.origRemote.toStringWithPort(), getProtocol().toString(), sentBytes, udiff); auto backendProtocol = backend->getProtocol(); if (backendProtocol == dnsdist::Protocol::DoUDP && !currentResponse.d_idstate.forwardedOverUDP) { @@ -315,7 +315,7 @@ IOState IncomingTCPConnectionState::sendResponse(const struct timeval& now, TCPR auto iostate = d_handler.tryWrite(d_currentResponse.d_buffer, d_currentPos, d_currentResponse.d_buffer.size()); if (iostate == IOState::Done) { DEBUGLOG("response sent from " << __PRETTY_FUNCTION__); - handleResponseSent(d_currentResponse); + handleResponseSent(d_currentResponse, d_currentResponse.d_buffer.size()); return iostate; } d_lastIOBlocked = true; @@ -1120,7 +1120,7 @@ void IncomingTCPConnectionState::handleIO() iostate = d_handler.tryWrite(d_currentResponse.d_buffer, d_currentPos, d_currentResponse.d_buffer.size()); if (iostate == IOState::Done) { DEBUGLOG("response sent from " << __PRETTY_FUNCTION__); - handleResponseSent(d_currentResponse); + handleResponseSent(d_currentResponse, d_currentResponse.d_buffer.size()); d_state = State::idle; } else { diff --git a/pdns/dnsdistdist/dnsdist-nghttp2-in.cc b/pdns/dnsdistdist/dnsdist-nghttp2-in.cc index a016363c6f..8458bc77bf 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2-in.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2-in.cc @@ -570,8 +570,9 @@ IOState IncomingHTTP2Connection::sendResponse(const struct timeval& now, TCPResp responseBuffer = std::move(response.d_buffer); } + auto sent = responseBuffer.size(); sendResponse(response.d_idstate.d_streamID, context, statusCode, d_ci.cs->dohFrontend->d_customResponseHeaders, contentType, sendContentType); - handleResponseSent(response); + handleResponseSent(response, sent); return hasPendingWrite() ? IOState::NeedWrite : IOState::Done; } diff --git a/pdns/dnsdistdist/dnsdist-tcp-upstream.hh b/pdns/dnsdistdist/dnsdist-tcp-upstream.hh index c6410df0c9..ba6ecd8d10 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-upstream.hh +++ b/pdns/dnsdistdist/dnsdist-tcp-upstream.hh @@ -137,7 +137,7 @@ public: void handleXFRResponse(const struct timeval& now, TCPResponse&& response) override; virtual IOState sendResponse(const struct timeval& now, TCPResponse&& response); - void handleResponseSent(TCPResponse& currentResponse); + void handleResponseSent(TCPResponse& currentResponse, size_t sentBytes); virtual IOState handleHandshake(const struct timeval& now); void handleHandshakeDone(const struct timeval& now); ProxyProtocolResult handleProxyProtocolPayload(); -- 2.47.2