From: Peter van Dijk Date: Mon, 14 Mar 2022 13:00:25 +0000 (+0100) Subject: dnsdist: more useful default ports for DoT/DoH backends X-Git-Tag: rec-4.7.0-beta1~61^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d0832592082f404c09dfff7fc07f5989e68e287b;p=thirdparty%2Fpdns.git dnsdist: more useful default ports for DoT/DoH backends --- diff --git a/pdns/dnsdist-lua.cc b/pdns/dnsdist-lua.cc index d478300ab2..76801f9b19 100644 --- a/pdns/dnsdist-lua.cc +++ b/pdns/dnsdist-lua.cc @@ -327,26 +327,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) serverAddressStr = boost::get(vars["address"]); } - try { - config.remote = ComboAddress(serverAddressStr, 53); - } - catch (const PDNSException& e) { - g_outputBuffer = "Error creating new server: " + string(e.reason); - errlog("Error creating new server with address %s: %s", serverAddressStr, e.reason); - return std::shared_ptr(); - } - catch (const std::exception& e) { - g_outputBuffer = "Error creating new server: " + string(e.what()); - errlog("Error creating new server with address %s: %s", serverAddressStr, e.what()); - return std::shared_ptr(); - } - - if (IsAnyAddress(config.remote)) { - g_outputBuffer = "Error creating new server: invalid address for a downstream server."; - errlog("Error creating new server: %s is not a valid address for a downstream server", serverAddressStr); - return std::shared_ptr(); - } - if (vars.count("source")) { /* handle source in the following forms: - v4 address ("192.0.2.1") @@ -577,7 +557,10 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } } + uint16_t serverPort = 53; + if (vars.count("tls")) { + serverPort = 853; config.d_tlsParams.d_provider = boost::get(vars.at("tls")); tlsCtx = getTLSContext(config.d_tlsParams); @@ -586,6 +569,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) throw std::runtime_error("Outgoing DNS over HTTPS support requested (via 'dohPath' on newServer()) but nghttp2 support is not available"); #endif + serverPort = 443; config.d_dohPath = boost::get(vars.at("dohPath")); if (vars.count("addXForwardedHeaders")) { @@ -594,6 +578,26 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } } + try { + config.remote = ComboAddress(serverAddressStr, serverPort); + } + catch (const PDNSException& e) { + g_outputBuffer = "Error creating new server: " + string(e.reason); + errlog("Error creating new server with address %s: %s", serverAddressStr, e.reason); + return std::shared_ptr(); + } + catch (const std::exception& e) { + g_outputBuffer = "Error creating new server: " + string(e.what()); + errlog("Error creating new server with address %s: %s", serverAddressStr, e.what()); + return std::shared_ptr(); + } + + if (IsAnyAddress(config.remote)) { + g_outputBuffer = "Error creating new server: invalid address for a downstream server."; + errlog("Error creating new server: %s is not a valid address for a downstream server", serverAddressStr); + return std::shared_ptr(); + } + if (vars.count("pool")) { if (auto* pool = boost::get(&vars["pool"])) { config.pools.insert(*pool);