mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 23:17:29 +00:00
go.mod,wgengine/magicsock: implement conn.InitiationAwareEndpoint (#16486)
Since a [*lazyEndpoint] makes wireguard-go responsible for peer ID, but wireguard-go may not yet be configured for said peer, we need a JIT hook around initiation message reception to call what is usually called from an [*endpoint]. Updates tailscale/corp#30042 Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
2
go.mod
2
go.mod
@@ -90,7 +90,7 @@ require (
|
||||
github.com/tailscale/setec v0.0.0-20250205144240-8898a29c3fbb
|
||||
github.com/tailscale/web-client-prebuilt v0.0.0-20250124233751-d4cd19a26976
|
||||
github.com/tailscale/wf v0.0.0-20240214030419-6fbb0a674ee6
|
||||
github.com/tailscale/wireguard-go v0.0.0-20250701223756-24483d7a0003
|
||||
github.com/tailscale/wireguard-go v0.0.0-20250707220504-1f398ae148a8
|
||||
github.com/tailscale/xnet v0.0.0-20240729143630-8497ac4dab2e
|
||||
github.com/tc-hib/winres v0.2.1
|
||||
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/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/wireguard-go v0.0.0-20250701223756-24483d7a0003 h1:chIzUDKxR0nXQQra0j41aqiiFNICs0FIC5ZCwDO7z3k=
|
||||
github.com/tailscale/wireguard-go v0.0.0-20250701223756-24483d7a0003/go.mod h1:BOm5fXUBFM+m9woLNBoxI9TaBXXhGNP50LX/TGIvGb4=
|
||||
github.com/tailscale/wireguard-go v0.0.0-20250707220504-1f398ae148a8 h1:Yjg/+1VVRcdY3DL9fs8g+QnZ1aizotU0pp0VSOSCuTQ=
|
||||
github.com/tailscale/wireguard-go v0.0.0-20250707220504-1f398ae148a8/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/go.mod h1:orPd6JZXXRyuDusYilywte7k094d7dycXXU5YnWsrwg=
|
||||
github.com/tc-hib/winres v0.2.1 h1:YDE0FiP0VmtRaDn7+aaChp1KiF4owBiJa5l964l5ujA=
|
||||
|
@@ -3777,17 +3777,45 @@ func (c *Conn) SetLastNetcheckReportForTest(ctx context.Context, report *netchec
|
||||
// lazyEndpoint is a wireguard [conn.Endpoint] for when magicsock received a
|
||||
// non-disco (presumably WireGuard) packet from a UDP address from which we
|
||||
// can't map to a Tailscale peer. But WireGuard most likely can, once it
|
||||
// decrypts it. So we implement the [conn.PeerAwareEndpoint] interface
|
||||
// from https://github.com/tailscale/wireguard-go/pull/27 to allow WireGuard
|
||||
// to tell us who it is later and get the correct [conn.Endpoint].
|
||||
// decrypts it. So we implement the [conn.InitiationAwareEndpoint] and
|
||||
// [conn.PeerAwareEndpoint] interfaces, to allow WireGuard to tell us who it is
|
||||
// later, just-in-time to configure the peer, and set the associated [epAddr]
|
||||
// in the [peerMap]. Future receives on the associated [epAddr] will then be
|
||||
// resolvable directly to an [*endpoint].
|
||||
type lazyEndpoint struct {
|
||||
c *Conn
|
||||
src epAddr
|
||||
}
|
||||
|
||||
var _ conn.InitiationAwareEndpoint = (*lazyEndpoint)(nil)
|
||||
var _ conn.PeerAwareEndpoint = (*lazyEndpoint)(nil)
|
||||
var _ conn.Endpoint = (*lazyEndpoint)(nil)
|
||||
|
||||
// InitiationMessagePublicKey implements [conn.InitiationAwareEndpoint].
|
||||
// wireguard-go calls us here if we passed it a [*lazyEndpoint] for an
|
||||
// initiation message, for which it might not have the relevant peer configured,
|
||||
// enabling us to just-in-time configure it and note its activity via
|
||||
// [*endpoint.noteRecvActivity], before it performs peer lookup and attempts
|
||||
// decryption.
|
||||
//
|
||||
// Reception of all other WireGuard message types implies pre-existing knowledge
|
||||
// of the peer by wireguard-go for it to do useful work. See
|
||||
// [userspaceEngine.maybeReconfigWireguardLocked] &
|
||||
// [userspaceEngine.noteRecvActivity] for more details around just-in-time
|
||||
// wireguard-go peer (de)configuration.
|
||||
func (le *lazyEndpoint) InitiationMessagePublicKey(peerPublicKey [32]byte) {
|
||||
pubKey := key.NodePublicFromRaw32(mem.B(peerPublicKey[:]))
|
||||
le.c.mu.Lock()
|
||||
defer le.c.mu.Unlock()
|
||||
ep, ok := le.c.peerMap.endpointForNodeKey(pubKey)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
now := mono.Now()
|
||||
ep.lastRecvUDPAny.StoreAtomic(now)
|
||||
ep.noteRecvActivity(le.src, now)
|
||||
}
|
||||
|
||||
func (le *lazyEndpoint) ClearSrc() {}
|
||||
func (le *lazyEndpoint) SrcIP() netip.Addr { return netip.Addr{} }
|
||||
|
||||
|
Reference in New Issue
Block a user