diff --git a/go.mod b/go.mod index d6952501123..94dd70c0c8a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome go 1.20 require ( - // TODO(a.garipov): Upgrade to v0.60. + // TODO(a.garipov): !! Upgrade to v0.60. github.com/AdguardTeam/dnsproxy v0.59.2-0.20231129094552-f661fdcf9edc github.com/AdguardTeam/golibs v0.17.2 github.com/AdguardTeam/urlfilter v0.17.3 diff --git a/internal/dnsforward/dnsforward_test.go b/internal/dnsforward/dnsforward_test.go index 7ab94f3a130..2c30ff6cbaf 100644 --- a/internal/dnsforward/dnsforward_test.go +++ b/internal/dnsforward/dnsforward_test.go @@ -54,10 +54,10 @@ const ( testMessagesCount = 10 ) -// testClientAddr is the common net.Addr for tests. +// testClientAddrPort is the common net.Addr for tests. // // TODO(a.garipov): Use more. -var testClientAddr = netip.MustParseAddrPort("1.2.3.4:12345") +var testClientAddrPort = netip.MustParseAddrPort("1.2.3.4:12345") func startDeferStop(t *testing.T, s *Server) { t.Helper() diff --git a/internal/dnsforward/filter_test.go b/internal/dnsforward/filter_test.go index db4189a1cbf..6559b308464 100644 --- a/internal/dnsforward/filter_test.go +++ b/internal/dnsforward/filter_test.go @@ -187,7 +187,7 @@ func TestHandleDNSRequest_handleDNSRequest(t *testing.T) { dctx := &proxy.DNSContext{ Proto: proxy.ProtoUDP, Req: tc.req, - Addr: netip.MustParseAddrPort("127.0.0.1:1"), + Addr: testClientAddrPort, } t.Run(tc.name, func(t *testing.T) { @@ -326,7 +326,7 @@ func TestHandleDNSRequest_filterDNSResponse(t *testing.T) { Proto: proxy.ProtoUDP, Req: tc.req, Res: resp, - Addr: netip.MustParseAddrPort("127.0.0.1:1"), + Addr: testClientAddrPort, } dctx := &dnsContext{ diff --git a/internal/dnsforward/http.go b/internal/dnsforward/http.go index d0594156489..ac82ea76f9f 100644 --- a/internal/dnsforward/http.go +++ b/internal/dnsforward/http.go @@ -129,10 +129,7 @@ func (s *Server) getDNSConfig() (c *jsonDNSConfig) { ratelimit := s.conf.Ratelimit ratelimitSubnetLenIPv4 := s.conf.RatelimitSubnetLenIPv4 ratelimitSubnetLenIPv6 := s.conf.RatelimitSubnetLenIPv6 - ratelimitWhitelist := slices.Clone(s.conf.RatelimitWhitelist) - if ratelimitWhitelist == nil { - ratelimitWhitelist = []netip.Addr{} - } + ratelimitWhitelist := append([]netip.Addr{}, s.conf.RatelimitWhitelist...) customIP := s.conf.EDNSClientSubnet.CustomIP enableEDNSClientSubnet := s.conf.EDNSClientSubnet.Enabled @@ -294,12 +291,6 @@ func (req *jsonDNSConfig) validate(privateNets netutil.SubnetSet) (err error) { return err } - err = req.checkRatelimitWhitelist() - if err != nil { - // Don't wrap the error since it's informative enough as is. - return err - } - err = req.checkBlockingMode() if err != nil { // Don't wrap the error since it's informative enough as is. @@ -408,21 +399,6 @@ func checkInclusion(ptr *int, minN, maxN int) (err error) { return nil } -// checkRatelimitWhitelist returns an error if any of IP addresses is invalid. -func (req *jsonDNSConfig) checkRatelimitWhitelist() (err error) { - if req.RatelimitWhitelist == nil { - return nil - } - - for i, ip := range *req.RatelimitWhitelist { - if !ip.IsValid() { - return fmt.Errorf("ratelimit whitelist: at index %d: invalid ip", i) - } - } - - return nil -} - // handleSetConfig handles requests to the POST /control/dns_config endpoint. func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) { req := &jsonDNSConfig{} diff --git a/internal/dnsforward/process_internal_test.go b/internal/dnsforward/process_internal_test.go index 9a018dbfbd9..18b04b3f67d 100644 --- a/internal/dnsforward/process_internal_test.go +++ b/internal/dnsforward/process_internal_test.go @@ -97,14 +97,14 @@ func TestServer_ProcessInitial(t *testing.T) { dctx := &dnsContext{ proxyCtx: &proxy.DNSContext{ Req: createTestMessageWithType(tc.target, tc.qType), - Addr: testClientAddr, + Addr: testClientAddrPort, RequestID: 1234, }, } gotRC := s.processInitial(dctx) assert.Equal(t, tc.wantRC, gotRC) - assert.Equal(t, testClientAddr.Addr(), gotAddr) + assert.Equal(t, testClientAddrPort.Addr(), gotAddr) if tc.wantRCode > 0 { gotResp := dctx.proxyCtx.Res @@ -201,7 +201,7 @@ func TestServer_ProcessFilteringAfterResponse(t *testing.T) { Proto: proxy.ProtoUDP, Req: tc.req, Res: resp, - Addr: testClientAddr, + Addr: testClientAddrPort, }, } @@ -412,10 +412,6 @@ func TestServer_ProcessDetermineLocal(t *testing.T) { want: assert.False, name: "invalid", cliAddr: netip.AddrPort{}, - }, { - want: assert.False, - name: "nil", - cliAddr: netip.AddrPort{}, }} for _, tc := range testCases { @@ -790,7 +786,7 @@ func TestServer_ProcessLocalPTR_usingResolvers(t *testing.T) { var dnsCtx *dnsContext setup := func(use bool) { proxyCtx = &proxy.DNSContext{ - Addr: testClientAddr, + Addr: testClientAddrPort, Req: createTestMessageWithType(reqAddr, dns.TypePTR), } dnsCtx = &dnsContext{ diff --git a/internal/dnsforward/stats_test.go b/internal/dnsforward/stats_test.go index 3b5dbde4e71..668b885b5cf 100644 --- a/internal/dnsforward/stats_test.go +++ b/internal/dnsforward/stats_test.go @@ -1,6 +1,7 @@ package dnsforward import ( + "net/netip" "testing" "time" @@ -64,6 +65,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name string domain string proto proxy.Proto + addr netip.AddrPort clientID string wantLogProto querylog.ClientProto wantStatClient string @@ -74,6 +76,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_udp", domain: domain, proto: proxy.ProtoUDP, + addr: testClientAddrPort, clientID: "", wantLogProto: "", wantStatClient: "1.2.3.4", @@ -84,6 +87,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_tls_clientid", domain: domain, proto: proxy.ProtoTLS, + addr: testClientAddrPort, clientID: "cli42", wantLogProto: querylog.ClientProtoDoT, wantStatClient: "cli42", @@ -94,6 +98,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_tls", domain: domain, proto: proxy.ProtoTLS, + addr: testClientAddrPort, clientID: "", wantLogProto: querylog.ClientProtoDoT, wantStatClient: "1.2.3.4", @@ -104,6 +109,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_quic", domain: domain, proto: proxy.ProtoQUIC, + addr: testClientAddrPort, clientID: "", wantLogProto: querylog.ClientProtoDoQ, wantStatClient: "1.2.3.4", @@ -114,6 +120,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_https", domain: domain, proto: proxy.ProtoHTTPS, + addr: testClientAddrPort, clientID: "", wantLogProto: querylog.ClientProtoDoH, wantStatClient: "1.2.3.4", @@ -124,6 +131,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_dnscrypt", domain: domain, proto: proxy.ProtoDNSCrypt, + addr: testClientAddrPort, clientID: "", wantLogProto: querylog.ClientProtoDNSCrypt, wantStatClient: "1.2.3.4", @@ -134,6 +142,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_udp_filtered", domain: domain, proto: proxy.ProtoUDP, + addr: testClientAddrPort, clientID: "", wantLogProto: "", wantStatClient: "1.2.3.4", @@ -144,6 +153,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_udp_sb", domain: domain, proto: proxy.ProtoUDP, + addr: testClientAddrPort, clientID: "", wantLogProto: "", wantStatClient: "1.2.3.4", @@ -154,6 +164,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_udp_ss", domain: domain, proto: proxy.ProtoUDP, + addr: testClientAddrPort, clientID: "", wantLogProto: "", wantStatClient: "1.2.3.4", @@ -164,6 +175,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_udp_pc", domain: domain, proto: proxy.ProtoUDP, + addr: testClientAddrPort, clientID: "", wantLogProto: "", wantStatClient: "1.2.3.4", @@ -174,9 +186,10 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { name: "success_udp_pc_empty_fqdn", domain: ".", proto: proxy.ProtoUDP, + addr: netip.MustParseAddrPort("4.3.2.1:1234"), clientID: "", wantLogProto: "", - wantStatClient: "1.2.3.4", + wantStatClient: "4.3.2.1", wantCode: resultCodeSuccess, reason: filtering.FilteredParental, wantStatResult: stats.RParental, @@ -203,7 +216,7 @@ func TestServer_ProcessQueryLogsAndStats(t *testing.T) { Proto: tc.proto, Req: req, Res: &dns.Msg{}, - Addr: testClientAddr, + Addr: tc.addr, Upstream: ups, } dctx := &dnsContext{