Skip to content

Commit

Permalink
feat: add dns.ipset_file setting
Browse files Browse the repository at this point in the history
  • Loading branch information
hellodword committed Jun 23, 2022
1 parent ce1b2bc commit e7bdbeb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion internal/dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ type FilteringConfig struct {
//
// DOMAIN[,DOMAIN].../IPSET_NAME
//
IpsetList []string `yaml:"ipset"`
IpsetList []string `yaml:"ipset"`
IpsetListFileName string `yaml:"ipset_file"`
}

// TLSConfig is the TLS configuration for HTTPS, DNS-over-HTTPS, and DNS-over-TLS
Expand Down
17 changes: 16 additions & 1 deletion internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net"
"net/http"
"os"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -480,7 +481,21 @@ func (s *Server) Prepare(config *ServerConfig) error {

// Initialize ipset configuration
// --
err := s.ipset.init(s.conf.IpsetList)
var ipsets []string
if s.conf.IpsetListFileName != "" {
data, err := os.ReadFile(s.conf.IpsetListFileName)
if err != nil {
return err
}

ipsets = stringutil.SplitTrimmed(string(data), "\n")

log.Debug("dns: using %d ipset list from file %s", len(ipsets), s.conf.IpsetListFileName)
} else {
ipsets = s.conf.IpsetList
}

err := s.ipset.init(ipsets)
if err != nil {
return err
}
Expand Down

0 comments on commit e7bdbeb

Please sign in to comment.