mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-14 23:17:29 +00:00
prober: perform DERP bandwidth probes over TUN device to mimic real client
Updates tailscale/corp#24635 Co-authored-by: Mario Minardi <mario@tailscale.com> Signed-off-by: Percy Wegmann <percy@tailscale.com>
This commit is contained in:

committed by
Percy Wegmann

parent
aa04f61d5e
commit
1ed9bd76d6
35
prober/tun_darwin.go
Normal file
35
prober/tun_darwin.go
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build darwin
|
||||
|
||||
package prober
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"os/exec"
|
||||
|
||||
"go4.org/netipx"
|
||||
)
|
||||
|
||||
const tunName = "utun"
|
||||
|
||||
func configureTUN(addr netip.Prefix, tunname string) error {
|
||||
cmd := exec.Command("ifconfig", tunname, "inet", addr.String(), addr.Addr().String())
|
||||
res, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add address: %w (%s)", err, string(res))
|
||||
}
|
||||
|
||||
net := netipx.PrefixIPNet(addr)
|
||||
nip := net.IP.Mask(net.Mask)
|
||||
nstr := fmt.Sprintf("%v/%d", nip, addr.Bits())
|
||||
cmd = exec.Command("route", "-q", "-n", "add", "-inet", nstr, "-iface", addr.Addr().String())
|
||||
res, err = cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add route: %w (%s)", err, string(res))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user