Pull request: AGDNS-2818-upd-golibs
Merge in DNS/adguard-home from AGDNS-2818-upd-golibs to master Squashed commit of the following: commit f2a41b85ec27b306407b3fa96778b266dc8232e9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 7 09:52:32 2025 +0300 client: imp code commit b4b668f7386c4abf0bbcf255c6c7b1edc5050727 Merge: c6f89e0b5b5c47054aAuthor: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed May 7 09:47:54 2025 +0300 Merge remote-tracking branch 'origin/master' into AGDNS-2818-upd-golibs # Conflicts: # go.mod # go.sum commit c6f89e0b5dcaf8842187e72c22cf9109a1c4edc9 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Apr 30 14:10:33 2025 +0300 client: imp code commit cf07b1802fb0f1aa005af86c2bd59485683582d2 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Apr 30 10:31:44 2025 +0300 client: imp code commit a10d4b1b9265f6eecd7a40746de058b961d6fdd7 Merge: 447a79ca6e5d0f0b11Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Wed Apr 30 10:24:00 2025 +0300 Merge remote-tracking branch 'origin/master' into AGDNS-2818-upd-golibs commit 447a79ca6eb296a339b1e8c57edddcfcce3efdc2 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Apr 28 13:02:40 2025 +0300 all: upd golibs commit 693ef4f39d628a97dbe94e1a0c5d2078f31b7e63 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Apr 28 12:47:39 2025 +0300 all: upd golibs commit a4f90eac8547eea74bfdaa8b1bb23e0502638777 Author: Dimitry Kolyshev <dkolyshev@adguard.com> Date: Mon Apr 28 10:25:33 2025 +0300 all: upd golibs
This commit is contained in:
2
go.mod
2
go.mod
@@ -4,7 +4,7 @@ go 1.24.2
|
||||
|
||||
require (
|
||||
github.com/AdguardTeam/dnsproxy v0.75.4
|
||||
github.com/AdguardTeam/golibs v0.32.8
|
||||
github.com/AdguardTeam/golibs v0.32.9
|
||||
github.com/AdguardTeam/urlfilter v0.20.0
|
||||
github.com/NYTimes/gziphandler v1.1.1
|
||||
github.com/ameshkov/dnscrypt/v2 v2.4.0
|
||||
|
||||
4
go.sum
4
go.sum
@@ -12,8 +12,8 @@ cloud.google.com/go/longrunning v0.6.7 h1:IGtfDWHhQCgCjwQjV9iiLnUta9LBCo8R9QmAFs
|
||||
cloud.google.com/go/longrunning v0.6.7/go.mod h1:EAFV3IZAKmM56TyiE6VAP3VoTzhZzySwI/YI1s/nRsY=
|
||||
github.com/AdguardTeam/dnsproxy v0.75.4 h1:hTnHh9HoTYKKhKqePpIxCzfecl7dAXykZTw2gcj0I5U=
|
||||
github.com/AdguardTeam/dnsproxy v0.75.4/go.mod h1:50OyTHao+uQzUJiXay08hgfvWQ3o2Q2WV99W8u8ypDE=
|
||||
github.com/AdguardTeam/golibs v0.32.8 h1:O3mc3kYcPkW3kbmd+gqzFNgUka13a+iBgFLThwOYSQE=
|
||||
github.com/AdguardTeam/golibs v0.32.8/go.mod h1:McV1QFFlKLElKa306V4OL/T2kr7564PhsayfvTWYBVs=
|
||||
github.com/AdguardTeam/golibs v0.32.9 h1:/6luT0aMOn05/s9eh1yA4lbcHgl0d1iEEvEBbIMMUk0=
|
||||
github.com/AdguardTeam/golibs v0.32.9/go.mod h1:McV1QFFlKLElKa306V4OL/T2kr7564PhsayfvTWYBVs=
|
||||
github.com/AdguardTeam/urlfilter v0.20.0 h1:X32qiuVCVd8WDYCEsbdZKfXMzwdVqrdulamtUi4rmzs=
|
||||
github.com/AdguardTeam/urlfilter v0.20.0/go.mod h1:gjrywLTxfJh6JOkwi9SU+frhP7kVVEZ5exFGkR99qpk=
|
||||
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"net"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -478,7 +477,7 @@ const ErrBadIdentifier errors.Error = "bad client identifier"
|
||||
func (p *FindParams) Set(id string) (err error) {
|
||||
*p = FindParams{}
|
||||
|
||||
isClientID := true
|
||||
isFound := false
|
||||
|
||||
if netutil.IsValidIPString(id) {
|
||||
// It is safe to use [netip.MustParseAddr] because it has already been
|
||||
@@ -488,24 +487,27 @@ func (p *FindParams) Set(id string) (err error) {
|
||||
|
||||
// Even if id can be parsed as an IP address, it may be a MAC address.
|
||||
// So do not return prematurely, continue parsing.
|
||||
isClientID = false
|
||||
isFound = true
|
||||
}
|
||||
|
||||
if canBeValidIPPrefixString(id) {
|
||||
p.Subnet, err = netip.ParsePrefix(id)
|
||||
if err == nil {
|
||||
isClientID = false
|
||||
}
|
||||
}
|
||||
|
||||
if canBeMACString(id) {
|
||||
if netutil.IsValidMACString(id) {
|
||||
p.MAC, err = net.ParseMAC(id)
|
||||
if err == nil {
|
||||
isClientID = false
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("parsing mac from %q: %w", id, err))
|
||||
}
|
||||
|
||||
isFound = true
|
||||
}
|
||||
|
||||
if !isClientID {
|
||||
if isFound {
|
||||
return nil
|
||||
}
|
||||
|
||||
if netutil.IsValidIPPrefixString(id) {
|
||||
// It is safe to use [netip.MustParsePrefix] because it has already been
|
||||
// validated that id contains the string representation of IP prefix.
|
||||
p.Subnet = netip.MustParsePrefix(id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -518,57 +520,6 @@ func (p *FindParams) Set(id string) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// canBeValidIPPrefixString is a best-effort check to determine if s is a valid
|
||||
// CIDR before using [netip.ParsePrefix], aimed at reducing allocations.
|
||||
//
|
||||
// TODO(s.chzhen): Replace this implementation with the more robust version
|
||||
// from golibs.
|
||||
func canBeValidIPPrefixString(s string) (ok bool) {
|
||||
ipStr, bitStr, ok := strings.Cut(s, "/")
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if bitStr == "" || len(bitStr) > 3 {
|
||||
return false
|
||||
}
|
||||
|
||||
bits := 0
|
||||
for _, c := range bitStr {
|
||||
if c < '0' || c > '9' {
|
||||
return false
|
||||
}
|
||||
|
||||
bits = bits*10 + int(c-'0')
|
||||
}
|
||||
|
||||
if bits > 128 {
|
||||
return false
|
||||
}
|
||||
|
||||
return netutil.IsValidIPString(ipStr)
|
||||
}
|
||||
|
||||
// canBeMACString is a best-effort check to determine if s is a valid MAC
|
||||
// address before using [net.ParseMAC], aimed at reducing allocations.
|
||||
//
|
||||
// TODO(s.chzhen): Replace this implementation with the more robust version
|
||||
// from golibs.
|
||||
func canBeMACString(s string) (ok bool) {
|
||||
switch len(s) {
|
||||
case
|
||||
len("0000.0000.0000"),
|
||||
len("00:00:00:00:00:00"),
|
||||
len("0000.0000.0000.0000"),
|
||||
len("00:00:00:00:00:00:00:00"),
|
||||
len("0000.0000.0000.0000.0000.0000.0000.0000.0000.0000"),
|
||||
len("00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00"):
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Find represents the parameters for searching a client. params must not be
|
||||
// nil and must have at least one non-empty field.
|
||||
func (s *Storage) Find(params *FindParams) (p *Persistent, ok bool) {
|
||||
|
||||
Reference in New Issue
Block a user