From 0a55f8c1c11dc6d2dfb1bed02489f92bab437ea1 Mon Sep 17 00:00:00 2001 From: Zhaozhong Ni Date: Mon, 30 Jul 2018 15:42:01 -0700 Subject: netstack: support disconnect-on-save option per fdbased link. PiperOrigin-RevId: 206659972 Change-Id: I5e0e035f97743b6525ad36bed2c802791609beaf --- pkg/tcpip/transport/tcp/connect.go | 4 +++- pkg/tcpip/transport/tcp/endpoint_state.go | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) (limited to 'pkg/tcpip/transport') diff --git a/pkg/tcpip/transport/tcp/connect.go b/pkg/tcpip/transport/tcp/connect.go index 8d70eb45a..b90d3fe48 100644 --- a/pkg/tcpip/transport/tcp/connect.go +++ b/pkg/tcpip/transport/tcp/connect.go @@ -1023,7 +1023,9 @@ func (e *endpoint) protocolMainLoop(handshake bool) *tcpip.Error { // Mark endpoint as closed. e.mu.Lock() - e.state = stateClosed + if e.state != stateError { + e.state = stateClosed + } // Lock released below. epilogue() diff --git a/pkg/tcpip/transport/tcp/endpoint_state.go b/pkg/tcpip/transport/tcp/endpoint_state.go index 9c2e8878f..6143390b3 100644 --- a/pkg/tcpip/transport/tcp/endpoint_state.go +++ b/pkg/tcpip/transport/tcp/endpoint_state.go @@ -52,10 +52,17 @@ func (e *endpoint) beforeSave() { case stateInitial, stateBound: case stateConnected: if e.route.Capabilities()&stack.CapabilitySaveRestore == 0 { - panic(tcpip.ErrSaveRejection{fmt.Errorf("endpoint cannot be saved in connected state: local %v:%d, remote %v:%d", e.id.LocalAddress, e.id.LocalPort, e.id.RemoteAddress, e.id.RemotePort)}) + if e.route.Capabilities()&stack.CapabilityDisconnectOk == 0 { + panic(tcpip.ErrSaveRejection{fmt.Errorf("endpoint cannot be saved in connected state: local %v:%d, remote %v:%d", e.id.LocalAddress, e.id.LocalPort, e.id.RemoteAddress, e.id.RemotePort)}) + } + e.resetConnectionLocked(tcpip.ErrConnectionAborted) + e.mu.Unlock() + e.Close() + e.mu.Lock() } if !e.workerRunning { - // The endpoint must be in acceptedChan. + // The endpoint must be in acceptedChan or has been just + // disconnected and closed. break } fallthrough -- cgit v1.2.3