Skip to content

Commit

Permalink
all: upd golibs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizzick committed Jan 12, 2024
1 parent 1e0ff4d commit 7b65a50
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 59 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/AdguardTeam/AdGuardHome
go 1.20

require (
github.com/AdguardTeam/dnsproxy v0.61.1
github.com/AdguardTeam/golibs v0.18.1
github.com/AdguardTeam/dnsproxy v0.61.2-0.20240110124936-129935dbd2ef
github.com/AdguardTeam/golibs v0.18.3-0.20240111124113-a7af1f1a1d62
github.com/AdguardTeam/urlfilter v0.17.3
github.com/NYTimes/gziphandler v1.1.1
github.com/ameshkov/dnscrypt/v2 v2.2.7
Expand Down Expand Up @@ -33,7 +33,7 @@ require (
github.com/ti-mo/netfilter v0.5.1
go.etcd.io/bbolt v1.3.8
golang.org/x/crypto v0.16.0
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848
golang.org/x/net v0.19.0
golang.org/x/sys v0.15.0
gopkg.in/natefinch/lumberjack.v2 v2.2.1
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/AdguardTeam/dnsproxy v0.61.1 h1:RdGVTHZR8N6eAyae13ORSlvn9qNeHK/h2g9mbVM/VS4=
github.com/AdguardTeam/dnsproxy v0.61.1/go.mod h1:IdmXdkpc+m+S2EajJkVZDZm//yQ4mQm2FCOugQpc/N8=
github.com/AdguardTeam/golibs v0.18.1 h1:6u0fvrIj2qjUsRdbIGJ9AR0g5QRSWdKIo/DYl3tp5aM=
github.com/AdguardTeam/golibs v0.18.1/go.mod h1:DKhCIXHcUYtBhU8ibTLKh1paUL96n5zhQBlx763sj+U=
github.com/AdguardTeam/dnsproxy v0.61.2-0.20240110124936-129935dbd2ef h1:NxFCH8JE+U1t1BNNydrY/i69pkY+BtUsgGUrlyP2vBE=
github.com/AdguardTeam/dnsproxy v0.61.2-0.20240110124936-129935dbd2ef/go.mod h1:qnR7RtTnHLgWab7A/T6U9N0mfczAWUnwK00jCqJIWIU=
github.com/AdguardTeam/golibs v0.18.3-0.20240111124113-a7af1f1a1d62 h1:M+oQ8gv8xskrSgCOUDo4NbpwaMsL/c7h6PIMcVUIhjw=
github.com/AdguardTeam/golibs v0.18.3-0.20240111124113-a7af1f1a1d62/go.mod h1:3WunclLLfrVAq7fYQRhd6f168FHOEMssnipVXCxDL/w=
github.com/AdguardTeam/urlfilter v0.17.3 h1:fg/ObbnO0Cv6aw0tW6N/ETDMhhNvmcUUOZ7HlmKC3rw=
github.com/AdguardTeam/urlfilter v0.17.3/go.mod h1:Jru7jFfeH2CoDf150uDs+rRYcZBzHHBz05r9REyDKyE=
github.com/NYTimes/gziphandler v1.1.1 h1:ZUDjpQae29j0ryrS0u/B8HZfJBtBQHjqw2rQ2cqUQ3I=
Expand Down Expand Up @@ -122,8 +122,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb h1:c0vyKkb6yr3KR7jEfJaOSv4lG7xPkbN6r52aJz1d8a8=
golang.org/x/exp v0.0.0-20231206192017-f3f8817b8deb/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
Expand Down
2 changes: 1 addition & 1 deletion internal/client/addrproc.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (p *DefaultAddrProc) processRDNS(ip netip.Addr) (host string) {
// resolving of private addresses is disabled.
func (p *DefaultAddrProc) shouldResolve(ip netip.Addr) (ok bool) {
return !ip.IsLoopback() &&
(p.usePrivateRDNS || !p.privateSubnets.Contains(ip.AsSlice()))
(p.usePrivateRDNS || !p.privateSubnets.Contains(ip))
}

// processWHOIS looks up the information about clients' IP addresses in the
Expand Down
11 changes: 5 additions & 6 deletions internal/dnsforward/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ type Config struct {
// BlockedHosts is the list of hosts that should be blocked.
BlockedHosts []string `yaml:"blocked_hosts"`

// TrustedProxies is the list of IP addresses and CIDR networks to detect
// proxy servers addresses the DoH requests from which should be handled.
// The value of nil or an empty slice for this field makes Proxy not trust
// any address.
TrustedProxies []string `yaml:"trusted_proxies"`
// TrustedProxies is the list of CIDR networks with proxy servers addresses
// from which the DoH requests should be handled. The value of nil or an
// empty slice for this field makes Proxy not trust any address.
TrustedProxies []netutil.Prefix `yaml:"trusted_proxies"`

// DNS cache settings

Expand Down Expand Up @@ -310,7 +309,7 @@ func (s *Server) newProxyConfig() (conf *proxy.Config, err error) {
RatelimitSubnetLenIPv6: srvConf.RatelimitSubnetLenIPv6,
RatelimitWhitelist: srvConf.RatelimitWhitelist,
RefuseAny: srvConf.RefuseAny,
TrustedProxies: srvConf.TrustedProxies,
TrustedProxies: netutil.UnembedPrefixes(srvConf.TrustedProxies),
CacheMinTTL: srvConf.CacheMinTTL,
CacheMaxTTL: srvConf.CacheMaxTTL,
CacheOptimistic: srvConf.CacheOptimistic,
Expand Down
4 changes: 2 additions & 2 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ func (s *Server) WriteDiskConfig(c *Config) {
c.AllowedClients = stringutil.CloneSlice(sc.AllowedClients)
c.DisallowedClients = stringutil.CloneSlice(sc.DisallowedClients)
c.BlockedHosts = stringutil.CloneSlice(sc.BlockedHosts)
c.TrustedProxies = stringutil.CloneSlice(sc.TrustedProxies)
c.TrustedProxies = slices.Clone(sc.TrustedProxies)
c.UpstreamDNS = stringutil.CloneSlice(sc.UpstreamDNS)
}

Expand Down Expand Up @@ -390,7 +390,7 @@ func (s *Server) Exchange(ip netip.Addr) (host string, ttl time.Duration, err er

var resolver *proxy.Proxy
var errMsg string
if s.privateNets.Contains(ip.AsSlice()) {
if s.privateNets.Contains(ip) {
if !s.conf.UsePrivateRDNS {
return "", 0, nil
}
Expand Down
16 changes: 4 additions & 12 deletions internal/dnsforward/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func (s *Server) processDetermineLocal(dctx *dnsContext) (rc resultCode) {

rc = resultCodeSuccess

dctx.isLocalClient = s.privateNets.Contains(dctx.proxyCtx.Addr.Addr().AsSlice())
dctx.isLocalClient = s.privateNets.Contains(dctx.proxyCtx.Addr.Addr())

return rc
}
Expand Down Expand Up @@ -491,14 +491,7 @@ func extractARPASubnet(domain string) (pref netip.Prefix, err error) {
}
}

var subnet *net.IPNet
subnet, err = netutil.SubnetFromReversedAddr(domain[idx:])
if err != nil {
// Don't wrap the error since it's informative enough as is.
return netip.Prefix{}, err
}

return netutil.IPNetToPrefixNoMapped(subnet)
return netutil.PrefixFromReversedAddr(domain[idx:])
}

// processRestrictLocal responds with NXDOMAIN to PTR requests for IP addresses
Expand Down Expand Up @@ -532,8 +525,7 @@ func (s *Server) processRestrictLocal(dctx *dnsContext) (rc resultCode) {
// assume that all the DHCP leases we give are locally served or at least
// shouldn't be accessible externally.
subnetAddr := subnet.Addr()
addrData := subnetAddr.AsSlice()
if !s.privateNets.Contains(addrData) {
if !s.privateNets.Contains(subnetAddr) {
return resultCodeSuccess
}

Expand All @@ -548,7 +540,7 @@ func (s *Server) processRestrictLocal(dctx *dnsContext) (rc resultCode) {
}

// Do not perform unreversing ever again.
dctx.unreversedReqIP = addrData
dctx.unreversedReqIP = subnetAddr.AsSlice()

// There is no need to filter request from external addresses since this
// code is only executed when the request is for locally served ARPA
Expand Down
2 changes: 1 addition & 1 deletion internal/dnsforward/upstreams.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func ValidateUpstreamsPrivate(upstreams []string, privateNets netutil.SubnetSet)
continue
}

if !privateNets.Contains(subnet.Addr().AsSlice()) {
if !privateNets.Contains(subnet.Addr()) {
errs = append(
errs,
fmt.Errorf("arpa domain %q should point to a locally-served network", domain),
Expand Down
4 changes: 1 addition & 3 deletions internal/filtering/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@ func hostsRewrites(
case dns.TypeAAAA:
isValidProto = netip.Addr.Is6
case dns.TypePTR:
// TODO(e.burkov): Add some [netip]-aware alternative to [netutil].
ip, err := netutil.IPFromReversedAddr(host)
addr, err := netutil.IPFromReversedAddr(host)
if err != nil {
log.Debug("filtering: failed to parse PTR record %q: %s", host, err)

return nil, nil, false
}

addr, _ := netip.AddrFromSlice(ip)
names := hs.ByAddr(addr)

for _, name := range names {
Expand Down
10 changes: 7 additions & 3 deletions internal/home/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/AdguardTeam/dnsproxy/fastip"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/timeutil"
"github.com/google/renameio/v2/maybe"
yaml "gopkg.in/yaml.v3"
Expand Down Expand Up @@ -200,7 +201,7 @@ type dnsConfig struct {

// PrivateNets is the set of IP networks for which the private reverse DNS
// resolver should be used.
PrivateNets []string `yaml:"private_networks"`
PrivateNets []netutil.Prefix `yaml:"private_networks"`

// UsePrivateRDNS defines if the PTR requests for unknown addresses from
// locally-served networks should be resolved via private PTR resolvers.
Expand Down Expand Up @@ -321,8 +322,11 @@ var config = &configuration{
Duration: fastip.DefaultPingWaitTimeout,
},

TrustedProxies: []string{"127.0.0.0/8", "::1/128"},
CacheSize: 4 * 1024 * 1024,
TrustedProxies: []netutil.Prefix{
{Prefix: netip.MustParsePrefix("127.0.0.0/8")},
{Prefix: netip.MustParsePrefix("::1/128")},
},
CacheSize: 4 * 1024 * 1024,

EDNSClientSubnet: &dnsforward.EDNSClientSubnet{
CustomIP: netip.Addr{},
Expand Down
26 changes: 5 additions & 21 deletions internal/home/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,11 @@ func initDNSServer(
httpReg aghhttp.RegisterFunc,
tlsConf *tlsConfigSettings,
) (err error) {
privateNets, err := parseSubnetSet(config.DNS.PrivateNets)
if err != nil {
return fmt.Errorf("preparing set of private subnets: %w", err)
}

Context.dnsServer, err = dnsforward.NewServer(dnsforward.DNSCreateParams{
DNSFilter: filters,
Stats: sts,
QueryLog: qlog,
PrivateNets: privateNets,
PrivateNets: parseSubnetSet(config.DNS.PrivateNets),
Anonymizer: anonymizer,
DHCPServer: dhcpSrv,
EtcHosts: Context.etcHosts,
Expand Down Expand Up @@ -169,26 +164,15 @@ func initDNSServer(
// parseSubnetSet parses a slice of subnets. If the slice is empty, it returns
// a subnet set that matches all locally served networks, see
// [netutil.IsLocallyServed].
func parseSubnetSet(nets []string) (s netutil.SubnetSet, err error) {
func parseSubnetSet(nets []netutil.Prefix) (s netutil.SubnetSet) {
switch len(nets) {
case 0:
// Use an optimized function-based matcher.
return netutil.SubnetSetFunc(netutil.IsLocallyServed), nil
return netutil.SubnetSetFunc(netutil.IsLocallyServed)
case 1:
s, err = netutil.ParseSubnet(nets[0])
if err != nil {
return nil, err
}

return s, nil
return nets[0]
default:
var nets []*net.IPNet
nets, err = netutil.ParseSubnets(config.DNS.PrivateNets...)
if err != nil {
return nil, err
}

return netutil.SliceSubnetSet(nets), nil
return netutil.SliceSubnetSet(netutil.UnembedPrefixes(nets))
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/whois/whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ var _ Interface = (*Default)(nil)
// Process makes WHOIS request and returns WHOIS information or nil. changed
// indicates that Info was updated since last request.
func (w *Default) Process(ctx context.Context, ip netip.Addr) (wi *Info, changed bool) {
if netutil.IsSpecialPurposeAddr(ip) {
if netutil.IsSpecialPurpose(ip) {
return nil, false
}

Expand Down

0 comments on commit 7b65a50

Please sign in to comment.