mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 21:27:31 +00:00
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.) perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. ) perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. ) goimports -w . Then delete some stuff from the net/netaddr shim package which is no longer neeed. Updates #5162 Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:

committed by
Brad Fitzpatrick

parent
6a396731eb
commit
a12aad6b47
@@ -9,8 +9,6 @@ package dnstype
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
)
|
||||
|
||||
// Resolver is the configuration for one DNS resolver.
|
||||
@@ -29,20 +27,20 @@ type Resolver struct {
|
||||
// BootstrapResolution may be empty, in which case clients should
|
||||
// look up the DoT/DoH server using their local "classic" DNS
|
||||
// resolver.
|
||||
BootstrapResolution []netaddr.IP `json:",omitempty"`
|
||||
BootstrapResolution []netip.Addr `json:",omitempty"`
|
||||
}
|
||||
|
||||
// IPPort returns r.Addr as an IP address and port if either
|
||||
// r.Addr is an IP address (the common case) or if r.Addr
|
||||
// is an IP:port (as done in tests).
|
||||
func (r *Resolver) IPPort() (ipp netaddr.IPPort, ok bool) {
|
||||
func (r *Resolver) IPPort() (ipp netip.AddrPort, ok bool) {
|
||||
if r.Addr == "" || r.Addr[0] == 'h' || r.Addr[0] == 't' {
|
||||
// Fast path to avoid ParseIP error allocation for obviously not IP
|
||||
// cases.
|
||||
return
|
||||
}
|
||||
if ip, err := netip.ParseAddr(r.Addr); err == nil {
|
||||
return netaddr.IPPortFrom(ip, 53), true
|
||||
return netip.AddrPortFrom(ip, 53), true
|
||||
}
|
||||
if ipp, err := netip.ParseAddrPort(r.Addr); err == nil {
|
||||
return ipp, true
|
||||
|
@@ -9,8 +9,8 @@ package dnstype
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/netip"
|
||||
|
||||
"tailscale.com/net/netaddr"
|
||||
"tailscale.com/types/views"
|
||||
)
|
||||
|
||||
@@ -58,12 +58,12 @@ func (v *ResolverView) UnmarshalJSON(b []byte) error {
|
||||
}
|
||||
|
||||
func (v ResolverView) Addr() string { return v.ж.Addr }
|
||||
func (v ResolverView) BootstrapResolution() views.Slice[netaddr.IP] {
|
||||
func (v ResolverView) BootstrapResolution() views.Slice[netip.Addr] {
|
||||
return views.SliceOf(v.ж.BootstrapResolution)
|
||||
}
|
||||
|
||||
// A compilation failure here means this code must be regenerated, with the command at the top of this file.
|
||||
var _ResolverViewNeedsRegeneration = Resolver(struct {
|
||||
Addr string
|
||||
BootstrapResolution []netaddr.IP
|
||||
BootstrapResolution []netip.Addr
|
||||
}{})
|
||||
|
Reference in New Issue
Block a user