diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-08-25 17:07:08 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-08-25 17:07:08 +0000 |
commit | 993cd0c9e6b58c8c28ccb25a9f445e50c7d4dfaa (patch) | |
tree | 4fcbd8eee097d7c5fc7a13447bc89f640ba5ecf3 /pkg/tcpip/transport | |
parent | f839b715ebad539a0d4604caa62610624ff4d166 (diff) | |
parent | b26f7503b545e106ea0934d2153aed54ee4374d3 (diff) |
Merge release-20200818.0-42-gb26f7503b (automated)
Diffstat (limited to 'pkg/tcpip/transport')
-rw-r--r-- | pkg/tcpip/transport/tcp/endpoint.go | 33 | ||||
-rw-r--r-- | pkg/tcpip/transport/tcp/tcp_state_autogen.go | 3 |
2 files changed, 36 insertions, 0 deletions
diff --git a/pkg/tcpip/transport/tcp/endpoint.go b/pkg/tcpip/transport/tcp/endpoint.go index 9c0f4c9f4..ff9b8804d 100644 --- a/pkg/tcpip/transport/tcp/endpoint.go +++ b/pkg/tcpip/transport/tcp/endpoint.go @@ -654,6 +654,9 @@ 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 } // UniqueID implements stack.TransportEndpoint.UniqueID. @@ -1007,6 +1010,26 @@ func (e *endpoint) Close() { return } + if e.linger.Enabled && e.linger.Timeout == 0 { + s := e.EndpointState() + isResetState := s == StateEstablished || s == StateCloseWait || s == StateFinWait1 || s == StateFinWait2 || s == StateSynRecv + if isResetState { + // Close the endpoint without doing full shutdown and + // send a RST. + e.resetConnectionLocked(tcpip.ErrConnectionAborted) + e.closeNoShutdownLocked() + + // Wake up worker to close the endpoint. + switch s { + case StateSynRecv: + e.notifyProtocolGoroutine(notifyClose) + default: + e.notifyProtocolGoroutine(notifyTickleWorker) + } + return + } + } + // Issue a shutdown so that the peer knows we won't send any more data // if we're connected, or stop accepting if we're listening. e.shutdownLocked(tcpip.ShutdownWrite | tcpip.ShutdownRead) @@ -1807,6 +1830,11 @@ func (e *endpoint) SetSockOpt(opt interface{}) *tcpip.Error { case tcpip.SocketDetachFilterOption: return nil + case tcpip.LingerOption: + e.LockUser() + e.linger = v + e.UnlockUser() + default: return nil } @@ -2032,6 +2060,11 @@ func (e *endpoint) GetSockOpt(opt interface{}) *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 bed45e9a1..77e0d0e97 100644 --- a/pkg/tcpip/transport/tcp/tcp_state_autogen.go +++ b/pkg/tcpip/transport/tcp/tcp_state_autogen.go @@ -222,6 +222,7 @@ func (x *endpoint) StateFields() []string { "closed", "txHash", "owner", + "linger", } } @@ -293,6 +294,7 @@ func (x *endpoint) StateSave(m state.Sink) { m.Save(59, &x.closed) m.Save(60, &x.txHash) m.Save(61, &x.owner) + m.Save(62, &x.linger) } func (x *endpoint) StateLoad(m state.Source) { @@ -354,6 +356,7 @@ func (x *endpoint) StateLoad(m state.Source) { m.Load(59, &x.closed) m.Load(60, &x.txHash) m.Load(61, &x.owner) + m.Load(62, &x.linger) m.LoadValue(3, new(string), func(y interface{}) { x.loadLastError(y.(string)) }) m.LoadValue(10, new(EndpointState), func(y interface{}) { x.loadState(y.(EndpointState)) }) m.LoadValue(25, new(unixTime), func(y interface{}) { x.loadRecentTSTime(y.(unixTime)) }) |