mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-07 05:06:30 +02:00
Fixes #19633 Fixes #13760 Change-Id: I0fa9423523a3a0fb1dfcde57de0f26e51723ff97 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
36 lines
918 B
Go
36 lines
918 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build darwin || ios
|
|
|
|
package netstack
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/netip"
|
|
"time"
|
|
|
|
"tailscale.com/net/ping"
|
|
)
|
|
|
|
// sendOutboundUserPing sends a non-privileged ICMP (or ICMPv6) ping to dstIP with the given timeout.
|
|
func (ns *Impl) sendOutboundUserPing(dstIP netip.Addr, timeout time.Duration) error {
|
|
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
|
defer cancel()
|
|
|
|
p := ping.New(ctx, ns.logf, nil)
|
|
p.Unprivileged = true
|
|
defer p.Close()
|
|
|
|
dst := &net.IPAddr{IP: dstIP.AsSlice(), Zone: dstIP.Zone()}
|
|
ns.logf("sendOutboundUserPing: forwarding ping to %s", dstIP)
|
|
d, err := p.Send(ctx, dst, []byte("tailscale-userping"))
|
|
if err != nil {
|
|
ns.logf("sendOutboundUserPing: ping to %s failed: %v", dstIP, err)
|
|
return err
|
|
}
|
|
ns.logf("sendOutboundUserPing: pong from %s in %v", dstIP, d)
|
|
return nil
|
|
}
|