summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/transport/tcp
diff options
context:
space:
mode:
authorLucas Manning <lucasmanning@google.com>2021-11-08 13:26:02 -0800
committergVisor bot <gvisor-bot@google.com>2021-11-08 13:28:38 -0800
commit84b38f4c6e065d3f9314a8abbb3f5857ed4fa44e (patch)
tree53eb76fa6d0612696f93ec6919185ea5a37ff3f9 /pkg/tcpip/transport/tcp
parent49d23beb283d0306c9ccf5300e73517153ddd3c2 (diff)
Add reference counting to packet buffers.
PiperOrigin-RevId: 408426639
Diffstat (limited to 'pkg/tcpip/transport/tcp')
-rw-r--r--pkg/tcpip/transport/tcp/connect.go2
-rw-r--r--pkg/tcpip/transport/tcp/testing/context/context.go3
2 files changed, 5 insertions, 0 deletions
diff --git a/pkg/tcpip/transport/tcp/connect.go b/pkg/tcpip/transport/tcp/connect.go
index 12df7a7b4..b1ab46c97 100644
--- a/pkg/tcpip/transport/tcp/connect.go
+++ b/pkg/tcpip/transport/tcp/connect.go
@@ -850,6 +850,7 @@ func sendTCPBatch(r *stack.Route, tf tcpFields, data buffer.VectorisedView, gso
pkt.GSOOptions = gso
pkts.PushBack(pkt)
}
+ defer pkts.DecRef()
if tf.ttl == 0 {
tf.ttl = r.DefaultTTL()
@@ -878,6 +879,7 @@ func sendTCP(r *stack.Route, tf tcpFields, data buffer.VectorisedView, gso stack
ReserveHeaderBytes: header.TCPMinimumSize + int(r.MaxHeaderLength()) + optLen,
Data: data,
})
+ defer pkt.DecRef()
pkt.GSOOptions = gso
pkt.Hash = tf.txHash
pkt.Owner = owner
diff --git a/pkg/tcpip/transport/tcp/testing/context/context.go b/pkg/tcpip/transport/tcp/testing/context/context.go
index 88bb99354..fd0eca4bd 100644
--- a/pkg/tcpip/transport/tcp/testing/context/context.go
+++ b/pkg/tcpip/transport/tcp/testing/context/context.go
@@ -421,6 +421,7 @@ func (c *Context) SendICMPPacket(typ header.ICMPv4Type, code header.ICMPv4Code,
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: buf.ToVectorisedView(),
})
+ defer pkt.DecRef()
c.linkEP.InjectInbound(ipv4.ProtocolNumber, pkt)
}
@@ -477,6 +478,7 @@ func (c *Context) SendSegment(s buffer.VectorisedView) {
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: s,
})
+ defer pkt.DecRef()
c.linkEP.InjectInbound(ipv4.ProtocolNumber, pkt)
}
@@ -486,6 +488,7 @@ func (c *Context) SendPacket(payload []byte, h *Headers) {
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
Data: c.BuildSegment(payload, h),
})
+ defer pkt.DecRef()
c.linkEP.InjectInbound(ipv4.ProtocolNumber, pkt)
}