From 8c9dc0babfd64d5f053039c898401f94c6be6d0d Mon Sep 17 00:00:00 2001 From: Lucas Manning Date: Tue, 18 Jan 2022 16:03:26 -0800 Subject: [PATCH] Update PacketBuffer to hold a Buffer struct instead of a Buffer pointer. The extra pointer indirection is not necessary and allows for a nil buffer. This change bumps the PacketBuffer struct size from 296 to 792 bytes. PiperOrigin-RevId: 422669812 --- pkg/buffer/view.go | 4 ++-- .../network/internal/fragmentation/fragmentation_test.go | 2 +- pkg/tcpip/stack/packet_buffer.go | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pkg/buffer/view.go b/pkg/buffer/view.go index a4610f977..53167c28a 100644 --- a/pkg/buffer/view.go +++ b/pkg/buffer/view.go @@ -380,8 +380,8 @@ func (v *View) Copy() (other View) { // Clone makes a more shallow copy compared to Copy. The underlying payload // slice (buffer.data) is shared but the buffers themselves are copied. -func (v *View) Clone() *View { - other := &View{ +func (v *View) Clone() View { + other := View{ size: v.size, } for buf := v.data.Front(); buf != nil; buf = buf.Next() { diff --git a/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go b/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go index e3e373e45..6f79abccf 100644 --- a/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go +++ b/pkg/tcpip/network/internal/fragmentation/fragmentation_test.go @@ -107,7 +107,7 @@ func TestFragmentationProcess(t *testing.T) { } for _, c := range processTestCases { t.Run(c.comment, func(t *testing.T) { - f := NewFragmentation(minBlockSize, 1024, 512, reassembleTimeout, &faketime.NullClock{}, nil) + f := NewFragmentation(minBlockSize, 2048, 512, reassembleTimeout, &faketime.NullClock{}, nil) firstFragmentProto := c.in[0].proto for i, in := range c.in { defer in.pkt.DecRef() diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go index 112a462ec..52fb18759 100644 --- a/pkg/tcpip/stack/packet_buffer.go +++ b/pkg/tcpip/stack/packet_buffer.go @@ -106,7 +106,7 @@ type PacketBuffer struct { // buf is the underlying buffer for the packet. See struct level docs for // details. - buf *buffer.Buffer + buf buffer.Buffer reserved int pushed int consumed int @@ -169,7 +169,6 @@ type PacketBuffer struct { func NewPacketBuffer(opts PacketBufferOptions) *PacketBuffer { pk := pkPool.Get().(*PacketBuffer) pk.reset() - pk.buf = &buffer.Buffer{} if opts.ReserveHeaderBytes != 0 { pk.buf.AppendOwned(make([]byte, opts.ReserveHeaderBytes)) pk.reserved = opts.ReserveHeaderBytes @@ -558,7 +557,7 @@ func (d PacketData) AppendView(v tcpipbuffer.View) { // frag and frag should not be used again. func MergeFragment(dst, frag *PacketBuffer) { frag.buf.TrimFront(int64(frag.dataOffset())) - dst.buf.Merge(frag.buf) + dst.buf.Merge(&frag.buf) } // ReadFromVV moves at most count bytes from the beginning of srcVV to the end