Skip to content

Commit

Permalink
all: cache ttl override
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Dec 18, 2023
1 parent 4fc6bf5 commit 51c7a52
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion client/src/components/Settings/Dns/Cache/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'))) {
Expand Down
17 changes: 9 additions & 8 deletions internal/dnsforward/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 51c7a52

Please sign in to comment.