From 8316d39b4282599681a827a50d6541c5cb4987ed Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Wed, 28 Nov 2018 18:24:04 +0300 Subject: [PATCH] Move filtering setting fields from main app to dnsforward. --- config.go | 64 +++++++++++++++++++--------------------- dnsforward/dnsforward.go | 12 ++++++++ 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/config.go b/config.go index 11692215..46de5f3b 100644 --- a/config.go +++ b/config.go @@ -44,25 +44,21 @@ type configuration struct { // field ordering is important -- yaml fields will mirror ordering from here type coreDNSConfig struct { - binaryFile string - coreFile string - Filters []filter `yaml:"-"` - Port int `yaml:"port"` - ProtectionEnabled bool `yaml:"protection_enabled"` - FilteringEnabled bool `yaml:"filtering_enabled"` - SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` - SafeSearchEnabled bool `yaml:"safesearch_enabled"` - ParentalEnabled bool `yaml:"parental_enabled"` - ParentalSensitivity int `yaml:"parental_sensitivity"` - BlockedResponseTTL uint32 `yaml:"blocked_response_ttl"` - QueryLogEnabled bool `yaml:"querylog_enabled"` - Ratelimit int `yaml:"ratelimit"` - RefuseAny bool `yaml:"refuse_any"` - Pprof string `yaml:"-"` - Cache string `yaml:"-"` - Prometheus string `yaml:"-"` - BootstrapDNS string `yaml:"bootstrap_dns"` - UpstreamDNS []string `yaml:"upstream_dns"` + binaryFile string + coreFile string + Filters []filter `yaml:"-"` + Port int `yaml:"port"` + + dnsforward.FilteringConfig `yaml:",inline"` + + QueryLogEnabled bool `yaml:"querylog_enabled"` + Ratelimit int `yaml:"ratelimit"` + RefuseAny bool `yaml:"refuse_any"` + Pprof string `yaml:"-"` + Cache string `yaml:"-"` + Prometheus string `yaml:"-"` + BootstrapDNS string `yaml:"bootstrap_dns"` + UpstreamDNS []string `yaml:"upstream_dns"` } // field ordering is important -- yaml fields will mirror ordering from here @@ -84,20 +80,22 @@ var config = configuration{ BindPort: 3000, BindHost: "127.0.0.1", CoreDNS: coreDNSConfig{ - Port: 53, - binaryFile: "coredns", // only filename, no path - coreFile: "Corefile", // only filename, no path - ProtectionEnabled: true, - FilteringEnabled: true, - SafeBrowsingEnabled: false, - BlockedResponseTTL: 10, // in seconds - QueryLogEnabled: true, - Ratelimit: 20, - RefuseAny: true, - BootstrapDNS: "8.8.8.8:53", - UpstreamDNS: defaultDNS, - Cache: "cache", - Prometheus: "prometheus :9153", + Port: 53, + binaryFile: "coredns", // only filename, no path + coreFile: "Corefile", // only filename, no path + FilteringConfig: dnsforward.FilteringConfig{ + ProtectionEnabled: true, + FilteringEnabled: true, + SafeBrowsingEnabled: false, + BlockedResponseTTL: 10, // in seconds + }, + QueryLogEnabled: true, + Ratelimit: 20, + RefuseAny: true, + BootstrapDNS: "8.8.8.8:53", + UpstreamDNS: defaultDNS, + Cache: "cache", + Prometheus: "prometheus :9153", }, Filters: []filter{ {Filter: dnsforward.Filter{ID: 1}, Enabled: true, URL: "https://adguardteam.github.io/AdGuardSDNSFilter/Filters/filter.txt", Name: "AdGuard Simplified Domain Names filter"}, diff --git a/dnsforward/dnsforward.go b/dnsforward/dnsforward.go index 45a66c53..c087d17e 100644 --- a/dnsforward/dnsforward.go +++ b/dnsforward/dnsforward.go @@ -72,12 +72,24 @@ func (s *Server) RUnlock() { } */ +type FilteringConfig struct { + ProtectionEnabled bool `yaml:"protection_enabled"` + FilteringEnabled bool `yaml:"filtering_enabled"` + SafeBrowsingEnabled bool `yaml:"safebrowsing_enabled"` + SafeSearchEnabled bool `yaml:"safesearch_enabled"` + ParentalEnabled bool `yaml:"parental_enabled"` + ParentalSensitivity int `yaml:"parental_sensitivity"` + BlockedResponseTTL uint32 `yaml:"blocked_response_ttl"` +} + // The zero ServerConfig is empty and ready for use. type ServerConfig struct { UDPListenAddr *net.UDPAddr // if nil, then default is is used (port 53 on *) BlockedResponseTTL uint32 // if 0, then default is used (3600) Upstreams []Upstream Filters []Filter + + FilteringConfig } var defaultValues = ServerConfig{