MCPcopy Index your code
hub / github.com/tailscale/tailscale / setTCPBufSizes

Function setTCPBufSizes

wgengine/netstack/netstack.go:294–330  ·  view source on GitHub ↗
(ipstack *stack.Stack)

Source from the content-addressed store, hash-verified

292const maxUDPPacketSize = tstun.MaxPacketSize
293
294func setTCPBufSizes(ipstack *stack.Stack) error {
295 // tcpip.TCP{Receive,Send}BufferSizeRangeOption is gVisor's version of
296 // Linux's tcp_{r,w}mem. Application within gVisor differs as some Linux
297 // features are not (yet) implemented, and socket buffer memory is not
298 // controlled within gVisor, e.g. we allocate *stack.PacketBuffer's for the
299 // write path within Tailscale. Therefore, we loosen our understanding of
300 // the relationship between these Linux and gVisor tunables. The chosen
301 // values are biased towards higher throughput on high bandwidth-delay
302 // product paths, except on memory-constrained platforms.
303 tcpRXBufOpt := tcpip.TCPReceiveBufferSizeRangeOption{
304 // Min is unused by gVisor at the time of writing, but partially plumbed
305 // for application by the TCP_WINDOW_CLAMP socket option.
306 Min: tcpRXBufMinSize,
307 // Default is used by gVisor at socket creation.
308 Default: tcpRXBufDefSize,
309 // Max is used by gVisor to cap the advertised receive window post-read.
310 // (tcp_moderate_rcvbuf=true, the default).
311 Max: tcpRXBufMaxSize,
312 }
313 tcpipErr := ipstack.SetTransportProtocolOption(tcp.ProtocolNumber, &tcpRXBufOpt)
314 if tcpipErr != nil {
315 return fmt.Errorf("could not set TCP RX buf size: %v", tcpipErr)
316 }
317 tcpTXBufOpt := tcpip.TCPSendBufferSizeRangeOption{
318 // Min in unused by gVisor at the time of writing.
319 Min: tcpTXBufMinSize,
320 // Default is used by gVisor at socket creation.
321 Default: tcpTXBufDefSize,
322 // Max is used by gVisor to cap the send window.
323 Max: tcpTXBufMaxSize,
324 }
325 tcpipErr = ipstack.SetTransportProtocolOption(tcp.ProtocolNumber, &tcpTXBufOpt)
326 if tcpipErr != nil {
327 return fmt.Errorf("could not set TCP TX buf size: %v", tcpipErr)
328 }
329 return nil
330}
331
332// Create creates and populates a new Impl.
333func Create(logf logger.Logf, tundev *tstun.Wrapper, e wgengine.Engine, mc *magicsock.Conn, dialer *tsdial.Dialer, dns *dns.Manager, pm *proxymap.Mapper) (*Impl, error) {

Callers 1

CreateFunction · 0.85

Calls 2

ErrorfMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…