From e26837d9e87223a477fd8beb3151d98eeb52c5cd Mon Sep 17 00:00:00 2001 From: Eugene Bujak Date: Fri, 30 Nov 2018 13:47:26 +0300 Subject: [PATCH] dnsfilter -- Add parameter to New() to supply optional initial config. --- coredns_plugin/coredns_plugin.go | 2 +- dnsfilter/dnsfilter.go | 5 ++++- dnsforward/dnsforward.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/coredns_plugin/coredns_plugin.go b/coredns_plugin/coredns_plugin.go index 356902c6..8d302fd3 100644 --- a/coredns_plugin/coredns_plugin.go +++ b/coredns_plugin/coredns_plugin.go @@ -77,7 +77,7 @@ func setupPlugin(c *caddy.Controller) (*plug, error) { // create new Plugin and copy default values p := &plug{ settings: defaultPluginSettings, - d: dnsfilter.New(), + d: dnsfilter.New(nil), } log.Println("Initializing the CoreDNS plugin") diff --git a/dnsfilter/dnsfilter.go b/dnsfilter/dnsfilter.go index e0958cda..7fd01be3 100644 --- a/dnsfilter/dnsfilter.go +++ b/dnsfilter/dnsfilter.go @@ -856,7 +856,7 @@ func (d *Dnsfilter) matchHost(host string) (Result, error) { // // New creates properly initialized DNS Filter that is ready to be used -func New() *Dnsfilter { +func New(c *Config) *Dnsfilter { d := new(Dnsfilter) d.storage = make(map[string]bool) @@ -879,6 +879,9 @@ func New() *Dnsfilter { } d.safeBrowsingServer = defaultSafebrowsingServer d.parentalServer = defaultParentalServer + if c != nil { + d.Config = *c + } return d } diff --git a/dnsforward/dnsforward.go b/dnsforward/dnsforward.go index bf7566a9..3a2de123 100644 --- a/dnsforward/dnsforward.go +++ b/dnsforward/dnsforward.go @@ -178,7 +178,7 @@ func (s *Server) Start(config *ServerConfig) error { if s.dnsFilter == nil { log.Printf("Creating dnsfilter") - s.dnsFilter = dnsfilter.New() + s.dnsFilter = dnsfilter.New(nil) } go s.packetLoop() @@ -322,7 +322,7 @@ func (s *Server) reconfigureFilters(new ServerConfig) { return } - dnsFilter := dnsfilter.New() + dnsFilter := dnsfilter.New(&new.Config) // sets safebrowsing, safesearch and parental for _, f := range newFilters { for _, rule := range f.Rules { err := dnsFilter.AddRule(rule, f.ID)