Skip to content

Commit

Permalink
Merge pull request #6688 from rgacogne/dnsdist-const-ds-remote
Browse files Browse the repository at this point in the history
 dnsdist: Mark the remote member of DownstreamState as const
  • Loading branch information
rgacogne committed May 29, 2018
2 parents c6cbc43 + 7340277 commit b7bf243
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
13 changes: 11 additions & 2 deletions pdns/dnsdist.cc
Expand Up @@ -1088,7 +1088,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<char*>(request), requestLen, &ss->remote);
ComboAddress remote(ss->remote);
fillMSGHdr(&msgh, &iov, cbuf, sizeof(cbuf), const_cast<char*>(request), requestLen, &remote);
addCMsgSrcAddr(&msgh, cbuf, &ss->sourceAddr, ss->sourceItf);
result = sendmsg(sd, &msgh, 0);
}
Expand Down Expand Up @@ -1705,7 +1706,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<const dnsheader *>(reply.c_str());

Expand Down
10 changes: 5 additions & 5 deletions pdns/dnsdist.hh
Expand Up @@ -466,10 +466,10 @@ class TCPClientCollection {
std::atomic<uint64_t> d_numthreads{0};
std::atomic<uint64_t> d_pos{0};
std::atomic<uint64_t> d_queued{0};
uint64_t d_maxthreads{0};
const uint64_t d_maxthreads{0};
std::mutex d_mutex;
int d_singlePipe[2];
bool d_useSinglePipe;
const bool d_useSinglePipe;
public:

TCPClientCollection(size_t maxThreads, bool useSinglePipe=false): d_maxthreads(maxThreads), d_singlePipe{-1,-1}, d_useSinglePipe(useSinglePipe)
Expand Down Expand Up @@ -537,10 +537,10 @@ struct DownstreamState
std::mutex connectLock;
std::unique_ptr<FDMultiplexer> mplexer{nullptr};
std::thread tid;
ComboAddress remote;
const ComboAddress remote;
QPSLimiter qps;
vector<IDState> idStates;
ComboAddress sourceAddr;
const ComboAddress sourceAddr;
checkfunc_t checkFunction;
DNSName checkName{"a.root-servers.net."};
QType checkType{QType::A};
Expand All @@ -565,7 +565,7 @@ struct DownstreamState
int tcpConnectTimeout{5};
int tcpRecvTimeout{30};
int tcpSendTimeout{30};
unsigned int sourceItf{0};
const unsigned int sourceItf{0};
uint16_t retries{5};
uint16_t xpfRRCode{0};
uint8_t currentCheckFailures{0};
Expand Down

0 comments on commit b7bf243

Please sign in to comment.