From 399a80785e9968a3b0007c5ab3d20a339d18377e Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Sat, 27 May 2023 22:47:38 -0700 Subject: [PATCH] wgengine/netstack: use ping6 on BSD platforms Various BSD-derived operating systems including macOS and FreeBSD require that ping6 be used for IPv6 destinations. The "ping" command does not understand an IPv6 destination. FreeBSD 13.x and later do handle IPv6 in the regular ping command, but also retain a ping6 command. We use ping6 on all versions of FreeBSD. Fixes https://github.com/tailscale/tailscale/issues/8225 Signed-off-by: Denton Gentry --- wgengine/netstack/netstack.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wgengine/netstack/netstack.go b/wgengine/netstack/netstack.go index 3457065db..7514fee5a 100644 --- a/wgengine/netstack/netstack.go +++ b/wgengine/netstack/netstack.go @@ -622,11 +622,21 @@ func (ns *Impl) userPing(dstIP netip.Addr, pingResPkt []byte) { switch runtime.GOOS { case "windows": err = exec.Command("ping", "-n", "1", "-w", "3000", dstIP.String()).Run() - case "darwin": + case "darwin", "freebsd": // 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() + ping := "ping" + if dstIP.Is6() { + ping = "ping6" + } + err = exec.Command(ping, "-c", "1", "-W", "2000", dstIP.String()).Run() + case "openbsd": + ping := "ping" + if dstIP.Is6() { + ping = "ping6" + } + err = exec.Command(ping, "-c", "1", "-w", "3", dstIP.String()).Run() case "android": ping := "/system/bin/ping" if dstIP.Is6() {