From: Remi Gacogne Date: Tue, 19 Mar 2024 09:44:16 +0000 (+0100) Subject: dnsdist: Properly account the failure to forward a query to a backend X-Git-Tag: dnsdist-1.9.2~10^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8d65f859be1fbb54de1d3051cfbc9cdec427c01c;p=thirdparty%2Fpdns.git dnsdist: Properly account the failure to forward a query to a backend Manually backported from b0b3480b98d41db821f681183f45d5d08db02f93 --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 3c32201aba..7b421236cd 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1236,34 +1236,37 @@ static bool applyRulesToQuery(LocalHolders& holders, DNSQuestion& dq, const stru return true; } -ssize_t udpClientSendRequestToBackend(const std::shared_ptr& ss, const int sd, const PacketBuffer& request, bool healthCheck) +ssize_t udpClientSendRequestToBackend(const std::shared_ptr& backend, const int sd, const PacketBuffer& request, bool healthCheck) { ssize_t result; - if (ss->d_config.sourceItf == 0) { + if (backend->d_config.sourceItf == 0) { result = send(sd, request.data(), request.size(), 0); } else { struct msghdr msgh; struct iovec iov; cmsgbuf_aligned cbuf; - ComboAddress remote(ss->d_config.remote); + ComboAddress remote(backend->d_config.remote); fillMSGHdr(&msgh, &iov, &cbuf, sizeof(cbuf), const_cast(reinterpret_cast(request.data())), request.size(), &remote); - addCMsgSrcAddr(&msgh, &cbuf, &ss->d_config.sourceAddr, ss->d_config.sourceItf); + addCMsgSrcAddr(&msgh, &cbuf, &backend->d_config.sourceAddr, backend->d_config.sourceItf); result = sendmsg(sd, &msgh, 0); } if (result == -1) { int savederrno = errno; - vinfolog("Error sending request to backend %s: %s", ss->d_config.remote.toStringWithPort(), stringerror(savederrno)); + vinfolog("Error sending request to backend %s: %s", backend->d_config.remote.toStringWithPort(), stringerror(savederrno)); /* This might sound silly, but on Linux send() might fail with EINVAL if the interface the socket was bound to doesn't exist anymore. We don't want to reconnect the real socket if the healthcheck failed, because it's not using the same socket. */ - if (!healthCheck && (savederrno == EINVAL || savederrno == ENODEV || savederrno == ENETUNREACH || savederrno == EBADF)) { - ss->reconnect(); + if (!healthCheck) { + if (savederrno == EINVAL || savederrno == ENODEV || savederrno == ENETUNREACH || savederrno == EBADF) { + backend->reconnect(); + } + backend->reportTimeoutOrError(); } }