prober: fix WithBandwidthProbing behavior with optional tunAddress

1ed9bd76d6 meant to make tunAddress be optional.

Updates tailscale/corp#24635

Change-Id: Idc4a8540b294e480df5bd291967024c04df751c0
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick 2024-12-16 12:11:38 -08:00 committed by Brad Fitzpatrick
parent 0cc2a8dc0d
commit 2506b81471
1 changed files with 8 additions and 6 deletions

View File

@ -51,7 +51,7 @@ type derpProber struct {
// Optional bandwidth probing.
bwInterval time.Duration
bwProbeSize int64
bwTUNIPv4Prefix *netip.Prefix
bwTUNIPv4Prefix *netip.Prefix // or nil to not use TUN
// Optionally restrict probes to a single regionCode.
regionCode string
@ -78,11 +78,12 @@ type DERPOpt func(*derpProber)
// `size` bytes will be regularly transferred through each DERP server, and each
// pair of DERP servers in every region. If tunAddress is specified, probes will
// use a TCP connection over a TUN device at this address in order to exercise
// TCP-in-TCP in similar fashion to TCP over Tailscale via DERP
// TCP-in-TCP in similar fashion to TCP over Tailscale via DERP.
func WithBandwidthProbing(interval time.Duration, size int64, tunAddress string) DERPOpt {
return func(d *derpProber) {
d.bwInterval = interval
d.bwProbeSize = size
if tunAddress != "" {
prefix, err := netip.ParsePrefix(fmt.Sprintf("%s/30", tunAddress))
if err != nil {
log.Fatalf("failed to parse IP prefix from bw-tun-ipv4-addr: %v", err)
@ -90,6 +91,7 @@ func WithBandwidthProbing(interval time.Duration, size int64, tunAddress string)
d.bwTUNIPv4Prefix = &prefix
}
}
}
// WithMeshProbing enables mesh probing. When enabled, a small message will be
// transferred through each DERP server and each pair of DERP servers.