mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
netstack: support disconnect-on-save option per fdbased link.
PiperOrigin-RevId: 206659972 Change-Id: I5e0e035f97743b6525ad36bed2c802791609beaf
This commit is contained in:
@@ -69,6 +69,8 @@ type Options struct {
|
||||
ChecksumOffload bool
|
||||
ClosedFunc func(*tcpip.Error)
|
||||
Address tcpip.LinkAddress
|
||||
SaveRestore bool
|
||||
DisconnectOk bool
|
||||
}
|
||||
|
||||
// New creates a new fd-based endpoint.
|
||||
@@ -89,6 +91,14 @@ func New(opts *Options) tcpip.LinkEndpointID {
|
||||
caps |= stack.CapabilityResolutionRequired
|
||||
}
|
||||
|
||||
if opts.SaveRestore {
|
||||
caps |= stack.CapabilitySaveRestore
|
||||
}
|
||||
|
||||
if opts.DisconnectOk {
|
||||
caps |= stack.CapabilityDisconnectOk
|
||||
}
|
||||
|
||||
e := &endpoint{
|
||||
fd: opts.FD,
|
||||
mtu: opts.MTU,
|
||||
|
||||
@@ -204,6 +204,7 @@ const (
|
||||
CapabilityChecksumOffload LinkEndpointCapabilities = 1 << iota
|
||||
CapabilityResolutionRequired
|
||||
CapabilitySaveRestore
|
||||
CapabilityDisconnectOk
|
||||
)
|
||||
|
||||
// LinkEndpoint is the interface implemented by data link layer protocols (e.g.,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user