Pull request: all: mv some utilities to netutil

Merge in DNS/adguard-home from mv-netutil to master

Squashed commit of the following:

commit 5698fceed656dca7f8644e7dbd7e1a7fc57a68ce
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Aug 9 15:44:17 2021 +0300

    dnsforward: add todos

commit 122fb6e3de658b296931e0f608cf24ef85547666
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon Aug 9 14:27:46 2021 +0300

    all: mv some utilities to netutil
This commit is contained in:
Ainar Garipov
2021-08-09 16:03:37 +03:00
parent 133a1c57b1
commit 9bd7294fad
37 changed files with 242 additions and 1033 deletions

View File

@@ -20,6 +20,7 @@ import (
"github.com/AdguardTeam/golibs/cache"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/miekg/dns"
)
@@ -81,7 +82,7 @@ type Server struct {
tableHostToIP hostToIPTable
tableHostToIPLock sync.Mutex
tableIPToHost *aghnet.IPMap
tableIPToHost *netutil.IPMap
tableIPToHostLock sync.Mutex
// clientIDCache is a temporary storage for clientIDs that were
@@ -141,7 +142,7 @@ func NewServer(p DNSCreateParams) (s *Server, err error) {
if p.LocalDomain == "" {
localDomainSuffix = defaultLocalDomainSuffix
} else {
err = aghnet.ValidateDomainName(p.LocalDomain)
err = netutil.ValidateDomainName(p.LocalDomain)
if err != nil {
return nil, fmt.Errorf("local domain: %w", err)
}
@@ -281,7 +282,12 @@ func (s *Server) Exchange(ip net.IP) (host string, err error) {
return "", nil
}
arpa := dns.Fqdn(aghnet.ReverseAddr(ip))
arpa, err := netutil.IPToReversedAddr(ip)
if err != nil {
return "", fmt.Errorf("reversing ip: %w", err)
}
arpa = dns.Fqdn(arpa)
req := &dns.Msg{
MsgHdr: dns.MsgHdr{
Id: dns.Id(),