Clear pending packet queue when nic is removed.

Updates #6910

PiperOrigin-RevId: 428925334
This commit is contained in:
Bhasker Hariharan
2022-02-15 18:28:40 -08:00
committed by gVisor bot
parent 1012b95b22
commit 0917380792
2 changed files with 18 additions and 0 deletions
+4
View File
@@ -316,9 +316,13 @@ func (n *nic) remove() tcpip.Error {
ep.Close()
}
// drain and drop any packets pending link resolution.
n.linkResQueue.cancel()
// Prevent packets from going down to the link before shutting the link down.
n.qDisc.Close()
n.NetworkLinkEndpoint.Attach(nil)
return nil
}
+14
View File
@@ -70,6 +70,20 @@ func (f *packetsPendingLinkResolution) init(nic *nic) {
f.mu.packets = make(map[<-chan struct{}][]pendingPacket)
}
// cancel drains all pending packet queues and release all packet
// references.
func (f *packetsPendingLinkResolution) cancel() {
f.mu.Lock()
defer f.mu.Unlock()
for ch, pendingPackets := range f.mu.packets {
for _, p := range pendingPackets {
p.pkt.DecRef()
}
delete(f.mu.packets, ch)
}
f.mu.cancelChans = nil
}
// dequeue any pending packets associated with ch.
//
// If err is nil, packets will be written and sent to the given remote link