]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Add timeout config per UDP backend server
authorpizchen <pizchen@gmail.com>
Sat, 15 Mar 2025 04:59:15 +0000 (12:59 +0800)
committerpizchen <pizchen@gmail.com>
Sat, 15 Mar 2025 04:59:15 +0000 (12:59 +0800)
Currently TCP backend has per server config option while UDP backend
can only use the global timeout setting. This change will add timeout
config per UDP backend server.

pdns/dnsdistdist/dnsdist-backend.cc
pdns/dnsdistdist/dnsdist-configuration-yaml.cc
pdns/dnsdistdist/dnsdist-console.cc
pdns/dnsdistdist/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs
pdns/dnsdistdist/dnsdist-settings-definitions.yml
pdns/dnsdistdist/dnsdist.hh
pdns/dnsdistdist/docs/reference/config.rst
pdns/dnsdistdist/docs/reference/yaml-settings.rst

index 0e96d711f306eac2b2113ecdea7479a23850f745..c82046d7ec13dc974578e9ac4c43c0ef0fdaa19c 100644 (file)
@@ -488,7 +488,7 @@ void DownstreamState::handleUDPTimeouts()
   }
 
   const auto& config = dnsdist::configuration::getImmutableConfiguration();
-  const auto udpTimeout = config.d_udpTimeout;
+  const auto udpTimeout = d_config.udpTimeout ? d_config.udpTimeout : config.d_udpTimeout;
   if (config.d_randomizeIDsToBackend) {
     auto map = d_idStatesMap.lock();
     for (auto it = map->begin(); it != map->end(); ) {
index 4780679c0f7260f966a3beec6642fdd676743d74..bb29fda5eaa14be55261c42ccad35ad9e2c4c8a9 100644 (file)
@@ -404,6 +404,7 @@ static std::shared_ptr<DownstreamState> createBackendFromConfiguration(const dns
   backendConfig.mustResolve = hcConf.must_resolve;
   backendConfig.maxCheckFailures = hcConf.max_failures;
   backendConfig.minRiseSuccesses = hcConf.rise;
+  backendConfig.udpTimeout = config.udp_timeout;
 
   getLuaFunctionFromConfiguration<DownstreamState::checkfunc_t>(backendConfig.checkFunction, hcConf.function, hcConf.lua, hcConf.lua_file, "backend health-check");
 
index 94ea4d2194b6b6493262eb305ca398a38eca4db4..dcdd436cb75dde38689fc4d270c67bbc1830de3b 100644 (file)
@@ -657,7 +657,7 @@ static const std::vector<dnsdist::console::ConsoleKeyword> s_consoleKeywords{
   {"newQPSLimiter", true, "rate, burst", "configure a QPS limiter with that rate and that burst capacity"},
   {"newRemoteLogger", true, "address:port [, timeout=2, maxQueuedEntries=100, reconnectWaitTime=1]", "create a Remote Logger object, to use with `RemoteLogAction()` and `RemoteLogResponseAction()`"},
   {"newRuleAction", true, R"(DNS rule, DNS action [, {uuid="UUID", name="name"}])", "return a pair of DNS Rule and DNS Action, to be used with `setRules()`"},
-  {"newServer", true, R"({address="ip:port", qps=1000, order=1, weight=10, pool="abuse", retries=5, tcpConnectTimeout=5, tcpSendTimeout=30, tcpRecvTimeout=30, checkName="a.root-servers.net.", checkType="A", maxCheckFailures=1, mustResolve=false, useClientSubnet=true, source="address|interface name|address@interface", sockets=1, reconnectOnUp=false})", "instantiate a server"},
+  {"newServer", true, R"({address="ip:port", qps=1000, order=1, weight=10, pool="abuse", retries=5, udpTimeout=0, tcpConnectTimeout=5, tcpSendTimeout=30, tcpRecvTimeout=30, checkName="a.root-servers.net.", checkType="A", maxCheckFailures=1, mustResolve=false, useClientSubnet=true, source="address|interface name|address@interface", sockets=1, reconnectOnUp=false})", "instantiate a server"},
   {"newServerPolicy", true, "name, function", "create a policy object from a Lua function"},
   {"newSuffixMatchNode", true, "", "returns a new SuffixMatchNode"},
   {"newSVCRecordParameters", true, "priority, target, mandatoryParams, alpns, noDefaultAlpn [, port [, ech [, ipv4hints [, ipv6hints [, additionalParameters ]]]]]", "return a new SVCRecordParameters object, to use with SpoofSVCAction"},
index 5371261fd22a24df8688568381b66b7241d89c47..0f8b0a2d53e55f8be7c39e831710935ddee6d653 100644 (file)
@@ -453,6 +453,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
                          getOptionalIntegerValue("newServer", vars, "tcpConnectTimeout", config.tcpConnectTimeout);
                          getOptionalIntegerValue("newServer", vars, "tcpSendTimeout", config.tcpSendTimeout);
                          getOptionalIntegerValue("newServer", vars, "tcpRecvTimeout", config.tcpRecvTimeout);
+                         getOptionalIntegerValue("newServer", vars, "udpTimeout", config.udpTimeout);
 
                          handleNewServerHealthCheckParameters(vars, config);
 
index cbc86e6e864462be105d3efa71b3619f44b3a688..9452e1fcdc0e056f6e2cb1de35766d696379e5b6 100644 (file)
@@ -1810,6 +1810,8 @@ mod dnsdistsettings {
         #[serde(default = "crate::U32::<1>::value", skip_serializing_if = "crate::U32::<1>::is_equal")]
         weight: u32,
         #[serde(default, skip_serializing_if = "crate::is_default")]
+        udp_timeout: u8,
+        #[serde(default, skip_serializing_if = "crate::is_default")]
         pools: Vec<String>,
         #[serde(default, skip_serializing_if = "crate::is_default")]
         tcp: OutgoingTcpConfiguration,
index 02510a3f622a2d868b16564b5f2c72bb66cf41fe..754ccf0cd868d87080fe3830e4e394e39952e03b 100644 (file)
@@ -1345,6 +1345,10 @@ backend:
       type: "u32"
       default: 1
       description: "The weight of this server, used by the `wrandom`, `whashed` and `chashed` policies, default: 1. Supported values are a minimum of 1, and a maximum of 2147483647"
+    - name: "udp_timeout"
+      type: "u8"
+      default: 0
+      description: "The udp backend query timeout value in seconds, default: 0. Supported values are a minimum of 1, and a maximum of 255. Value greater than 0 will override global UDP timeout setting"
     - name: "pools"
       type: "Vec<String>"
       default: ""
index 1ea7104cc0f025c533fecc49447995fbd3edb9a7..20fe358d1fbebd8dbfa041d6233d5073c6047021 100644 (file)
@@ -589,6 +589,7 @@ struct DownstreamState : public std::enable_shared_from_this<DownstreamState>
     LazyHealthCheckMode d_lazyHealthCheckMode{LazyHealthCheckMode::TimeoutOrServFail};
     uint8_t maxCheckFailures{1};
     uint8_t minRiseSuccesses{1};
+    uint8_t udpTimeout{0};
     Availability availability{Availability::Auto};
     bool d_tlsSubjectIsAddr{false};
     bool mustResolve{false};
index 5594fd61a1b2c72ed4c7dc0aea6a3d4356604312..8fb57ad7ef1f87556088c6c8c4a0d0d896a14a9f 100644 (file)
@@ -695,6 +695,7 @@ Servers
     ``qps``                                  ``number``            "Limit the number of queries per second to ``number``, when using the `firstAvailable` policy"
     ``order``                                ``number``            "The order of this server, used by the `leastOutstanding` and `firstAvailable` policies"
     ``weight``                               ``number``            "The weight of this server, used by the `wrandom`, `whashed` and `chashed` policies, default: 1. Supported values are a minimum of 1, and a maximum of 2147483647."
+    ``udpTimeout``                           ``number``            "The timeout (in seconds) of a UDP query attempt"
     ``pool``                                 ``string|{string}``   "The pools this server belongs to (unset or empty string means default pool) as a string or table of strings"
     ``retries``                              ``number``            "The number of TCP connection attempts to the backend, for a given query"
     ``tcpConnectTimeout``                    ``number``            "The timeout (in seconds) of a TCP connection attempt"
index db3cdd900ecff5732ba140a8dff5005bbc20ec83..ede608b6c1076717d583337708f31ced9e614676 100644 (file)
@@ -77,6 +77,7 @@ Generic settings for backends
 - **queries_per_second**: Unsigned integer ``(0)`` - Limit the number of queries per second to ``number``, when using the ``firstAvailable`` policy
 - **order**: Unsigned integer ``(1)`` - The order of this server, used by the `leastOutstanding` and `firstAvailable` policies
 - **weight**: Unsigned integer ``(1)`` - The weight of this server, used by the `wrandom`, `whashed` and `chashed` policies, default: 1. Supported values are a minimum of 1, and a maximum of 2147483647
+- **udp_timeout**: Unsigned integer ``(0)`` - The udp backend query timeout value in seconds, default: 0. Supported values are a minimum of 1, and a maximum of 255. Value greater than 0 will override global UDP timeout setting
 - **pools**: Sequence of String ``("")`` - List of pools to place this backend into. By default a server is placed in the default ("") pool
 - **tcp**: :ref:`OutgoingTcpConfiguration <yaml-settings-OutgoingTcpConfiguration>` - TCP-related settings for a backend
 - **ip_bind_addr_no_port**: Boolean ``(true)`` - Whether to enable ``IP_BIND_ADDRESS_NO_PORT`` if available