Files
coder/codersdk/healthsdk/interfaces.go
Ethan 6e7f65bc59 fix(cli): properly handle build log streaming during coder ping (#15600)
Closes #15584.

- The `Collecting Diagnostics` spinner now starts after the workspace
build logs (if any) have finished streaming.
- Removes network interfaces with negative MTUs from `healthsdk`
diagnostics.
- Improves the wording on diagnostics for MTUs below the 'safe' value to
indicate that direct connections may be degraded, or rendered unusable
(i.e. if every packet is dropped).
2024-11-20 15:50:12 +11:00

84 lines
2.2 KiB
Go

package healthsdk
import (
"net"
"tailscale.com/net/interfaces"
"github.com/coder/coder/v2/coderd/healthcheck/health"
)
// gVisor is nominally permitted to send packets up to 1280.
// Wireguard adds 30 bytes (1310)
// UDP adds 8 bytes (1318)
// IP adds 20-60 bytes (1338-1378)
// So, it really needs to be 1378 to be totally safe
const safeMTU = 1378
// @typescript-ignore InterfacesReport
type InterfacesReport struct {
BaseReport
Interfaces []Interface `json:"interfaces"`
}
// @typescript-ignore Interface
type Interface struct {
Name string `json:"name"`
MTU int `json:"mtu"`
Addresses []string `json:"addresses"`
}
func RunInterfacesReport() (InterfacesReport, error) {
st, err := interfaces.GetState()
if err != nil {
return InterfacesReport{}, err
}
return generateInterfacesReport(st), nil
}
func generateInterfacesReport(st *interfaces.State) (report InterfacesReport) {
report.Severity = health.SeverityOK
for name, iface := range st.Interface {
// macOS has a ton of random interfaces, so to keep things helpful, let's filter out any
// that:
//
// - are not enabled
// - don't have any addresses
// - have only link-local addresses (e.g. fe80:...)
if (iface.Flags & net.FlagUp) == 0 {
continue
}
addrs := st.InterfaceIPs[name]
if len(addrs) == 0 {
continue
}
var r bool
healthIface := Interface{
Name: iface.Name,
MTU: iface.MTU,
}
for _, addr := range addrs {
healthIface.Addresses = append(healthIface.Addresses, addr.String())
if addr.Addr().IsLinkLocalUnicast() || addr.Addr().IsLinkLocalMulticast() {
continue
}
r = true
}
if !r {
continue
}
report.Interfaces = append(report.Interfaces, healthIface)
// Some loopback interfaces on Windows have a negative MTU, which we can
// safely ignore in diagnostics.
if iface.MTU > 0 && iface.MTU < safeMTU {
report.Severity = health.SeverityWarning
report.Warnings = append(report.Warnings,
health.Messagef(health.CodeInterfaceSmallMTU,
"Network interface %s has MTU %d (less than %d), which may degrade the quality of direct "+
"connections or render them unusable.", iface.Name, iface.MTU, safeMTU),
)
}
}
return report
}