Remove VectorisedView everywhere.

PiperOrigin-RevId: 453471156
This commit is contained in:
Lucas Manning
2022-06-07 10:36:23 -07:00
committed by gVisor bot
parent a30c81cd80
commit e64458ff08
75 changed files with 415 additions and 1545 deletions
+1 -1
View File
@@ -28,7 +28,6 @@ _templates:
PACKAGES: >
./pkg/tcpip
./pkg/tcpip/adapters/gonet
./pkg/tcpip/buffer
./pkg/tcpip/header
./pkg/tcpip/link/channel
./pkg/tcpip/network/ipv4
@@ -37,6 +36,7 @@ _templates:
./pkg/tcpip/transport/icmp
./pkg/tcpip/transport/tcp
./pkg/tcpip/transport/udp
./pkg/buffer
./pkg/waiter
env:
# Force a clean checkout every time to avoid reuse of files between runs.
+9
View File
@@ -18,6 +18,8 @@
// well as the ability to grow via either prepend or append, as well as shrink.
package buffer
import "bytes"
// buffer encapsulates a queueable byte buffer.
//
// +stateify savable
@@ -103,3 +105,10 @@ func (b *buffer) WriteMove(n int) {
func (b *buffer) WriteSlice() []byte {
return b.data[b.write:]
}
// Reader returns a bytes.Reader for v.
func (b *buffer) Reader() bytes.Reader {
var r bytes.Reader
r.Reset(b.ReadSlice())
return r
}
+10
View File
@@ -15,6 +15,7 @@
package buffer
import (
"bytes"
"fmt"
"io"
)
@@ -611,3 +612,12 @@ func (x Range) Len() int {
}
return l
}
// Readers returns a bytes.Reader for each of bufs's underlying buffers.
func (v *View) Readers() []bytes.Reader {
readers := make([]bytes.Reader, 0, v.data.Len())
for buf := v.data.Front(); buf != nil; buf = buf.Next() {
readers = append(readers, buf.Reader())
}
return readers
}
-1
View File
@@ -194,7 +194,6 @@ go_library(
"//pkg/sentry/usage",
"//pkg/sync",
"//pkg/sync/locking",
"//pkg/tcpip/buffer",
"//pkg/usermem",
],
)
+1 -1
View File
@@ -94,6 +94,7 @@ go_library(
deps = [
"//pkg/abi/linux",
"//pkg/atomicbitops",
"//pkg/buffer",
"//pkg/context",
"//pkg/errors/linuxerr",
"//pkg/fdnotifier",
@@ -109,7 +110,6 @@ go_library(
"//pkg/sync/locking",
"//pkg/syserr",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/unet",
"//pkg/waiter",
"@org_golang_x_sys//unix:go_default_library",
+1 -2
View File
@@ -18,7 +18,6 @@ import (
"gvisor.dev/gvisor/pkg/context"
"gvisor.dev/gvisor/pkg/syserr"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/waiter"
)
@@ -167,7 +166,7 @@ func (q *queue) Enqueue(ctx context.Context, data [][]byte, c ControlMessages, f
notify = q.dataList.Front() == nil
q.used += l
q.dataList.PushBack(&message{
Data: buffer.View(v),
Data: v,
Control: c,
Address: from,
})
+2 -3
View File
@@ -22,7 +22,6 @@ import (
"gvisor.dev/gvisor/pkg/log"
"gvisor.dev/gvisor/pkg/syserr"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/waiter"
)
@@ -282,7 +281,7 @@ type message struct {
messageEntry
// Data is the Message payload.
Data buffer.View
Data []byte
// Control is auxiliary control message data that goes along with the
// data.
@@ -314,7 +313,7 @@ func (m *message) Peek() *message {
//
// Preconditions: n <= m.Length().
func (m *message) Truncate(n int64) {
m.Data.CapLength(int(n))
m.Data = m.Data[:n]
}
// A Receiver can be used to receive Messages.
-1
View File
@@ -32,7 +32,6 @@ go_library(
deps = [
"//pkg/atomicbitops",
"//pkg/sync",
"//pkg/tcpip/buffer",
"//pkg/waiter",
],
)
-1
View File
@@ -9,7 +9,6 @@ go_library(
deps = [
"//pkg/sync",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/stack",
"//pkg/tcpip/transport/tcp",
"//pkg/tcpip/transport/udp",
+1 -2
View File
@@ -26,7 +26,6 @@ import (
"gvisor.dev/gvisor/pkg/sync"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
@@ -240,7 +239,7 @@ type TCPConn struct {
// read contains bytes that have been read from the endpoint,
// but haven't yet been returned.
read buffer.View
read []byte
}
// NewTCPConn creates a new TCPConn.
-24
View File
@@ -1,24 +0,0 @@
load("//tools:defs.bzl", "go_library", "go_test")
package(licenses = ["notice"])
go_library(
name = "buffer",
srcs = [
"view.go",
"view_unsafe.go",
],
visibility = ["//visibility:public"],
)
go_test(
name = "buffer_x_test",
size = "small",
srcs = [
"view_test.go",
],
deps = [
":buffer",
"//pkg/tcpip",
],
)
-315
View File
@@ -1,315 +0,0 @@
// Copyright 2018 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Package buffer provides the implementation of a buffer view.
package buffer
import (
"bytes"
"fmt"
"io"
)
// View is a slice of a buffer, with convenience methods.
type View []byte
// NewView allocates a new buffer and returns an initialized view that covers
// the whole buffer.
func NewView(size int) View {
return make(View, size)
}
// NewViewFromBytes allocates a new buffer and copies in the given bytes.
func NewViewFromBytes(b []byte) View {
return append(View(nil), b...)
}
// TrimFront removes the first "count" bytes from the visible section of the
// buffer.
func (v *View) TrimFront(count int) {
*v = (*v)[count:]
}
// CapLength irreversibly reduces the length of the visible section of the
// buffer to the value specified.
func (v *View) CapLength(length int) {
// We also set the slice cap because if we don't, one would be able to
// expand the view back to include the region just excluded. We want to
// prevent that to avoid potential data leak if we have uninitialized
// data in excluded region.
*v = (*v)[:length:length]
}
// Reader returns a bytes.Reader for v.
func (v *View) Reader() bytes.Reader {
var r bytes.Reader
r.Reset(*v)
return r
}
// ToVectorisedView returns a VectorisedView containing the receiver.
func (v View) ToVectorisedView() VectorisedView {
if len(v) == 0 {
return VectorisedView{}
}
return NewVectorisedView(len(v), []View{v})
}
// IsEmpty returns whether v is of length zero.
func (v View) IsEmpty() bool {
return len(v) == 0
}
// Size returns the length of v.
func (v View) Size() int {
return len(v)
}
// VectorisedView is a vectorised version of View using non contiguous memory.
// It supports all the convenience methods supported by View.
//
// +stateify savable
type VectorisedView struct {
views []View
size int
}
// NewVectorisedView creates a new vectorised view from an already-allocated
// slice of View and sets its size.
func NewVectorisedView(size int, views []View) VectorisedView {
return VectorisedView{views: views, size: size}
}
// TrimFront removes the first "count" bytes of the vectorised view. It panics
// if count > vv.Size().
func (vv *VectorisedView) TrimFront(count int) {
for count > 0 && len(vv.views) > 0 {
if count < len(vv.views[0]) {
vv.size -= count
vv.views[0].TrimFront(count)
return
}
count -= len(vv.views[0])
vv.removeFirst()
}
}
// Read implements io.Reader.
func (vv *VectorisedView) Read(b []byte) (copied int, err error) {
count := len(b)
for count > 0 && len(vv.views) > 0 {
if count < len(vv.views[0]) {
vv.size -= count
copy(b[copied:], vv.views[0][:count])
vv.views[0].TrimFront(count)
copied += count
return copied, nil
}
count -= len(vv.views[0])
copy(b[copied:], vv.views[0])
copied += len(vv.views[0])
vv.removeFirst()
}
if copied == 0 {
return 0, io.EOF
}
return copied, nil
}
// ReadToVV reads up to n bytes from vv to dstVV and removes them from vv. It
// returns the number of bytes copied.
func (vv *VectorisedView) ReadToVV(dstVV *VectorisedView, count int) (copied int) {
for count > 0 && len(vv.views) > 0 {
if count < len(vv.views[0]) {
vv.size -= count
dstVV.AppendView(vv.views[0][:count])
vv.views[0].TrimFront(count)
copied += count
return
}
count -= len(vv.views[0])
dstVV.AppendView(vv.views[0])
copied += len(vv.views[0])
vv.removeFirst()
}
return copied
}
// ReadTo reads up to count bytes from vv to dst. It also removes them from vv
// unless peek is true.
func (vv *VectorisedView) ReadTo(dst io.Writer, peek bool) (int, error) {
var err error
done := 0
for _, v := range vv.Views() {
var n int
n, err = dst.Write(v)
done += n
if err != nil {
break
}
if n != len(v) {
panic(fmt.Sprintf("io.Writer.Write succeeded with incomplete write: %d != %d", n, len(v)))
}
}
if !peek {
vv.TrimFront(done)
}
return done, err
}
// CapLength irreversibly reduces the length of the vectorised view.
func (vv *VectorisedView) CapLength(length int) {
if length < 0 {
length = 0
}
if vv.size < length {
return
}
vv.size = length
for i := range vv.views {
v := &vv.views[i]
if len(*v) >= length {
if length == 0 {
vv.views = vv.views[:i]
} else {
v.CapLength(length)
vv.views = vv.views[:i+1]
}
return
}
length -= len(*v)
}
}
// Clone returns a clone of this VectorisedView.
// If the buffer argument is large enough to contain all the Views of this
// VectorisedView, the method will avoid allocations and use the buffer to
// store the Views of the clone.
func (vv VectorisedView) Clone(buffer []View) VectorisedView {
return VectorisedView{views: append(buffer[:0], vv.views...), size: vv.size}
}
// PullUp returns the first "count" bytes of the vectorised view. If those
// bytes aren't already contiguous inside the vectorised view, PullUp will
// reallocate as needed to make them contiguous. PullUp fails and returns false
// when count > vv.Size().
func (vv *VectorisedView) PullUp(count int) (View, bool) {
if len(vv.views) == 0 {
return nil, count == 0
}
if count <= len(vv.views[0]) {
return vv.views[0][:count], true
}
if count > vv.size {
return nil, false
}
newFirst := NewView(count)
i := 0
for offset := 0; offset < count; i++ {
copy(newFirst[offset:], vv.views[i])
if count-offset < len(vv.views[i]) {
vv.views[i].TrimFront(count - offset)
break
}
offset += len(vv.views[i])
vv.views[i] = nil
}
// We're guaranteed that i > 0, since count is too large for the first
// view.
vv.views[i-1] = newFirst
vv.views = vv.views[i-1:]
return newFirst, true
}
// Size returns the size in bytes of the entire content stored in the
// vectorised view.
func (vv *VectorisedView) Size() int {
return vv.size
}
// MemSize returns the estimation size of the vv in memory, including backing
// buffer data.
func (vv *VectorisedView) MemSize() int {
var size int
for _, v := range vv.views {
size += cap(v)
}
return size + cap(vv.views)*viewStructSize + vectorisedViewStructSize
}
// ToView returns a single view containing the content of the vectorised view.
//
// If the vectorised view contains a single view, that view will be returned
// directly.
func (vv *VectorisedView) ToView() View {
if len(vv.views) == 1 {
return vv.views[0]
}
return vv.ToOwnedView()
}
// ToOwnedView returns a single view containing the content of the vectorised
// view that vv does not own.
func (vv *VectorisedView) ToOwnedView() View {
u := make([]byte, 0, vv.size)
for _, v := range vv.views {
u = append(u, v...)
}
return u
}
// Views returns the slice containing the all views.
func (vv *VectorisedView) Views() []View {
return vv.views
}
// Append appends the views in a vectorised view to this vectorised view.
func (vv *VectorisedView) Append(vv2 VectorisedView) {
vv.views = append(vv.views, vv2.views...)
vv.size += vv2.size
}
// AppendView appends the given view into this vectorised view.
func (vv *VectorisedView) AppendView(v View) {
if len(v) == 0 {
return
}
vv.views = append(vv.views, v)
vv.size += len(v)
}
// AppendViews appends views to vv.
func (vv *VectorisedView) AppendViews(views []View) {
vv.views = append(vv.views, views...)
for _, v := range views {
vv.size += len(v)
}
}
// Readers returns a bytes.Reader for each of vv's views.
func (vv *VectorisedView) Readers() []bytes.Reader {
readers := make([]bytes.Reader, 0, len(vv.views))
for _, v := range vv.views {
readers = append(readers, v.Reader())
}
return readers
}
// removeFirst panics when len(vv.views) < 1.
func (vv *VectorisedView) removeFirst() {
vv.size -= len(vv.views[0])
vv.views[0] = nil
vv.views = vv.views[1:]
}
File diff suppressed because it is too large Load Diff
-22
View File
@@ -1,22 +0,0 @@
// Copyright 2021 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package buffer
import "unsafe"
const (
vectorisedViewStructSize = int(unsafe.Sizeof(VectorisedView{}))
viewStructSize = int(unsafe.Sizeof(View{}))
)
+1 -1
View File
@@ -8,8 +8,8 @@ go_library(
srcs = ["checker.go"],
visibility = ["//visibility:public"],
deps = [
"//pkg/buffer",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/header",
"//pkg/tcpip/seqnum",
"@com_github_google_go_cmp//cmp:go_default_library",
+4 -4
View File
@@ -23,8 +23,8 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header"
"gvisor.dev/gvisor/pkg/tcpip/seqnum"
)
@@ -1546,7 +1546,7 @@ func IPv6WithExtHdr(t *testing.T, b []byte, checkers ...NetworkChecker) {
payloadIterator := header.MakeIPv6PayloadIterator(
header.IPv6ExtensionHeaderIdentifier(ipv6.NextHeader()),
buffer.View(ipv6.Payload()).ToVectorisedView(),
buffer.NewWithData(ipv6.Payload()),
)
var rawPayloadHeader header.IPv6RawPayloadHeader
@@ -1570,7 +1570,7 @@ func IPv6WithExtHdr(t *testing.T, b []byte, checkers ...NetworkChecker) {
networkHeader := ipv6HeaderWithExtHdr{
IPv6: ipv6,
transport: tcpip.TransportProtocolNumber(rawPayloadHeader.Identifier),
payload: rawPayloadHeader.Buf.ToView(),
payload: rawPayloadHeader.Buf.Flatten(),
}
for _, checker := range checkers {
@@ -1594,7 +1594,7 @@ func IPv6ExtHdr(headers ...IPv6ExtHdrChecker) NetworkChecker {
payloadIterator := header.MakeIPv6PayloadIterator(
header.IPv6ExtensionHeaderIdentifier(extHdrs.IPv6.NextHeader()),
buffer.View(extHdrs.IPv6.Payload()).ToVectorisedView(),
buffer.NewWithData(extHdrs.IPv6.Payload()),
)
for _, check := range headers {
+2 -3
View File
@@ -32,7 +32,6 @@ go_library(
deps = [
"//pkg/buffer",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/seqnum",
"@com_github_google_btree//:go_default_library",
],
@@ -51,9 +50,9 @@ go_test(
],
deps = [
":header",
"//pkg/buffer",
"//pkg/rand",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/prependable",
"//pkg/tcpip/testutil",
"@com_github_google_go_cmp//cmp:go_default_library",
@@ -71,8 +70,8 @@ go_test(
],
library = ":header",
deps = [
"//pkg/buffer",
"//pkg/tcpip",
"//pkg/tcpip/buffer",
"//pkg/tcpip/testutil",
"@com_github_google_go_cmp//cmp:go_default_library",
],
-13
View File
@@ -22,7 +22,6 @@ import (
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip"
tcpipbuffer "gvisor.dev/gvisor/pkg/tcpip/buffer"
)
// ChecksumSize is the size of a checksum.
@@ -193,18 +192,6 @@ func Checksum(buf []byte, initial uint16) uint16 {
return s
}
// ChecksumVV calculates the checksum (as defined in RFC 1071) of the bytes in
// the given VectorizedView.
//
// The initial checksum must have been computed on an even number of bytes.
func ChecksumVV(vv tcpipbuffer.VectorisedView, initial uint16) uint16 {
var c Checksumer
for _, v := range vv.Views() {
c.Add([]byte(v))
}
return ChecksumCombine(initial, c.Checksum())
}
// ChecksumBuffer calculates the checksum (as defined in RFC 1071) of the
// bytes in the given Buffer.
//
+16 -20
View File
@@ -23,8 +23,8 @@ import (
"sync"
"testing"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
"gvisor.dev/gvisor/pkg/tcpip/header"
)
@@ -63,8 +63,8 @@ func TestChecksumer(t *testing.T) {
{
name: "TwoEvenViews",
data: [][]byte{
buffer.NewViewFromBytes([]byte{98, 1, 9, 0}),
buffer.NewViewFromBytes([]byte{9, 0, 5, 4}),
[]byte{98, 1, 9, 0},
[]byte{9, 0, 5, 4},
},
want: 30981,
},
@@ -206,18 +206,16 @@ func TestICMPv4Checksum(t *testing.T) {
if _, err := rnd.Read(buf); err != nil {
t.Fatalf("rnd.Read failed: %v", err)
}
vv := buffer.NewVectorisedView(len(buf), []buffer.View{
buffer.NewViewFromBytes(buf[:5]),
buffer.NewViewFromBytes(buf[5:]),
})
b := buffer.NewWithData(buf[:5])
b.AppendOwned(buf[5:])
want := header.Checksum(vv.ToView(), 0)
want := header.Checksum(b.Flatten(), 0)
want = ^header.Checksum(h, want)
h.SetChecksum(want)
testICMPChecksum(t, h.Checksum, func() uint16 {
return header.ICMPv4Checksum(h, header.ChecksumVV(vv, 0))
}, want, fmt.Sprintf("header: {% x} data {% x}", h, vv.ToView()))
return header.ICMPv4Checksum(h, header.ChecksumBuffer(b, 0))
}, want, fmt.Sprintf("header: {% x} data {% x}", h, b.Flatten()))
}
func TestICMPv6Checksum(t *testing.T) {
@@ -233,17 +231,15 @@ func TestICMPv6Checksum(t *testing.T) {
if _, err := rnd.Read(buf); err != nil {
t.Fatalf("rnd.Read failed: %v", err)
}
vv := buffer.NewVectorisedView(len(buf), []buffer.View{
buffer.NewViewFromBytes(buf[:7]),
buffer.NewViewFromBytes(buf[7:10]),
buffer.NewViewFromBytes(buf[10:]),
})
b := buffer.NewWithData(buf[:7])
b.AppendOwned(buf[7:10])
b.AppendOwned(buf[10:])
dst := header.IPv6Loopback
src := header.IPv6Loopback
want := header.PseudoHeaderChecksum(header.ICMPv6ProtocolNumber, src, dst, uint16(len(h)+vv.Size()))
want = header.Checksum(vv.ToView(), want)
want := header.PseudoHeaderChecksum(header.ICMPv6ProtocolNumber, src, dst, uint16(len(h)+int(b.Size())))
want = header.Checksum(b.Flatten(), want)
want = ^header.Checksum(h, want)
h.SetChecksum(want)
@@ -252,10 +248,10 @@ func TestICMPv6Checksum(t *testing.T) {
Header: h,
Src: src,
Dst: dst,
PayloadCsum: header.ChecksumVV(vv, 0),
PayloadLen: vv.Size(),
PayloadCsum: header.ChecksumBuffer(b, 0),
PayloadLen: int(b.Size()),
})
}, want, fmt.Sprintf("header: {% x} data {% x}", h, vv.ToView()))
}, want, fmt.Sprintf("header: {% x} data {% x}", h, b.Flatten()))
}
func randomAddress(size int) tcpip.Address {
+8 -8
View File
@@ -23,8 +23,8 @@ import (
"io"
"math"
"gvisor.dev/gvisor/pkg/buffer"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/buffer"
)
// IPv6ExtensionHeaderIdentifier is an IPv6 extension header identifier.
@@ -161,7 +161,7 @@ type IPv6PayloadHeader interface {
// header.
type IPv6RawPayloadHeader struct {
Identifier IPv6ExtensionHeaderIdentifier
Buf buffer.VectorisedView
Buf buffer.Buffer
}
// isIPv6PayloadHeader implements IPv6PayloadHeader.isIPv6PayloadHeader.
@@ -469,7 +469,7 @@ type IPv6PayloadIterator struct {
// reader is an io.Reader over payload.
reader bufio.Reader
payload buffer.VectorisedView
payload buffer.Buffer
// Indicates to the iterator that it should return the remaining payload as a
// raw payload on the next call to Next.
@@ -501,7 +501,7 @@ func (i IPv6PayloadIterator) ParseOffset() uint32 {
// MakeIPv6PayloadIterator returns an iterator over the IPv6 payload containing
// extension headers, or a raw payload if the payload cannot be parsed.
func MakeIPv6PayloadIterator(nextHdrIdentifier IPv6ExtensionHeaderIdentifier, payload buffer.VectorisedView) IPv6PayloadIterator {
func MakeIPv6PayloadIterator(nextHdrIdentifier IPv6ExtensionHeaderIdentifier, payload buffer.Buffer) IPv6PayloadIterator {
readers := payload.Readers()
readerPs := make([]io.Reader, 0, len(readers))
for i := range readers {
@@ -510,7 +510,7 @@ func MakeIPv6PayloadIterator(nextHdrIdentifier IPv6ExtensionHeaderIdentifier, pa
return IPv6PayloadIterator{
nextHdrIdentifier: nextHdrIdentifier,
payload: payload.Clone(nil),
payload: payload.Clone(),
// We need a buffer of size 1 for calls to bufio.Reader.ReadByte.
reader: *bufio.NewReaderSize(io.MultiReader(readerPs...), 1),
nextOffset: IPv6FixedHeaderSize,
@@ -525,7 +525,7 @@ func MakeIPv6PayloadIterator(nextHdrIdentifier IPv6ExtensionHeaderIdentifier, pa
func (i *IPv6PayloadIterator) AsRawHeader(consume bool) IPv6RawPayloadHeader {
identifier := i.nextHdrIdentifier
var buf buffer.VectorisedView
var buf buffer.Buffer
if consume {
// Since we consume the iterator, we return the payload as is.
buf = i.payload
@@ -537,7 +537,7 @@ func (i *IPv6PayloadIterator) AsRawHeader(consume bool) IPv6RawPayloadHeader {
nextOffset: i.nextOffset,
}
} else {
buf = i.payload.Clone(nil)
buf = i.payload.Clone()
}
return IPv6RawPayloadHeader{Identifier: identifier, Buf: buf}
@@ -675,7 +675,7 @@ func (i *IPv6PayloadIterator) nextHeaderData(fragmentHdr bool, bytes []byte) (IP
}
n, err := io.ReadFull(&i.reader, bytes)
i.payload.TrimFront(n)
i.payload.TrimFront(int64(n))
if err != nil {
return 0, nil, fmt.Errorf("read %d out of %d extension header data bytes (length = %d) for header with id = %d: %w", n, bytesLen, length, i.nextHdrIdentifier, err)
}

Some files were not shown because too many files have changed in this diff Show More