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
This commit is contained in:
Lucas Manning
2022-01-18 16:06:43 -08:00
committed by gVisor bot
parent 2f6454681c
commit 8c9dc0babf
3 changed files with 5 additions and 6 deletions
+2 -2
View File
@@ -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() {
@@ -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()
+2 -3
View File
@@ -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