diff --git a/client/src/components/Settings/Dns/Cache/Form.js b/client/src/components/Settings/Dns/Cache/Form.js index 0f51e117246..c772019f099 100644 --- a/client/src/components/Settings/Dns/Cache/Form.js +++ b/client/src/components/Settings/Dns/Cache/Form.js @@ -41,7 +41,7 @@ const Form = ({ cache_ttl_max, cache_ttl_min, } = useSelector((state) => state.form[FORM_NAME.CACHE].values, shallowEqual); - const minExceedsMax = cache_ttl_min > cache_ttl_max; + const minExceedsMax = cache_ttl_min > 0 && cache_ttl_max > 0 && cache_ttl_min > cache_ttl_max; const handleClearCache = () => { if (window.confirm(t('confirm_dns_cache_clear'))) { diff --git a/internal/dnsforward/http.go b/internal/dnsforward/http.go index ac82ea76f9f..1e628278099 100644 --- a/internal/dnsforward/http.go +++ b/internal/dnsforward/http.go @@ -346,23 +346,24 @@ func (req *jsonDNSConfig) validateUpstreamDNSServers(privateNets netutil.SubnetS // checkCacheTTL returns an error if the configuration of the cache TTL is // invalid. func (req *jsonDNSConfig) checkCacheTTL() (err error) { - if req.CacheMinTTL == nil && req.CacheMaxTTL == nil { + if req.CacheMinTTL == nil || req.CacheMaxTTL == nil { return nil } - var minTTL, maxTTL uint32 - if req.CacheMinTTL != nil { + var ( minTTL = *req.CacheMinTTL - } - if req.CacheMaxTTL != nil { maxTTL = *req.CacheMaxTTL - } + ) - if minTTL <= maxTTL { + if minTTL == 0 || maxTTL == 0 { return nil } - return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") + if minTTL > maxTTL { + return errors.Error("cache_ttl_min must be less or equal than cache_ttl_max") + } + + return nil } // checkRatelimitSubnetMaskLen returns an error if the length of the subnet mask