From: Remi Gacogne Date: Mon, 28 May 2018 16:29:58 +0000 (+0200) Subject: dnsdist: Mark the remote member of DownstreamState as const X-Git-Tag: dnsdist-1.3.1~51^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a23538429a66c392498bb39c8b95931ff99e2c49;p=pdns dnsdist: Mark the remote member of DownstreamState as const --- diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index 44ec64f42..c8e0ead05 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1074,7 +1074,8 @@ static ssize_t udpClientSendRequestToBackend(DownstreamState* ss, const int sd, struct msghdr msgh; struct iovec iov; char cbuf[256]; - fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), const_cast(request), requestLen, &ss->remote); + ComboAddress remote(ss->remote); + fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), const_cast(request), requestLen, &remote); addCMsgSrcAddr(&msgh, cbuf, &ss->sourceAddr, ss->sourceItf); result = sendmsg(sd, &msgh, 0); } @@ -1688,7 +1689,15 @@ try } string reply; - sock.recvFrom(reply, ds.remote); + ComboAddress from; + sock.recvFrom(reply, from); + + /* we are using a connected socket but hey.. */ + if (from != ds.remote) { + if (g_verboseHealthChecks) + infolog("Invalid health check response received from %s, expecting one from %s", from.toStringWithPort(), ds.remote.toStringWithPort()); + return false; + } const dnsheader * responseHeader = reinterpret_cast(reply.c_str()); diff --git a/pdns/dnsdist.hh b/pdns/dnsdist.hh index 96a050b8d..e478a09cf 100644 --- a/pdns/dnsdist.hh +++ b/pdns/dnsdist.hh @@ -503,7 +503,7 @@ struct DownstreamState std::mutex socketsLock; std::unique_ptr mplexer{nullptr}; std::thread tid; - ComboAddress remote; + const ComboAddress remote; QPSLimiter qps; vector idStates; ComboAddress sourceAddr;