From: pizchen Date: Sat, 15 Mar 2025 04:59:15 +0000 (+0800) Subject: Add timeout config per UDP backend server X-Git-Tag: dnsdist-2.0.0-alpha1~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c11e0ee2dad6d8c31f8849f5613984be53311245;p=thirdparty%2Fpdns.git Add timeout config per UDP backend server 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. --- diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index 0e96d711f3..c82046d7ec 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -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(); ) { diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 4780679c0f..bb29fda5ea 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -404,6 +404,7 @@ static std::shared_ptr createBackendFromConfiguration(const dns backendConfig.mustResolve = hcConf.must_resolve; backendConfig.maxCheckFailures = hcConf.max_failures; backendConfig.minRiseSuccesses = hcConf.rise; + backendConfig.udpTimeout = config.udp_timeout; getLuaFunctionFromConfiguration(backendConfig.checkFunction, hcConf.function, hcConf.lua, hcConf.lua_file, "backend health-check"); diff --git a/pdns/dnsdistdist/dnsdist-console.cc b/pdns/dnsdistdist/dnsdist-console.cc index 94ea4d2194..dcdd436cb7 100644 --- a/pdns/dnsdistdist/dnsdist-console.cc +++ b/pdns/dnsdistdist/dnsdist-console.cc @@ -657,7 +657,7 @@ static const std::vector 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"}, diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 5371261fd2..0f8b0a2d53 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -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); diff --git a/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs b/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs index cbc86e6e86..9452e1fcdc 100644 --- a/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs +++ b/pdns/dnsdistdist/dnsdist-rust-lib/rust/src/lib.rs @@ -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, #[serde(default, skip_serializing_if = "crate::is_default")] tcp: OutgoingTcpConfiguration, diff --git a/pdns/dnsdistdist/dnsdist-settings-definitions.yml b/pdns/dnsdistdist/dnsdist-settings-definitions.yml index 02510a3f62..754ccf0cd8 100644 --- a/pdns/dnsdistdist/dnsdist-settings-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-settings-definitions.yml @@ -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" default: "" diff --git a/pdns/dnsdistdist/dnsdist.hh b/pdns/dnsdistdist/dnsdist.hh index 1ea7104cc0..20fe358d1f 100644 --- a/pdns/dnsdistdist/dnsdist.hh +++ b/pdns/dnsdistdist/dnsdist.hh @@ -589,6 +589,7 @@ struct DownstreamState : public std::enable_shared_from_this 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}; diff --git a/pdns/dnsdistdist/docs/reference/config.rst b/pdns/dnsdistdist/docs/reference/config.rst index 5594fd61a1..8fb57ad7ef 100644 --- a/pdns/dnsdistdist/docs/reference/config.rst +++ b/pdns/dnsdistdist/docs/reference/config.rst @@ -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" diff --git a/pdns/dnsdistdist/docs/reference/yaml-settings.rst b/pdns/dnsdistdist/docs/reference/yaml-settings.rst index db3cdd900e..ede608b6c1 100644 --- a/pdns/dnsdistdist/docs/reference/yaml-settings.rst +++ b/pdns/dnsdistdist/docs/reference/yaml-settings.rst @@ -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 ` - TCP-related settings for a backend - **ip_bind_addr_no_port**: Boolean ``(true)`` - Whether to enable ``IP_BIND_ADDRESS_NO_PORT`` if available