Skip to content

Commit

Permalink
dnsdist: Set the shared XSK frames in the XskWorker constructor
Browse files Browse the repository at this point in the history
(cherry picked from commit ae2d10d)
  • Loading branch information
rgacogne committed Jul 12, 2024
1 parent b7b915d commit 3389c33
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 22 deletions.
12 changes: 4 additions & 8 deletions pdns/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -809,12 +809,10 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
std::shared_ptr<XskSocket> socket;
parseXskVars(vars, socket);
if (socket) {
udpCS->xskInfo = XskWorker::create(XskWorker::Type::Bidirectional);
udpCS->xskInfo->setSharedFrames(socket->sharedEmptyFrameOffset);
udpCS->xskInfo = XskWorker::create(XskWorker::Type::Bidirectional, socket->sharedEmptyFrameOffset);
socket->addWorker(udpCS->xskInfo);
socket->addWorkerRoute(udpCS->xskInfo, loc);
udpCS->xskInfoResponder = XskWorker::create(XskWorker::Type::OutgoingOnly);
udpCS->xskInfoResponder->setSharedFrames(socket->sharedEmptyFrameOffset);
udpCS->xskInfoResponder = XskWorker::create(XskWorker::Type::OutgoingOnly, socket->sharedEmptyFrameOffset);
socket->addWorker(udpCS->xskInfoResponder);
vinfolog("Enabling XSK in %s mode for incoming UDP packets to %s", socket->getXDPMode(), loc.toStringWithPort());
}
Expand Down Expand Up @@ -866,12 +864,10 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
std::shared_ptr<XskSocket> socket;
parseXskVars(vars, socket);
if (socket) {
udpCS->xskInfo = XskWorker::create(XskWorker::Type::Bidirectional);
udpCS->xskInfo->setSharedFrames(socket->sharedEmptyFrameOffset);
udpCS->xskInfo = XskWorker::create(XskWorker::Type::Bidirectional, socket->sharedEmptyFrameOffset);
socket->addWorker(udpCS->xskInfo);
socket->addWorkerRoute(udpCS->xskInfo, loc);
udpCS->xskInfoResponder = XskWorker::create(XskWorker::Type::OutgoingOnly);
udpCS->xskInfoResponder->setSharedFrames(socket->sharedEmptyFrameOffset);
udpCS->xskInfoResponder = XskWorker::create(XskWorker::Type::OutgoingOnly, socket->sharedEmptyFrameOffset);
socket->addWorker(udpCS->xskInfoResponder);
vinfolog("Enabling XSK in %s mode for incoming UDP packets to %s", socket->getXDPMode(), loc.toStringWithPort());
}
Expand Down
3 changes: 1 addition & 2 deletions pdns/dnsdistdist/dnsdist-backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -905,10 +905,9 @@ void DownstreamState::registerXsk(std::vector<std::shared_ptr<XskSocket>>& xsks)
d_config.sourceMACAddr = d_xskSockets.at(0)->getSourceMACAddress();

for (auto& xsk : d_xskSockets) {
auto xskInfo = XskWorker::create(XskWorker::Type::Bidirectional);
auto xskInfo = XskWorker::create(XskWorker::Type::Bidirectional, xsk->sharedEmptyFrameOffset);
d_xskInfos.push_back(xskInfo);
xsk->addWorker(xskInfo);
xskInfo->setSharedFrames(xsk->sharedEmptyFrameOffset);
}
reconnect(false);
}
Expand Down
13 changes: 4 additions & 9 deletions pdns/xsk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ void XskWorker::notify(int desc)
}
}

XskWorker::XskWorker(XskWorker::Type type) :
d_type(type), workerWaker(createEventfd()), xskSocketWaker(createEventfd())
XskWorker::XskWorker(XskWorker::Type type, const std::shared_ptr<LockGuarded<std::vector<uint64_t>>>& frames) :
d_sharedEmptyFrameOffset(frames), d_type(type), workerWaker(createEventfd()), xskSocketWaker(createEventfd())
{
}

Expand Down Expand Up @@ -1134,9 +1134,9 @@ void XskWorker::notifyXskSocket() const
notify(xskSocketWaker);
}

std::shared_ptr<XskWorker> XskWorker::create(Type type)
std::shared_ptr<XskWorker> XskWorker::create(Type type, const std::shared_ptr<LockGuarded<std::vector<uint64_t>>>& frames)
{
return std::make_shared<XskWorker>(type);
return std::make_shared<XskWorker>(type, frames);
}

void XskSocket::addWorker(std::shared_ptr<XskWorker> worker)
Expand All @@ -1160,11 +1160,6 @@ void XskSocket::removeWorkerRoute(const ComboAddress& dest)
d_workerRoutes.lock()->erase(dest);
}

void XskWorker::setSharedFrames(std::shared_ptr<LockGuarded<vector<uint64_t>>>& frames)
{
d_sharedEmptyFrameOffset = frames;
}

void XskWorker::setUmemBufBase(uint8_t* base)
{
d_umemBufBase = base;
Expand Down
5 changes: 2 additions & 3 deletions pdns/xsk.hh
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,9 @@ public:

static int createEventfd();
static void notify(int desc);
static std::shared_ptr<XskWorker> create(Type);
static std::shared_ptr<XskWorker> create(Type type, const std::shared_ptr<LockGuarded<std::vector<uint64_t>>>& frames);

XskWorker(Type);
void setSharedFrames(std::shared_ptr<LockGuarded<vector<uint64_t>>>& frames);
XskWorker(Type type, const std::shared_ptr<LockGuarded<std::vector<uint64_t>>>& frames);
void setUmemBufBase(uint8_t* base);
void pushToProcessingQueue(XskPacket& packet);
void pushToSendQueue(XskPacket& packet);
Expand Down

0 comments on commit 3389c33

Please sign in to comment.