@ -116,19 +116,19 @@ type userspaceEngine struct {
pingers map [ wgkey . Key ] * pinger // legacy pingers for pre-discovery peers
pingers map [ wgkey . Key ] * pinger // legacy pingers for pre-discovery peers
pendOpen map [ flowtrack . Tuple ] * pendingOpenFlow // see pendopen.go
pendOpen map [ flowtrack . Tuple ] * pendingOpenFlow // see pendopen.go
networkMapCallbacks map [ * someHandle ] NetworkMapCallback
networkMapCallbacks map [ * someHandle ] NetworkMapCallback
tsIPByIPPort map [ netaddr . IPPort ] netaddr . IP // allows registration of IP:ports as belonging to a certain Tailscale IP for whois lookups
tsIPByIPPort map [ netaddr . IPPort ] netaddr . IP // allows registration of IP:ports as belonging to a certain Tailscale IP for whois lookups
pongCallback map [ [ 8 ] byte ] func ( ) // for TSMP pong responses
pongCallback map [ [ 8 ] byte ] func ( packet . TSMPPongReply ) // for TSMP pong responses
// Lock ordering: magicsock.Conn.mu, wgLock, then mu.
// Lock ordering: magicsock.Conn.mu, wgLock, then mu.
}
}
// InternalsGetter is implemented by Engines that can export their internals.
// InternalsGetter is implemented by Engines that can export their internals.
type InternalsGetter interface {
type InternalsGetter interface {
GetInternals ( ) ( * tstun . Wrapper , * magicsock . Conn )
GetInternals ( ) ( _ * tstun . Wrapper , _ * magicsock . Conn , ok bool )
}
}
func ( e * userspaceEngine ) GetInternals ( ) ( * tstun . Wrapper , * magicsock . Conn ) {
func ( e * userspaceEngine ) GetInternals ( ) ( _ * tstun . Wrapper , _ * magicsock . Conn , ok bool ) {
return e . tundev , e . magicConn
return e . tundev , e . magicConn , true
}
}
// Config is the engine configuration.
// Config is the engine configuration.
@ -310,13 +310,13 @@ func NewUserspaceEngine(logf logger.Logf, conf Config) (_ Engine, reterr error)
SkipBindUpdate : true ,
SkipBindUpdate : true ,
}
}
e . tundev . OnTSMPPongReceived = func ( data [ 8 ] byte ) {
e . tundev . OnTSMPPongReceived = func ( pong packet . TSMPPongReply ) {
e . mu . Lock ( )
e . mu . Lock ( )
defer e . mu . Unlock ( )
defer e . mu . Unlock ( )
cb := e . pongCallback [ d ata]
cb := e . pongCallback [ pong. D ata]
e . logf ( "wgengine: got TSMP pong %02x ; cb=%v", data , cb != nil )
e . logf ( "wgengine: got TSMP pong %02x , peerAPIPort=%v; cb=%v", pong . Data , pong . PeerAPIPort , cb != nil )
if cb != nil {
if cb != nil {
go cb ( )
go cb ( pong )
}
}
}
}
@ -1389,12 +1389,13 @@ func (e *userspaceEngine) sendTSMPPing(ip netaddr.IP, peer *tailcfg.Node, res *i
e . setTSMPPongCallback ( data , nil )
e . setTSMPPongCallback ( data , nil )
} )
} )
t0 := time . Now ( )
t0 := time . Now ( )
e . setTSMPPongCallback ( data , func ( ) {
e . setTSMPPongCallback ( data , func ( pong packet . TSMPPongReply ) {
expireTimer . Stop ( )
expireTimer . Stop ( )
d := time . Since ( t0 )
d := time . Since ( t0 )
res . LatencySeconds = d . Seconds ( )
res . LatencySeconds = d . Seconds ( )
res . NodeIP = ip . String ( )
res . NodeIP = ip . String ( )
res . NodeName = peer . ComputedName
res . NodeName = peer . ComputedName
res . PeerAPIPort = pong . PeerAPIPort
cb ( res )
cb ( res )
} )
} )
@ -1406,11 +1407,11 @@ func (e *userspaceEngine) sendTSMPPing(ip netaddr.IP, peer *tailcfg.Node, res *i
e . tundev . InjectOutbound ( tsmpPing )
e . tundev . InjectOutbound ( tsmpPing )
}
}
func ( e * userspaceEngine ) setTSMPPongCallback ( data [ 8 ] byte , cb func ( ) ) {
func ( e * userspaceEngine ) setTSMPPongCallback ( data [ 8 ] byte , cb func ( packet . TSMPPongReply ) ) {
e . mu . Lock ( )
e . mu . Lock ( )
defer e . mu . Unlock ( )
defer e . mu . Unlock ( )
if e . pongCallback == nil {
if e . pongCallback == nil {
e . pongCallback = map [ [ 8 ] byte ] func ( ) { }
e . pongCallback = map [ [ 8 ] byte ] func ( packet . TSMPPongReply ) { }
}
}
if cb == nil {
if cb == nil {
delete ( e . pongCallback , data )
delete ( e . pongCallback , data )