From bbd1a19e0194aabdd745c5196e1eaeb196d7e196 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Tue, 25 Mar 2025 10:55:10 +0100 Subject: [PATCH] dnsdist: Do not register Xsk sockets on configuration check or client mode It does not make sense, and in some cases might lead to a crash because the Xsk socket is actually an empty shared pointer in client mode. --- pdns/dnsdistdist/dnsdist-configuration-yaml.cc | 2 +- pdns/dnsdistdist/dnsdist-lua.cc | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 00d2c5aa1d..c2816a98d6 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -486,8 +486,8 @@ static std::shared_ptr createBackendFromConfiguration(const dns if (!xskMap) { throw std::runtime_error("XSK map " + std::string(config.xsk) + " attached to backend " + std::string(config.address) + " not found"); } - downstream->registerXsk(*xskMap); if (!configCheck) { + downstream->registerXsk(*xskMap); infolog("Added downstream server %s via XSK in %s mode", std::string(config.address), xskMap->at(0)->getXDPMode()); } } diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 0f8b0a2d53..4ad34ccfb5 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -611,7 +611,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) auto ret = std::make_shared(std::move(config), std::move(tlsCtx), !(client || configCheck)); #ifdef HAVE_XSK LuaArray> luaXskSockets; - if (getOptionalValue>>(vars, "xskSockets", luaXskSockets) > 0 && !luaXskSockets.empty()) { + if (!client && !configCheck && getOptionalValue>>(vars, "xskSockets", luaXskSockets) > 0 && !luaXskSockets.empty()) { if (dnsdist::configuration::isImmutableConfigurationDone()) { throw std::runtime_error("Adding a server with xsk at runtime is not supported"); } @@ -638,6 +638,13 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) else if (!(client || configCheck)) { infolog("Added downstream server %s", ret->d_config.remote.toStringWithPort()); } + + if (client || configCheck) { + /* consume these in client or configuration check mode, to prevent warnings */ + std::string mac; + getOptionalValue(vars, "MACAddr", mac); + getOptionalValue>>(vars, "xskSockets", luaXskSockets); + } #else /* HAVE_XSK */ if (!(client || configCheck)) { infolog("Added downstream server %s", ret->d_config.remote.toStringWithPort()); -- 2.47.2