dnsfilter -- Add parameter to New() to supply optional initial config.
This commit is contained in:
parent
3ecc0ee24b
commit
e26837d9e8
|
@ -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")
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue