mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-06 00:22:20 -08:00
Provide a shared TCP configuration helper for future DERP, control, and log-upload socket policy. Apply optional keepalive and user-timeout settings before protocol wrapping, and report each result independently so callers can choose whether to fall back or reject a connection. Add a checked user-timeout setter that validates duration bounds and reports unsupported platforms or sockets instead of silently succeeding. Preserve the existing best-effort APIs and all service defaults. Reuse net.TCPConn keepalive configuration; do not introduce RTO tuning or infer hardware offload support. Test actual Linux socket settings on dialed and accepted connections, zero-config behavior, invalid values, partial failures, and timeout reset. Updates tailscale/corp#50948 Change-Id: I8151ab81b8630610ba3ef2e2ec54b62caebadf65 Signed-off-by: James Tucker <[email protected]>
26 lines
1003 B
Go
26 lines
1003 B
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package ktimeout
|
|
|
|
import (
|
|
"fmt"
|
|
"math"
|
|
"time"
|
|
)
|
|
|
|
// SetUserTimeoutChecked sets the TCP user timeout on fd, or returns an error
|
|
// wrapping errors.ErrUnsupported if this platform or socket does not support it.
|
|
// Unlike SetUserTimeout, it does not silently succeed on unsupported platforms.
|
|
// Success does not imply keepalive offload or any application-health guarantee.
|
|
//
|
|
// timeout must be a nonnegative whole number of milliseconds no greater than
|
|
// math.MaxInt32 milliseconds. Zero restores the kernel's default behavior.
|
|
// Invalid values are rejected before touching the socket.
|
|
func SetUserTimeoutChecked(fd uintptr, timeout time.Duration) error {
|
|
if timeout < 0 || timeout%time.Millisecond != 0 || timeout/time.Millisecond > math.MaxInt32 {
|
|
return fmt.Errorf("invalid TCP user timeout %v: want whole milliseconds in [0, %d]", timeout, math.MaxInt32)
|
|
}
|
|
return setUserTimeoutChecked(fd, timeout)
|
|
}
|