dnsfilter -- Add parameter to New() to supply optional initial config.

This commit is contained in:
Eugene Bujak 2018-11-30 13:47:26 +03:00
parent 3ecc0ee24b
commit e26837d9e8
3 changed files with 7 additions and 4 deletions

View File

@ -77,7 +77,7 @@ func setupPlugin(c *caddy.Controller) (*plug, error) {
// create new Plugin and copy default values // create new Plugin and copy default values
p := &plug{ p := &plug{
settings: defaultPluginSettings, settings: defaultPluginSettings,
d: dnsfilter.New(), d: dnsfilter.New(nil),
} }
log.Println("Initializing the CoreDNS plugin") log.Println("Initializing the CoreDNS plugin")

View File

@ -856,7 +856,7 @@ func (d *Dnsfilter) matchHost(host string) (Result, error) {
// //
// New creates properly initialized DNS Filter that is ready to be used // New creates properly initialized DNS Filter that is ready to be used
func New() *Dnsfilter { func New(c *Config) *Dnsfilter {
d := new(Dnsfilter) d := new(Dnsfilter)
d.storage = make(map[string]bool) d.storage = make(map[string]bool)
@ -879,6 +879,9 @@ func New() *Dnsfilter {
} }
d.safeBrowsingServer = defaultSafebrowsingServer d.safeBrowsingServer = defaultSafebrowsingServer
d.parentalServer = defaultParentalServer d.parentalServer = defaultParentalServer
if c != nil {
d.Config = *c
}
return d return d
} }

View File

@ -178,7 +178,7 @@ func (s *Server) Start(config *ServerConfig) error {
if s.dnsFilter == nil { if s.dnsFilter == nil {
log.Printf("Creating dnsfilter") log.Printf("Creating dnsfilter")
s.dnsFilter = dnsfilter.New() s.dnsFilter = dnsfilter.New(nil)
} }
go s.packetLoop() go s.packetLoop()
@ -322,7 +322,7 @@ func (s *Server) reconfigureFilters(new ServerConfig) {
return return
} }
dnsFilter := dnsfilter.New() dnsFilter := dnsfilter.New(&new.Config) // sets safebrowsing, safesearch and parental
for _, f := range newFilters { for _, f := range newFilters {
for _, rule := range f.Rules { for _, rule := range f.Rules {
err := dnsFilter.AddRule(rule, f.ID) err := dnsFilter.AddRule(rule, f.ID)