]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: more useful default ports for DoT/DoH backends 11415/head
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 14 Mar 2022 13:00:25 +0000 (14:00 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Mon, 14 Mar 2022 13:00:25 +0000 (14:00 +0100)
pdns/dnsdist-lua.cc

index d478300ab20fb0201d390d621d5630615c772826..76801f9b1964db5899ca0a95c3b4ab83d3476add 100644 (file)
@@ -327,26 +327,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
                            serverAddressStr = boost::get<string>(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<DownstreamState>();
-                         }
-                         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<DownstreamState>();
-                         }
-
-                         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<DownstreamState>();
-                         }
-
                          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<string>(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<string>(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<DownstreamState>();
+                         }
+                         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<DownstreamState>();
+                         }
+
+                         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<DownstreamState>();
+                         }
+
                          if (vars.count("pool")) {
                            if (auto* pool = boost::get<string>(&vars["pool"])) {
                              config.pools.insert(*pool);