Pull request 2338: AGDNS-2665-upstream-timeout
Merge in DNS/adguard-home from AGDNS-2665-upstream-timeout to master
Squashed commit of the following:
commit b4041c97f2ccd371a9cff8312bda72f4c18496b9
Merge: d939b3b3e b92a3cfb8
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Feb 7 16:15:19 2025 +0300
Merge branch 'master' into AGDNS-2665-upstream-timeout
commit d939b3b3ef2345d315c05a3730e81e1f1ea9f79f
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date: Fri Feb 7 16:10:06 2025 +0300
client: imp i18n
commit 52089adb6c28d8c47f5a916d9df941c5fddea1fc
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Feb 6 18:39:53 2025 +0300
all: fix typo
commit aca08b1873c9f39b8c1da0439a9057117e1dacce
Author: Ildar Kamalov <ik@adguard.com>
Date: Thu Feb 6 15:19:30 2025 +0300
client: rearrange upstream timeout settings
commit 48e75fabe2f65aeac7156a020cce3d4c2412e5f9
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue Feb 4 20:48:53 2025 +0300
github: upd actions cache
commit 64bac193fc834a975e6913bb86a6bf27e54c382a
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue Feb 4 20:28:54 2025 +0300
all: imp code
commit 95c73698985dc528a4af6ff0d3b8a301da1f0d4a
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Mon Feb 3 16:25:35 2025 +0300
all: upstream timeout
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/netutil"
|
||||
"github.com/AdguardTeam/golibs/stringutil"
|
||||
"github.com/AdguardTeam/golibs/validate"
|
||||
)
|
||||
|
||||
// jsonDNSConfig is the JSON representation of the DNS server configuration.
|
||||
@@ -53,6 +54,9 @@ type jsonDNSConfig struct {
|
||||
// rate limiting requests.
|
||||
RatelimitSubnetLenIPv6 *int `json:"ratelimit_subnet_len_ipv6"`
|
||||
|
||||
// UpstreamTimeout is an upstream timeout in seconds.
|
||||
UpstreamTimeout *int `json:"upstream_timeout"`
|
||||
|
||||
// RatelimitWhitelist is a list of IP addresses excluded from rate limiting.
|
||||
RatelimitWhitelist *[]netip.Addr `json:"ratelimit_whitelist"`
|
||||
|
||||
@@ -147,6 +151,7 @@ func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
|
||||
ratelimitSubnetLenIPv4 := s.conf.RatelimitSubnetLenIPv4
|
||||
ratelimitSubnetLenIPv6 := s.conf.RatelimitSubnetLenIPv6
|
||||
ratelimitWhitelist := append([]netip.Addr{}, s.conf.RatelimitWhitelist...)
|
||||
upstreamTimeout := int(s.conf.UpstreamTimeout.Seconds())
|
||||
|
||||
customIP := s.conf.EDNSClientSubnet.CustomIP
|
||||
enableEDNSClientSubnet := s.conf.EDNSClientSubnet.Enabled
|
||||
@@ -192,6 +197,7 @@ func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
|
||||
RatelimitSubnetLenIPv4: &ratelimitSubnetLenIPv4,
|
||||
RatelimitSubnetLenIPv6: &ratelimitSubnetLenIPv6,
|
||||
RatelimitWhitelist: &ratelimitWhitelist,
|
||||
UpstreamTimeout: &upstreamTimeout,
|
||||
EDNSCSCustomIP: customIP,
|
||||
EDNSCSEnabled: &enableEDNSClientSubnet,
|
||||
EDNSCSUseCustom: &useCustom,
|
||||
@@ -302,6 +308,12 @@ func (req *jsonDNSConfig) validate(
|
||||
return err
|
||||
}
|
||||
|
||||
err = req.checkUpstreamTimeout()
|
||||
if err != nil {
|
||||
// Don't wrap the error since it's informative enough as is.
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -437,6 +449,16 @@ func (req *jsonDNSConfig) checkRatelimitSubnetMaskLen() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkUpstreamTimeout returns an error if the configuration of the upstream
|
||||
// timeout is invalid.
|
||||
func (req *jsonDNSConfig) checkUpstreamTimeout() (err error) {
|
||||
if req.UpstreamTimeout == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return validate.NoLessThan("upstream_timeout", *req.UpstreamTimeout, 1)
|
||||
}
|
||||
|
||||
// checkInclusion returns an error if a ptr is not nil and points to value,
|
||||
// that not in the inclusive range between minN and maxN.
|
||||
func checkInclusion(ptr *int, minN, maxN int) (err error) {
|
||||
@@ -588,6 +610,14 @@ func (s *Server) setConfigRestartable(dc *jsonDNSConfig) (shouldRestart bool) {
|
||||
shouldRestart = true
|
||||
}
|
||||
|
||||
if dc.UpstreamTimeout != nil {
|
||||
ut := time.Duration(*dc.UpstreamTimeout) * time.Second
|
||||
if s.conf.UpstreamTimeout != ut {
|
||||
s.conf.UpstreamTimeout = ut
|
||||
shouldRestart = true
|
||||
}
|
||||
}
|
||||
|
||||
return shouldRestart
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user