From 6be48dfcc611aa9a947fca2184696cbebb91dd90 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 17 Jan 2022 13:46:51 -0800 Subject: [PATCH] wgengine/netstack: fix netstack ping timeout on darwin -W is milliseconds on darwin, not seconds, and empirically it's milliseconds after a 1 second base. Change-Id: I2520619e6699d9c505d9645ce4dfee4973555227 Signed-off-by: Brad Fitzpatrick --- wgengine/netstack/netstack.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go index 3022ba520..9c30185f0 100644 --- a/wgengine/netstack/netstack.go +++ b/wgengine/netstack/netstack.go @@ -426,6 +426,11 @@ func (ns *Impl) userPing(dstIP netaddr.IP, pingResPkt []byte) { switch runtime.GOOS { case "windows": err = exec.Command("ping", "-n", "1", "-w", "3000", dstIP.String()).Run() + case "darwin": + // Note: 2000 ms is actually 1 second + 2,000 + // milliseconds extra for 3 seconds total. + // See https://github.com/tailscale/tailscale/pull/3753 for details. + err = exec.Command("ping", "-c", "1", "-W", "2000", dstIP.String()).Run() case "android": ping := "/system/bin/ping" if dstIP.Is6() { @@ -447,7 +452,15 @@ func (ns *Impl) userPing(dstIP netaddr.IP, pingResPkt []byte) { } d := time.Since(t0) if err != nil { - ns.logf("exec ping of %v failed in %v: %v", dstIP, d, err) + if d < time.Second/2 { + // If it failed quicker than the 3 second + // timeout we gave above (500 ms is a + // reasonable threshold), then assume the ping + // failed for problems finding/running + // ping. We don't want to log if the host is + // just down. + ns.logf("exec ping of %v failed in %v: %v", dstIP, d, err) + } return } if debugNetstack {