mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-13 06:07:34 +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
36
prober/tun_linux.go
Normal file
36
prober/tun_linux.go
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build linux
|
||||
|
||||
package prober
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
|
||||
"github.com/tailscale/netlink"
|
||||
"go4.org/netipx"
|
||||
)
|
||||
|
||||
const tunName = "derpprobe"
|
||||
|
||||
func configureTUN(addr netip.Prefix, tunname string) error {
|
||||
link, err := netlink.LinkByName(tunname)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to look up link %q: %w", tunname, err)
|
||||
}
|
||||
|
||||
// We need to bring the TUN device up before assigning an address. This
|
||||
// allows the OS to automatically create a route for it. Otherwise, we'd
|
||||
// have to manually create the route.
|
||||
if err := netlink.LinkSetUp(link); err != nil {
|
||||
return fmt.Errorf("failed to bring tun %q up: %w", tunname, err)
|
||||
}
|
||||
|
||||
if err := netlink.AddrReplace(link, &netlink.Addr{IPNet: netipx.PrefixIPNet(addr)}); err != nil {
|
||||
return fmt.Errorf("failed to add address: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user