Documentation ¶
Overview ¶
Package agdnet contains network-related utilities.
TODO(a.garipov): Move stuff to netutil.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AndroidMetricDomainReplacement ¶
AndroidMetricDomainReplacement returns an empty string if fqdn is not ending with androidMetricFQDNSuffix. Otherwise it returns an appropriate replacement domain name.
Example ¶
package main import ( "fmt" "github.com/AdguardTeam/AdGuardDNS/internal/agdnet" ) func main() { printResult := func(input string) { fmt.Printf("%-42q: %q\n", input, agdnet.AndroidMetricDomainReplacement(input)) } anAndroidDomain := "12345678-dnsotls-ds.metric.gstatic.com." printResult(anAndroidDomain) anAndroidDomain = "123456-dnsohttps-ds.metric.gstatic.com." printResult(anAndroidDomain) notAndroidDomain := "example.com" printResult(notAndroidDomain) }
Output: "12345678-dnsotls-ds.metric.gstatic.com." : "00000000-dnsotls-ds.metric.gstatic.com." "123456-dnsohttps-ds.metric.gstatic.com." : "000000-dnsohttps-ds.metric.gstatic.com." "example.com" : ""
func NormalizeDomain ¶
NormalizeDomain returns lowercased version of the host without the final dot.
TODO(a.garipov): Move to golibs.
func NormalizeQueryDomain ¶
NormalizeQueryDomain returns a lowercased version of the host without the final dot, unless the host is ".", in which case it returns the unchanged host. That is the special case to allow matching queries like:
dig IN NS '.'
Types ¶
type CachingResolver ¶
type CachingResolver struct {
// contains filtered or unexported fields
}
CachingResolver caches resolved results for hosts for a certain time, regardless of the actual TTLs of the records. It is used for caching the results of lookups of hostnames that don't change their IP addresses often.
func NewCachingResolver ¶
func NewCachingResolver(resolver Resolver, ttl time.Duration) (c *CachingResolver)
NewCachingResolver returns a new caching resolver.
func (*CachingResolver) LookupNetIP ¶
func (c *CachingResolver) LookupNetIP( ctx context.Context, fam netutil.AddrFamily, host string, ) (ips []netip.Addr, err error)
LookupNetIP implements the Resolver interface for *CachingResolver. host should be normalized. Slice ips and its elements must not be mutated.
type DefaultResolver ¶
type DefaultResolver struct{}
DefaultResolver uses net.DefaultResolver to resolve addresses.
func (DefaultResolver) LookupNetIP ¶
func (DefaultResolver) LookupNetIP( ctx context.Context, fam netutil.AddrFamily, host string, ) (ips []netip.Addr, err error)
LookupNetIP implements the Resolver interface for DefaultResolver.
type PrefixNetAddr ¶
PrefixNetAddr is a wrapper around netip.Prefix that makes it a net.Addr.
Example (String) ¶
package main import ( "fmt" "net/netip" "github.com/AdguardTeam/AdGuardDNS/internal/agdnet" ) func main() { fmt.Println(&agdnet.PrefixNetAddr{ Prefix: netip.MustParsePrefix("1.2.3.4/32"), Net: "", Port: 5678, }) fmt.Println(&agdnet.PrefixNetAddr{ Prefix: netip.MustParsePrefix("1.2.3.0/24"), Net: "", Port: 5678, }) }
Output: 1.2.3.4:5678 1.2.3.0:5678/24
func (*PrefixNetAddr) Network ¶
func (addr *PrefixNetAddr) Network() (n string)
Network implements the net.Addr interface for *PrefixNetAddr.
func (*PrefixNetAddr) String ¶
func (addr *PrefixNetAddr) String() (n string)
String implements the net.Addr interface for *PrefixNetAddr. It returns either a simple IP:port address or one with the prefix length appended after a slash, depending on whether or not subnet is a single-address subnet. This is done to make using the IP:port part easier to split off using functions like strings.Cut.
type Resolver ¶
type Resolver interface { // LookupNetIP returns a slice of host's IP addresses of family specified by // fam, which must be either [netutil.AddrFamilyIPv4] or // [netutil.AddrFamilyIPv6]. LookupNetIP( ctx context.Context, fam netutil.AddrFamily, host string, ) (ips []netip.Addr, err error) }
Resolver is the DNS resolver interface.
See net.Resolver.
TODO(a.garipov): Move to golibs and unite with the one in module dnsproxy.