summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/stack/nic.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/stack/nic.go')
-rw-r--r--pkg/tcpip/stack/nic.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/pkg/tcpip/stack/nic.go b/pkg/tcpip/stack/nic.go
index b9b5c35c8..7cfb836ca 100644
--- a/pkg/tcpip/stack/nic.go
+++ b/pkg/tcpip/stack/nic.go
@@ -372,7 +372,7 @@ func (n *nic) WritePacketToRemote(remoteLinkAddr tcpip.LinkAddress, protocol tcp
}
func (n *nic) writePacket(r RouteInfo, protocol tcpip.NetworkProtocolNumber, pkt *PacketBuffer) tcpip.Error {
- // WritePacket takes ownership of pkt, calculate numBytes first.
+ // WritePacket modifies pkt, calculate numBytes first.
numBytes := pkt.Size()
pkt.EgressRoute = r
@@ -754,6 +754,7 @@ func (n *nic) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcp
packetEPPkt = NewPacketBuffer(PacketBufferOptions{
Data: PayloadSince(pkt.LinkHeader()).ToVectorisedView(),
})
+ defer packetEPPkt.DecRef()
// If a link header was populated in the original packet buffer, then
// populate it in the packet buffer we provide to packet endpoints as
// packet endpoints inspect link headers.
@@ -761,7 +762,9 @@ func (n *nic) DeliverNetworkPacket(remote, local tcpip.LinkAddress, protocol tcp
packetEPPkt.PktType = tcpip.PacketHost
}
- ep.HandlePacket(n.id, local, protocol, packetEPPkt.Clone())
+ clone := packetEPPkt.Clone()
+ defer clone.DecRef()
+ ep.HandlePacket(n.id, local, protocol, clone)
}
n.packetEPs.mu.Lock()
@@ -811,14 +814,16 @@ func (n *nic) deliverOutboundPacket(remote tcpip.LinkAddress, pkt *PacketBuffer)
ReserveHeaderBytes: pkt.AvailableHeaderBytes(),
Data: PayloadSince(pkt.NetworkHeader()).ToVectorisedView(),
})
+ defer packetEPPkt.DecRef()
// Add the link layer header as outgoing packets are intercepted before
// the link layer header is created and packet endpoints are interested
// in the link header.
n.LinkEndpoint.AddHeader(local, remote, pkt.NetworkProtocolNumber, packetEPPkt)
packetEPPkt.PktType = tcpip.PacketOutgoing
}
-
- ep.HandlePacket(n.id, local, pkt.NetworkProtocolNumber, packetEPPkt.Clone())
+ clone := packetEPPkt.Clone()
+ defer clone.DecRef()
+ ep.HandlePacket(n.id, local, pkt.NetworkProtocolNumber, clone)
})
}