]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Reduce the complexity of the YAML frontend code
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Jun 2025 12:21:38 +0000 (14:21 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Jun 2025 12:21:38 +0000 (14:21 +0200)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-configuration-yaml.cc

index 184e92aae12eac2f2c60d51c1026f565119455c9..65db4d389b4ac1232fe21818fb981f7d46cdd03f 100644 (file)
@@ -663,6 +663,25 @@ static void loadDynamicBlockConfiguration(const dnsdist::rust::settings::Dynamic
   }
 }
 
+static void handleAdditionalAddressesForFrontend(const std::shared_ptr<ClientState>& state, const std::string& protocol, const ::rust::Vec<::rust::String>& additionalAddresses)
+{
+  if (protocol == "dot" || protocol == "doh") {
+    for (const auto& addr : additionalAddresses) {
+      try {
+        ComboAddress address{std::string(addr)};
+        state->d_additionalAddresses.emplace_back(address, -1);
+      }
+      catch (const PDNSException& e) {
+        errlog("Unable to parse additional address %s for %s bind: %s", std::string(addr), protocol, e.reason);
+      }
+    }
+  }
+  else if (!additionalAddresses.empty()) {
+    throw std::runtime_error("Passing a non-empty additional_addresses value to a " + protocol + " frontend is not supported");
+  }
+}
+
+
 static void loadBinds(const ::rust::Vec<dnsdist::rust::settings::BindConfiguration>& binds)
 {
   for (const auto& bind : binds) {
@@ -706,20 +725,7 @@ static void loadBinds(const ::rust::Vec<dnsdist::rust::settings::BindConfigurati
           state->d_tcpConcurrentConnectionsLimit = bind.tcp.max_concurrent_connections;
         }
 
-        if (protocol == "dot" || protocol == "doh") {
-          for (const auto& addr : bind.additional_addresses) {
-            try {
-              ComboAddress address{std::string(addr)};
-              state->d_additionalAddresses.emplace_back(address, -1);
-            }
-            catch (const PDNSException& e) {
-              errlog("Unable to parse additional address %s for %s bind: %s", std::string(addr), protocol, e.reason);
-            }
-          }
-        }
-        else if (!bind.additional_addresses.empty()) {
-          throw std::runtime_error("Passing a non-empty additional_addresses value to a " + protocol + " frontend is not supported");
-        }
+        handleAdditionalAddressesForFrontend(state, protocol, bind.additional_addresses);
 
         if (protocol == "dnscrypt") {
 #if defined(HAVE_DNSCRYPT)