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 <dgentry@tailscale.com>
pull/8233/head
Denton Gentry 2 years ago committed by Denton Gentry
parent c0b4a54146
commit 399a80785e

@ -622,11 +622,21 @@ func (ns *Impl) userPing(dstIP netip.Addr, pingResPkt []byte) {
switch runtime.GOOS { switch runtime.GOOS {
case "windows": case "windows":
err = exec.Command("ping", "-n", "1", "-w", "3000", dstIP.String()).Run() 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 // Note: 2000 ms is actually 1 second + 2,000
// milliseconds extra for 3 seconds total. // milliseconds extra for 3 seconds total.
// See https://github.com/tailscale/tailscale/pull/3753 for details. // 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": case "android":
ping := "/system/bin/ping" ping := "/system/bin/ping"
if dstIP.Is6() { if dstIP.Is6() {

Loading…
Cancel
Save