mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Internal change.
PiperOrigin-RevId: 278979065
This commit is contained in:
@@ -594,6 +594,11 @@ func newEndpoint(s *stack.Stack, netProto tcpip.NetworkProtocolNumber, waiterQue
|
||||
e.rcvAutoParams.disabled = !bool(mrb)
|
||||
}
|
||||
|
||||
var de DelayEnabled
|
||||
if err := s.TransportProtocolOption(ProtocolNumber, &de); err == nil && de {
|
||||
e.SetSockOptInt(tcpip.DelayOption, 1)
|
||||
}
|
||||
|
||||
if p := s.GetTCPProbe(); p != nil {
|
||||
e.probe = p
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ const (
|
||||
// protocol. See: https://tools.ietf.org/html/rfc2018.
|
||||
type SACKEnabled bool
|
||||
|
||||
// DelayEnabled option can be used to enable Nagle's algorithm in the TCP protocol.
|
||||
type DelayEnabled bool
|
||||
|
||||
// SendBufferSizeOption allows the default, min and max send buffer sizes for
|
||||
// TCP endpoints to be queried or configured.
|
||||
type SendBufferSizeOption struct {
|
||||
@@ -84,6 +87,7 @@ const (
|
||||
type protocol struct {
|
||||
mu sync.Mutex
|
||||
sackEnabled bool
|
||||
delayEnabled bool
|
||||
sendBufferSize SendBufferSizeOption
|
||||
recvBufferSize ReceiveBufferSizeOption
|
||||
congestionControl string
|
||||
@@ -97,7 +101,7 @@ func (*protocol) Number() tcpip.TransportProtocolNumber {
|
||||
}
|
||||
|
||||
// NewEndpoint creates a new tcp endpoint.
|
||||
func (*protocol) NewEndpoint(stack *stack.Stack, netProto tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
|
||||
func (p *protocol) NewEndpoint(stack *stack.Stack, netProto tcpip.NetworkProtocolNumber, waiterQueue *waiter.Queue) (tcpip.Endpoint, *tcpip.Error) {
|
||||
return newEndpoint(stack, netProto, waiterQueue), nil
|
||||
}
|
||||
|
||||
@@ -165,6 +169,12 @@ func (p *protocol) SetOption(option interface{}) *tcpip.Error {
|
||||
p.mu.Unlock()
|
||||
return nil
|
||||
|
||||
case DelayEnabled:
|
||||
p.mu.Lock()
|
||||
p.delayEnabled = bool(v)
|
||||
p.mu.Unlock()
|
||||
return nil
|
||||
|
||||
case SendBufferSizeOption:
|
||||
if v.Min <= 0 || v.Default < v.Min || v.Default > v.Max {
|
||||
return tcpip.ErrInvalidOptionValue
|
||||
@@ -216,6 +226,12 @@ func (p *protocol) Option(option interface{}) *tcpip.Error {
|
||||
p.mu.Unlock()
|
||||
return nil
|
||||
|
||||
case *DelayEnabled:
|
||||
p.mu.Lock()
|
||||
*v = DelayEnabled(p.delayEnabled)
|
||||
p.mu.Unlock()
|
||||
return nil
|
||||
|
||||
case *SendBufferSizeOption:
|
||||
p.mu.Lock()
|
||||
*v = p.sendBufferSize
|
||||
|
||||
@@ -4848,3 +4848,48 @@ func TestReceiveBufferAutoTuning(t *testing.T) {
|
||||
payloadSize *= 2
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelayEnabled(t *testing.T) {
|
||||
c := context.New(t, defaultMTU)
|
||||
defer c.Cleanup()
|
||||
checkDelayOption(t, c, false, 0) // Delay is disabled by default.
|
||||
|
||||
for _, v := range []struct {
|
||||
delayEnabled tcp.DelayEnabled
|
||||
wantDelayOption int
|
||||
}{
|
||||
{delayEnabled: false, wantDelayOption: 0},
|
||||
{delayEnabled: true, wantDelayOption: 1},
|
||||
} {
|
||||
c := context.New(t, defaultMTU)
|
||||
defer c.Cleanup()
|
||||
if err := c.Stack().SetTransportProtocolOption(tcp.ProtocolNumber, v.delayEnabled); err != nil {
|
||||
t.Fatalf("SetTransportProtocolOption(tcp, %t) failed: %v", v.delayEnabled, err)
|
||||
}
|
||||
checkDelayOption(t, c, v.delayEnabled, v.wantDelayOption)
|
||||
}
|
||||
}
|
||||
|
||||
func checkDelayOption(t *testing.T, c *context.Context, wantDelayEnabled tcp.DelayEnabled, wantDelayOption int) {
|
||||
t.Helper()
|
||||
|
||||
var gotDelayEnabled tcp.DelayEnabled
|
||||
if err := c.Stack().TransportProtocolOption(tcp.ProtocolNumber, &gotDelayEnabled); err != nil {
|
||||
t.Fatalf("TransportProtocolOption(tcp, &gotDelayEnabled) failed: %v", err)
|
||||
}
|
||||
if gotDelayEnabled != wantDelayEnabled {
|
||||
t.Errorf("TransportProtocolOption(tcp, &gotDelayEnabled) got %t, want %t", gotDelayEnabled, wantDelayEnabled)
|
||||
}
|
||||
|
||||
ep, err := c.Stack().NewEndpoint(tcp.ProtocolNumber, ipv4.ProtocolNumber, new(waiter.Queue))
|
||||
if err != nil {
|
||||
t.Fatalf("NewEndPoint(tcp, ipv4, new(waiter.Queue)) failed: %v", err)
|
||||
}
|
||||
gotDelayOption, err := ep.GetSockOptInt(tcpip.DelayOption)
|
||||
if err != nil {
|
||||
t.Fatalf("ep.GetSockOptInt(tcpip.DelayOption) failed: %v", err)
|
||||
}
|
||||
if gotDelayOption != wantDelayOption {
|
||||
t.Errorf("ep.GetSockOptInt(tcpip.DelayOption) got: %d, want: %d", gotDelayOption, wantDelayOption)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user