mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-27 07:38:49 +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
@@ -81,13 +81,13 @@ type peerInfo struct {
|
||||
// that when we're deleting this node, we can rapidly find out the
|
||||
// keys that need deleting from peerMap.byIPPort without having to
|
||||
// iterate over every IPPort known for any peer.
|
||||
ipPorts map[netaddr.IPPort]bool
|
||||
ipPorts map[netip.AddrPort]bool
|
||||
}
|
||||
|
||||
func newPeerInfo(ep *endpoint) *peerInfo {
|
||||
return &peerInfo{
|
||||
ep: ep,
|
||||
ipPorts: map[netaddr.IPPort]bool{},
|
||||
ipPorts: map[netip.AddrPort]bool{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ func newPeerInfo(ep *endpoint) *peerInfo {
|
||||
// Doesn't do any locking, all access must be done with Conn.mu held.
|
||||
type peerMap struct {
|
||||
byNodeKey map[key.NodePublic]*peerInfo
|
||||
byIPPort map[netaddr.IPPort]*peerInfo
|
||||
byIPPort map[netip.AddrPort]*peerInfo
|
||||
|
||||
// nodesOfDisco contains the set of nodes that are using a
|
||||
// DiscoKey. Usually those sets will be just one node.
|
||||
@@ -107,7 +107,7 @@ type peerMap struct {
|
||||
func newPeerMap() peerMap {
|
||||
return peerMap{
|
||||
byNodeKey: map[key.NodePublic]*peerInfo{},
|
||||
byIPPort: map[netaddr.IPPort]*peerInfo{},
|
||||
byIPPort: map[netip.AddrPort]*peerInfo{},
|
||||
nodesOfDisco: map[key.DiscoPublic]map[key.NodePublic]bool{},
|
||||
}
|
||||
}
|
||||
@@ -137,7 +137,7 @@ func (m *peerMap) endpointForNodeKey(nk key.NodePublic) (ep *endpoint, ok bool)
|
||||
|
||||
// endpointForIPPort returns the endpoint for the peer we
|
||||
// believe to be at ipp, or nil if we don't know of any such peer.
|
||||
func (m *peerMap) endpointForIPPort(ipp netaddr.IPPort) (ep *endpoint, ok bool) {
|
||||
func (m *peerMap) endpointForIPPort(ipp netip.AddrPort) (ep *endpoint, ok bool) {
|
||||
if info, ok := m.byIPPort[ipp]; ok {
|
||||
return info.ep, true
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (m *peerMap) upsertEndpoint(ep *endpoint, oldDiscoKey key.DiscoPublic) {
|
||||
// This should only be called with a fully verified mapping of ipp to
|
||||
// nk, because calling this function defines the endpoint we hand to
|
||||
// WireGuard for packets received from ipp.
|
||||
func (m *peerMap) setNodeKeyForIPPort(ipp netaddr.IPPort, nk key.NodePublic) {
|
||||
func (m *peerMap) setNodeKeyForIPPort(ipp netip.AddrPort, nk key.NodePublic) {
|
||||
if pi := m.byIPPort[ipp]; pi != nil {
|
||||
delete(pi.ipPorts, ipp)
|
||||
delete(m.byIPPort, ipp)
|
||||
@@ -579,7 +579,7 @@ func NewConn(opts Options) (*Conn, error) {
|
||||
|
||||
// ignoreSTUNPackets sets a STUN packet processing func that does nothing.
|
||||
func (c *Conn) ignoreSTUNPackets() {
|
||||
c.stunReceiveFunc.Store(func([]byte, netaddr.IPPort) {})
|
||||
c.stunReceiveFunc.Store(func([]byte, netip.AddrPort) {})
|
||||
}
|
||||
|
||||
// doPeriodicSTUN is called (in a new goroutine) by
|
||||
@@ -843,7 +843,7 @@ func (c *Conn) callNetInfoCallbackLocked(ni *tailcfg.NetInfo) {
|
||||
// discoKey. It's used in tests to enable receiving of packets from
|
||||
// addr without having to spin up the entire active discovery
|
||||
// machinery.
|
||||
func (c *Conn) addValidDiscoPathForTest(nodeKey key.NodePublic, addr netaddr.IPPort) {
|
||||
func (c *Conn) addValidDiscoPathForTest(nodeKey key.NodePublic, addr netip.AddrPort) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
c.peerMap.setNodeKeyForIPPort(addr, nodeKey)
|
||||
@@ -908,7 +908,7 @@ func (c *Conn) Ping(peer *tailcfg.Node, res *ipnstate.PingResult, cb func(*ipnst
|
||||
}
|
||||
|
||||
// c.mu must be held
|
||||
func (c *Conn) populateCLIPingResponseLocked(res *ipnstate.PingResult, latency time.Duration, ep netaddr.IPPort) {
|
||||
func (c *Conn) populateCLIPingResponseLocked(res *ipnstate.PingResult, latency time.Duration, ep netip.AddrPort) {
|
||||
res.LatencySeconds = latency.Seconds()
|
||||
if ep.Addr() != derpMagicIPAddr {
|
||||
res.Endpoint = ep.String()
|
||||
@@ -1008,7 +1008,7 @@ func (c *Conn) goDerpConnect(node int) {
|
||||
if node == 0 {
|
||||
return
|
||||
}
|
||||
go c.derpWriteChanOfAddr(netaddr.IPPortFrom(derpMagicIPAddr, uint16(node)), key.NodePublic{})
|
||||
go c.derpWriteChanOfAddr(netip.AddrPortFrom(derpMagicIPAddr, uint16(node)), key.NodePublic{})
|
||||
}
|
||||
|
||||
// determineEndpoints returns the machine's endpoint addresses. It
|
||||
@@ -1017,7 +1017,7 @@ func (c *Conn) goDerpConnect(node int) {
|
||||
// c.mu must NOT be held.
|
||||
func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, error) {
|
||||
var havePortmap bool
|
||||
var portmapExt netaddr.IPPort
|
||||
var portmapExt netip.AddrPort
|
||||
if runtime.GOOS != "js" {
|
||||
portmapExt, havePortmap = c.portMapper.GetCachedMappingOrStartCreatingOne()
|
||||
}
|
||||
@@ -1040,14 +1040,14 @@ func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, erro
|
||||
}, nil
|
||||
}
|
||||
|
||||
var already map[netaddr.IPPort]tailcfg.EndpointType // endpoint -> how it was found
|
||||
var already map[netip.AddrPort]tailcfg.EndpointType // endpoint -> how it was found
|
||||
var eps []tailcfg.Endpoint // unique endpoints
|
||||
|
||||
ipp := func(s string) (ipp netaddr.IPPort) {
|
||||
ipp := func(s string) (ipp netip.AddrPort) {
|
||||
ipp, _ = netip.ParseAddrPort(s)
|
||||
return
|
||||
}
|
||||
addAddr := func(ipp netaddr.IPPort, et tailcfg.EndpointType) {
|
||||
addAddr := func(ipp netip.AddrPort, et tailcfg.EndpointType) {
|
||||
if !ipp.IsValid() || (debugOmitLocalAddresses && et == tailcfg.EndpointLocal) {
|
||||
return
|
||||
}
|
||||
@@ -1100,7 +1100,7 @@ func (c *Conn) determineEndpoints(ctx context.Context) ([]tailcfg.Endpoint, erro
|
||||
ips = loopback
|
||||
}
|
||||
for _, ip := range ips {
|
||||
addAddr(netaddr.IPPortFrom(ip, uint16(localAddr.Port)), tailcfg.EndpointLocal)
|
||||
addAddr(netip.AddrPortFrom(ip, uint16(localAddr.Port)), tailcfg.EndpointLocal)
|
||||
}
|
||||
} else {
|
||||
// Our local endpoint is bound to a particular address.
|
||||
@@ -1186,7 +1186,7 @@ var errNoUDP = errors.New("no UDP available on platform")
|
||||
|
||||
// sendUDP sends UDP packet b to ipp.
|
||||
// See sendAddr's docs on the return value meanings.
|
||||
func (c *Conn) sendUDP(ipp netaddr.IPPort, b []byte) (sent bool, err error) {
|
||||
func (c *Conn) sendUDP(ipp netip.AddrPort, b []byte) (sent bool, err error) {
|
||||
if runtime.GOOS == "js" {
|
||||
return false, errNoUDP
|
||||
}
|
||||
@@ -1235,7 +1235,7 @@ func (c *Conn) sendUDPStd(addr netip.AddrPort, b []byte) (sent bool, err error)
|
||||
// An example of when they might be different: sending to an
|
||||
// IPv6 address when the local machine doesn't have IPv6 support
|
||||
// returns (false, nil); it's not an error, but nothing was sent.
|
||||
func (c *Conn) sendAddr(addr netaddr.IPPort, pubKey key.NodePublic, b []byte) (sent bool, err error) {
|
||||
func (c *Conn) sendAddr(addr netip.AddrPort, pubKey key.NodePublic, b []byte) (sent bool, err error) {
|
||||
if addr.Addr() != derpMagicIPAddr {
|
||||
return c.sendUDP(addr, b)
|
||||
}
|
||||
@@ -1281,7 +1281,7 @@ const bufferedDerpWritesBeforeDrop = 32
|
||||
//
|
||||
// If peer is non-zero, it can be used to find an active reverse
|
||||
// path, without using addr.
|
||||
func (c *Conn) derpWriteChanOfAddr(addr netaddr.IPPort, peer key.NodePublic) chan<- derpWriteRequest {
|
||||
func (c *Conn) derpWriteChanOfAddr(addr netip.AddrPort, peer key.NodePublic) chan<- derpWriteRequest {
|
||||
if addr.Addr() != derpMagicIPAddr {
|
||||
return nil
|
||||
}
|
||||
@@ -1468,7 +1468,7 @@ type derpReadResult struct {
|
||||
|
||||
// runDerpReader runs in a goroutine for the life of a DERP
|
||||
// connection, handling received packets.
|
||||
func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netaddr.IPPort, dc *derphttp.Client, wg *syncs.WaitGroupChan, startGate <-chan struct{}) {
|
||||
func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netip.AddrPort, dc *derphttp.Client, wg *syncs.WaitGroupChan, startGate <-chan struct{}) {
|
||||
defer wg.Decr()
|
||||
defer dc.Close()
|
||||
|
||||
@@ -1599,7 +1599,7 @@ func (c *Conn) runDerpReader(ctx context.Context, derpFakeAddr netaddr.IPPort, d
|
||||
}
|
||||
|
||||
type derpWriteRequest struct {
|
||||
addr netaddr.IPPort
|
||||
addr netip.AddrPort
|
||||
pubKey key.NodePublic
|
||||
b []byte // copied; ownership passed to receiver
|
||||
}
|
||||
@@ -1666,9 +1666,9 @@ func (c *Conn) receiveIPv4(b []byte) (n int, ep conn.Endpoint, err error) {
|
||||
//
|
||||
// ok is whether this read should be reported up to wireguard-go (our
|
||||
// caller).
|
||||
func (c *Conn) receiveIP(b []byte, ipp netaddr.IPPort, cache *ippEndpointCache) (ep *endpoint, ok bool) {
|
||||
func (c *Conn) receiveIP(b []byte, ipp netip.AddrPort, cache *ippEndpointCache) (ep *endpoint, ok bool) {
|
||||
if stun.Is(b) {
|
||||
c.stunReceiveFunc.Load().(func([]byte, netaddr.IPPort))(b, ipp)
|
||||
c.stunReceiveFunc.Load().(func([]byte, netip.AddrPort))(b, ipp)
|
||||
return nil, false
|
||||
}
|
||||
if c.handleDiscoMessage(b, ipp, key.NodePublic{}) {
|
||||
@@ -1734,7 +1734,7 @@ func (c *Conn) processDERPReadResult(dm derpReadResult, b []byte) (n int, ep *en
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
ipp := netaddr.IPPortFrom(derpMagicIPAddr, uint16(regionID))
|
||||
ipp := netip.AddrPortFrom(derpMagicIPAddr, uint16(regionID))
|
||||
if c.handleDiscoMessage(b[:n], ipp, dm.src) {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -1771,7 +1771,7 @@ const (
|
||||
//
|
||||
// The dstKey should only be non-zero if the dstDisco key
|
||||
// unambiguously maps to exactly one peer.
|
||||
func (c *Conn) sendDiscoMessage(dst netaddr.IPPort, dstKey key.NodePublic, dstDisco key.DiscoPublic, m disco.Message, logLevel discoLogLevel) (sent bool, err error) {
|
||||
func (c *Conn) sendDiscoMessage(dst netip.AddrPort, dstKey key.NodePublic, dstDisco key.DiscoPublic, m disco.Message, logLevel discoLogLevel) (sent bool, err error) {
|
||||
c.mu.Lock()
|
||||
if c.closed {
|
||||
c.mu.Unlock()
|
||||
@@ -1842,7 +1842,7 @@ func (c *Conn) sendDiscoMessage(dst netaddr.IPPort, dstKey key.NodePublic, dstDi
|
||||
// src.Port() being the region ID) and the derpNodeSrc will be the node key
|
||||
// it was received from at the DERP layer. derpNodeSrc is zero when received
|
||||
// over UDP.
|
||||
func (c *Conn) handleDiscoMessage(msg []byte, src netaddr.IPPort, derpNodeSrc key.NodePublic) (isDiscoMsg bool) {
|
||||
func (c *Conn) handleDiscoMessage(msg []byte, src netip.AddrPort, derpNodeSrc key.NodePublic) (isDiscoMsg bool) {
|
||||
const headerLen = len(disco.Magic) + key.DiscoPublicRawLen
|
||||
if len(msg) < headerLen || string(msg[:len(disco.Magic)]) != disco.Magic {
|
||||
return false
|
||||
@@ -2012,7 +2012,7 @@ func (c *Conn) unambiguousNodeKeyOfPingLocked(dm *disco.Ping, dk key.DiscoPublic
|
||||
|
||||
// di is the discoInfo of the source of the ping.
|
||||
// derpNodeSrc is non-zero if the ping arrived via DERP.
|
||||
func (c *Conn) handlePingLocked(dm *disco.Ping, src netaddr.IPPort, di *discoInfo, derpNodeSrc key.NodePublic) {
|
||||
func (c *Conn) handlePingLocked(dm *disco.Ping, src netip.AddrPort, di *discoInfo, derpNodeSrc key.NodePublic) {
|
||||
likelyHeartBeat := src == di.lastPingFrom && time.Since(di.lastPingTime) < 5*time.Second
|
||||
di.lastPingFrom = src
|
||||
di.lastPingTime = time.Now()
|
||||
@@ -2089,7 +2089,7 @@ func (c *Conn) handlePingLocked(dm *disco.Ping, src netaddr.IPPort, di *discoInf
|
||||
// flipping primary DERPs in the 0-30ms it takes to confirm our STUN endpoint.
|
||||
// If they do, traffic will just go over DERP for a bit longer until the next
|
||||
// discovery round.
|
||||
func (c *Conn) enqueueCallMeMaybe(derpAddr netaddr.IPPort, de *endpoint) {
|
||||
func (c *Conn) enqueueCallMeMaybe(derpAddr netip.AddrPort, de *endpoint) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
@@ -2114,7 +2114,7 @@ func (c *Conn) enqueueCallMeMaybe(derpAddr netaddr.IPPort, de *endpoint) {
|
||||
return
|
||||
}
|
||||
|
||||
eps := make([]netaddr.IPPort, 0, len(c.lastEndpoints))
|
||||
eps := make([]netip.AddrPort, 0, len(c.lastEndpoints))
|
||||
for _, ep := range c.lastEndpoints {
|
||||
eps = append(eps, ep.Addr)
|
||||
}
|
||||
@@ -2347,7 +2347,7 @@ func (c *Conn) SetNetworkMap(nm *netmap.NetworkMap) {
|
||||
c: c,
|
||||
publicKey: n.Key,
|
||||
sentPing: map[stun.TxID]sentPing{},
|
||||
endpointState: map[netaddr.IPPort]*endpointState{},
|
||||
endpointState: map[netip.AddrPort]*endpointState{},
|
||||
}
|
||||
if !n.DiscoKey.IsZero() {
|
||||
ep.discoKey = n.DiscoKey
|
||||
@@ -2425,7 +2425,7 @@ func (c *Conn) closeAllDerpLocked(why string) {
|
||||
// maybeCloseDERPsOnRebind, in response to a rebind, closes all
|
||||
// DERP connections that don't have a local address in okayLocalIPs
|
||||
// and pings all those that do.
|
||||
func (c *Conn) maybeCloseDERPsOnRebind(okayLocalIPs []netaddr.IPPrefix) {
|
||||
func (c *Conn) maybeCloseDERPsOnRebind(okayLocalIPs []netip.Prefix) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
for regionID, ad := range c.activeDerp {
|
||||
@@ -2910,7 +2910,7 @@ func (c *Conn) Rebind() {
|
||||
return
|
||||
}
|
||||
|
||||
var ifIPs []netaddr.IPPrefix
|
||||
var ifIPs []netip.Prefix
|
||||
if c.linkMon != nil {
|
||||
st := c.linkMon.InterfaceState()
|
||||
defIf := st.DefaultRouteInterface
|
||||
@@ -2934,7 +2934,7 @@ func (c *Conn) resetEndpointStates() {
|
||||
}
|
||||
|
||||
// packIPPort packs an IPPort into the form wanted by WireGuard.
|
||||
func packIPPort(ua netaddr.IPPort) []byte {
|
||||
func packIPPort(ua netip.AddrPort) []byte {
|
||||
ip := ua.Addr().Unmap()
|
||||
a := ip.As16()
|
||||
ipb := a[:]
|
||||
@@ -3000,12 +3000,12 @@ func (c *RebindingUDPConn) ReadFrom(b []byte) (int, net.Addr, error) {
|
||||
|
||||
// ReadFromNetaddr reads a packet from c into b.
|
||||
// It returns the number of bytes copied and the return address.
|
||||
// It is identical to c.ReadFrom, except that it returns a netaddr.IPPort instead of a net.Addr.
|
||||
// It is identical to c.ReadFrom, except that it returns a netip.AddrPort instead of a net.Addr.
|
||||
// ReadFromNetaddr is designed to work with specific underlying connection types.
|
||||
// If c's underlying connection returns a non-*net.UPDAddr return address, ReadFromNetaddr will return an error.
|
||||
// ReadFromNetaddr exists because it removes an allocation per read,
|
||||
// when c's underlying connection is a net.UDPConn.
|
||||
func (c *RebindingUDPConn) ReadFromNetaddr(b []byte) (n int, ipp netaddr.IPPort, err error) {
|
||||
func (c *RebindingUDPConn) ReadFromNetaddr(b []byte) (n int, ipp netip.AddrPort, err error) {
|
||||
for {
|
||||
pconn := c.currentConn()
|
||||
|
||||
@@ -3019,12 +3019,12 @@ func (c *RebindingUDPConn) ReadFromNetaddr(b []byte) (n int, ipp netaddr.IPPort,
|
||||
n, addr, err = pconn.ReadFrom(b)
|
||||
pAddr, ok := addr.(*net.UDPAddr)
|
||||
if addr != nil && !ok {
|
||||
return 0, netaddr.IPPort{}, fmt.Errorf("RebindingUDPConn.ReadFromNetaddr: underlying connection returned address of type %T, want *netaddr.UDPAddr", addr)
|
||||
return 0, netip.AddrPort{}, fmt.Errorf("RebindingUDPConn.ReadFromNetaddr: underlying connection returned address of type %T, want *netaddr.UDPAddr", addr)
|
||||
}
|
||||
if pAddr != nil {
|
||||
ipp, ok = netaddr.FromStdAddr(pAddr.IP, pAddr.Port, pAddr.Zone)
|
||||
if !ok {
|
||||
return 0, netaddr.IPPort{}, errors.New("netaddr.FromStdAddr failed")
|
||||
return 0, netip.AddrPort{}, errors.New("netaddr.FromStdAddr failed")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3167,7 +3167,7 @@ func simpleDur(d time.Duration) time.Duration {
|
||||
return d.Round(time.Minute)
|
||||
}
|
||||
|
||||
func sbPrintAddr(sb *strings.Builder, a netaddr.IPPort) {
|
||||
func sbPrintAddr(sb *strings.Builder, a netip.AddrPort) {
|
||||
is6 := a.Addr().Is6()
|
||||
if is6 {
|
||||
sb.WriteByte('[')
|
||||
@@ -3205,9 +3205,9 @@ func (c *Conn) UpdateStatus(sb *ipnstate.StatusBuilder) {
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
var tailscaleIPs []netaddr.IP
|
||||
var tailscaleIPs []netip.Addr
|
||||
if c.netMap != nil {
|
||||
tailscaleIPs = make([]netaddr.IP, 0, len(c.netMap.Addresses))
|
||||
tailscaleIPs = make([]netip.Addr, 0, len(c.netMap.Addresses))
|
||||
for _, addr := range c.netMap.Addresses {
|
||||
if !addr.IsSingleIP() {
|
||||
continue
|
||||
@@ -3250,7 +3250,7 @@ func (c *Conn) UpdateStatus(sb *ipnstate.StatusBuilder) {
|
||||
})
|
||||
}
|
||||
|
||||
func ippDebugString(ua netaddr.IPPort) string {
|
||||
func ippDebugString(ua netip.AddrPort) string {
|
||||
if ua.Addr() == derpMagicIPAddr {
|
||||
return fmt.Sprintf("derp-%d", ua.Port())
|
||||
}
|
||||
@@ -3268,7 +3268,7 @@ type endpoint struct {
|
||||
// These fields are initialized once and never modified.
|
||||
c *Conn
|
||||
publicKey key.NodePublic // peer public key (for WireGuard + DERP)
|
||||
fakeWGAddr netaddr.IPPort // the UDP address we tell wireguard-go we're using
|
||||
fakeWGAddr netip.AddrPort // the UDP address we tell wireguard-go we're using
|
||||
wgEndpoint string // string from ParseEndpoint, holds a JSON-serialized wgcfg.Endpoints
|
||||
|
||||
// mu protects all following fields.
|
||||
@@ -3280,14 +3280,14 @@ type endpoint struct {
|
||||
heartBeatTimer *time.Timer // nil when idle
|
||||
lastSend mono.Time // last time there was outgoing packets sent to this peer (from wireguard-go)
|
||||
lastFullPing mono.Time // last time we pinged all endpoints
|
||||
derpAddr netaddr.IPPort // fallback/bootstrap path, if non-zero (non-zero for well-behaved clients)
|
||||
derpAddr netip.AddrPort // fallback/bootstrap path, if non-zero (non-zero for well-behaved clients)
|
||||
|
||||
bestAddr addrLatency // best non-DERP path; zero if none
|
||||
bestAddrAt mono.Time // time best address re-confirmed
|
||||
trustBestAddrUntil mono.Time // time when bestAddr expires
|
||||
sentPing map[stun.TxID]sentPing
|
||||
endpointState map[netaddr.IPPort]*endpointState
|
||||
isCallMeMaybeEP map[netaddr.IPPort]bool
|
||||
endpointState map[netip.AddrPort]*endpointState
|
||||
isCallMeMaybeEP map[netip.AddrPort]bool
|
||||
|
||||
pendingCLIPings []pendingCLIPing // any outstanding "tailscale ping" commands running
|
||||
}
|
||||
@@ -3390,9 +3390,9 @@ func (st *endpointState) shouldDeleteLocked() bool {
|
||||
}
|
||||
}
|
||||
|
||||
func (de *endpoint) deleteEndpointLocked(ep netaddr.IPPort) {
|
||||
func (de *endpoint) deleteEndpointLocked(ep netip.AddrPort) {
|
||||
delete(de.endpointState, ep)
|
||||
if de.bestAddr.IPPort == ep {
|
||||
if de.bestAddr.AddrPort == ep {
|
||||
de.bestAddr = addrLatency{}
|
||||
}
|
||||
}
|
||||
@@ -3403,12 +3403,12 @@ const pongHistoryCount = 64
|
||||
type pongReply struct {
|
||||
latency time.Duration
|
||||
pongAt mono.Time // when we received the pong
|
||||
from netaddr.IPPort // the pong's src (usually same as endpoint map key)
|
||||
pongSrc netaddr.IPPort // what they reported they heard
|
||||
from netip.AddrPort // the pong's src (usually same as endpoint map key)
|
||||
pongSrc netip.AddrPort // what they reported they heard
|
||||
}
|
||||
|
||||
type sentPing struct {
|
||||
to netaddr.IPPort
|
||||
to netip.AddrPort
|
||||
at mono.Time
|
||||
timer *time.Timer // timeout timer
|
||||
purpose discoPingPurpose
|
||||
@@ -3422,7 +3422,7 @@ func (de *endpoint) initFakeUDPAddr() {
|
||||
addr[0] = 0xfd
|
||||
addr[1] = 0x00
|
||||
binary.BigEndian.PutUint64(addr[2:], uint64(reflect.ValueOf(de).Pointer()))
|
||||
de.fakeWGAddr = netaddr.IPPortFrom(netaddr.IPFrom16(addr), 12345)
|
||||
de.fakeWGAddr = netip.AddrPortFrom(netaddr.IPFrom16(addr), 12345)
|
||||
}
|
||||
|
||||
// noteRecvActivity records receive activity on de, and invokes
|
||||
@@ -3467,8 +3467,8 @@ func (de *endpoint) canP2P() bool {
|
||||
// addr may be non-zero.
|
||||
//
|
||||
// de.mu must be held.
|
||||
func (de *endpoint) addrForSendLocked(now mono.Time) (udpAddr, derpAddr netaddr.IPPort) {
|
||||
udpAddr = de.bestAddr.IPPort
|
||||
func (de *endpoint) addrForSendLocked(now mono.Time) (udpAddr, derpAddr netip.AddrPort) {
|
||||
udpAddr = de.bestAddr.AddrPort
|
||||
if !udpAddr.IsValid() || now.After(de.trustBestAddrUntil) {
|
||||
// We had a bestAddr but it expired so send both to it
|
||||
// and DERP.
|
||||
@@ -3639,7 +3639,7 @@ func (de *endpoint) removeSentPingLocked(txid stun.TxID, sp sentPing) {
|
||||
//
|
||||
// The caller should use de.discoKey as the discoKey argument.
|
||||
// It is passed in so that sendDiscoPing doesn't need to lock de.mu.
|
||||
func (de *endpoint) sendDiscoPing(ep netaddr.IPPort, discoKey key.DiscoPublic, txid stun.TxID, logLevel discoLogLevel) {
|
||||
func (de *endpoint) sendDiscoPing(ep netip.AddrPort, discoKey key.DiscoPublic, txid stun.TxID, logLevel discoLogLevel) {
|
||||
selfPubKey, _ := de.c.publicKeyAtomic.Load().(key.NodePublic)
|
||||
sent, _ := de.c.sendDiscoMessage(ep, de.publicKey, discoKey, &disco.Ping{
|
||||
TxID: [12]byte(txid),
|
||||
@@ -3668,7 +3668,7 @@ const (
|
||||
pingCLI
|
||||
)
|
||||
|
||||
func (de *endpoint) startPingLocked(ep netaddr.IPPort, now mono.Time, purpose discoPingPurpose) {
|
||||
func (de *endpoint) startPingLocked(ep netip.AddrPort, now mono.Time, purpose discoPingPurpose) {
|
||||
if !de.canP2P() {
|
||||
panic("tried to disco ping a peer that can't disco")
|
||||
}
|
||||
@@ -3749,7 +3749,7 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node) {
|
||||
de.resetLocked()
|
||||
}
|
||||
if n.DERP == "" {
|
||||
de.derpAddr = netaddr.IPPort{}
|
||||
de.derpAddr = netip.AddrPort{}
|
||||
} else {
|
||||
de.derpAddr, _ = netip.ParseAddrPort(n.DERP)
|
||||
}
|
||||
@@ -3788,7 +3788,7 @@ func (de *endpoint) updateFromNode(n *tailcfg.Node) {
|
||||
//
|
||||
// This is called once we've already verified that we got a valid
|
||||
// discovery message from de via ep.
|
||||
func (de *endpoint) addCandidateEndpoint(ep netaddr.IPPort) {
|
||||
func (de *endpoint) addCandidateEndpoint(ep netip.AddrPort) {
|
||||
de.mu.Lock()
|
||||
defer de.mu.Unlock()
|
||||
|
||||
@@ -3833,7 +3833,7 @@ func (de *endpoint) noteConnectivityChange() {
|
||||
// It should be called with the Conn.mu held.
|
||||
//
|
||||
// It reports whether m.TxID corresponds to a ping that this endpoint sent.
|
||||
func (de *endpoint) handlePongConnLocked(m *disco.Pong, di *discoInfo, src netaddr.IPPort) (knownTxID bool) {
|
||||
func (de *endpoint) handlePongConnLocked(m *disco.Pong, di *discoInfo, src netip.AddrPort) (knownTxID bool) {
|
||||
de.mu.Lock()
|
||||
defer de.mu.Unlock()
|
||||
|
||||
@@ -3890,7 +3890,7 @@ func (de *endpoint) handlePongConnLocked(m *disco.Pong, di *discoInfo, src netad
|
||||
de.c.logf("magicsock: disco: node %v %v now using %v", de.publicKey.ShortString(), de.discoShort, sp.to)
|
||||
de.bestAddr = thisPong
|
||||
}
|
||||
if de.bestAddr.IPPort == thisPong.IPPort {
|
||||
if de.bestAddr.AddrPort == thisPong.AddrPort {
|
||||
de.bestAddr.latency = latency
|
||||
de.bestAddrAt = now
|
||||
de.trustBestAddrUntil = now.Add(trustUDPAddrDuration)
|
||||
@@ -3901,13 +3901,13 @@ func (de *endpoint) handlePongConnLocked(m *disco.Pong, di *discoInfo, src netad
|
||||
|
||||
// addrLatency is an IPPort with an associated latency.
|
||||
type addrLatency struct {
|
||||
netaddr.IPPort
|
||||
netip.AddrPort
|
||||
latency time.Duration
|
||||
}
|
||||
|
||||
// betterAddr reports whether a is a better addr to use than b.
|
||||
func betterAddr(a, b addrLatency) bool {
|
||||
if a.IPPort == b.IPPort {
|
||||
if a.AddrPort == b.AddrPort {
|
||||
return false
|
||||
}
|
||||
if !b.IsValid() {
|
||||
@@ -3965,7 +3965,7 @@ func (de *endpoint) handleCallMeMaybe(m *disco.CallMeMaybe) {
|
||||
for ep := range de.isCallMeMaybeEP {
|
||||
de.isCallMeMaybeEP[ep] = false // mark for deletion
|
||||
}
|
||||
var newEPs []netaddr.IPPort
|
||||
var newEPs []netip.AddrPort
|
||||
for _, ep := range m.MyNumber {
|
||||
if ep.Addr().Is6() && ep.Addr().IsLinkLocalUnicast() {
|
||||
// We send these out, but ignore them for now.
|
||||
@@ -4074,9 +4074,9 @@ func (de *endpoint) numStopAndReset() int64 {
|
||||
func derpStr(s string) string { return strings.ReplaceAll(s, "127.3.3.40:", "derp-") }
|
||||
|
||||
// ippEndpointCache is a mutex-free single-element cache, mapping from
|
||||
// a single netaddr.IPPort to a single endpoint.
|
||||
// a single netip.AddrPort to a single endpoint.
|
||||
type ippEndpointCache struct {
|
||||
ipp netaddr.IPPort
|
||||
ipp netip.AddrPort
|
||||
gen int64
|
||||
de *endpoint
|
||||
}
|
||||
@@ -4107,7 +4107,7 @@ type discoInfo struct {
|
||||
// Mutable fields follow, owned by Conn.mu:
|
||||
|
||||
// lastPingFrom is the src of a ping for discoKey.
|
||||
lastPingFrom netaddr.IPPort
|
||||
lastPingFrom netip.AddrPort
|
||||
|
||||
// lastPingTime is the last time of a ping for discoKey.
|
||||
lastPingTime time.Time
|
||||
|
Reference in New Issue
Block a user