+ dns: new settings for cache

This commit is contained in:
Simon Zolin 2020-06-16 15:38:27 +03:00
parent ec6ca93acd
commit a5c0381c46
3 changed files with 38 additions and 0 deletions

View File

@ -894,6 +894,9 @@ Response:
"dnssec_enabled": true | false
"disable_ipv6": true | false,
"upstream_mode": "" | "parallel" | "fastest_addr"
"cache_size": 1234, // in bytes
"cache_ttl_min": 1234, // in seconds
"cache_ttl_max": 1234, // in seconds
}
@ -916,6 +919,9 @@ Request:
"dnssec_enabled": true | false
"disable_ipv6": true | false,
"upstream_mode": "" | "parallel" | "fastest_addr"
"cache_size": 1234, // in bytes
"cache_ttl_min": 1234, // in seconds
"cache_ttl_max": 1234, // in seconds
}
Response:

View File

@ -34,6 +34,9 @@ type dnsConfigJSON struct {
DNSSECEnabled bool `json:"dnssec_enabled"`
DisableIPv6 bool `json:"disable_ipv6"`
UpstreamMode string `json:"upstream_mode"`
CacheSize uint32 `json:"cache_size"`
CacheMinTTL uint32 `json:"cache_ttl_min"`
CacheMaxTTL uint32 `json:"cache_ttl_max"`
}
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
@ -50,6 +53,9 @@ func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
resp.EDNSCSEnabled = s.conf.EnableEDNSClientSubnet
resp.DNSSECEnabled = s.conf.EnableDNSSEC
resp.DisableIPv6 = s.conf.AAAADisabled
resp.CacheSize = s.conf.CacheSize
resp.CacheMinTTL = s.conf.CacheMinTTL
resp.CacheMaxTTL = s.conf.CacheMaxTTL
if s.conf.FastestAddr {
resp.UpstreamMode = "fastest_addr"
} else if s.conf.AllServers {
@ -126,6 +132,11 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
return
}
if req.CacheMinTTL > req.CacheMaxTTL {
httpError(r, w, http.StatusBadRequest, "cache_ttl_min must be less or equal than cache_ttl_max")
return
}
restart := false
s.Lock()
@ -177,6 +188,21 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
s.conf.AAAADisabled = req.DisableIPv6
}
if js.Exists("cache_size") {
s.conf.CacheSize = req.CacheSize
restart = true
}
if js.Exists("cache_ttl_min") {
s.conf.CacheMinTTL = req.CacheMinTTL
restart = true
}
if js.Exists("cache_ttl_max") {
s.conf.CacheMaxTTL = req.CacheMaxTTL
restart = true
}
if js.Exists("upstream_mode") {
s.conf.FastestAddr = false
s.conf.AllServers = false

View File

@ -1019,6 +1019,12 @@ components:
type: boolean
dnssec_enabled:
type: boolean
cache_size:
type: integer
cache_ttl_min:
type: integer
cache_ttl_max:
type: integer
upstream_mode:
enum:
- ""