feat(cli): add p2p diagnostics to ping (#14426)

First PR to address #14244.

Adds common potential reasons as to why a direct connection to the workspace agent couldn't be established to `coder ping`:
- If the Coder deployment administrator has blocked direction connections (`CODER_BLOCK_DIRECT`).
- If the client has no STUN servers within it's DERP map.
- If the client or agent appears to be behind a hard NAT, as per Tailscale `netInfo.MappingVariesByDestIP`

Also adds a warning if the client or agent has a network interface below the 'safe' MTU for tailnet. This warning is always displayed at the end of a `coder ping`.
This commit is contained in:
Ethan
2024-08-28 15:39:01 +10:00
committed by GitHub
parent b36d979a60
commit 8c15192433
8 changed files with 298 additions and 5 deletions

View File

@ -294,6 +294,9 @@ func NewConn(options *Options) (conn *Conn, err error) {
}()
if server.telemetryStore != nil {
server.wireguardEngine.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
server.mutex.Lock()
server.lastNetInfo = ni.Clone()
server.mutex.Unlock()
server.telemetryStore.setNetInfo(ni)
nodeUp.setNetInfo(ni)
server.telemetryStore.pingPeer(server)
@ -304,7 +307,12 @@ func NewConn(options *Options) (conn *Conn, err error) {
})
go server.watchConnChange()
} else {
server.wireguardEngine.SetNetInfoCallback(nodeUp.setNetInfo)
server.wireguardEngine.SetNetInfoCallback(func(ni *tailcfg.NetInfo) {
server.mutex.Lock()
server.lastNetInfo = ni.Clone()
server.mutex.Unlock()
nodeUp.setNetInfo(ni)
})
}
server.wireguardEngine.SetStatusCallback(nodeUp.setStatus)
server.magicConn.SetDERPForcedWebsocketCallback(nodeUp.setDERPForcedWebsocket)
@ -373,6 +381,13 @@ type Conn struct {
watchCancel func()
trafficStats *connstats.Statistics
lastNetInfo *tailcfg.NetInfo
}
func (c *Conn) GetNetInfo() *tailcfg.NetInfo {
c.mutex.Lock()
defer c.mutex.Unlock()
return c.lastNetInfo.Clone()
}
func (c *Conn) SetTunnelDestination(id uuid.UUID) {