diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-12-14 20:11:32 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-12-14 20:11:32 +0000 |
commit | 22ae84e87a245ca815d04548b1f3ca6ae5f07af2 (patch) | |
tree | 77e7ba1afc34cb67cbf2ab3ed11ab9f612111bb5 /pkg/tcpip | |
parent | 702553edddb87e4aa93a190840948539233f61fc (diff) | |
parent | 2e191cb3f72858c61943168a69b0aff0fda6ee45 (diff) |
Merge release-20201208.0-43-g2e191cb3f (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/socketops.go | 40 | ||||
-rw-r--r-- | pkg/tcpip/tcpip.go | 4 | ||||
-rw-r--r-- | pkg/tcpip/tcpip_state_autogen.go | 3 | ||||
-rw-r--r-- | pkg/tcpip/transport/icmp/endpoint.go | 22 | ||||
-rw-r--r-- | pkg/tcpip/transport/icmp/icmp_state_autogen.go | 11 | ||||
-rw-r--r-- | pkg/tcpip/transport/packet/endpoint.go | 21 | ||||
-rw-r--r-- | pkg/tcpip/transport/packet/packet_state_autogen.go | 11 | ||||
-rw-r--r-- | pkg/tcpip/transport/raw/endpoint.go | 21 | ||||
-rw-r--r-- | pkg/tcpip/transport/raw/raw_state_autogen.go | 11 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/endpoint.go | 16 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/tcp_state_autogen.go | 7 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/endpoint.go | 13 | ||||
-rw-r--r-- | pkg/tcpip/transport/udp/udp_state_autogen.go | 7 |
13 files changed, 58 insertions, 129 deletions
diff --git a/pkg/tcpip/socketops.go b/pkg/tcpip/socketops.go index 3d29b31ee..b60a5fd76 100644 --- a/pkg/tcpip/socketops.go +++ b/pkg/tcpip/socketops.go @@ -16,6 +16,8 @@ package tcpip import ( "sync/atomic" + + "gvisor.dev/gvisor/pkg/sync" ) // SocketOptionsHandler holds methods that help define endpoint specific @@ -77,24 +79,24 @@ type SocketOptions struct { // These fields are accessed and modified using atomic operations. - // broadcastEnabled determines whether datagram sockets are allowed to send - // packets to a broadcast address. + // broadcastEnabled determines whether datagram sockets are allowed to + // send packets to a broadcast address. broadcastEnabled uint32 - // passCredEnabled determines whether SCM_CREDENTIALS socket control messages - // are enabled. + // passCredEnabled determines whether SCM_CREDENTIALS socket control + // messages are enabled. passCredEnabled uint32 // noChecksumEnabled determines whether UDP checksum is disabled while // transmitting for this socket. noChecksumEnabled uint32 - // reuseAddressEnabled determines whether Bind() should allow reuse of local - // address. + // reuseAddressEnabled determines whether Bind() should allow reuse of + // local address. reuseAddressEnabled uint32 - // reusePortEnabled determines whether to permit multiple sockets to be bound - // to an identical socket address. + // reusePortEnabled determines whether to permit multiple sockets to be + // bound to an identical socket address. reusePortEnabled uint32 // keepAliveEnabled determines whether TCP keepalive is enabled for this @@ -142,6 +144,13 @@ type SocketOptions struct { // receiveOriginalDstAddress is used to specify if the original destination of // the incoming packet should be returned as an ancillary message. receiveOriginalDstAddress uint32 + + // mu protects the access to the below fields. + mu sync.Mutex `state:"nosave"` + + // linger determines the amount of time the socket should linger before + // close. We currently implement this option for TCP socket only. + linger LingerOption } // InitHandler initializes the handler. This must be called before using the @@ -338,3 +347,18 @@ func (*SocketOptions) GetOutOfBandInline() bool { // SetOutOfBandInline sets value for SO_OOBINLINE option. We currently do not // support disabling this option. func (*SocketOptions) SetOutOfBandInline(bool) {} + +// GetLinger gets value for SO_LINGER option. +func (so *SocketOptions) GetLinger() LingerOption { + so.mu.Lock() + linger := so.linger + so.mu.Unlock() + return linger +} + +// SetLinger sets value for SO_LINGER option. +func (so *SocketOptions) SetLinger(linger LingerOption) { + so.mu.Lock() + so.linger = linger + so.mu.Unlock() +} diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go index 24f20203b..45fa62720 100644 --- a/pkg/tcpip/tcpip.go +++ b/pkg/tcpip/tcpip.go @@ -1145,10 +1145,6 @@ type LingerOption struct { Timeout time.Duration } -func (*LingerOption) isGettableSocketOption() {} - -func (*LingerOption) isSettableSocketOption() {} - // IPPacketInfo is the message structure for IP_PKTINFO. // // +stateify savable diff --git a/pkg/tcpip/tcpip_state_autogen.go b/pkg/tcpip/tcpip_state_autogen.go index 36ef19575..a2c33e1f0 100644 --- a/pkg/tcpip/tcpip_state_autogen.go +++ b/pkg/tcpip/tcpip_state_autogen.go @@ -29,6 +29,7 @@ func (so *SocketOptions) StateFields() []string { "delayOptionEnabled", "corkOptionEnabled", "receiveOriginalDstAddress", + "linger", } } @@ -53,6 +54,7 @@ func (so *SocketOptions) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(14, &so.delayOptionEnabled) stateSinkObject.Save(15, &so.corkOptionEnabled) stateSinkObject.Save(16, &so.receiveOriginalDstAddress) + stateSinkObject.Save(17, &so.linger) } func (so *SocketOptions) afterLoad() {} @@ -75,6 +77,7 @@ func (so *SocketOptions) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(14, &so.delayOptionEnabled) stateSourceObject.Load(15, &so.corkOptionEnabled) stateSourceObject.Load(16, &so.receiveOriginalDstAddress) + stateSourceObject.Load(17, &so.linger) } func (e *Error) StateTypeName() string { diff --git a/pkg/tcpip/transport/icmp/endpoint.go b/pkg/tcpip/transport/icmp/endpoint.go index 80c01f2cb..74fe19e98 100644 --- a/pkg/tcpip/transport/icmp/endpoint.go +++ b/pkg/tcpip/transport/icmp/endpoint.go @@ -75,8 +75,6 @@ type endpoint struct { route *stack.Route `state:"manual"` ttl uint8 stats tcpip.TransportEndpointStats `state:"nosave"` - // linger is used for SO_LINGER socket option. - linger tcpip.LingerOption // owner is used to get uid and gid of the packet. owner tcpip.PacketOwner @@ -338,15 +336,6 @@ func (e *endpoint) Peek([][]byte) (int64, *tcpip.Error) { // SetSockOpt sets a socket option. func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error { - switch v := opt.(type) { - case *tcpip.SocketDetachFilterOption: - return nil - - case *tcpip.LingerOption: - e.mu.Lock() - e.linger = *v - e.mu.Unlock() - } return nil } @@ -399,16 +388,7 @@ func (e *endpoint) GetSockOptInt(opt tcpip.SockOptInt) (int, *tcpip.Error) { // GetSockOpt implements tcpip.Endpoint.GetSockOpt. func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) *tcpip.Error { - switch o := opt.(type) { - case *tcpip.LingerOption: - e.mu.Lock() - *o = e.linger - e.mu.Unlock() - return nil - - default: - return tcpip.ErrUnknownProtocolOption - } + return tcpip.ErrUnknownProtocolOption } func send4(r *stack.Route, ident uint16, data buffer.View, ttl uint8, owner tcpip.PacketOwner) *tcpip.Error { diff --git a/pkg/tcpip/transport/icmp/icmp_state_autogen.go b/pkg/tcpip/transport/icmp/icmp_state_autogen.go index 0fcfe0dd8..28a734f05 100644 --- a/pkg/tcpip/transport/icmp/icmp_state_autogen.go +++ b/pkg/tcpip/transport/icmp/icmp_state_autogen.go @@ -59,7 +59,6 @@ func (e *endpoint) StateFields() []string { "shutdownFlags", "state", "ttl", - "linger", "owner", "ops", } @@ -81,9 +80,8 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(10, &e.shutdownFlags) stateSinkObject.Save(11, &e.state) stateSinkObject.Save(12, &e.ttl) - stateSinkObject.Save(13, &e.linger) - stateSinkObject.Save(14, &e.owner) - stateSinkObject.Save(15, &e.ops) + stateSinkObject.Save(13, &e.owner) + stateSinkObject.Save(14, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -99,9 +97,8 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(10, &e.shutdownFlags) stateSourceObject.Load(11, &e.state) stateSourceObject.Load(12, &e.ttl) - stateSourceObject.Load(13, &e.linger) - stateSourceObject.Load(14, &e.owner) - stateSourceObject.Load(15, &e.ops) + stateSourceObject.Load(13, &e.owner) + stateSourceObject.Load(14, &e.ops) stateSourceObject.LoadValue(6, new(int), func(y interface{}) { e.loadRcvBufSizeMax(y.(int)) }) stateSourceObject.AfterLoad(e.afterLoad) } diff --git a/pkg/tcpip/transport/packet/endpoint.go b/pkg/tcpip/transport/packet/endpoint.go index 1e7debbb4..9faab4b9e 100644 --- a/pkg/tcpip/transport/packet/endpoint.go +++ b/pkg/tcpip/transport/packet/endpoint.go @@ -85,8 +85,6 @@ type endpoint struct { stats tcpip.TransportEndpointStats `state:"nosave"` bound bool boundNIC tcpip.NICID - // linger is used for SO_LINGER socket option. - linger tcpip.LingerOption // lastErrorMu protects lastError. lastErrorMu sync.Mutex `state:"nosave"` @@ -306,16 +304,10 @@ func (ep *endpoint) Readiness(mask waiter.EventMask) waiter.EventMask { // used with SetSockOpt, and this function always returns // tcpip.ErrNotSupported. func (ep *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error { - switch v := opt.(type) { + switch opt.(type) { case *tcpip.SocketDetachFilterOption: return nil - case *tcpip.LingerOption: - ep.mu.Lock() - ep.linger = *v - ep.mu.Unlock() - return nil - default: return tcpip.ErrUnknownProtocolOption } @@ -376,16 +368,7 @@ func (ep *endpoint) LastError() *tcpip.Error { // GetSockOpt implements tcpip.Endpoint.GetSockOpt. func (ep *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) *tcpip.Error { - switch o := opt.(type) { - case *tcpip.LingerOption: - ep.mu.Lock() - *o = ep.linger - ep.mu.Unlock() - return nil - - default: - return tcpip.ErrNotSupported - } + return tcpip.ErrNotSupported } // GetSockOptInt implements tcpip.Endpoint.GetSockOptInt. diff --git a/pkg/tcpip/transport/packet/packet_state_autogen.go b/pkg/tcpip/transport/packet/packet_state_autogen.go index 42236056b..ccb66800b 100644 --- a/pkg/tcpip/transport/packet/packet_state_autogen.go +++ b/pkg/tcpip/transport/packet/packet_state_autogen.go @@ -63,7 +63,6 @@ func (ep *endpoint) StateFields() []string { "closed", "bound", "boundNIC", - "linger", "lastError", "ops", } @@ -74,7 +73,7 @@ func (ep *endpoint) StateSave(stateSinkObject state.Sink) { var rcvBufSizeMaxValue int = ep.saveRcvBufSizeMax() stateSinkObject.SaveValue(6, rcvBufSizeMaxValue) var lastErrorValue string = ep.saveLastError() - stateSinkObject.SaveValue(15, lastErrorValue) + stateSinkObject.SaveValue(14, lastErrorValue) stateSinkObject.Save(0, &ep.TransportEndpointInfo) stateSinkObject.Save(1, &ep.DefaultSocketOptionsHandler) stateSinkObject.Save(2, &ep.netProto) @@ -88,8 +87,7 @@ func (ep *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(11, &ep.closed) stateSinkObject.Save(12, &ep.bound) stateSinkObject.Save(13, &ep.boundNIC) - stateSinkObject.Save(14, &ep.linger) - stateSinkObject.Save(16, &ep.ops) + stateSinkObject.Save(15, &ep.ops) } func (ep *endpoint) StateLoad(stateSourceObject state.Source) { @@ -106,10 +104,9 @@ func (ep *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(11, &ep.closed) stateSourceObject.Load(12, &ep.bound) stateSourceObject.Load(13, &ep.boundNIC) - stateSourceObject.Load(14, &ep.linger) - stateSourceObject.Load(16, &ep.ops) + stateSourceObject.Load(15, &ep.ops) stateSourceObject.LoadValue(6, new(int), func(y interface{}) { ep.loadRcvBufSizeMax(y.(int)) }) - stateSourceObject.LoadValue(15, new(string), func(y interface{}) { ep.loadLastError(y.(string)) }) + stateSourceObject.LoadValue(14, new(string), func(y interface{}) { ep.loadLastError(y.(string)) }) stateSourceObject.AfterLoad(ep.afterLoad) } diff --git a/pkg/tcpip/transport/raw/endpoint.go b/pkg/tcpip/transport/raw/endpoint.go index d9a664c03..eee3f11c1 100644 --- a/pkg/tcpip/transport/raw/endpoint.go +++ b/pkg/tcpip/transport/raw/endpoint.go @@ -85,8 +85,6 @@ type endpoint struct { // Connect(), and is valid only when conneted is true. route *stack.Route `state:"manual"` stats tcpip.TransportEndpointStats `state:"nosave"` - // linger is used for SO_LINGER socket option. - linger tcpip.LingerOption // owner is used to get uid and gid of the packet. owner tcpip.PacketOwner @@ -532,16 +530,10 @@ func (e *endpoint) Readiness(mask waiter.EventMask) waiter.EventMask { // SetSockOpt implements tcpip.Endpoint.SetSockOpt. func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error { - switch v := opt.(type) { + switch opt.(type) { case *tcpip.SocketDetachFilterOption: return nil - case *tcpip.LingerOption: - e.mu.Lock() - e.linger = *v - e.mu.Unlock() - return nil - default: return tcpip.ErrUnknownProtocolOption } @@ -593,16 +585,7 @@ func (e *endpoint) SetSockOptInt(opt tcpip.SockOptInt, v int) *tcpip.Error { // GetSockOpt implements tcpip.Endpoint.GetSockOpt. func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) *tcpip.Error { - switch o := opt.(type) { - case *tcpip.LingerOption: - e.mu.Lock() - *o = e.linger - e.mu.Unlock() - return nil - - default: - return tcpip.ErrUnknownProtocolOption - } + return tcpip.ErrUnknownProtocolOption } // GetSockOptInt implements tcpip.Endpoint.GetSockOptInt. diff --git a/pkg/tcpip/transport/raw/raw_state_autogen.go b/pkg/tcpip/transport/raw/raw_state_autogen.go index 6a216ccc2..a7ecccb20 100644 --- a/pkg/tcpip/transport/raw/raw_state_autogen.go +++ b/pkg/tcpip/transport/raw/raw_state_autogen.go @@ -59,7 +59,6 @@ func (e *endpoint) StateFields() []string { "closed", "connected", "bound", - "linger", "owner", "ops", } @@ -81,9 +80,8 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(10, &e.closed) stateSinkObject.Save(11, &e.connected) stateSinkObject.Save(12, &e.bound) - stateSinkObject.Save(13, &e.linger) - stateSinkObject.Save(14, &e.owner) - stateSinkObject.Save(15, &e.ops) + stateSinkObject.Save(13, &e.owner) + stateSinkObject.Save(14, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -99,9 +97,8 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(10, &e.closed) stateSourceObject.Load(11, &e.connected) stateSourceObject.Load(12, &e.bound) - stateSourceObject.Load(13, &e.linger) - stateSourceObject.Load(14, &e.owner) - stateSourceObject.Load(15, &e.ops) + stateSourceObject.Load(13, &e.owner) + stateSourceObject.Load(14, &e.ops) stateSourceObject.LoadValue(6, new(int), func(y interface{}) { e.loadRcvBufSizeMax(y.(int)) }) stateSourceObject.AfterLoad(e.afterLoad) } diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index 69512ebef..7a37c10bb 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -674,9 +674,6 @@ type endpoint struct { // owner is used to get uid and gid of the packet. owner tcpip.PacketOwner - // linger is used for SO_LINGER socket option. - linger tcpip.LingerOption - // ops is used to get socket level options. ops tcpip.SocketOptions } @@ -1040,7 +1037,8 @@ func (e *endpoint) Close() { return } - if e.linger.Enabled && e.linger.Timeout == 0 { + linger := e.SocketOptions().GetLinger() + if linger.Enabled && linger.Timeout == 0 { s := e.EndpointState() isResetState := s == StateEstablished || s == StateCloseWait || s == StateFinWait1 || s == StateFinWait2 || s == StateSynRecv if isResetState { @@ -1906,11 +1904,6 @@ func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error { case *tcpip.SocketDetachFilterOption: return nil - case *tcpip.LingerOption: - e.LockUser() - e.linger = *v - e.UnlockUser() - default: return nil } @@ -2071,11 +2064,6 @@ func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) *tcpip.Error { Port: port, } - case *tcpip.LingerOption: - e.LockUser() - *o = e.linger - e.UnlockUser() - default: return tcpip.ErrUnknownProtocolOption } diff --git a/pkg/tcpip/transport/tcp/tcp_state_autogen.go b/pkg/tcpip/transport/tcp/tcp_state_autogen.go index 71090ab61..8eba0efeb 100644 --- a/pkg/tcpip/transport/tcp/tcp_state_autogen.go +++ b/pkg/tcpip/transport/tcp/tcp_state_autogen.go @@ -217,7 +217,6 @@ func (e *endpoint) StateFields() []string { "closed", "txHash", "owner", - "linger", "ops", } } @@ -290,8 +289,7 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(58, &e.closed) stateSinkObject.Save(59, &e.txHash) stateSinkObject.Save(60, &e.owner) - stateSinkObject.Save(61, &e.linger) - stateSinkObject.Save(62, &e.ops) + stateSinkObject.Save(61, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -351,8 +349,7 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(58, &e.closed) stateSourceObject.Load(59, &e.txHash) stateSourceObject.Load(60, &e.owner) - stateSourceObject.Load(61, &e.linger) - stateSourceObject.Load(62, &e.ops) + stateSourceObject.Load(61, &e.ops) stateSourceObject.LoadValue(4, new(string), func(y interface{}) { e.loadHardError(y.(string)) }) stateSourceObject.LoadValue(5, new(string), func(y interface{}) { e.loadLastError(y.(string)) }) stateSourceObject.LoadValue(13, new(EndpointState), func(y interface{}) { e.loadState(y.(EndpointState)) }) diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go index 3a2baba14..763d1d654 100644 --- a/pkg/tcpip/transport/udp/endpoint.go +++ b/pkg/tcpip/transport/udp/endpoint.go @@ -144,9 +144,6 @@ type endpoint struct { // owner is used to get uid and gid of the packet. owner tcpip.PacketOwner - // linger is used for SO_LINGER socket option. - linger tcpip.LingerOption - // ops is used to get socket level options. ops tcpip.SocketOptions } @@ -768,11 +765,6 @@ func (e *endpoint) SetSockOpt(opt tcpip.SettableSocketOption) *tcpip.Error { case *tcpip.SocketDetachFilterOption: return nil - - case *tcpip.LingerOption: - e.mu.Lock() - e.linger = *v - e.mu.Unlock() } return nil } @@ -851,11 +843,6 @@ func (e *endpoint) GetSockOpt(opt tcpip.GettableSocketOption) *tcpip.Error { *o = tcpip.BindToDeviceOption(e.bindToDevice) e.mu.RUnlock() - case *tcpip.LingerOption: - e.mu.RLock() - *o = e.linger - e.mu.RUnlock() - default: return tcpip.ErrUnknownProtocolOption } diff --git a/pkg/tcpip/transport/udp/udp_state_autogen.go b/pkg/tcpip/transport/udp/udp_state_autogen.go index 451d8eff0..ec0a8c902 100644 --- a/pkg/tcpip/transport/udp/udp_state_autogen.go +++ b/pkg/tcpip/transport/udp/udp_state_autogen.go @@ -82,7 +82,6 @@ func (e *endpoint) StateFields() []string { "multicastMemberships", "effectiveNetProtos", "owner", - "linger", "ops", } } @@ -118,8 +117,7 @@ func (e *endpoint) StateSave(stateSinkObject state.Sink) { stateSinkObject.Save(24, &e.multicastMemberships) stateSinkObject.Save(25, &e.effectiveNetProtos) stateSinkObject.Save(26, &e.owner) - stateSinkObject.Save(27, &e.linger) - stateSinkObject.Save(28, &e.ops) + stateSinkObject.Save(27, &e.ops) } func (e *endpoint) StateLoad(stateSourceObject state.Source) { @@ -148,8 +146,7 @@ func (e *endpoint) StateLoad(stateSourceObject state.Source) { stateSourceObject.Load(24, &e.multicastMemberships) stateSourceObject.Load(25, &e.effectiveNetProtos) stateSourceObject.Load(26, &e.owner) - stateSourceObject.Load(27, &e.linger) - stateSourceObject.Load(28, &e.ops) + stateSourceObject.Load(27, &e.ops) stateSourceObject.LoadValue(6, new(int), func(y interface{}) { e.loadRcvBufSizeMax(y.(int)) }) stateSourceObject.LoadValue(19, new(string), func(y interface{}) { e.loadLastError(y.(string)) }) stateSourceObject.AfterLoad(e.afterLoad) |