2019-10-30 08:52:58 +00:00
|
|
|
package dnsforward
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-12-02 15:06:50 +00:00
|
|
|
"io"
|
2019-10-30 08:52:58 +00:00
|
|
|
"net/http"
|
2022-10-21 18:42:00 +01:00
|
|
|
"net/netip"
|
2024-02-08 17:39:18 +00:00
|
|
|
"slices"
|
2021-06-15 15:36:49 +01:00
|
|
|
"time"
|
2019-10-30 08:52:58 +00:00
|
|
|
|
2021-12-16 17:54:59 +00:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
2023-08-30 16:26:02 +01:00
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/filtering"
|
2024-02-05 13:12:27 +00:00
|
|
|
"github.com/AdguardTeam/dnsproxy/proxy"
|
2019-10-30 08:52:58 +00:00
|
|
|
"github.com/AdguardTeam/dnsproxy/upstream"
|
2021-05-24 15:28:11 +01:00
|
|
|
"github.com/AdguardTeam/golibs/errors"
|
2019-10-30 08:52:58 +00:00
|
|
|
"github.com/AdguardTeam/golibs/log"
|
2021-08-09 14:03:37 +01:00
|
|
|
"github.com/AdguardTeam/golibs/netutil"
|
2021-07-29 15:40:31 +01:00
|
|
|
"github.com/AdguardTeam/golibs/stringutil"
|
2019-10-30 08:52:58 +00:00
|
|
|
)
|
|
|
|
|
2022-09-06 15:09:54 +01:00
|
|
|
// jsonDNSConfig is the JSON representation of the DNS server configuration.
|
2023-03-22 10:42:20 +00:00
|
|
|
//
|
|
|
|
// TODO(s.chzhen): Split it into smaller pieces. Use aghalg.NullBool instead
|
|
|
|
// of *bool.
|
2022-09-06 15:09:54 +01:00
|
|
|
type jsonDNSConfig struct {
|
2023-03-22 10:42:20 +00:00
|
|
|
// Upstreams is the list of upstream DNS servers.
|
|
|
|
Upstreams *[]string `json:"upstream_dns"`
|
|
|
|
|
|
|
|
// UpstreamsFile is the file containing upstream DNS servers.
|
|
|
|
UpstreamsFile *string `json:"upstream_dns_file"`
|
|
|
|
|
|
|
|
// Bootstraps is the list of DNS servers resolving IP addresses of the
|
|
|
|
// upstream DoH/DoT resolvers.
|
|
|
|
Bootstraps *[]string `json:"bootstrap_dns"`
|
|
|
|
|
2023-08-30 11:21:31 +01:00
|
|
|
// Fallbacks is the list of fallback DNS servers used when upstream DNS
|
|
|
|
// servers are not responding.
|
|
|
|
Fallbacks *[]string `json:"fallback_dns"`
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
// ProtectionEnabled defines if protection is enabled.
|
|
|
|
ProtectionEnabled *bool `json:"protection_enabled"`
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
// Ratelimit is the number of requests per second allowed per client.
|
|
|
|
Ratelimit *uint32 `json:"ratelimit"`
|
|
|
|
|
|
|
|
// RatelimitSubnetLenIPv4 is a subnet length for IPv4 addresses used for
|
|
|
|
// rate limiting requests.
|
|
|
|
RatelimitSubnetLenIPv4 *int `json:"ratelimit_subnet_len_ipv4"`
|
|
|
|
|
|
|
|
// RatelimitSubnetLenIPv6 is a subnet length for IPv6 addresses used for
|
|
|
|
// rate limiting requests.
|
|
|
|
RatelimitSubnetLenIPv6 *int `json:"ratelimit_subnet_len_ipv6"`
|
|
|
|
|
|
|
|
// RatelimitWhitelist is a list of IP addresses excluded from rate limiting.
|
2023-12-05 14:43:50 +00:00
|
|
|
RatelimitWhitelist *[]netip.Addr `json:"ratelimit_whitelist"`
|
2023-03-22 10:42:20 +00:00
|
|
|
|
|
|
|
// BlockingMode defines the way blocked responses are constructed.
|
2023-08-30 16:26:02 +01:00
|
|
|
BlockingMode *filtering.BlockingMode `json:"blocking_mode"`
|
2023-03-22 10:42:20 +00:00
|
|
|
|
|
|
|
// EDNSCSEnabled defines if EDNS Client Subnet is enabled.
|
|
|
|
EDNSCSEnabled *bool `json:"edns_cs_enabled"`
|
|
|
|
|
|
|
|
// EDNSCSUseCustom defines if EDNSCSCustomIP should be used.
|
|
|
|
EDNSCSUseCustom *bool `json:"edns_cs_use_custom"`
|
|
|
|
|
|
|
|
// DNSSECEnabled defines if DNSSEC is enabled.
|
|
|
|
DNSSECEnabled *bool `json:"dnssec_enabled"`
|
|
|
|
|
|
|
|
// DisableIPv6 defines if IPv6 addresses should be dropped.
|
|
|
|
DisableIPv6 *bool `json:"disable_ipv6"`
|
|
|
|
|
|
|
|
// UpstreamMode defines the way DNS requests are constructed.
|
2023-12-25 11:16:48 +00:00
|
|
|
UpstreamMode *jsonUpstreamMode `json:"upstream_mode"`
|
2023-03-22 10:42:20 +00:00
|
|
|
|
2023-09-13 11:58:12 +01:00
|
|
|
// BlockedResponseTTL is the TTL for blocked responses.
|
|
|
|
BlockedResponseTTL *uint32 `json:"blocked_response_ttl"`
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
// CacheSize in bytes.
|
|
|
|
CacheSize *uint32 `json:"cache_size"`
|
|
|
|
|
|
|
|
// CacheMinTTL is custom minimum TTL for cached DNS responses.
|
|
|
|
CacheMinTTL *uint32 `json:"cache_ttl_min"`
|
|
|
|
|
|
|
|
// CacheMaxTTL is custom maximum TTL for cached DNS responses.
|
|
|
|
CacheMaxTTL *uint32 `json:"cache_ttl_max"`
|
|
|
|
|
|
|
|
// CacheOptimistic defines if expired entries should be served.
|
|
|
|
CacheOptimistic *bool `json:"cache_optimistic"`
|
|
|
|
|
|
|
|
// ResolveClients defines if clients IPs should be resolved into hostnames.
|
|
|
|
ResolveClients *bool `json:"resolve_clients"`
|
|
|
|
|
|
|
|
// UsePrivateRDNS defines if privates DNS resolvers should be used.
|
|
|
|
UsePrivateRDNS *bool `json:"use_private_ptr_resolvers"`
|
|
|
|
|
|
|
|
// LocalPTRUpstreams is the list of local private DNS resolvers.
|
|
|
|
LocalPTRUpstreams *[]string `json:"local_ptr_upstreams"`
|
|
|
|
|
|
|
|
// BlockingIPv4 is custom IPv4 address for blocked A requests.
|
2023-08-23 14:58:24 +01:00
|
|
|
BlockingIPv4 netip.Addr `json:"blocking_ipv4"`
|
2023-03-22 10:42:20 +00:00
|
|
|
|
|
|
|
// BlockingIPv6 is custom IPv6 address for blocked AAAA requests.
|
2023-08-23 14:58:24 +01:00
|
|
|
BlockingIPv6 netip.Addr `json:"blocking_ipv6"`
|
2023-03-22 10:42:20 +00:00
|
|
|
|
2023-03-24 12:11:47 +00:00
|
|
|
// DisabledUntil is a timestamp until when the protection is disabled.
|
|
|
|
DisabledUntil *time.Time `json:"protection_disabled_until"`
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
// EDNSCSCustomIP is custom IP for EDNS Client Subnet.
|
|
|
|
EDNSCSCustomIP netip.Addr `json:"edns_cs_custom_ip"`
|
|
|
|
|
|
|
|
// DefaultLocalPTRUpstreams is used to pass the addresses from
|
|
|
|
// systemResolvers to the front-end. It's not a pointer to the slice since
|
|
|
|
// there is no need to omit it while decoding from JSON.
|
|
|
|
DefaultLocalPTRUpstreams []string `json:"default_local_ptr_upstreams,omitempty"`
|
2019-11-08 11:59:12 +00:00
|
|
|
}
|
|
|
|
|
2023-12-25 11:16:48 +00:00
|
|
|
// jsonUpstreamMode is a enumeration of upstream modes.
|
|
|
|
type jsonUpstreamMode string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// jsonUpstreamModeEmpty is the default value on frontend, it is used as
|
|
|
|
// jsonUpstreamModeLoadBalance mode.
|
|
|
|
//
|
|
|
|
// Deprecated: Use jsonUpstreamModeLoadBalance instead.
|
|
|
|
jsonUpstreamModeEmpty jsonUpstreamMode = ""
|
|
|
|
|
|
|
|
jsonUpstreamModeLoadBalance jsonUpstreamMode = "load_balance"
|
|
|
|
jsonUpstreamModeParallel jsonUpstreamMode = "parallel"
|
|
|
|
jsonUpstreamModeFastestAddr jsonUpstreamMode = "fastest_addr"
|
|
|
|
)
|
|
|
|
|
2022-09-06 15:09:54 +01:00
|
|
|
func (s *Server) getDNSConfig() (c *jsonDNSConfig) {
|
2023-04-11 13:02:29 +01:00
|
|
|
protectionEnabled, protectionDisabledUntil := s.UpdatedProtectionStatus()
|
2023-03-24 12:11:47 +00:00
|
|
|
|
2021-05-26 15:55:19 +01:00
|
|
|
s.serverLock.RLock()
|
|
|
|
defer s.serverLock.RUnlock()
|
2021-04-07 18:16:06 +01:00
|
|
|
|
2021-07-29 15:40:31 +01:00
|
|
|
upstreams := stringutil.CloneSliceOrEmpty(s.conf.UpstreamDNS)
|
2020-11-20 14:32:41 +00:00
|
|
|
upstreamFile := s.conf.UpstreamDNSFileName
|
2021-07-29 15:40:31 +01:00
|
|
|
bootstraps := stringutil.CloneSliceOrEmpty(s.conf.BootstrapDNS)
|
2023-08-30 11:21:31 +01:00
|
|
|
fallbacks := stringutil.CloneSliceOrEmpty(s.conf.FallbackDNS)
|
2023-09-04 15:18:43 +01:00
|
|
|
blockingMode, blockingIPv4, blockingIPv6 := s.dnsFilter.BlockingMode()
|
2023-09-13 11:58:12 +01:00
|
|
|
blockedResponseTTL := s.dnsFilter.BlockedResponseTTL()
|
2021-04-07 18:16:06 +01:00
|
|
|
ratelimit := s.conf.Ratelimit
|
2023-11-15 16:27:13 +00:00
|
|
|
ratelimitSubnetLenIPv4 := s.conf.RatelimitSubnetLenIPv4
|
|
|
|
ratelimitSubnetLenIPv6 := s.conf.RatelimitSubnetLenIPv6
|
2023-12-05 14:43:50 +00:00
|
|
|
ratelimitWhitelist := append([]netip.Addr{}, s.conf.RatelimitWhitelist...)
|
2023-03-22 10:42:20 +00:00
|
|
|
|
|
|
|
customIP := s.conf.EDNSClientSubnet.CustomIP
|
2023-03-01 13:16:16 +00:00
|
|
|
enableEDNSClientSubnet := s.conf.EDNSClientSubnet.Enabled
|
2023-03-22 10:42:20 +00:00
|
|
|
useCustom := s.conf.EDNSClientSubnet.UseCustom
|
|
|
|
|
2021-04-07 18:16:06 +01:00
|
|
|
enableDNSSEC := s.conf.EnableDNSSEC
|
|
|
|
aaaaDisabled := s.conf.AAAADisabled
|
|
|
|
cacheSize := s.conf.CacheSize
|
|
|
|
cacheMinTTL := s.conf.CacheMinTTL
|
|
|
|
cacheMaxTTL := s.conf.CacheMaxTTL
|
2021-07-14 19:03:56 +01:00
|
|
|
cacheOptimistic := s.conf.CacheOptimistic
|
2023-07-18 15:02:07 +01:00
|
|
|
resolveClients := s.conf.AddrProcConf.UseRDNS
|
2021-05-26 15:55:19 +01:00
|
|
|
usePrivateRDNS := s.conf.UsePrivateRDNS
|
2021-07-29 15:40:31 +01:00
|
|
|
localPTRUpstreams := stringutil.CloneSliceOrEmpty(s.conf.LocalPTRResolvers)
|
2023-03-24 12:11:47 +00:00
|
|
|
|
2023-12-25 11:16:48 +00:00
|
|
|
var upstreamMode jsonUpstreamMode
|
|
|
|
switch s.conf.UpstreamMode {
|
|
|
|
case UpstreamModeLoadBalance:
|
|
|
|
// TODO(d.kolyshev): Support jsonUpstreamModeLoadBalance on frontend instead
|
|
|
|
// of jsonUpstreamModeEmpty.
|
|
|
|
upstreamMode = jsonUpstreamModeEmpty
|
|
|
|
case UpstreamModeParallel:
|
|
|
|
upstreamMode = jsonUpstreamModeParallel
|
|
|
|
case UpstreamModeFastestAddr:
|
|
|
|
upstreamMode = jsonUpstreamModeFastestAddr
|
2020-06-10 13:33:23 +01:00
|
|
|
}
|
2021-04-07 18:16:06 +01:00
|
|
|
|
2023-09-28 17:11:11 +01:00
|
|
|
defPTRUps, err := s.defaultLocalPTRUpstreams()
|
2021-06-01 12:28:34 +01:00
|
|
|
if err != nil {
|
2023-09-28 17:11:11 +01:00
|
|
|
log.Error("dnsforward: %s", err)
|
2021-06-01 12:28:34 +01:00
|
|
|
}
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
return &jsonDNSConfig{
|
|
|
|
Upstreams: &upstreams,
|
|
|
|
UpstreamsFile: &upstreamFile,
|
|
|
|
Bootstraps: &bootstraps,
|
2023-08-30 11:21:31 +01:00
|
|
|
Fallbacks: &fallbacks,
|
2023-03-22 10:42:20 +00:00
|
|
|
ProtectionEnabled: &protectionEnabled,
|
|
|
|
BlockingMode: &blockingMode,
|
|
|
|
BlockingIPv4: blockingIPv4,
|
|
|
|
BlockingIPv6: blockingIPv6,
|
2023-11-15 16:27:13 +00:00
|
|
|
Ratelimit: &ratelimit,
|
|
|
|
RatelimitSubnetLenIPv4: &ratelimitSubnetLenIPv4,
|
|
|
|
RatelimitSubnetLenIPv6: &ratelimitSubnetLenIPv6,
|
|
|
|
RatelimitWhitelist: &ratelimitWhitelist,
|
2023-03-22 10:42:20 +00:00
|
|
|
EDNSCSCustomIP: customIP,
|
|
|
|
EDNSCSEnabled: &enableEDNSClientSubnet,
|
|
|
|
EDNSCSUseCustom: &useCustom,
|
|
|
|
DNSSECEnabled: &enableDNSSEC,
|
|
|
|
DisableIPv6: &aaaaDisabled,
|
2023-09-13 11:58:12 +01:00
|
|
|
BlockedResponseTTL: &blockedResponseTTL,
|
2023-03-22 10:42:20 +00:00
|
|
|
CacheSize: &cacheSize,
|
|
|
|
CacheMinTTL: &cacheMinTTL,
|
|
|
|
CacheMaxTTL: &cacheMaxTTL,
|
|
|
|
CacheOptimistic: &cacheOptimistic,
|
|
|
|
UpstreamMode: &upstreamMode,
|
|
|
|
ResolveClients: &resolveClients,
|
|
|
|
UsePrivateRDNS: &usePrivateRDNS,
|
|
|
|
LocalPTRUpstreams: &localPTRUpstreams,
|
2023-09-28 17:11:11 +01:00
|
|
|
DefaultLocalPTRUpstreams: defPTRUps,
|
2023-04-11 13:02:29 +01:00
|
|
|
DisabledUntil: protectionDisabledUntil,
|
2021-06-01 12:28:34 +01:00
|
|
|
}
|
2023-03-22 10:42:20 +00:00
|
|
|
}
|
2020-11-20 14:32:41 +00:00
|
|
|
|
2023-09-28 17:11:11 +01:00
|
|
|
// defaultLocalPTRUpstreams returns the list of default local PTR resolvers
|
|
|
|
// filtered of AdGuard Home's own DNS server addresses. It may appear empty.
|
|
|
|
func (s *Server) defaultLocalPTRUpstreams() (ups []string, err error) {
|
2023-11-16 11:05:10 +00:00
|
|
|
matcher, err := s.conf.ourAddrsSet()
|
2023-09-28 17:11:11 +01:00
|
|
|
if err != nil {
|
2023-10-05 13:26:19 +01:00
|
|
|
// Don't wrap the error because it's informative enough as is.
|
|
|
|
return nil, err
|
2023-09-28 17:11:11 +01:00
|
|
|
}
|
|
|
|
|
2024-02-01 10:46:28 +00:00
|
|
|
sysResolvers := slices.DeleteFunc(slices.Clone(s.sysResolvers.Addrs()), matcher.Has)
|
2023-10-05 13:26:19 +01:00
|
|
|
ups = make([]string, 0, len(sysResolvers))
|
|
|
|
for _, r := range sysResolvers {
|
|
|
|
ups = append(ups, r.String())
|
2023-09-28 17:11:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ups, nil
|
|
|
|
}
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
// handleGetConfig handles requests to the GET /control/dns_info endpoint.
|
|
|
|
func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) {
|
|
|
|
resp := s.getDNSConfig()
|
2023-08-29 18:03:40 +01:00
|
|
|
aghhttp.WriteJSONResponseOK(w, r, resp)
|
2019-11-08 11:59:12 +00:00
|
|
|
}
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
// checkBlockingMode returns an error if blocking mode is invalid.
|
2022-09-06 15:09:54 +01:00
|
|
|
func (req *jsonDNSConfig) checkBlockingMode() (err error) {
|
2020-11-20 14:32:41 +00:00
|
|
|
if req.BlockingMode == nil {
|
2022-09-06 15:09:54 +01:00
|
|
|
return nil
|
2019-11-08 13:19:56 +00:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:09:54 +01:00
|
|
|
return validateBlockingMode(*req.BlockingMode, req.BlockingIPv4, req.BlockingIPv6)
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
|
|
|
|
2023-12-25 11:16:48 +00:00
|
|
|
// checkUpstreamMode returns an error if the upstream mode is invalid.
|
|
|
|
func (req *jsonDNSConfig) checkUpstreamMode() (err error) {
|
2023-11-15 16:27:13 +00:00
|
|
|
if req.UpstreamMode == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-12-25 11:16:48 +00:00
|
|
|
switch um := *req.UpstreamMode; um {
|
|
|
|
case
|
|
|
|
jsonUpstreamModeEmpty,
|
|
|
|
jsonUpstreamModeLoadBalance,
|
|
|
|
jsonUpstreamModeParallel,
|
|
|
|
jsonUpstreamModeFastestAddr:
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("upstream_mode: incorrect value %q", um)
|
2023-11-15 16:27:13 +00:00
|
|
|
}
|
2022-02-14 13:56:14 +00:00
|
|
|
}
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
// checkBootstrap returns an error if any bootstrap address is invalid.
|
2022-09-06 15:09:54 +01:00
|
|
|
func (req *jsonDNSConfig) checkBootstrap() (err error) {
|
2022-02-14 13:56:14 +00:00
|
|
|
if req.Bootstraps == nil {
|
|
|
|
return nil
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:56:14 +00:00
|
|
|
var b string
|
2024-01-16 10:18:22 +00:00
|
|
|
defer func() { err = errors.Annotate(err, "checking bootstrap %s: %w", b) }()
|
2022-02-14 13:56:14 +00:00
|
|
|
|
|
|
|
for _, b = range *req.Bootstraps {
|
|
|
|
if b == "" {
|
|
|
|
return errors.Error("empty")
|
|
|
|
}
|
|
|
|
|
2024-01-16 10:18:22 +00:00
|
|
|
var resolver *upstream.UpstreamResolver
|
|
|
|
if resolver, err = upstream.NewUpstreamResolver(b, nil); err != nil {
|
2023-11-15 16:27:13 +00:00
|
|
|
// Don't wrap the error because it's informative enough as is.
|
2022-02-14 13:56:14 +00:00
|
|
|
return err
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
2024-01-16 10:18:22 +00:00
|
|
|
|
|
|
|
if err = resolver.Close(); err != nil {
|
|
|
|
return fmt.Errorf("closing %s: %w", b, err)
|
|
|
|
}
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:56:14 +00:00
|
|
|
return nil
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 11:21:31 +01:00
|
|
|
// checkFallbacks returns an error if any fallback address is invalid.
|
|
|
|
func (req *jsonDNSConfig) checkFallbacks() (err error) {
|
|
|
|
if req.Fallbacks == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-02-05 13:12:27 +00:00
|
|
|
_, err = proxy.ParseUpstreamsConfig(*req.Fallbacks, &upstream.Options{})
|
2023-08-30 11:21:31 +01:00
|
|
|
if err != nil {
|
2023-11-15 16:27:13 +00:00
|
|
|
return fmt.Errorf("fallback servers: %w", err)
|
2023-08-30 11:21:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-02-14 13:56:14 +00:00
|
|
|
// validate returns an error if any field of req is invalid.
|
2023-11-15 16:27:13 +00:00
|
|
|
//
|
|
|
|
// TODO(s.chzhen): Parse, don't validate.
|
2022-09-06 15:09:54 +01:00
|
|
|
func (req *jsonDNSConfig) validate(privateNets netutil.SubnetSet) (err error) {
|
2023-11-15 16:27:13 +00:00
|
|
|
defer func() { err = errors.Annotate(err, "validating dns config: %w") }()
|
|
|
|
|
|
|
|
err = req.validateUpstreamDNSServers(privateNets)
|
|
|
|
if err != nil {
|
|
|
|
// Don't wrap the error since it's informative enough as is.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = req.checkRatelimitSubnetMaskLen()
|
|
|
|
if err != nil {
|
|
|
|
// Don't wrap the error since it's informative enough as is.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = req.checkBlockingMode()
|
|
|
|
if err != nil {
|
|
|
|
// Don't wrap the error since it's informative enough as is.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-12-25 11:16:48 +00:00
|
|
|
err = req.checkUpstreamMode()
|
2023-11-15 16:27:13 +00:00
|
|
|
if err != nil {
|
|
|
|
// Don't wrap the error since it's informative enough as is.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = req.checkCacheTTL()
|
|
|
|
if err != nil {
|
|
|
|
// Don't wrap the error since it's informative enough as is.
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// validateUpstreamDNSServers returns an error if any field of req is invalid.
|
|
|
|
func (req *jsonDNSConfig) validateUpstreamDNSServers(privateNets netutil.SubnetSet) (err error) {
|
2022-02-14 13:56:14 +00:00
|
|
|
if req.Upstreams != nil {
|
2024-02-05 13:12:27 +00:00
|
|
|
_, err = proxy.ParseUpstreamsConfig(*req.Upstreams, &upstream.Options{})
|
2022-02-14 13:56:14 +00:00
|
|
|
if err != nil {
|
2023-11-15 16:27:13 +00:00
|
|
|
return fmt.Errorf("upstream servers: %w", err)
|
2022-02-14 13:56:14 +00:00
|
|
|
}
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
|
|
|
|
2022-02-14 13:56:14 +00:00
|
|
|
if req.LocalPTRUpstreams != nil {
|
2022-03-18 10:37:27 +00:00
|
|
|
err = ValidateUpstreamsPrivate(*req.LocalPTRUpstreams, privateNets)
|
2022-02-14 13:56:14 +00:00
|
|
|
if err != nil {
|
2023-11-15 16:27:13 +00:00
|
|
|
return fmt.Errorf("private upstream servers: %w", err)
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
2022-02-14 13:56:14 +00:00
|
|
|
}
|
2020-11-20 14:32:41 +00:00
|
|
|
|
2022-02-14 13:56:14 +00:00
|
|
|
err = req.checkBootstrap()
|
|
|
|
if err != nil {
|
2023-11-15 16:27:13 +00:00
|
|
|
// Don't wrap the error since it's informative enough as is.
|
2022-02-14 13:56:14 +00:00
|
|
|
return err
|
2019-11-08 13:19:56 +00:00
|
|
|
}
|
|
|
|
|
2023-08-30 11:21:31 +01:00
|
|
|
err = req.checkFallbacks()
|
|
|
|
if err != nil {
|
2023-11-15 16:27:13 +00:00
|
|
|
// Don't wrap the error since it's informative enough as is.
|
2023-08-30 11:21:31 +01:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
return nil
|
2022-09-06 15:09:54 +01:00
|
|
|
}
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
var minTTL, maxTTL uint32
|
|
|
|
if req.CacheMinTTL != nil {
|
|
|
|
minTTL = *req.CacheMinTTL
|
|
|
|
}
|
2023-12-26 13:52:33 +00:00
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
if req.CacheMaxTTL != nil {
|
|
|
|
maxTTL = *req.CacheMaxTTL
|
|
|
|
}
|
|
|
|
|
2023-12-26 13:52:33 +00:00
|
|
|
return validateCacheTTL(minTTL, maxTTL)
|
2019-11-08 13:19:56 +00:00
|
|
|
}
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
// checkRatelimitSubnetMaskLen returns an error if the length of the subnet mask
|
|
|
|
// for IPv4 or IPv6 addresses is invalid.
|
|
|
|
func (req *jsonDNSConfig) checkRatelimitSubnetMaskLen() (err error) {
|
|
|
|
err = checkInclusion(req.RatelimitSubnetLenIPv4, 0, netutil.IPv4BitLen)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ratelimit_subnet_len_ipv4 is invalid: %w", err)
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
2020-12-21 12:43:27 +00:00
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
err = checkInclusion(req.RatelimitSubnetLenIPv6, 0, netutil.IPv6BitLen)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("ratelimit_subnet_len_ipv6 is invalid: %w", err)
|
2020-08-21 13:54:16 +01:00
|
|
|
}
|
2023-11-15 16:27:13 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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) {
|
|
|
|
if ptr == nil {
|
|
|
|
return nil
|
2020-08-21 13:54:16 +01:00
|
|
|
}
|
2020-11-20 14:32:41 +00:00
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
n := *ptr
|
|
|
|
switch {
|
|
|
|
case n < minN:
|
|
|
|
return fmt.Errorf("value %d less than min %d", n, minN)
|
|
|
|
case n > maxN:
|
|
|
|
return fmt.Errorf("value %d greater than max %d", n, maxN)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
// handleSetConfig handles requests to the POST /control/dns_config endpoint.
|
2019-11-08 11:59:12 +00:00
|
|
|
func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
|
2022-09-06 15:09:54 +01:00
|
|
|
req := &jsonDNSConfig{}
|
2022-02-14 13:56:14 +00:00
|
|
|
err := json.NewDecoder(r.Body).Decode(req)
|
2022-01-13 12:05:44 +00:00
|
|
|
if err != nil {
|
2022-02-14 13:56:14 +00:00
|
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "decoding request: %s", err)
|
2021-12-16 17:54:59 +00:00
|
|
|
|
2019-11-08 11:59:12 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-18 10:37:27 +00:00
|
|
|
err = req.validate(s.privateNets)
|
2022-02-14 13:56:14 +00:00
|
|
|
if err != nil {
|
|
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "%s", err)
|
2021-12-16 17:54:59 +00:00
|
|
|
|
2020-07-03 18:35:04 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-26 10:29:33 +00:00
|
|
|
restart := s.setConfig(req)
|
|
|
|
s.conf.ConfigModified()
|
|
|
|
|
|
|
|
if restart {
|
2022-02-14 13:56:14 +00:00
|
|
|
err = s.Reconfigure(nil)
|
|
|
|
if err != nil {
|
2021-12-16 17:54:59 +00:00
|
|
|
aghhttp.Error(r, w, http.StatusInternalServerError, "%s", err)
|
2020-11-20 14:32:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
// setConfig sets the server parameters. shouldRestart is true if the server
|
|
|
|
// should be restarted to apply changes.
|
2022-09-06 15:09:54 +01:00
|
|
|
func (s *Server) setConfig(dc *jsonDNSConfig) (shouldRestart bool) {
|
2021-05-26 15:55:19 +01:00
|
|
|
s.serverLock.Lock()
|
|
|
|
defer s.serverLock.Unlock()
|
2021-03-26 10:29:33 +00:00
|
|
|
|
|
|
|
if dc.BlockingMode != nil {
|
2023-09-04 15:18:43 +01:00
|
|
|
s.dnsFilter.SetBlockingMode(*dc.BlockingMode, dc.BlockingIPv4, dc.BlockingIPv6)
|
|
|
|
}
|
|
|
|
|
2023-09-13 11:58:12 +01:00
|
|
|
if dc.BlockedResponseTTL != nil {
|
|
|
|
s.dnsFilter.SetBlockedResponseTTL(*dc.BlockedResponseTTL)
|
|
|
|
}
|
|
|
|
|
2023-09-04 15:18:43 +01:00
|
|
|
if dc.ProtectionEnabled != nil {
|
|
|
|
s.dnsFilter.SetProtectionEnabled(*dc.ProtectionEnabled)
|
2020-04-22 17:14:04 +01:00
|
|
|
}
|
2021-03-26 10:29:33 +00:00
|
|
|
|
|
|
|
if dc.UpstreamMode != nil {
|
2023-12-25 11:16:48 +00:00
|
|
|
s.conf.UpstreamMode = mustParseUpstreamMode(*dc.UpstreamMode)
|
|
|
|
} else {
|
|
|
|
s.conf.UpstreamMode = UpstreamModeLoadBalance
|
2021-03-26 10:29:33 +00:00
|
|
|
}
|
|
|
|
|
2023-03-22 10:42:20 +00:00
|
|
|
if dc.EDNSCSUseCustom != nil && *dc.EDNSCSUseCustom {
|
|
|
|
s.conf.EDNSClientSubnet.CustomIP = dc.EDNSCSCustomIP
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:09:54 +01:00
|
|
|
setIfNotNil(&s.conf.EnableDNSSEC, dc.DNSSECEnabled)
|
|
|
|
setIfNotNil(&s.conf.AAAADisabled, dc.DisableIPv6)
|
|
|
|
|
|
|
|
return s.setConfigRestartable(dc)
|
|
|
|
}
|
|
|
|
|
2023-12-25 11:16:48 +00:00
|
|
|
// mustParseUpstreamMode returns an upstream mode parsed from jsonUpstreamMode.
|
|
|
|
// Panics in case of invalid value.
|
|
|
|
func mustParseUpstreamMode(mode jsonUpstreamMode) (um UpstreamMode) {
|
|
|
|
switch mode {
|
|
|
|
case jsonUpstreamModeEmpty, jsonUpstreamModeLoadBalance:
|
|
|
|
return UpstreamModeLoadBalance
|
|
|
|
case jsonUpstreamModeParallel:
|
|
|
|
return UpstreamModeParallel
|
|
|
|
case jsonUpstreamModeFastestAddr:
|
|
|
|
return UpstreamModeFastestAddr
|
|
|
|
default:
|
|
|
|
// Should never happen, since the value should be validated.
|
|
|
|
panic(fmt.Errorf("unexpected upstream mode: %q", mode))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:09:54 +01:00
|
|
|
// setIfNotNil sets the value pointed at by currentPtr to the value pointed at
|
|
|
|
// by newPtr if newPtr is not nil. currentPtr must not be nil.
|
|
|
|
func setIfNotNil[T any](currentPtr, newPtr *T) (hasSet bool) {
|
|
|
|
if newPtr == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
*currentPtr = *newPtr
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// setConfigRestartable sets the parameters which trigger a restart.
|
|
|
|
// shouldRestart is true if the server should be restarted to apply changes.
|
|
|
|
// s.serverLock is expected to be locked.
|
2023-07-18 15:02:07 +01:00
|
|
|
//
|
|
|
|
// TODO(a.garipov): Some of these could probably be updated without a restart.
|
|
|
|
// Inspect and consider refactoring.
|
2022-09-06 15:09:54 +01:00
|
|
|
func (s *Server) setConfigRestartable(dc *jsonDNSConfig) (shouldRestart bool) {
|
|
|
|
for _, hasSet := range []bool{
|
|
|
|
setIfNotNil(&s.conf.UpstreamDNS, dc.Upstreams),
|
|
|
|
setIfNotNil(&s.conf.LocalPTRResolvers, dc.LocalPTRUpstreams),
|
|
|
|
setIfNotNil(&s.conf.UpstreamDNSFileName, dc.UpstreamsFile),
|
|
|
|
setIfNotNil(&s.conf.BootstrapDNS, dc.Bootstraps),
|
2023-08-30 11:21:31 +01:00
|
|
|
setIfNotNil(&s.conf.FallbackDNS, dc.Fallbacks),
|
2023-03-01 13:16:16 +00:00
|
|
|
setIfNotNil(&s.conf.EDNSClientSubnet.Enabled, dc.EDNSCSEnabled),
|
2023-03-22 10:42:20 +00:00
|
|
|
setIfNotNil(&s.conf.EDNSClientSubnet.UseCustom, dc.EDNSCSUseCustom),
|
2022-09-06 15:09:54 +01:00
|
|
|
setIfNotNil(&s.conf.CacheSize, dc.CacheSize),
|
|
|
|
setIfNotNil(&s.conf.CacheMinTTL, dc.CacheMinTTL),
|
|
|
|
setIfNotNil(&s.conf.CacheMaxTTL, dc.CacheMaxTTL),
|
|
|
|
setIfNotNil(&s.conf.CacheOptimistic, dc.CacheOptimistic),
|
2023-07-18 15:02:07 +01:00
|
|
|
setIfNotNil(&s.conf.AddrProcConf.UseRDNS, dc.ResolveClients),
|
|
|
|
setIfNotNil(&s.conf.UsePrivateRDNS, dc.UsePrivateRDNS),
|
2023-11-15 16:27:13 +00:00
|
|
|
setIfNotNil(&s.conf.RatelimitSubnetLenIPv4, dc.RatelimitSubnetLenIPv4),
|
|
|
|
setIfNotNil(&s.conf.RatelimitSubnetLenIPv6, dc.RatelimitSubnetLenIPv6),
|
|
|
|
setIfNotNil(&s.conf.RatelimitWhitelist, dc.RatelimitWhitelist),
|
2022-09-06 15:09:54 +01:00
|
|
|
} {
|
|
|
|
shouldRestart = shouldRestart || hasSet
|
|
|
|
if shouldRestart {
|
|
|
|
break
|
|
|
|
}
|
2021-04-07 18:16:06 +01:00
|
|
|
}
|
|
|
|
|
2023-11-15 16:27:13 +00:00
|
|
|
if dc.Ratelimit != nil && s.conf.Ratelimit != *dc.Ratelimit {
|
|
|
|
s.conf.Ratelimit = *dc.Ratelimit
|
2022-09-06 15:09:54 +01:00
|
|
|
shouldRestart = true
|
2021-05-26 15:55:19 +01:00
|
|
|
}
|
|
|
|
|
2022-09-06 15:09:54 +01:00
|
|
|
return shouldRestart
|
2019-11-08 11:59:12 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 18:16:06 +01:00
|
|
|
// upstreamJSON is a request body for handleTestUpstreamDNS endpoint.
|
2019-10-30 08:52:58 +00:00
|
|
|
type upstreamJSON struct {
|
2021-04-07 18:16:06 +01:00
|
|
|
Upstreams []string `json:"upstream_dns"`
|
|
|
|
BootstrapDNS []string `json:"bootstrap_dns"`
|
2023-09-06 10:29:45 +01:00
|
|
|
FallbackDNS []string `json:"fallback_dns"`
|
2021-04-07 18:16:06 +01:00
|
|
|
PrivateUpstreams []string `json:"private_upstream"`
|
2019-10-30 08:52:58 +00:00
|
|
|
}
|
|
|
|
|
2023-11-16 11:05:10 +00:00
|
|
|
// closeBoots closes all the provided bootstrap servers and logs errors if any.
|
|
|
|
func closeBoots(boots []*upstream.UpstreamResolver) {
|
|
|
|
for _, c := range boots {
|
|
|
|
logCloserErr(c, "dnsforward: closing bootstrap %s: %s", c.Address())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-27 18:18:29 +01:00
|
|
|
// handleTestUpstreamDNS handles requests to the POST /control/test_upstream_dns
|
|
|
|
// endpoint.
|
2021-04-07 18:16:06 +01:00
|
|
|
func (s *Server) handleTestUpstreamDNS(w http.ResponseWriter, r *http.Request) {
|
|
|
|
req := &upstreamJSON{}
|
|
|
|
err := json.NewDecoder(r.Body).Decode(req)
|
2019-10-30 08:52:58 +00:00
|
|
|
if err != nil {
|
2021-12-16 17:54:59 +00:00
|
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "Failed to read request body: %s", err)
|
2021-04-07 18:16:06 +01:00
|
|
|
|
|
|
|
return
|
2019-10-30 08:52:58 +00:00
|
|
|
}
|
2021-04-07 18:16:06 +01:00
|
|
|
|
2023-11-16 11:05:10 +00:00
|
|
|
req.BootstrapDNS = stringutil.FilterOut(req.BootstrapDNS, IsCommentOrEmpty)
|
2023-10-27 18:18:29 +01:00
|
|
|
|
2023-06-30 10:41:10 +01:00
|
|
|
opts := &upstream.Options{
|
|
|
|
Timeout: s.conf.UpstreamTimeout,
|
|
|
|
PreferIPv6: s.conf.BootstrapPreferIPv6,
|
|
|
|
}
|
2023-11-16 11:05:10 +00:00
|
|
|
|
|
|
|
var boots []*upstream.UpstreamResolver
|
|
|
|
opts.Bootstrap, boots, err = s.createBootstrap(req.BootstrapDNS, opts)
|
|
|
|
if err != nil {
|
|
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "Failed to parse bootstrap servers: %s", err)
|
|
|
|
|
|
|
|
return
|
2023-06-30 10:41:10 +01:00
|
|
|
}
|
2023-11-16 11:05:10 +00:00
|
|
|
defer closeBoots(boots)
|
2021-04-07 18:16:06 +01:00
|
|
|
|
2023-11-28 13:40:52 +00:00
|
|
|
cv := newUpstreamConfigValidator(req.Upstreams, req.FallbackDNS, req.PrivateUpstreams, opts)
|
|
|
|
cv.check()
|
|
|
|
cv.close()
|
2019-10-30 08:52:58 +00:00
|
|
|
|
2023-11-28 13:40:52 +00:00
|
|
|
aghhttp.WriteJSONResponseOK(w, r, cv.status())
|
2019-10-30 08:52:58 +00:00
|
|
|
}
|
|
|
|
|
2022-12-02 15:06:50 +00:00
|
|
|
// handleCacheClear is the handler for the POST /control/cache_clear HTTP API.
|
|
|
|
func (s *Server) handleCacheClear(w http.ResponseWriter, _ *http.Request) {
|
|
|
|
s.dnsProxy.ClearCache()
|
|
|
|
_, _ = io.WriteString(w, "OK")
|
|
|
|
}
|
|
|
|
|
2023-03-24 12:11:47 +00:00
|
|
|
// protectionJSON is an object for /control/protection endpoint.
|
|
|
|
type protectionJSON struct {
|
|
|
|
Enabled bool `json:"enabled"`
|
|
|
|
Duration uint `json:"duration"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// handleSetProtection is a handler for the POST /control/protection HTTP API.
|
|
|
|
func (s *Server) handleSetProtection(w http.ResponseWriter, r *http.Request) {
|
|
|
|
protectionReq := &protectionJSON{}
|
|
|
|
err := json.NewDecoder(r.Body).Decode(protectionReq)
|
|
|
|
if err != nil {
|
|
|
|
aghhttp.Error(r, w, http.StatusBadRequest, "reading req: %s", err)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var disabledUntil *time.Time
|
|
|
|
if protectionReq.Duration > 0 {
|
|
|
|
if protectionReq.Enabled {
|
|
|
|
aghhttp.Error(
|
|
|
|
r,
|
|
|
|
w,
|
|
|
|
http.StatusBadRequest,
|
|
|
|
"Setting a duration is only allowed with protection disabling",
|
|
|
|
)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
calcTime := time.Now().Add(time.Duration(protectionReq.Duration) * time.Millisecond)
|
|
|
|
disabledUntil = &calcTime
|
|
|
|
}
|
|
|
|
|
|
|
|
func() {
|
|
|
|
s.serverLock.Lock()
|
|
|
|
defer s.serverLock.Unlock()
|
|
|
|
|
2023-09-04 15:18:43 +01:00
|
|
|
s.dnsFilter.SetProtectionStatus(protectionReq.Enabled, disabledUntil)
|
2023-03-24 12:11:47 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
s.conf.ConfigModified()
|
|
|
|
|
|
|
|
aghhttp.OK(w)
|
|
|
|
}
|
|
|
|
|
2022-08-29 13:54:41 +01:00
|
|
|
// handleDoH is the DNS-over-HTTPs handler.
|
|
|
|
//
|
2020-05-29 09:15:31 +01:00
|
|
|
// Control flow:
|
2022-08-29 13:54:41 +01:00
|
|
|
//
|
|
|
|
// HTTP server
|
|
|
|
// -> dnsforward.handleDoH
|
|
|
|
// -> dnsforward.ServeHTTP
|
|
|
|
// -> proxy.ServeHTTP
|
|
|
|
// -> proxy.handleDNSRequest
|
|
|
|
// -> dnsforward.handleDNSRequest
|
2021-06-18 16:13:36 +01:00
|
|
|
func (s *Server) handleDoH(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if !s.conf.TLSAllowUnencryptedDoH && r.TLS == nil {
|
2021-12-16 17:54:59 +00:00
|
|
|
aghhttp.Error(r, w, http.StatusNotFound, "Not Found")
|
2022-10-03 16:08:05 +01:00
|
|
|
|
2020-02-27 08:48:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !s.IsRunning() {
|
2021-12-16 17:54:59 +00:00
|
|
|
aghhttp.Error(r, w, http.StatusInternalServerError, "dns server is not running")
|
2022-10-03 16:08:05 +01:00
|
|
|
|
2020-02-27 08:48:59 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s.ServeHTTP(w, r)
|
|
|
|
}
|
|
|
|
|
2019-10-30 08:52:58 +00:00
|
|
|
func (s *Server) registerHandlers() {
|
2023-01-23 16:10:56 +00:00
|
|
|
if webRegistered || s.conf.HTTPRegister == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-13 14:26:57 +00:00
|
|
|
s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig)
|
|
|
|
s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig)
|
|
|
|
s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS)
|
2023-03-24 12:11:47 +00:00
|
|
|
s.conf.HTTPRegister(http.MethodPost, "/control/protection", s.handleSetProtection)
|
2019-10-30 12:11:16 +00:00
|
|
|
|
2021-01-13 14:26:57 +00:00
|
|
|
s.conf.HTTPRegister(http.MethodGet, "/control/access/list", s.handleAccessList)
|
|
|
|
s.conf.HTTPRegister(http.MethodPost, "/control/access/set", s.handleAccessSet)
|
2020-02-27 08:48:59 +00:00
|
|
|
|
2022-12-02 15:06:50 +00:00
|
|
|
s.conf.HTTPRegister(http.MethodPost, "/control/cache_clear", s.handleCacheClear)
|
|
|
|
|
2021-02-02 11:15:13 +00:00
|
|
|
// Register both versions, with and without the trailing slash, to
|
|
|
|
// prevent a 301 Moved Permanently redirect when clients request the
|
|
|
|
// path without the trailing slash. Those redirects break some clients.
|
|
|
|
//
|
|
|
|
// See go doc net/http.ServeMux.
|
|
|
|
//
|
|
|
|
// See also https://github.com/AdguardTeam/AdGuardHome/issues/2628.
|
2021-06-18 16:13:36 +01:00
|
|
|
s.conf.HTTPRegister("", "/dns-query", s.handleDoH)
|
|
|
|
s.conf.HTTPRegister("", "/dns-query/", s.handleDoH)
|
2023-01-23 16:10:56 +00:00
|
|
|
|
|
|
|
webRegistered = true
|
2019-10-30 08:52:58 +00:00
|
|
|
}
|