Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dns.ipset_file setting #4686

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ and this project adheres to
See also the [v0.107.13 GitHub milestone][ms-v0.107.13].

[ms-v0.107.13]: https://github.com/AdguardTeam/AdGuardHome/milestone/49?closed=1

### Added

- The `dns.ipset_file` property in the configuration file now allows you to
load the ipset list from a separate file instead of setting all upstreams
in AdGuard Home settings. ([#4686]).
-->


Expand Down
23 changes: 23 additions & 0 deletions internal/dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ type FilteringConfig struct {
// DOMAIN[,DOMAIN].../IPSET_NAME
//
IpsetList []string `yaml:"ipset"`

// IpsetListFileName, if set, points to the file with ipset configuration.
// The format is the same as in IpsetList.
IpsetListFileName string `yaml:"ipset_file"`
}

// TLSConfig is the TLS configuration for HTTPS, DNS-over-HTTPS, and DNS-over-TLS
Expand Down Expand Up @@ -501,3 +505,22 @@ func (s *Server) onGetCertificate(ch *tls.ClientHelloInfo) (*tls.Certificate, er
}
return &s.conf.cert, nil
}

// prepareIpsetListSettings - prepares ipset list settings
func (s *Server) prepareIpsetListSettings() error {
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
}

return s.ipset.init(ipsets)
}
2 changes: 1 addition & 1 deletion internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func (s *Server) Prepare(conf *ServerConfig) (err error) {

s.initDefaultSettings()

err = s.ipset.init(s.conf.IpsetList)
err = s.prepareIpsetListSettings()
if err != nil {
// Don't wrap the error, because it's informative enough as is.
return err
Expand Down