From: Remi Gacogne Date: Mon, 24 Mar 2025 11:46:42 +0000 (+0100) Subject: dnsdist: Load Lua bindings before parsing yaml configuration X-Git-Tag: dnsdist-2.0.0-alpha2~115^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df96ecad8bc6d7c506e75db624e6d6887f84a4c7;p=thirdparty%2Fpdns.git dnsdist: Load Lua bindings before parsing yaml configuration We need the Lua bindings so that inline and loaded from a file Lua syntax work. Our regression tests did not catch this because the setup always created an empty Lua file, causing the Lua bindings to be loaded. This commit also fixes that by not creating (and removing if needed) empty Lua files in the regression tests setup. --- diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index 6d2d077950..6613248126 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -3288,9 +3288,11 @@ static std::optional lookForTentativeConfigurationFileWithExtension static bool loadConfigurationFromFile(const std::string& configurationFile, bool isClient, bool configCheck) { if (boost::ends_with(configurationFile, ".yml")) { + // the bindings are always needed, for example for inline Lua + dnsdist::lua::setupLuaBindingsOnly(*(g_lua.lock()), isClient, configCheck); + if (auto tentativeLuaConfFile = lookForTentativeConfigurationFileWithExtension(configurationFile, "lua")) { vinfolog("Loading configuration from auto-discovered Lua file %s", *tentativeLuaConfFile); - dnsdist::lua::setupLuaBindingsOnly(*(g_lua.lock()), isClient, configCheck); dnsdist::configuration::lua::loadLuaConfigurationFile(*(g_lua.lock()), *tentativeLuaConfFile, configCheck); } vinfolog("Loading configuration from YAML file %s", configurationFile); diff --git a/regression-tests.dnsdist/dnsdisttests.py b/regression-tests.dnsdist/dnsdisttests.py index fbf757454d..65b17224ec 100644 --- a/regression-tests.dnsdist/dnsdisttests.py +++ b/regression-tests.dnsdist/dnsdisttests.py @@ -153,13 +153,16 @@ class DNSDistTest(AssertEqualDNSMessageMixin, unittest.TestCase): if not cls._yaml_config_template: confFile = luaConfFile - with open(luaConfFile, 'w') as conf: + if len(cls._config_template.strip(' \n\t')) > 0: + with open(luaConfFile, 'w') as conf: conf.write("-- Autogenerated by dnsdisttests.py\n") conf.write(f"-- dnsdist will listen on {cls._dnsDistPort}\n") conf.write(cls._config_template % params) if not cls._yaml_config_template: - conf.write("\n") - conf.write("setSecurityPollSuffix('')") + conf.write("\n") + conf.write("setSecurityPollSuffix('')") + elif os.path.exists(luaConfFile): + os.unlink(luaConfFile) if cls._skipListeningOnCL: dnsdistcmd = [os.environ['DNSDISTBIN'], '--supervised', '-C', confFile ]