Pull request 1893: all: imp logs; upd dnsproxy
Updates #5285. Squashed commit of the following: commit 8e7d17505492b6983ba9e713455b98652938d73d Author: Ainar Garipov <A.Garipov@AdGuard.COM> Date: Wed Jun 28 13:33:14 2023 +0300 all: imp logs; upd dnsproxy
This commit is contained in:
parent
cf7c12c97b
commit
6889837785
|
@ -124,6 +124,7 @@ In this release, the schema version has changed from 20 to 22.
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- Excessive error logging when using DNS-over-QUIC ([#5285]).
|
||||||
- Cannot set `bind_host` in AdGuardHome.yaml (docker version)([#4231], [#4235]).
|
- Cannot set `bind_host` in AdGuardHome.yaml (docker version)([#4231], [#4235]).
|
||||||
- The blocklists can now be deleted properly ([#5700]).
|
- The blocklists can now be deleted properly ([#5700]).
|
||||||
- Queries with the question-section target `.`, for example `NS .`, are now
|
- Queries with the question-section target `.`, for example `NS .`, are now
|
||||||
|
@ -135,6 +136,7 @@ In this release, the schema version has changed from 20 to 22.
|
||||||
[#1577]: https://github.com/AdguardTeam/AdGuardHome/issues/1577
|
[#1577]: https://github.com/AdguardTeam/AdGuardHome/issues/1577
|
||||||
[#4231]: https://github.com/AdguardTeam/AdGuardHome/issues/4231
|
[#4231]: https://github.com/AdguardTeam/AdGuardHome/issues/4231
|
||||||
[#4235]: https://github.com/AdguardTeam/AdGuardHome/pull/4235
|
[#4235]: https://github.com/AdguardTeam/AdGuardHome/pull/4235
|
||||||
|
[#5285]: https://github.com/AdguardTeam/AdGuardHome/issues/5285
|
||||||
[#5700]: https://github.com/AdguardTeam/AdGuardHome/issues/5700
|
[#5700]: https://github.com/AdguardTeam/AdGuardHome/issues/5700
|
||||||
[#5910]: https://github.com/AdguardTeam/AdGuardHome/issues/5910
|
[#5910]: https://github.com/AdguardTeam/AdGuardHome/issues/5910
|
||||||
[#5913]: https://github.com/AdguardTeam/AdGuardHome/issues/5913
|
[#5913]: https://github.com/AdguardTeam/AdGuardHome/issues/5913
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -3,7 +3,8 @@ module github.com/AdguardTeam/AdGuardHome
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/AdguardTeam/dnsproxy v0.50.2
|
// TODO(a.garipov): Update to a tagged version when it's released.
|
||||||
|
github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768
|
||||||
github.com/AdguardTeam/golibs v0.13.3
|
github.com/AdguardTeam/golibs v0.13.3
|
||||||
github.com/AdguardTeam/urlfilter v0.16.1
|
github.com/AdguardTeam/urlfilter v0.16.1
|
||||||
github.com/NYTimes/gziphandler v1.1.1
|
github.com/NYTimes/gziphandler v1.1.1
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -1,5 +1,5 @@
|
||||||
github.com/AdguardTeam/dnsproxy v0.50.2 h1:p1471SsMZ6SMo7T51Olw4aNluahvMwSLMorwxYV18ts=
|
github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768 h1:5Ia6wA+tqAlTyzuaOVGSlHmb0osLWXeJUs3NxCuC4gA=
|
||||||
github.com/AdguardTeam/dnsproxy v0.50.2/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8=
|
github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8=
|
||||||
github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
|
github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
|
||||||
github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw=
|
github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw=
|
||||||
github.com/AdguardTeam/golibs v0.13.3 h1:RT3QbzThtaLiFLkIUDS6/hlGEXrh0zYvdf4bd7UWpGo=
|
github.com/AdguardTeam/golibs v0.13.3 h1:RT3QbzThtaLiFLkIUDS6/hlGEXrh0zYvdf4bd7UWpGo=
|
||||||
|
|
|
@ -145,10 +145,13 @@ func (s *Server) handleDNSRequest(_ *proxy.Proxy, pctx *proxy.DNSContext) error
|
||||||
// processRecursion checks the incoming request and halts its handling by
|
// processRecursion checks the incoming request and halts its handling by
|
||||||
// answering NXDOMAIN if s has tried to resolve it recently.
|
// answering NXDOMAIN if s has tried to resolve it recently.
|
||||||
func (s *Server) processRecursion(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processRecursion(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing recursion")
|
||||||
|
defer log.Debug("dnsforward: finished processing recursion")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
|
|
||||||
if msg := pctx.Req; msg != nil && s.recDetector.check(*msg) {
|
if msg := pctx.Req; msg != nil && s.recDetector.check(*msg) {
|
||||||
log.Debug("recursion detected resolving %q", msg.Question[0].Name)
|
log.Debug("dnsforward: recursion detected resolving %q", msg.Question[0].Name)
|
||||||
pctx.Res = s.genNXDomain(pctx.Req)
|
pctx.Res = s.genNXDomain(pctx.Req)
|
||||||
|
|
||||||
return resultCodeFinish
|
return resultCodeFinish
|
||||||
|
@ -158,10 +161,13 @@ func (s *Server) processRecursion(dctx *dnsContext) (rc resultCode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// processInitial terminates the following processing for some requests if
|
// processInitial terminates the following processing for some requests if
|
||||||
// needed and enriches the ctx with some client-specific information.
|
// needed and enriches dctx with some client-specific information.
|
||||||
//
|
//
|
||||||
// TODO(e.burkov): Decompose into less general processors.
|
// TODO(e.burkov): Decompose into less general processors.
|
||||||
func (s *Server) processInitial(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processInitial(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing initial")
|
||||||
|
defer log.Debug("dnsforward: finished processing initial")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
q := pctx.Req.Question[0]
|
q := pctx.Req.Question[0]
|
||||||
qt := q.Qtype
|
qt := q.Qtype
|
||||||
|
@ -282,6 +288,9 @@ func (s *Server) onDHCPLeaseChanged(flags int) {
|
||||||
//
|
//
|
||||||
// See https://www.ietf.org/archive/id/draft-ietf-add-ddr-10.html.
|
// See https://www.ietf.org/archive/id/draft-ietf-add-ddr-10.html.
|
||||||
func (s *Server) processDDRQuery(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processDDRQuery(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing ddr")
|
||||||
|
defer log.Debug("dnsforward: finished processing ddr")
|
||||||
|
|
||||||
if !s.conf.HandleDDR {
|
if !s.conf.HandleDDR {
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
}
|
}
|
||||||
|
@ -375,6 +384,9 @@ func (s *Server) makeDDRResponse(req *dns.Msg) (resp *dns.Msg) {
|
||||||
// processDetermineLocal determines if the client's IP address is from locally
|
// processDetermineLocal determines if the client's IP address is from locally
|
||||||
// served network and saves the result into the context.
|
// served network and saves the result into the context.
|
||||||
func (s *Server) processDetermineLocal(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processDetermineLocal(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing local detection")
|
||||||
|
defer log.Debug("dnsforward: finished processing local detection")
|
||||||
|
|
||||||
rc = resultCodeSuccess
|
rc = resultCodeSuccess
|
||||||
|
|
||||||
var ip net.IP
|
var ip net.IP
|
||||||
|
@ -405,6 +417,9 @@ func (s *Server) dhcpHostToIP(host string) (ip netip.Addr, ok bool) {
|
||||||
//
|
//
|
||||||
// TODO(a.garipov): Adapt to AAAA as well.
|
// TODO(a.garipov): Adapt to AAAA as well.
|
||||||
func (s *Server) processDHCPHosts(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processDHCPHosts(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing dhcp hosts")
|
||||||
|
defer log.Debug("dnsforward: finished processing dhcp hosts")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
req := pctx.Req
|
req := pctx.Req
|
||||||
q := req.Question[0]
|
q := req.Question[0]
|
||||||
|
@ -544,6 +559,9 @@ func extractARPASubnet(domain string) (pref netip.Prefix, err error) {
|
||||||
// processRestrictLocal responds with NXDOMAIN to PTR requests for IP addresses
|
// processRestrictLocal responds with NXDOMAIN to PTR requests for IP addresses
|
||||||
// in locally served network from external clients.
|
// in locally served network from external clients.
|
||||||
func (s *Server) processRestrictLocal(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processRestrictLocal(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing local restriction")
|
||||||
|
defer log.Debug("dnsforward: finished processing local restriction")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
req := pctx.Req
|
req := pctx.Req
|
||||||
q := req.Question[0]
|
q := req.Question[0]
|
||||||
|
@ -613,6 +631,9 @@ func (s *Server) ipToDHCPHost(ip netip.Addr) (host string, ok bool) {
|
||||||
// processDHCPAddrs responds to PTR requests if the target IP is leased by the
|
// processDHCPAddrs responds to PTR requests if the target IP is leased by the
|
||||||
// DHCP server.
|
// DHCP server.
|
||||||
func (s *Server) processDHCPAddrs(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processDHCPAddrs(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing dhcp addrs")
|
||||||
|
defer log.Debug("dnsforward: finished processing dhcp addrs")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
if pctx.Res != nil {
|
if pctx.Res != nil {
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
|
@ -658,6 +679,9 @@ func (s *Server) processDHCPAddrs(dctx *dnsContext) (rc resultCode) {
|
||||||
// processLocalPTR responds to PTR requests if the target IP is detected to be
|
// processLocalPTR responds to PTR requests if the target IP is detected to be
|
||||||
// inside the local network and the query was not answered from DHCP.
|
// inside the local network and the query was not answered from DHCP.
|
||||||
func (s *Server) processLocalPTR(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processLocalPTR(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing local ptr")
|
||||||
|
defer log.Debug("dnsforward: finished processing local ptr")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
if pctx.Res != nil {
|
if pctx.Res != nil {
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
|
@ -692,6 +716,9 @@ func (s *Server) processLocalPTR(dctx *dnsContext) (rc resultCode) {
|
||||||
|
|
||||||
// Apply filtering logic
|
// Apply filtering logic
|
||||||
func (s *Server) processFilteringBeforeRequest(ctx *dnsContext) (rc resultCode) {
|
func (s *Server) processFilteringBeforeRequest(ctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing filtering before req")
|
||||||
|
defer log.Debug("dnsforward: finished processing filtering before req")
|
||||||
|
|
||||||
if ctx.proxyCtx.Res != nil {
|
if ctx.proxyCtx.Res != nil {
|
||||||
// Go on since the response is already set.
|
// Go on since the response is already set.
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
|
@ -725,6 +752,9 @@ func ipStringFromAddr(addr net.Addr) (ipStr string) {
|
||||||
|
|
||||||
// processUpstream passes request to upstream servers and handles the response.
|
// processUpstream passes request to upstream servers and handles the response.
|
||||||
func (s *Server) processUpstream(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processUpstream(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing upstream")
|
||||||
|
defer log.Debug("dnsforward: finished processing upstream")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
req := pctx.Req
|
req := pctx.Req
|
||||||
q := req.Question[0]
|
q := req.Question[0]
|
||||||
|
@ -871,6 +901,9 @@ func (s *Server) setCustomUpstream(pctx *proxy.DNSContext, clientID string) {
|
||||||
|
|
||||||
// Apply filtering logic after we have received response from upstream servers
|
// Apply filtering logic after we have received response from upstream servers
|
||||||
func (s *Server) processFilteringAfterResponse(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processFilteringAfterResponse(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing filtering after req")
|
||||||
|
defer log.Debug("dnsforward: finished processing filtering after req")
|
||||||
|
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
switch res := dctx.result; res.Reason {
|
switch res := dctx.result; res.Reason {
|
||||||
case filtering.NotFilteredAllowList:
|
case filtering.NotFilteredAllowList:
|
||||||
|
|
|
@ -58,7 +58,7 @@ type hostToIPTable = map[string]netip.Addr
|
||||||
// TODO(e.burkov): Use the [DHCP] interface instead.
|
// TODO(e.burkov): Use the [DHCP] interface instead.
|
||||||
type ipToHostTable = map[netip.Addr]string
|
type ipToHostTable = map[netip.Addr]string
|
||||||
|
|
||||||
// DHCP is an interface for accesing DHCP lease data needed in this package.
|
// DHCP is an interface for accessing DHCP lease data needed in this package.
|
||||||
type DHCP interface {
|
type DHCP interface {
|
||||||
// HostByIP returns the hostname of the DHCP client with the given IP
|
// HostByIP returns the hostname of the DHCP client with the given IP
|
||||||
// address. The address will be netip.Addr{} if there is no such client,
|
// address. The address will be netip.Addr{} if there is no such client,
|
||||||
|
@ -236,7 +236,7 @@ func (s *Server) Close() {
|
||||||
s.dnsProxy = nil
|
s.dnsProxy = nil
|
||||||
|
|
||||||
if err := s.ipset.close(); err != nil {
|
if err := s.ipset.close(); err != nil {
|
||||||
log.Error("closing ipset: %s", err)
|
log.Error("dnsforward: closing ipset: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ func (s *Server) setupResolvers(localAddrs []string) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("upstreams to resolve PTR for local addresses: %v", localAddrs)
|
log.Debug("dnsforward: upstreams to resolve ptr for local addresses: %v", localAddrs)
|
||||||
|
|
||||||
var upsConfig *proxy.UpstreamConfig
|
var upsConfig *proxy.UpstreamConfig
|
||||||
upsConfig, err = proxy.ParseUpstreamsConfig(
|
upsConfig, err = proxy.ParseUpstreamsConfig(
|
||||||
|
@ -677,7 +677,9 @@ func (s *Server) Reconfigure(conf *ServerConfig) error {
|
||||||
s.serverLock.Lock()
|
s.serverLock.Lock()
|
||||||
defer s.serverLock.Unlock()
|
defer s.serverLock.Unlock()
|
||||||
|
|
||||||
log.Print("Start reconfiguring the server")
|
log.Info("dnsforward: starting reconfiguring server")
|
||||||
|
defer log.Info("dnsforward: finished reconfiguring server")
|
||||||
|
|
||||||
err := s.stopLocked()
|
err := s.stopLocked()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("could not reconfigure the server: %w", err)
|
return fmt.Errorf("could not reconfigure the server: %w", err)
|
||||||
|
@ -729,13 +731,13 @@ func (s *Server) IsBlockedClient(ip netip.Addr, clientID string) (blocked bool,
|
||||||
// Allow if at least one of the checks allows in allowlist mode, but block
|
// Allow if at least one of the checks allows in allowlist mode, but block
|
||||||
// if at least one of the checks blocks in blocklist mode.
|
// if at least one of the checks blocks in blocklist mode.
|
||||||
if allowlistMode && blockedByIP && blockedByClientID {
|
if allowlistMode && blockedByIP && blockedByClientID {
|
||||||
log.Debug("client %v (id %q) is not in access allowlist", ip, clientID)
|
log.Debug("dnsforward: client %v (id %q) is not in access allowlist", ip, clientID)
|
||||||
|
|
||||||
// Return now without substituting the empty rule for the
|
// Return now without substituting the empty rule for the
|
||||||
// clientID because the rule can't be empty here.
|
// clientID because the rule can't be empty here.
|
||||||
return true, rule
|
return true, rule
|
||||||
} else if !allowlistMode && (blockedByIP || blockedByClientID) {
|
} else if !allowlistMode && (blockedByIP || blockedByClientID) {
|
||||||
log.Debug("client %v (id %q) is in access blocklist", ip, clientID)
|
log.Debug("dnsforward: client %v (id %q) is in access blocklist", ip, clientID)
|
||||||
|
|
||||||
blocked = true
|
blocked = true
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,9 @@ func ipsFromAnswer(ans []dns.RR) (ip4s, ip6s []net.IP) {
|
||||||
|
|
||||||
// process adds the resolved IP addresses to the domain's ipsets, if any.
|
// process adds the resolved IP addresses to the domain's ipsets, if any.
|
||||||
func (c *ipsetCtx) process(dctx *dnsContext) (rc resultCode) {
|
func (c *ipsetCtx) process(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: ipset: started processing")
|
||||||
|
defer log.Debug("dnsforward: ipset: finished processing")
|
||||||
|
|
||||||
if c.skipIpsetProcessing(dctx) {
|
if c.skipIpsetProcessing(dctx) {
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
}
|
}
|
||||||
|
@ -125,12 +128,12 @@ func (c *ipsetCtx) process(dctx *dnsContext) (rc resultCode) {
|
||||||
n, err := c.ipsetMgr.Add(host, ip4s, ip6s)
|
n, err := c.ipsetMgr.Add(host, ip4s, ip6s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Consider ipset errors non-critical to the request.
|
// Consider ipset errors non-critical to the request.
|
||||||
log.Error("ipset: adding host ips: %s", err)
|
log.Error("dnsforward: ipset: adding host ips: %s", err)
|
||||||
|
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Debug("ipset: added %d new ipset entries", n)
|
log.Debug("dnsforward: ipset: added %d new ipset entries", n)
|
||||||
|
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,60 +17,78 @@ import (
|
||||||
|
|
||||||
// Write Stats data and logs
|
// Write Stats data and logs
|
||||||
func (s *Server) processQueryLogsAndStats(dctx *dnsContext) (rc resultCode) {
|
func (s *Server) processQueryLogsAndStats(dctx *dnsContext) (rc resultCode) {
|
||||||
|
log.Debug("dnsforward: started processing querylog and stats")
|
||||||
|
defer log.Debug("dnsforward: finished processing querylog and stats")
|
||||||
|
|
||||||
elapsed := time.Since(dctx.startTime)
|
elapsed := time.Since(dctx.startTime)
|
||||||
pctx := dctx.proxyCtx
|
pctx := dctx.proxyCtx
|
||||||
|
|
||||||
shouldLog := true
|
q := pctx.Req.Question[0]
|
||||||
msg := pctx.Req
|
|
||||||
q := msg.Question[0]
|
|
||||||
host := strings.ToLower(strings.TrimSuffix(q.Name, "."))
|
host := strings.ToLower(strings.TrimSuffix(q.Name, "."))
|
||||||
|
|
||||||
// don't log ANY request if refuseAny is enabled
|
|
||||||
if q.Qtype == dns.TypeANY && s.conf.RefuseAny {
|
|
||||||
shouldLog = false
|
|
||||||
}
|
|
||||||
|
|
||||||
ip, _ := netutil.IPAndPortFromAddr(pctx.Addr)
|
ip, _ := netutil.IPAndPortFromAddr(pctx.Addr)
|
||||||
ip = slices.Clone(ip)
|
ip = slices.Clone(ip)
|
||||||
|
|
||||||
s.serverLock.RLock()
|
|
||||||
defer s.serverLock.RUnlock()
|
|
||||||
|
|
||||||
s.anonymizer.Load()(ip)
|
s.anonymizer.Load()(ip)
|
||||||
|
|
||||||
log.Debug("client ip: %s", ip)
|
log.Debug("dnsforward: client ip for stats and querylog: %s", ip)
|
||||||
|
|
||||||
ipStr := ip.String()
|
ipStr := ip.String()
|
||||||
ids := []string{ipStr, dctx.clientID}
|
ids := []string{ipStr, dctx.clientID}
|
||||||
|
qt, cl := q.Qtype, q.Qclass
|
||||||
|
|
||||||
// Synchronize access to s.queryLog and s.stats so they won't be suddenly
|
// Synchronize access to s.queryLog and s.stats so they won't be suddenly
|
||||||
// uninitialized while in use. This can happen after proxy server has been
|
// uninitialized while in use. This can happen after proxy server has been
|
||||||
// stopped, but its workers haven't yet exited.
|
// stopped, but its workers haven't yet exited.
|
||||||
if shouldLog &&
|
s.serverLock.RLock()
|
||||||
s.queryLog != nil &&
|
defer s.serverLock.RUnlock()
|
||||||
// TODO(s.chzhen): Use dnsforward.dnsContext when it will start
|
|
||||||
// containing persistent client.
|
if s.shouldLog(host, qt, cl, ids) {
|
||||||
s.queryLog.ShouldLog(host, q.Qtype, q.Qclass, ids) {
|
|
||||||
s.logQuery(dctx, pctx, elapsed, ip)
|
s.logQuery(dctx, pctx, elapsed, ip)
|
||||||
} else {
|
} else {
|
||||||
log.Debug(
|
log.Debug(
|
||||||
"dnsforward: request %s %s from %s ignored; not logging",
|
"dnsforward: request %s %s %q from %s ignored; not adding to querylog",
|
||||||
dns.Type(q.Qtype),
|
dns.Class(cl),
|
||||||
|
dns.Type(qt),
|
||||||
host,
|
host,
|
||||||
ip,
|
ip,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.stats != nil &&
|
if s.shouldCountStat(host, qt, cl, ids) {
|
||||||
// TODO(s.chzhen): Use dnsforward.dnsContext when it will start
|
|
||||||
// containing persistent client.
|
|
||||||
s.stats.ShouldCount(host, q.Qtype, q.Qclass, ids) {
|
|
||||||
s.updateStats(dctx, elapsed, *dctx.result, ipStr)
|
s.updateStats(dctx, elapsed, *dctx.result, ipStr)
|
||||||
|
} else {
|
||||||
|
log.Debug(
|
||||||
|
"dnsforward: request %s %s %q from %s ignored; not counting in stats",
|
||||||
|
dns.Class(cl),
|
||||||
|
dns.Type(qt),
|
||||||
|
host,
|
||||||
|
ip,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resultCodeSuccess
|
return resultCodeSuccess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// shouldLog returns true if the query with the given data should be logged in
|
||||||
|
// the query log. s.serverLock is expected to be locked.
|
||||||
|
func (s *Server) shouldLog(host string, qt, cl uint16, ids []string) (ok bool) {
|
||||||
|
if qt == dns.TypeANY && s.conf.RefuseAny {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO(s.chzhen): Use dnsforward.dnsContext when it will start containing
|
||||||
|
// persistent client.
|
||||||
|
return s.queryLog != nil && s.queryLog.ShouldLog(host, qt, cl, ids)
|
||||||
|
}
|
||||||
|
|
||||||
|
// shouldCountStat returns true if the query with the given data should be
|
||||||
|
// counted in the statistics. s.serverLock is expected to be locked.
|
||||||
|
func (s *Server) shouldCountStat(host string, qt, cl uint16, ids []string) (ok bool) {
|
||||||
|
// TODO(s.chzhen): Use dnsforward.dnsContext when it will start containing
|
||||||
|
// persistent client.
|
||||||
|
return s.stats != nil && s.stats.ShouldCount(host, qt, cl, ids)
|
||||||
|
}
|
||||||
|
|
||||||
// logQuery pushes the request details into the query log.
|
// logQuery pushes the request details into the query log.
|
||||||
func (s *Server) logQuery(
|
func (s *Server) logQuery(
|
||||||
dctx *dnsContext,
|
dctx *dnsContext,
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"golang.org/x/exp/slices"
|
"golang.org/x/exp/slices"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DHCP is an interface for accesing DHCP lease data the [clientsContainer]
|
// DHCP is an interface for accessing DHCP lease data the [clientsContainer]
|
||||||
// needs.
|
// needs.
|
||||||
type DHCP interface {
|
type DHCP interface {
|
||||||
// Leases returns all the DHCP leases.
|
// Leases returns all the DHCP leases.
|
||||||
|
|
|
@ -4,8 +4,8 @@ go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/fzipp/gocyclo v0.6.0
|
github.com/fzipp/gocyclo v0.6.0
|
||||||
github.com/golangci/misspell v0.4.0
|
github.com/golangci/misspell v0.4.1
|
||||||
github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28
|
github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601
|
||||||
github.com/kisielk/errcheck v1.6.3
|
github.com/kisielk/errcheck v1.6.3
|
||||||
github.com/kyoh86/looppointer v0.2.1
|
github.com/kyoh86/looppointer v0.2.1
|
||||||
github.com/securego/gosec/v2 v2.16.0
|
github.com/securego/gosec/v2 v2.16.0
|
||||||
|
@ -14,11 +14,11 @@ require (
|
||||||
golang.org/x/vuln v0.1.0
|
golang.org/x/vuln v0.1.0
|
||||||
honnef.co/go/tools v0.4.3
|
honnef.co/go/tools v0.4.3
|
||||||
mvdan.cc/gofumpt v0.5.0
|
mvdan.cc/gofumpt v0.5.0
|
||||||
mvdan.cc/unparam v0.0.0-20230312165513-e84e2d14e3b8
|
mvdan.cc/unparam v0.0.0-20230610194454-9ea02bef9868
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/BurntSushi/toml v1.3.1 // indirect
|
github.com/BurntSushi/toml v1.3.2 // indirect
|
||||||
github.com/google/go-cmp v0.5.9 // indirect
|
github.com/google/go-cmp v0.5.9 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
github.com/gookit/color v1.5.3 // indirect
|
github.com/gookit/color v1.5.3 // indirect
|
||||||
|
@ -26,7 +26,7 @@ require (
|
||||||
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 // indirect
|
github.com/nbutton23/zxcvbn-go v0.0.0-20210217022336-fa2cb2858354 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||||
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
|
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 // indirect
|
||||||
golang.org/x/exp/typeparams v0.0.0-20230522175609-2e198f4a06a1 // indirect
|
golang.org/x/exp/typeparams v0.0.0-20230626212559-97b1e661b5df // indirect
|
||||||
golang.org/x/mod v0.11.0 // indirect
|
golang.org/x/mod v0.11.0 // indirect
|
||||||
golang.org/x/sync v0.3.0 // indirect
|
golang.org/x/sync v0.3.0 // indirect
|
||||||
golang.org/x/sys v0.9.0 // indirect
|
golang.org/x/sys v0.9.0 // indirect
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
github.com/BurntSushi/toml v1.3.1 h1:rHnDkSK+/g6DlREUK73PkmIs60pqrnuduK+JmP++JmU=
|
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
|
||||||
github.com/BurntSushi/toml v1.3.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
|
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
@ -8,8 +8,8 @@ github.com/fzipp/gocyclo v0.6.0 h1:lsblElZG7d3ALtGMx9fmxeTKZaLLpU8mET09yN4BBLo=
|
||||||
github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
|
github.com/fzipp/gocyclo v0.6.0/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
|
||||||
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
|
||||||
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI=
|
||||||
github.com/golangci/misspell v0.4.0 h1:KtVB/hTK4bbL/S6bs64rYyk8adjmh1BygbBiaAiX+a0=
|
github.com/golangci/misspell v0.4.1 h1:+y73iSicVy2PqyX7kmUefHusENlrP9YwuHZHPLGQj/g=
|
||||||
github.com/golangci/misspell v0.4.0/go.mod h1:W6O/bwV6lGDxUCChm2ykw9NQdd5bYd1Xkjo88UcWyJc=
|
github.com/golangci/misspell v0.4.1/go.mod h1:9mAN1quEo3DlpbaIKKyEvRxK1pwqR9s/Sea1bJCtlNI=
|
||||||
github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786 h1:rcv+Ippz6RAtvaGgKxc+8FQIpxHgsF+HBzPyYL2cyVU=
|
github.com/google/go-cmdtest v0.4.1-0.20220921163831-55ab3332a786 h1:rcv+Ippz6RAtvaGgKxc+8FQIpxHgsF+HBzPyYL2cyVU=
|
||||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
|
@ -19,8 +19,8 @@ github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE=
|
github.com/gookit/color v1.5.3 h1:twfIhZs4QLCtimkP7MOxlF3A0U/5cDPseRT9M/+2SCE=
|
||||||
github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE=
|
github.com/gookit/color v1.5.3/go.mod h1:NUzwzeehUfl7GIb36pqId+UGmRfQcU/WiiyTTeNjHtE=
|
||||||
github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28 h1:9alfqbrhuD+9fLZ4iaAVwhlp5PEhmnBt7yvK2Oy5C1U=
|
github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601 h1:mrEEilTAUmaAORhssPPkxj84TsHrPMLBGW2Z4SoTxm8=
|
||||||
github.com/gordonklaus/ineffassign v0.0.0-20230107090616-13ace0543b28/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0=
|
github.com/gordonklaus/ineffassign v0.0.0-20230610083614-0e73809eb601/go.mod h1:Qcp2HIAYhR7mNUVSIxZww3Guk4it82ghYcEXIAk+QT0=
|
||||||
github.com/kisielk/errcheck v1.6.3 h1:dEKh+GLHcWm2oN34nMvDzn1sqI0i0WxPvrgiJA5JuM8=
|
github.com/kisielk/errcheck v1.6.3 h1:dEKh+GLHcWm2oN34nMvDzn1sqI0i0WxPvrgiJA5JuM8=
|
||||||
github.com/kisielk/errcheck v1.6.3/go.mod h1:nXw/i/MfnvRHqXa7XXmQMUB0oNFGuBrNI8d8NLy0LPw=
|
github.com/kisielk/errcheck v1.6.3/go.mod h1:nXw/i/MfnvRHqXa7XXmQMUB0oNFGuBrNI8d8NLy0LPw=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
|
@ -53,8 +53,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
|
golang.org/x/exp v0.0.0-20230321023759-10a507213a29 h1:ooxPy7fPvB4kwsA2h+iBNHkAbp/4JxTSwCmvdjEYmug=
|
||||||
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
golang.org/x/exp v0.0.0-20230321023759-10a507213a29/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||||
golang.org/x/exp/typeparams v0.0.0-20230522175609-2e198f4a06a1 h1:pnP8r+W8Fm7XJ8CWtXi4S9oJmPBTrkfYN/dNbaPj6Y4=
|
golang.org/x/exp/typeparams v0.0.0-20230626212559-97b1e661b5df h1:jfUqBujZx2dktJVEmZpCkyngz7MWrVv1y9kLOqFNsqw=
|
||||||
golang.org/x/exp/typeparams v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
|
golang.org/x/exp/typeparams v0.0.0-20230626212559-97b1e661b5df/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
|
||||||
|
@ -112,5 +112,5 @@ honnef.co/go/tools v0.4.3 h1:o/n5/K5gXqk8Gozvs2cnL0F2S1/g1vcGCAx2vETjITw=
|
||||||
honnef.co/go/tools v0.4.3/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA=
|
honnef.co/go/tools v0.4.3/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA=
|
||||||
mvdan.cc/gofumpt v0.5.0 h1:0EQ+Z56k8tXjj/6TQD25BFNKQXpCvT0rnansIc7Ug5E=
|
mvdan.cc/gofumpt v0.5.0 h1:0EQ+Z56k8tXjj/6TQD25BFNKQXpCvT0rnansIc7Ug5E=
|
||||||
mvdan.cc/gofumpt v0.5.0/go.mod h1:HBeVDtMKRZpXyxFciAirzdKklDlGu8aAy1wEbH5Y9js=
|
mvdan.cc/gofumpt v0.5.0/go.mod h1:HBeVDtMKRZpXyxFciAirzdKklDlGu8aAy1wEbH5Y9js=
|
||||||
mvdan.cc/unparam v0.0.0-20230312165513-e84e2d14e3b8 h1:VuJo4Mt0EVPychre4fNlDWDuE5AjXtPJpRUWqZDQhaI=
|
mvdan.cc/unparam v0.0.0-20230610194454-9ea02bef9868 h1:F4Q7pXcrU9UiU1fq0ZWqSOxKjNAteRuDr7JDk7uVLRQ=
|
||||||
mvdan.cc/unparam v0.0.0-20230312165513-e84e2d14e3b8/go.mod h1:Oh/d7dEtzsNHGOq1Cdv8aMm3KdKhVvPbRQcM8WFpBR8=
|
mvdan.cc/unparam v0.0.0-20230610194454-9ea02bef9868/go.mod h1:6ZaiQyI7Tiq0HQ56g6N8TlkSd80/LyagZeaw8mb7jYE=
|
||||||
|
|
Loading…
Reference in New Issue