* dnsforward: use new dnsfilter interface

This commit is contained in:
Simon Zolin 2019-05-16 17:32:15 +03:00
parent 5ec747b30b
commit 096a959987
1 changed files with 11 additions and 5 deletions

View File

@ -202,14 +202,20 @@ func (s *Server) startInternal(config *ServerConfig) error {
// Initializes the DNS filter
func (s *Server) initDNSFilter() error {
log.Tracef("Creating dnsfilter")
s.dnsFilter = dnsfilter.New(&s.conf.Config)
// add rules only if they are enabled
var filters map[int]string
filters = nil
if s.conf.FilteringEnabled {
err := s.dnsFilter.AddRules(s.conf.Filters)
if err != nil {
return errorx.Decorate(err, "could not initialize dnsfilter")
filters = make(map[int]string)
for _, f := range s.conf.Filters {
filters[int(f.ID)] = string(f.Data)
}
}
s.dnsFilter = dnsfilter.New(&s.conf.Config, filters)
if s.dnsFilter == nil {
return fmt.Errorf("could not initialize dnsfilter")
}
return nil
}