mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-08 07:07:21 +02:00
wgengine/magicsock: make lazyEndpoint load bearing for UDP relay (#16435)
Cryptokey Routing identification is now required to set an [epAddr] into the peerMap for Geneve-encapsulated [epAddr]s. Updates tailscale/corp#27502 Updates tailscale/corp#29422 Updates tailscale/corp#30042 Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
parent
172e26b3e3
commit
f9e7131772
2
go.mod
2
go.mod
@ -90,7 +90,7 @@ require (
|
|||||||
github.com/tailscale/setec v0.0.0-20250205144240-8898a29c3fbb
|
github.com/tailscale/setec v0.0.0-20250205144240-8898a29c3fbb
|
||||||
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976
|
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976
|
||||||
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6
|
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6
|
||||||
github.com/tailscale/wireguard-go v0.0.0-20250530210235-65cd6eed7d7f
|
github.com/tailscale/wireguard-go v0.0.0-20250701223756-24483d7a0003
|
||||||
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e
|
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e
|
||||||
github.com/tc-hib/winres v0.2.1
|
github.com/tc-hib/winres v0.2.1
|
||||||
github.com/tcnksm/go-httpstat v0.2.0
|
github.com/tcnksm/go-httpstat v0.2.0
|
||||||
|
4
go.sum
4
go.sum
@ -975,8 +975,8 @@ github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976 h1:U
|
|||||||
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976/go.mod h1:agQPE6y6ldqCOui2gkIh7ZMztTkIQKH049tv8siLuNQ=
|
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976/go.mod h1:agQPE6y6ldqCOui2gkIh7ZMztTkIQKH049tv8siLuNQ=
|
||||||
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6 h1:l10Gi6w9jxvinoiq15g8OToDdASBni4CyJOdHY1Hr8M=
|
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6 h1:l10Gi6w9jxvinoiq15g8OToDdASBni4CyJOdHY1Hr8M=
|
||||||
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6/go.mod h1:ZXRML051h7o4OcI0d3AaILDIad/Xw0IkXaHM17dic1Y=
|
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6/go.mod h1:ZXRML051h7o4OcI0d3AaILDIad/Xw0IkXaHM17dic1Y=
|
||||||
github.com/tailscale/wireguard-go v0.0.0-20250530210235-65cd6eed7d7f h1:vg3PmQdq1BbB2V81iC1VBICQtfwbVGZ/4A/p7QKXTK0=
|
github.com/tailscale/wireguard-go v0.0.0-20250701223756-24483d7a0003 h1:chIzUDKxR0nXQQra0j41aqiiFNICs0FIC5ZCwDO7z3k=
|
||||||
github.com/tailscale/wireguard-go v0.0.0-20250530210235-65cd6eed7d7f/go.mod h1:BOm5fXUBFM+m9woLNBoxI9TaBXXhGNP50LX/TGIvGb4=
|
github.com/tailscale/wireguard-go v0.0.0-20250701223756-24483d7a0003/go.mod h1:BOm5fXUBFM+m9woLNBoxI9TaBXXhGNP50LX/TGIvGb4=
|
||||||
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e h1:zOGKqN5D5hHhiYUp091JqK7DPCqSARyUfduhGUY8Bek=
|
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e h1:zOGKqN5D5hHhiYUp091JqK7DPCqSARyUfduhGUY8Bek=
|
||||||
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e/go.mod h1:orPd6JZXXRyuDusYilywte7k094d7dycXXU5YnWsrwg=
|
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e/go.mod h1:orPd6JZXXRyuDusYilywte7k094d7dycXXU5YnWsrwg=
|
||||||
github.com/tc-hib/winres v0.2.1 h1:YDE0FiP0VmtRaDn7+aaChp1KiF4owBiJa5l964l5ujA=
|
github.com/tc-hib/winres v0.2.1 h1:YDE0FiP0VmtRaDn7+aaChp1KiF4owBiJa5l964l5ujA=
|
||||||
|
@ -126,7 +126,6 @@ func (de *endpoint) udpRelayEndpointReady(maybeBest addrQuality) {
|
|||||||
de.c.logf("magicsock: disco: node %v %v now using %v mtu=%v", de.publicKey.ShortString(), de.discoShort(), maybeBest.epAddr, maybeBest.wireMTU)
|
de.c.logf("magicsock: disco: node %v %v now using %v mtu=%v", de.publicKey.ShortString(), de.discoShort(), maybeBest.epAddr, maybeBest.wireMTU)
|
||||||
de.setBestAddrLocked(maybeBest)
|
de.setBestAddrLocked(maybeBest)
|
||||||
de.trustBestAddrUntil = mono.Now().Add(trustUDPAddrDuration)
|
de.trustBestAddrUntil = mono.Now().Add(trustUDPAddrDuration)
|
||||||
de.c.peerMap.setNodeKeyForEpAddr(maybeBest.epAddr, de.publicKey)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (de *endpoint) setBestAddrLocked(v addrQuality) {
|
func (de *endpoint) setBestAddrLocked(v addrQuality) {
|
||||||
|
@ -1695,8 +1695,13 @@ func (c *Conn) receiveIP(b []byte, ipp netip.AddrPort, cache *epAddrEndpointCach
|
|||||||
c.mu.Unlock()
|
c.mu.Unlock()
|
||||||
if !ok {
|
if !ok {
|
||||||
if c.controlKnobs != nil && c.controlKnobs.DisableCryptorouting.Load() {
|
if c.controlKnobs != nil && c.controlKnobs.DisableCryptorouting.Load() {
|
||||||
|
// Note: UDP relay is dependent on cryptorouting enablement. We
|
||||||
|
// only update Geneve-encapsulated [epAddr]s in the [peerMap]
|
||||||
|
// via [lazyEndpoint].
|
||||||
return nil, 0, false
|
return nil, 0, false
|
||||||
}
|
}
|
||||||
|
// TODO(jwhited): reuse [lazyEndpoint] across calls to receiveIP()
|
||||||
|
// for the same batch & [epAddr] src.
|
||||||
return &lazyEndpoint{c: c, src: src}, size, true
|
return &lazyEndpoint{c: c, src: src}, size, true
|
||||||
}
|
}
|
||||||
cache.epAddr = src
|
cache.epAddr = src
|
||||||
@ -1704,6 +1709,8 @@ func (c *Conn) receiveIP(b []byte, ipp netip.AddrPort, cache *epAddrEndpointCach
|
|||||||
cache.gen = de.numStopAndReset()
|
cache.gen = de.numStopAndReset()
|
||||||
ep = de
|
ep = de
|
||||||
}
|
}
|
||||||
|
// TODO(jwhited): consider the implications of not recording this receive
|
||||||
|
// activity due to an early [lazyEndpoint] return above.
|
||||||
now := mono.Now()
|
now := mono.Now()
|
||||||
ep.lastRecvUDPAny.StoreAtomic(now)
|
ep.lastRecvUDPAny.StoreAtomic(now)
|
||||||
ep.noteRecvActivity(src, now)
|
ep.noteRecvActivity(src, now)
|
||||||
@ -3793,14 +3800,27 @@ func (le *lazyEndpoint) DstIP() netip.Addr { return netip.Addr{} }
|
|||||||
func (le *lazyEndpoint) SrcToString() string { return le.src.String() }
|
func (le *lazyEndpoint) SrcToString() string { return le.src.String() }
|
||||||
func (le *lazyEndpoint) DstToString() string { return "dst" }
|
func (le *lazyEndpoint) DstToString() string { return "dst" }
|
||||||
func (le *lazyEndpoint) DstToBytes() []byte { return nil }
|
func (le *lazyEndpoint) DstToBytes() []byte { return nil }
|
||||||
func (le *lazyEndpoint) GetPeerEndpoint(peerPublicKey [32]byte) conn.Endpoint {
|
|
||||||
|
// FromPeer implements [conn.PeerAwareEndpoint]. We return a [*lazyEndpoint] in
|
||||||
|
// our [conn.ReceiveFunc]s when we are unable to identify the peer at WireGuard
|
||||||
|
// packet reception time, pre-decryption. If wireguard-go successfully decrypts
|
||||||
|
// the packet it calls us here, and we update our [peerMap] in order to
|
||||||
|
// associate le.src with peerPublicKey.
|
||||||
|
func (le *lazyEndpoint) FromPeer(peerPublicKey [32]byte) {
|
||||||
pubKey := key.NodePublicFromRaw32(mem.B(peerPublicKey[:]))
|
pubKey := key.NodePublicFromRaw32(mem.B(peerPublicKey[:]))
|
||||||
le.c.mu.Lock()
|
le.c.mu.Lock()
|
||||||
defer le.c.mu.Unlock()
|
defer le.c.mu.Unlock()
|
||||||
ep, ok := le.c.peerMap.endpointForNodeKey(pubKey)
|
ep, ok := le.c.peerMap.endpointForNodeKey(pubKey)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
le.c.logf("magicsock: lazyEndpoint.GetPeerEndpoint(%v) found: %v", pubKey.ShortString(), ep.nodeAddr)
|
// TODO(jwhited): Consider [lazyEndpoint] effectiveness as a means to make
|
||||||
return ep
|
// this the sole call site for setNodeKeyForEpAddr. If this is the sole
|
||||||
|
// call site, and we always update the mapping based on successful
|
||||||
|
// Cryptokey Routing identification events, then we can go ahead and make
|
||||||
|
// [epAddr]s singular per peer (like they are for Geneve-encapsulated ones
|
||||||
|
// already).
|
||||||
|
// See http://go/corp/29422 & http://go/corp/30042
|
||||||
|
le.c.peerMap.setNodeKeyForEpAddr(le.src, pubKey)
|
||||||
|
le.c.logf("magicsock: lazyEndpoint.FromPeer(%v) setting epAddr(%v) in peerMap for node(%v)", pubKey.ShortString(), le.src, ep.nodeAddr)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user