From a23538429a66c392498bb39c8b95931ff99e2c49 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Mon, 28 May 2018 18:29:58 +0200 Subject: [PATCH] dnsdist: Mark the remote member of DownstreamState as const --- pdns/dnsdist.cc | 13 +++++++++++-- pdns/dnsdist.hh | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) 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; -- 2.40.0