summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/link/fdbased/endpoint.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/link/fdbased/endpoint.go')
-rw-r--r--pkg/tcpip/link/fdbased/endpoint.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/pkg/tcpip/link/fdbased/endpoint.go b/pkg/tcpip/link/fdbased/endpoint.go
index 2bb1be5d6..01d1ad3c8 100644
--- a/pkg/tcpip/link/fdbased/endpoint.go
+++ b/pkg/tcpip/link/fdbased/endpoint.go
@@ -57,6 +57,7 @@ import (
// NetworkDispatcher.
type linkDispatcher interface {
dispatch() (bool, tcpip.Error)
+ Cancel()
}
// PacketDispatchMode are the various supported methods of receiving and
@@ -322,9 +323,24 @@ func isSocketFD(fd int) (bool, error) {
return (stat.Mode & unix.S_IFSOCK) == unix.S_IFSOCK, nil
}
+func (e *endpoint) detach() {
+ for _, d := range e.inboundDispatchers {
+ d.Cancel()
+ }
+ e.Wait()
+}
+
// Attach launches the goroutine that reads packets from the file descriptor and
// dispatches them via the provided dispatcher.
func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) {
+ if (e.dispatcher != nil) {
+ e.detach()
+ }
+
+ if (dispatcher == nil) {
+ return
+ }
+
e.dispatcher = dispatcher
// Link endpoints are not savable. When transportation endpoints are
// saved, they stop sending outgoing packets and all incoming packets