diff --git a/AGHTechDoc.md b/AGHTechDoc.md index 51dc3442..17e94307 100644 --- a/AGHTechDoc.md +++ b/AGHTechDoc.md @@ -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: diff --git a/dnsforward/dnsforward_http.go b/dnsforward/dnsforward_http.go index 4ccfd10b..b3caecbc 100644 --- a/dnsforward/dnsforward_http.go +++ b/dnsforward/dnsforward_http.go @@ -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 diff --git a/openapi/openapi.yaml b/openapi/openapi.yaml index 15e2963b..22579caa 100644 --- a/openapi/openapi.yaml +++ b/openapi/openapi.yaml @@ -1016,6 +1016,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: - ""