Skip to content

Commit

Permalink
dnsdist: Relax file descriptor check for XSK-enabled backends
Browse files Browse the repository at this point in the history
We cannot guarantee that the response will be coming via XSK, so
we need to accept that a response that does not come from the
expected socket descriptor.
  • Loading branch information
rgacogne committed Jan 23, 2024
1 parent 28580be commit 97a2ad3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 16 deletions.
4 changes: 1 addition & 3 deletions pdns/dnsdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ void responderThread(std::shared_ptr<DownstreamState> dss)
continue;
}

if (fd != ids->backendFD) {
if (!ids->isXSK() && fd != ids->backendFD) {
dss->restoreState(queryId, std::move(*ids));
continue;
}
Expand Down Expand Up @@ -1992,8 +1992,6 @@ bool XskProcessQuery(ClientState& cs, LocalHolders& holders, XskPacket& packet)
return false;
}
else {
const auto& xskInfo = ss->pickWorkerForSending();
ids.backendFD = xskInfo->workerWaker;
assignOutgoingUDPQueryToBackend(ss, dh->id, dq, query, false);
auto sourceAddr = ss->pickSourceAddressForSending();
packet.setAddr(sourceAddr, ss->d_config.sourceMACAddr, ss->d_config.remote, ss->d_config.destMACAddr);
Expand Down
1 change: 0 additions & 1 deletion pdns/dnsdist.hh
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,6 @@ public:
#ifdef HAVE_XSK
void registerXsk(std::vector<std::shared_ptr<XskSocket>>& xsks);
[[nodiscard]] ComboAddress pickSourceAddressForSending();
[[nodiscard]] const std::shared_ptr<XskWorker>& pickWorkerForSending();
#endif /* HAVE_XSK */

dnsdist::Protocol getProtocol() const
Expand Down
10 changes: 0 additions & 10 deletions pdns/dnsdistdist/dnsdist-backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,16 +887,6 @@ void DownstreamState::submitHealthCheckResult(bool initial, bool newResult)
return (*addresses)[idx % numberOfAddresses];
}

[[nodiscard]] const std::shared_ptr<XskWorker>& DownstreamState::pickWorkerForSending()
{
auto numberOfWorkers = d_xskInfos.size();
if (numberOfWorkers == 0) {
throw std::runtime_error("No XSK worker available for sending XSK data to backend " + getNameWithAddr());
}
size_t idx = dnsdist::getRandomValue(numberOfWorkers);
return d_xskInfos[idx % numberOfWorkers];
}

void DownstreamState::registerXsk(std::vector<std::shared_ptr<XskSocket>>& xsks)
{
d_xskSockets = xsks;
Expand Down
2 changes: 0 additions & 2 deletions pdns/dnsdistdist/dnsdist-xsk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ void XskResponderThread(std::shared_ptr<DownstreamState> dss, std::shared_ptr<Xs
auto localRespRuleActions = g_respruleactions.getLocal();
auto localCacheInsertedRespRuleActions = g_cacheInsertedRespRuleActions.getLocal();
auto pollfds = getPollFdsForWorker(*xskInfo);
const auto xskFd = xskInfo->workerWaker.getHandle();
while (!dss->isStopped()) {
poll(pollfds.data(), pollfds.size(), -1);
bool needNotify = false;
Expand All @@ -63,7 +62,6 @@ void XskResponderThread(std::shared_ptr<DownstreamState> dss, std::shared_ptr<Xs
auto ids = dss->getState(queryId);
if (ids) {
if (!ids->isXSK()) {
// if (xskFd != ids->backendFD || !ids->isXSK()) {
dss->restoreState(queryId, std::move(*ids));
ids = std::nullopt;
}
Expand Down

0 comments on commit 97a2ad3

Please sign in to comment.