mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Replace VectorisedView in network endpoints.
PiperOrigin-RevId: 451267391
This commit is contained in:
committed by
gVisor bot
parent
6f5e475674
commit
6103b4b3b6
@@ -11,6 +11,7 @@ go_test(
|
||||
"multicast_group_test.go",
|
||||
],
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/sync",
|
||||
|
||||
@@ -27,10 +27,10 @@ go_test(
|
||||
srcs = ["arp_test.go"],
|
||||
deps = [
|
||||
":arp",
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/faketime",
|
||||
"//pkg/tcpip/header",
|
||||
"//pkg/tcpip/link/channel",
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/refs"
|
||||
"gvisor.dev/gvisor/pkg/refsvfs2"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/channel"
|
||||
@@ -182,9 +182,8 @@ func TestMalformedPacket(t *testing.T) {
|
||||
c := makeTestContext(t, 0, 0)
|
||||
defer c.cleanup()
|
||||
|
||||
v := make(buffer.View, header.ARPSize)
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: v.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(make([]byte, header.ARPSize)),
|
||||
})
|
||||
|
||||
c.linkEP.InjectInbound(arp.ProtocolNumber, pkt)
|
||||
@@ -208,9 +207,8 @@ func TestDisabledEndpoint(t *testing.T) {
|
||||
}
|
||||
ep.Disable()
|
||||
|
||||
v := make(buffer.View, header.ARPSize)
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: v.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(make([]byte, header.ARPSize)),
|
||||
})
|
||||
|
||||
c.linkEP.InjectInbound(arp.ProtocolNumber, pkt)
|
||||
@@ -231,7 +229,7 @@ func TestDirectReply(t *testing.T) {
|
||||
const senderMAC = "\x01\x02\x03\x04\x05\x06"
|
||||
const senderIPv4 = "\x0a\x00\x00\x02"
|
||||
|
||||
v := make(buffer.View, header.ARPSize)
|
||||
v := make([]byte, header.ARPSize)
|
||||
h := header.ARP(v)
|
||||
h.SetIPv4OverEthernet()
|
||||
h.SetOp(header.ARPReply)
|
||||
@@ -242,7 +240,7 @@ func TestDirectReply(t *testing.T) {
|
||||
copy(h.ProtocolAddressTarget(), stackAddr)
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: v.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(v),
|
||||
})
|
||||
|
||||
c.linkEP.InjectInbound(arp.ProtocolNumber, pkt)
|
||||
@@ -298,7 +296,7 @@ func TestDirectRequest(t *testing.T) {
|
||||
outgoingReplies := c.s.Stats().ARP.OutgoingRepliesSent.Value()
|
||||
|
||||
// Inject an incoming ARP request.
|
||||
v := make(buffer.View, header.ARPSize)
|
||||
v := make([]byte, header.ARPSize)
|
||||
h := header.ARP(v)
|
||||
h.SetIPv4OverEthernet()
|
||||
h.SetOp(header.ARPRequest)
|
||||
@@ -306,7 +304,7 @@ func TestDirectRequest(t *testing.T) {
|
||||
copy(h.ProtocolAddressSender(), test.senderAddr)
|
||||
copy(h.ProtocolAddressTarget(), test.targetAddr)
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: v.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(v),
|
||||
})
|
||||
c.linkEP.InjectInbound(arp.ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
|
||||
@@ -27,6 +27,7 @@ go_library(
|
||||
"//pkg/tcpip/network/ipv6:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/log",
|
||||
"//pkg/sync",
|
||||
"//pkg/tcpip",
|
||||
@@ -46,9 +47,9 @@ go_test(
|
||||
],
|
||||
library = ":fragmentation",
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/faketime",
|
||||
"//pkg/tcpip/network/internal/testutil",
|
||||
"//pkg/tcpip/stack",
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/log"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
|
||||
@@ -286,8 +286,8 @@ func (f *Fragmentation) releaseReassemblersLocked() {
|
||||
|
||||
// PacketFragmenter is the book-keeping struct for packet fragmentation.
|
||||
type PacketFragmenter struct {
|
||||
transportHeader buffer.View
|
||||
data buffer.VectorisedView
|
||||
transportHeader []byte
|
||||
data buffer.Buffer
|
||||
reserve int
|
||||
fragmentPayloadLen int
|
||||
fragmentCount int
|
||||
@@ -312,9 +312,9 @@ func MakePacketFragmenter(pkt *stack.PacketBuffer, fragmentPayloadLen uint32, re
|
||||
// TODO(gvisor.dev/issue/3912): Once Authentication or ESP Headers are
|
||||
// supported for outbound packets, the fragmentable data should not include
|
||||
// these headers.
|
||||
var fragmentableData buffer.VectorisedView
|
||||
fragmentableData.AppendView(pkt.TransportHeader().View())
|
||||
fragmentableData.Append(pkt.Data().ExtractVV())
|
||||
fragmentableData := buffer.NewWithData(pkt.TransportHeader().View())
|
||||
pktBuf := pkt.Data().AsBuffer()
|
||||
fragmentableData.Merge(&pktBuf)
|
||||
fragmentCount := (uint32(fragmentableData.Size()) + fragmentPayloadLen - 1) / fragmentPayloadLen
|
||||
|
||||
return PacketFragmenter{
|
||||
@@ -344,7 +344,7 @@ func (pf *PacketFragmenter) BuildNextFragment() (*stack.PacketBuffer, int, int,
|
||||
})
|
||||
|
||||
// Copy data for the fragment.
|
||||
copied := fragPkt.Data().ReadFromVV(&pf.data, pf.fragmentPayloadLen)
|
||||
copied := fragPkt.Data().ReadFromBuffer(&pf.data, pf.fragmentPayloadLen)
|
||||
|
||||
offset := pf.fragmentOffset
|
||||
pf.fragmentOffset += copied
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/internal/testutil"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
@@ -30,19 +30,19 @@ import (
|
||||
// advances.
|
||||
const reassembleTimeout = 1
|
||||
|
||||
// vv is a helper to build VectorisedView from different strings.
|
||||
func vv(size int, pieces ...string) buffer.VectorisedView {
|
||||
views := make([]buffer.View, len(pieces))
|
||||
for i, p := range pieces {
|
||||
views[i] = []byte(p)
|
||||
// buf is a helper to build a Buffer from different strings.
|
||||
func buf(size int, pieces ...string) buffer.Buffer {
|
||||
buf := buffer.Buffer{}
|
||||
for _, p := range pieces {
|
||||
buf.Append([]byte(p))
|
||||
}
|
||||
|
||||
return buffer.NewVectorisedView(size, views)
|
||||
return buf
|
||||
}
|
||||
|
||||
func pkt(size int, pieces ...string) *stack.PacketBuffer {
|
||||
return stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv(size, pieces...),
|
||||
Payload: buf(size, pieces...),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ type processInput struct {
|
||||
}
|
||||
|
||||
type processOutput struct {
|
||||
vv buffer.VectorisedView
|
||||
buf buffer.Buffer
|
||||
proto uint8
|
||||
done bool
|
||||
}
|
||||
@@ -74,8 +74,8 @@ func TestFragmentationProcess(t *testing.T) {
|
||||
{id: FragmentID{ID: 0}, first: 2, last: 3, more: false, pkt: pkt(2, "23")},
|
||||
},
|
||||
out: []processOutput{
|
||||
{vv: buffer.VectorisedView{}, done: false},
|
||||
{vv: vv(4, "01", "23"), done: true},
|
||||
{buf: buffer.Buffer{}, done: false},
|
||||
{buf: buf(4, "01", "23"), done: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -85,8 +85,8 @@ func TestFragmentationProcess(t *testing.T) {
|
||||
{id: FragmentID{ID: 0}, first: 2, last: 3, more: false, proto: 17, pkt: pkt(2, "23")},
|
||||
},
|
||||
out: []processOutput{
|
||||
{vv: buffer.VectorisedView{}, done: false},
|
||||
{vv: vv(4, "01", "23"), proto: 6, done: true},
|
||||
{buf: buffer.Buffer{}, done: false},
|
||||
{buf: buf(4, "01", "23"), proto: 6, done: true},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -98,10 +98,10 @@ func TestFragmentationProcess(t *testing.T) {
|
||||
{id: FragmentID{ID: 0}, first: 2, last: 3, more: false, pkt: pkt(2, "23")},
|
||||
},
|
||||
out: []processOutput{
|
||||
{vv: buffer.VectorisedView{}, done: false},
|
||||
{vv: buffer.VectorisedView{}, done: false},
|
||||
{vv: vv(4, "ab", "cd"), done: true},
|
||||
{vv: vv(4, "01", "23"), done: true},
|
||||
{buf: buffer.Buffer{}, done: false},
|
||||
{buf: buffer.Buffer{}, done: false},
|
||||
{buf: buf(4, "ab", "cd"), done: true},
|
||||
{buf: buf(4, "01", "23"), done: true},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -124,7 +124,7 @@ func TestFragmentationProcess(t *testing.T) {
|
||||
in.id, in.first, in.last, in.more, in.proto, done, c.out[i].done)
|
||||
}
|
||||
if c.out[i].done {
|
||||
if diff := cmp.Diff(c.out[i].vv.ToOwnedView(), resPkt.Data().AsRange().ToOwnedView()); diff != "" {
|
||||
if diff := cmp.Diff(c.out[i].buf.Flatten(), resPkt.Data().AsRange().ToOwnedView()); diff != "" {
|
||||
t.Errorf("got Process(%+v, %d, %d, %t, %d, %#v) result mismatch (-want, +got):\n%s",
|
||||
in.id, in.first, in.last, in.more, in.proto, in.pkt, diff)
|
||||
}
|
||||
@@ -525,8 +525,8 @@ func TestPacketFragmenter(t *testing.T) {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
pkt := testutil.MakeRandPkt(test.transportHeaderLen, reserve, []int{test.payloadSize}, proto)
|
||||
defer pkt.DecRef()
|
||||
originalPayload := stack.PayloadSince(pkt.TransportHeader())
|
||||
var reassembledPayload buffer.VectorisedView
|
||||
originalPayload := []byte(stack.PayloadSince(pkt.TransportHeader()))
|
||||
var reassembledPayload buffer.Buffer
|
||||
pf := MakePacketFragmenter(pkt, test.fragmentPayloadLen, reserve)
|
||||
for i := 0; ; i++ {
|
||||
fragPkt, offset, copied, more := pf.BuildNextFragment()
|
||||
@@ -553,7 +553,8 @@ func TestPacketFragmenter(t *testing.T) {
|
||||
if got := fragPkt.TransportHeader().View().Size(); got != 0 {
|
||||
t.Errorf("(fragment #%d) got fragPkt.TransportHeader().View().Size() = %d, want = 0", i, got)
|
||||
}
|
||||
reassembledPayload.AppendViews(fragPkt.Data().Views())
|
||||
fragBuf := fragPkt.Data().AsBuffer()
|
||||
reassembledPayload.Merge(&fragBuf)
|
||||
if !more {
|
||||
if i != len(test.wantFragments)-1 {
|
||||
t.Errorf("got fragment count = %d, want = %d", i, len(test.wantFragments)-1)
|
||||
@@ -561,7 +562,7 @@ func TestPacketFragmenter(t *testing.T) {
|
||||
break
|
||||
}
|
||||
}
|
||||
if diff := cmp.Diff(reassembledPayload.ToView(), originalPayload); diff != "" {
|
||||
if diff := cmp.Diff(reassembledPayload.Flatten(), originalPayload); diff != "" {
|
||||
t.Errorf("reassembledPayload mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
)
|
||||
@@ -37,8 +37,8 @@ type processParams struct {
|
||||
func TestReassemblerProcess(t *testing.T) {
|
||||
const proto = 99
|
||||
|
||||
v := func(size int) buffer.View {
|
||||
payload := buffer.NewView(size)
|
||||
v := func(size int) []byte {
|
||||
payload := make([]byte, size)
|
||||
for i := 1; i < size; i++ {
|
||||
payload[i] = uint8(i) * 3
|
||||
}
|
||||
@@ -46,12 +46,12 @@ func TestReassemblerProcess(t *testing.T) {
|
||||
}
|
||||
|
||||
pkt := func(sizes ...int) *stack.PacketBuffer {
|
||||
var vv buffer.VectorisedView
|
||||
var buf buffer.Buffer
|
||||
for _, size := range sizes {
|
||||
vv.AppendView(v(size))
|
||||
buf.Append(v(size))
|
||||
}
|
||||
return stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv,
|
||||
Payload: buf,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ go_test(
|
||||
srcs = ["route_table_test.go"],
|
||||
library = ":multicast",
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/faketime",
|
||||
"//pkg/tcpip/stack",
|
||||
"//pkg/tcpip/testutil",
|
||||
@@ -38,10 +38,10 @@ go_test(
|
||||
srcs = ["example_test.go"],
|
||||
deps = [
|
||||
":multicast",
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/faketime",
|
||||
"//pkg/tcpip/stack",
|
||||
"//pkg/tcpip/testutil",
|
||||
|
||||
@@ -20,10 +20,10 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/refs"
|
||||
"gvisor.dev/gvisor/pkg/refsvfs2"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/network/internal/multicast"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
@@ -129,7 +129,7 @@ func deliverPktLocally(*stack.PacketBuffer) {
|
||||
|
||||
func newPacketBuffer(body string) *stack.PacketBuffer {
|
||||
return stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: buffer.View(body).ToVectorisedView(),
|
||||
Payload: buffer.NewWithData([]byte(body)),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/refs"
|
||||
"gvisor.dev/gvisor/pkg/refsvfs2"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/testutil"
|
||||
@@ -47,7 +47,7 @@ var (
|
||||
|
||||
func newPacketBuffer(body string) *stack.PacketBuffer {
|
||||
return stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: buffer.View(body).ToVectorisedView(),
|
||||
Payload: buffer.NewWithData([]byte(body)),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -258,10 +258,10 @@ func TestAddInstalledRouteWithPending(t *testing.T) {
|
||||
defer pkt.DecRef()
|
||||
|
||||
cmpOpts := []cmp.Option{
|
||||
cmp.Transformer("AsViews", func(pkt *stack.PacketBuffer) []buffer.View {
|
||||
return pkt.Views()
|
||||
cmp.Transformer("AsSlices", func(pkt *stack.PacketBuffer) [][]byte {
|
||||
return pkt.Slices()
|
||||
}),
|
||||
cmp.Comparer(func(a []buffer.View, b []buffer.View) bool {
|
||||
cmp.Comparer(func(a [][]byte, b [][]byte) bool {
|
||||
return cmp.Equal(a, b)
|
||||
}),
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ go_library(
|
||||
"//pkg/tcpip/tests/integration:__pkg__",
|
||||
],
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/header",
|
||||
"//pkg/tcpip/stack",
|
||||
],
|
||||
|
||||
@@ -20,8 +20,8 @@ import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
||||
"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/stack"
|
||||
)
|
||||
@@ -104,19 +104,19 @@ func (ep *MockLinkEndpoint) Close() {
|
||||
// the other headers. The payload is made from Views of the sizes listed in
|
||||
// viewSizes.
|
||||
func MakeRandPkt(transportHeaderLength int, extraHeaderReserveLength int, viewSizes []int, proto tcpip.NetworkProtocolNumber) *stack.PacketBuffer {
|
||||
var views buffer.VectorisedView
|
||||
var buffer buffer.Buffer
|
||||
|
||||
for _, s := range viewSizes {
|
||||
newView := buffer.NewView(s)
|
||||
newView := make([]byte, s)
|
||||
if _, err := rand.Read(newView); err != nil {
|
||||
panic(fmt.Sprintf("rand.Read: %s", err))
|
||||
}
|
||||
views.AppendView(newView)
|
||||
buffer.Append(newView)
|
||||
}
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: transportHeaderLength + extraHeaderReserveLength,
|
||||
Data: views,
|
||||
Payload: buffer,
|
||||
})
|
||||
pkt.NetworkProtocolNumber = proto
|
||||
if _, err := rand.Read(pkt.TransportHeader().Push(transportHeaderLength)); err != nil {
|
||||
|
||||
@@ -21,10 +21,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/refsvfs2"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
tcpipbuffer "gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/checker"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/link/channel"
|
||||
@@ -98,7 +99,7 @@ type testObject struct {
|
||||
// checkValues verifies that the transport protocol, data contents, src & dst
|
||||
// addresses of a packet match what's expected. If any field doesn't match, the
|
||||
// test fails.
|
||||
func (t *testObject) checkValues(protocol tcpip.TransportProtocolNumber, v buffer.View, srcAddr, dstAddr tcpip.Address) {
|
||||
func (t *testObject) checkValues(protocol tcpip.TransportProtocolNumber, v []byte, srcAddr, dstAddr tcpip.Address) {
|
||||
if protocol != t.protocol {
|
||||
t.t.Errorf("protocol = %v, want %v", protocol, t.protocol)
|
||||
}
|
||||
@@ -371,7 +372,7 @@ func (*testInterface) CheckLocalAddress(tcpip.NetworkProtocolNumber, tcpip.Addre
|
||||
func TestSourceAddressValidation(t *testing.T) {
|
||||
rxIPv4ICMP := func(e *channel.Endpoint, src tcpip.Address) {
|
||||
totalLen := header.IPv4MinimumSize + header.ICMPv4MinimumSize
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
pkt := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
|
||||
pkt.SetType(header.ICMPv4Echo)
|
||||
pkt.SetCode(0)
|
||||
@@ -388,7 +389,7 @@ func TestSourceAddressValidation(t *testing.T) {
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
|
||||
pktBuf := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(hdr.View()),
|
||||
})
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, pktBuf)
|
||||
pktBuf.DecRef()
|
||||
@@ -396,7 +397,7 @@ func TestSourceAddressValidation(t *testing.T) {
|
||||
|
||||
rxIPv6ICMP := func(e *channel.Endpoint, src tcpip.Address) {
|
||||
totalLen := header.IPv6MinimumSize + header.ICMPv6MinimumSize
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
pkt := header.ICMPv6(hdr.Prepend(header.ICMPv6MinimumSize))
|
||||
pkt.SetType(header.ICMPv6EchoRequest)
|
||||
pkt.SetCode(0)
|
||||
@@ -415,7 +416,7 @@ func TestSourceAddressValidation(t *testing.T) {
|
||||
DstAddr: localIPv6Addr,
|
||||
})
|
||||
pktBuf := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(hdr.View()),
|
||||
})
|
||||
e.InjectInbound(header.IPv6ProtocolNumber, pktBuf)
|
||||
pktBuf.DecRef()
|
||||
@@ -609,7 +610,7 @@ func TestIPv4Send(t *testing.T) {
|
||||
defer ep.Close()
|
||||
|
||||
// Allocate and initialize the payload view.
|
||||
payload := buffer.NewView(100)
|
||||
payload := make([]byte, 100)
|
||||
for i := 0; i < len(payload); i++ {
|
||||
payload[i] = uint8(i)
|
||||
}
|
||||
@@ -617,7 +618,7 @@ func TestIPv4Send(t *testing.T) {
|
||||
// Setup the packet buffer.
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: int(ep.MaxHeaderLength()),
|
||||
Data: payload.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(payload),
|
||||
})
|
||||
defer pkt.DecRef()
|
||||
|
||||
@@ -658,7 +659,7 @@ func TestReceive(t *testing.T) {
|
||||
handlePacket: func(t *testing.T, ep stack.NetworkEndpoint, nic *testInterface) {
|
||||
const totalLen = header.IPv4MinimumSize + 30 /* payload length */
|
||||
|
||||
view := buffer.NewView(totalLen)
|
||||
view := make([]byte, totalLen)
|
||||
ip := header.IPv4(view)
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
TotalLength: totalLen,
|
||||
@@ -681,7 +682,7 @@ func TestReceive(t *testing.T) {
|
||||
nic.testObject.contents = view[header.IPv4MinimumSize:totalLen]
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: view.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(view),
|
||||
})
|
||||
ep.HandlePacket(pkt)
|
||||
pkt.DecRef()
|
||||
@@ -695,7 +696,7 @@ func TestReceive(t *testing.T) {
|
||||
epAddr: localIPv6Addr.WithPrefix(),
|
||||
handlePacket: func(t *testing.T, ep stack.NetworkEndpoint, nic *testInterface) {
|
||||
const payloadLen = 30
|
||||
view := buffer.NewView(header.IPv6MinimumSize + payloadLen)
|
||||
view := make([]byte, header.IPv6MinimumSize+payloadLen)
|
||||
ip := header.IPv6(view)
|
||||
ip.Encode(&header.IPv6Fields{
|
||||
PayloadLength: payloadLen,
|
||||
@@ -717,7 +718,7 @@ func TestReceive(t *testing.T) {
|
||||
nic.testObject.contents = view[header.IPv6MinimumSize:][:payloadLen]
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: view.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(view),
|
||||
})
|
||||
ep.HandlePacket(pkt)
|
||||
pkt.DecRef()
|
||||
@@ -873,7 +874,7 @@ func TestIPv4ReceiveControl(t *testing.T) {
|
||||
}
|
||||
|
||||
const dataOffset = header.IPv4MinimumSize*2 + header.ICMPv4MinimumSize
|
||||
view := buffer.NewView(dataOffset + dataLen)
|
||||
view := make([]byte, dataOffset+dataLen)
|
||||
|
||||
// Create the outer IPv4 header.
|
||||
ip := header.IPv4(view)
|
||||
@@ -964,7 +965,7 @@ func TestIPv4FragmentationReceive(t *testing.T) {
|
||||
|
||||
totalLen := header.IPv4MinimumSize + 24
|
||||
|
||||
frag1 := buffer.NewView(totalLen)
|
||||
frag1 := make([]byte, totalLen)
|
||||
ip1 := header.IPv4(frag1)
|
||||
ip1.Encode(&header.IPv4Fields{
|
||||
TotalLength: uint16(totalLen),
|
||||
@@ -982,7 +983,7 @@ func TestIPv4FragmentationReceive(t *testing.T) {
|
||||
frag1[i] = uint8(i)
|
||||
}
|
||||
|
||||
frag2 := buffer.NewView(totalLen)
|
||||
frag2 := make([]byte, totalLen)
|
||||
ip2 := header.IPv4(frag2)
|
||||
ip2.Encode(&header.IPv4Fields{
|
||||
TotalLength: uint16(totalLen),
|
||||
@@ -1018,7 +1019,7 @@ func TestIPv4FragmentationReceive(t *testing.T) {
|
||||
|
||||
// Send first segment.
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: frag1.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(frag1),
|
||||
})
|
||||
ep.HandlePacket(pkt)
|
||||
pkt.DecRef()
|
||||
@@ -1032,7 +1033,7 @@ func TestIPv4FragmentationReceive(t *testing.T) {
|
||||
|
||||
// Send second segment.
|
||||
pkt = stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: frag2.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(frag2),
|
||||
})
|
||||
ep.HandlePacket(pkt)
|
||||
pkt.DecRef()
|
||||
@@ -1064,7 +1065,7 @@ func TestIPv6Send(t *testing.T) {
|
||||
}
|
||||
|
||||
// Allocate and initialize the payload view.
|
||||
payload := buffer.NewView(100)
|
||||
payload := make([]byte, 100)
|
||||
for i := 0; i < len(payload); i++ {
|
||||
payload[i] = uint8(i)
|
||||
}
|
||||
@@ -1072,7 +1073,7 @@ func TestIPv6Send(t *testing.T) {
|
||||
// Setup the packet buffer.
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: int(ep.MaxHeaderLength()),
|
||||
Data: payload.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(payload),
|
||||
})
|
||||
defer pkt.DecRef()
|
||||
// Issue the write.
|
||||
@@ -1225,7 +1226,7 @@ func TestIPv6ReceiveControl(t *testing.T) {
|
||||
if c.fragmentOffset != nil {
|
||||
dataOffset += header.IPv6FragmentHeaderSize
|
||||
}
|
||||
view := buffer.NewView(dataOffset + dataLen)
|
||||
view := make([]byte, dataOffset+dataLen)
|
||||
|
||||
// Create the outer IPv6 header.
|
||||
ip := header.IPv6(view)
|
||||
@@ -1309,10 +1310,10 @@ func TestIPv6ReceiveControl(t *testing.T) {
|
||||
// after truncation, is large enough to hold a network header, it makes part of
|
||||
// view the packet's NetworkHeader and the rest its Data. Otherwise all of view
|
||||
// becomes Data.
|
||||
func truncatedPacket(view buffer.View, trunc, netHdrLen int) *stack.PacketBuffer {
|
||||
func truncatedPacket(view []byte, trunc, netHdrLen int) *stack.PacketBuffer {
|
||||
v := view[:len(view)-trunc]
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: v.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(v),
|
||||
})
|
||||
return pkt
|
||||
}
|
||||
@@ -1360,7 +1361,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum tcpip.NetworkProtocolNumber
|
||||
nicAddr tcpip.AddressWithPrefix
|
||||
remoteAddr tcpip.Address
|
||||
pktGen func(*testing.T, tcpip.Address) buffer.VectorisedView
|
||||
pktGen func(*testing.T, tcpip.Address) buffer.Buffer
|
||||
checker func(*testing.T, *stack.PacketBuffer, tcpip.Address)
|
||||
expectedErr tcpip.Error
|
||||
}{
|
||||
@@ -1370,9 +1371,9 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv4.ProtocolNumber,
|
||||
nicAddr: localIPv4AddrWithPrefix,
|
||||
remoteAddr: remoteIPv4Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
totalLen := header.IPv4MinimumSize + len(data)
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
if n := copy(hdr.Prepend(len(data)), data); n != len(data) {
|
||||
t.Fatalf("copied %d bytes, expected %d bytes", n, len(data))
|
||||
}
|
||||
@@ -1383,7 +1384,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv4Addr,
|
||||
})
|
||||
return hdr.View().ToVectorisedView()
|
||||
return buffer.NewWithData(hdr.View())
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv4Any {
|
||||
@@ -1411,9 +1412,9 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv4.ProtocolNumber,
|
||||
nicAddr: localIPv4AddrWithPrefix,
|
||||
remoteAddr: remoteIPv4Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
totalLen := header.IPv4MinimumSize + len(data)
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
if n := copy(hdr.Prepend(len(data)), data); n != len(data) {
|
||||
t.Fatalf("copied %d bytes, expected %d bytes", n, len(data))
|
||||
}
|
||||
@@ -1425,7 +1426,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
DstAddr: remoteIPv4Addr,
|
||||
})
|
||||
ip.SetHeaderLength(header.IPv4MinimumSize - 1)
|
||||
return hdr.View().ToVectorisedView()
|
||||
return buffer.NewWithData(hdr.View())
|
||||
},
|
||||
expectedErr: &tcpip.ErrMalformedHeader{},
|
||||
},
|
||||
@@ -1435,7 +1436,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv4.ProtocolNumber,
|
||||
nicAddr: localIPv4AddrWithPrefix,
|
||||
remoteAddr: remoteIPv4Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
ip := header.IPv4(make([]byte, header.IPv4MinimumSize))
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
Protocol: transportProto,
|
||||
@@ -1443,7 +1444,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv4Addr,
|
||||
})
|
||||
return buffer.View(ip[:len(ip)-1]).ToVectorisedView()
|
||||
return buffer.NewWithData(ip[:len(ip)-1])
|
||||
},
|
||||
expectedErr: &tcpip.ErrMalformedHeader{},
|
||||
},
|
||||
@@ -1453,7 +1454,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv4.ProtocolNumber,
|
||||
nicAddr: localIPv4AddrWithPrefix,
|
||||
remoteAddr: remoteIPv4Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
ip := header.IPv4(make([]byte, header.IPv4MinimumSize))
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
Protocol: transportProto,
|
||||
@@ -1461,7 +1462,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv4Addr,
|
||||
})
|
||||
return buffer.View(ip).ToVectorisedView()
|
||||
return buffer.NewWithData(ip)
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv4Any {
|
||||
@@ -1489,10 +1490,10 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv4.ProtocolNumber,
|
||||
nicAddr: localIPv4AddrWithPrefix,
|
||||
remoteAddr: remoteIPv4Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
ipHdrLen := int(header.IPv4MinimumSize + ipv4Options.Length())
|
||||
totalLen := ipHdrLen + len(data)
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
if n := copy(hdr.Prepend(len(data)), data); n != len(data) {
|
||||
t.Fatalf("copied %d bytes, expected %d bytes", n, len(data))
|
||||
}
|
||||
@@ -1504,7 +1505,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
DstAddr: remoteIPv4Addr,
|
||||
Options: ipv4Options,
|
||||
})
|
||||
return hdr.View().ToVectorisedView()
|
||||
return buffer.NewWithData(hdr.View())
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv4Any {
|
||||
@@ -1534,7 +1535,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv4.ProtocolNumber,
|
||||
nicAddr: localIPv4AddrWithPrefix,
|
||||
remoteAddr: remoteIPv4Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
ip := header.IPv4(make([]byte, header.IPv4MinimumSize+ipv4Options.Length()))
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
Protocol: transportProto,
|
||||
@@ -1543,9 +1544,9 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
DstAddr: remoteIPv4Addr,
|
||||
Options: ipv4Options,
|
||||
})
|
||||
vv := buffer.View(ip).ToVectorisedView()
|
||||
vv.AppendView(data)
|
||||
return vv
|
||||
buf := buffer.NewWithData(ip)
|
||||
buf.Append(data)
|
||||
return buf
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv4Any {
|
||||
@@ -1575,9 +1576,9 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv6.ProtocolNumber,
|
||||
nicAddr: localIPv6AddrWithPrefix,
|
||||
remoteAddr: remoteIPv6Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
totalLen := header.IPv6MinimumSize + len(data)
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
if n := copy(hdr.Prepend(len(data)), data); n != len(data) {
|
||||
t.Fatalf("copied %d bytes, expected %d bytes", n, len(data))
|
||||
}
|
||||
@@ -1588,7 +1589,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv6Addr,
|
||||
})
|
||||
return hdr.View().ToVectorisedView()
|
||||
return buffer.NewWithData(hdr.View())
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv6Any {
|
||||
@@ -1615,9 +1616,9 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv6.ProtocolNumber,
|
||||
nicAddr: localIPv6AddrWithPrefix,
|
||||
remoteAddr: remoteIPv6Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
totalLen := header.IPv6MinimumSize + len(ipv6FragmentExtHdr) + len(data)
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
if n := copy(hdr.Prepend(len(data)), data); n != len(data) {
|
||||
t.Fatalf("copied %d bytes, expected %d bytes", n, len(data))
|
||||
}
|
||||
@@ -1633,7 +1634,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv6Addr,
|
||||
})
|
||||
return hdr.View().ToVectorisedView()
|
||||
return buffer.NewWithData(hdr.View())
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv6Any {
|
||||
@@ -1660,7 +1661,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv6.ProtocolNumber,
|
||||
nicAddr: localIPv6AddrWithPrefix,
|
||||
remoteAddr: remoteIPv6Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
ip := header.IPv6(make([]byte, header.IPv6MinimumSize))
|
||||
ip.Encode(&header.IPv6Fields{
|
||||
TransportProtocol: transportProto,
|
||||
@@ -1668,7 +1669,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv6Addr,
|
||||
})
|
||||
return buffer.View(ip).ToVectorisedView()
|
||||
return buffer.NewWithData(ip)
|
||||
},
|
||||
checker: func(t *testing.T, pkt *stack.PacketBuffer, src tcpip.Address) {
|
||||
if src == header.IPv6Any {
|
||||
@@ -1695,7 +1696,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
protoNum: ipv6.ProtocolNumber,
|
||||
nicAddr: localIPv6AddrWithPrefix,
|
||||
remoteAddr: remoteIPv6Addr,
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.VectorisedView {
|
||||
pktGen: func(t *testing.T, src tcpip.Address) buffer.Buffer {
|
||||
ip := header.IPv6(make([]byte, header.IPv6MinimumSize))
|
||||
ip.Encode(&header.IPv6Fields{
|
||||
TransportProtocol: transportProto,
|
||||
@@ -1703,7 +1704,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: remoteIPv4Addr,
|
||||
})
|
||||
return buffer.View(ip[:len(ip)-1]).ToVectorisedView()
|
||||
return buffer.NewWithData(ip[:len(ip)-1])
|
||||
},
|
||||
expectedErr: &tcpip.ErrMalformedHeader{},
|
||||
},
|
||||
@@ -1758,7 +1759,7 @@ func TestWriteHeaderIncludedPacket(t *testing.T) {
|
||||
|
||||
{
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: test.pktGen(t, subTest.srcAddr),
|
||||
Payload: test.pktGen(t, subTest.srcAddr),
|
||||
})
|
||||
err := r.WriteHeaderIncludedPacket(pkt)
|
||||
pkt.DecRef()
|
||||
@@ -1798,9 +1799,9 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
// IPv4 function to create a IP packet and send it to the stack.
|
||||
// The packet should generate an error response. We can do that by using an
|
||||
// unknown transport protocol (254).
|
||||
rxIPv4Bad := func(e *channel.Endpoint, src tcpip.Address, payload []byte) buffer.View {
|
||||
rxIPv4Bad := func(e *channel.Endpoint, src tcpip.Address, payload []byte) []byte {
|
||||
totalLen := header.IPv4MinimumSize + len(payload)
|
||||
hdr := buffer.NewPrependable(header.IPv4MinimumSize)
|
||||
hdr := tcpipbuffer.NewPrependable(header.IPv4MinimumSize)
|
||||
ip := header.IPv4(hdr.Prepend(header.IPv4MinimumSize))
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
TotalLength: uint16(totalLen),
|
||||
@@ -1810,13 +1811,13 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
DstAddr: localIPv4Addr,
|
||||
})
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
vv := hdr.View().ToVectorisedView()
|
||||
vv.AppendView(buffer.View(payload))
|
||||
buf := buffer.NewWithData(hdr.View())
|
||||
buf.Append(payload)
|
||||
// Take a copy before InjectInbound takes ownership of vv
|
||||
// as vv may be changed during the call.
|
||||
v := vv.ToView()
|
||||
v := buf.Flatten()
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv,
|
||||
Payload: buf,
|
||||
})
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
@@ -1828,8 +1829,8 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
// ICMP error response and have enough data to allow the testing of the
|
||||
// inclusion of the errant packet. Use `unknown next header' to generate
|
||||
// the error.
|
||||
rxIPv6Bad := func(e *channel.Endpoint, src tcpip.Address, payload []byte) buffer.View {
|
||||
hdr := buffer.NewPrependable(header.IPv6MinimumSize)
|
||||
rxIPv6Bad := func(e *channel.Endpoint, src tcpip.Address, payload []byte) []byte {
|
||||
hdr := tcpipbuffer.NewPrependable(header.IPv6MinimumSize)
|
||||
ip := header.IPv6(hdr.Prepend(header.IPv6MinimumSize))
|
||||
ip.Encode(&header.IPv6Fields{
|
||||
PayloadLength: uint16(len(payload)),
|
||||
@@ -1838,21 +1839,21 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
SrcAddr: src,
|
||||
DstAddr: localIPv6Addr,
|
||||
})
|
||||
vv := hdr.View().ToVectorisedView()
|
||||
vv.AppendView(buffer.View(payload))
|
||||
buf := buffer.NewWithData(hdr.View())
|
||||
buf.Append(payload)
|
||||
// Take a copy before InjectInbound takes ownership of vv
|
||||
// as vv may be changed during the call.
|
||||
v := vv.ToView()
|
||||
v := buf.Flatten()
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv,
|
||||
Payload: buf,
|
||||
})
|
||||
e.InjectInbound(header.IPv6ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
return v
|
||||
}
|
||||
|
||||
v4Checker := func(t *testing.T, pkt *stack.PacketBuffer, payload buffer.View) {
|
||||
v4Checker := func(t *testing.T, pkt *stack.PacketBuffer, payload []byte) {
|
||||
// We already know the entire packet is the right size so we can use its
|
||||
// length to calculate the right payload size to check.
|
||||
expectedPayloadLength := pkt.Size() - header.IPv4MinimumSize - header.ICMPv4MinimumSize
|
||||
@@ -1870,7 +1871,7 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
)
|
||||
}
|
||||
|
||||
v6Checker := func(t *testing.T, pkt *stack.PacketBuffer, payload buffer.View) {
|
||||
v6Checker := func(t *testing.T, pkt *stack.PacketBuffer, payload []byte) {
|
||||
// We already know the entire packet is the right size so we can use its
|
||||
// length to calculate the right payload size to check.
|
||||
expectedPayloadLength := pkt.Size() - header.IPv6MinimumSize - header.ICMPv6MinimumSize
|
||||
@@ -1888,8 +1889,8 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
srcAddress tcpip.Address
|
||||
injector func(*channel.Endpoint, tcpip.Address, []byte) buffer.View
|
||||
checker func(*testing.T, *stack.PacketBuffer, buffer.View)
|
||||
injector func(*channel.Endpoint, tcpip.Address, []byte) []byte
|
||||
checker func(*testing.T, *stack.PacketBuffer, []byte)
|
||||
payloadLength int // Not including IP header.
|
||||
linkMTU uint32 // Largest IP packet that the link can send as payload.
|
||||
replyLength int // Total size of IP/ICMP packet expected back.
|
||||
@@ -2006,7 +2007,7 @@ func TestICMPInclusionSize(t *testing.T) {
|
||||
e := addLinkEndpointToStackWithMTU(t, s, test.linkMTU)
|
||||
defer e.Close()
|
||||
// Allocate and initialize the payload view.
|
||||
payload := buffer.NewView(test.payloadLength)
|
||||
payload := make([]byte, test.payloadLength)
|
||||
for i := 0; i < len(payload); i++ {
|
||||
payload[i] = uint8(i)
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/atomicbitops",
|
||||
"//pkg/buffer",
|
||||
"//pkg/sync",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
@@ -35,6 +36,7 @@ go_test(
|
||||
"main_test.go",
|
||||
],
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/sync",
|
||||
|
||||
@@ -17,8 +17,8 @@ package ipv4
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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/header/parse"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
@@ -324,11 +324,11 @@ func (e *endpoint) handleICMP(pkt *stack.PacketBuffer) {
|
||||
replyICMPHdr.SetChecksum(0)
|
||||
replyICMPHdr.SetChecksum(^header.Checksum(replyData, 0))
|
||||
|
||||
replyVV := buffer.View(replyIPHdr).ToVectorisedView()
|
||||
replyVV.AppendView(replyData)
|
||||
replyBuf := buffer.NewWithData(replyIPHdr)
|
||||
replyBuf.AppendOwned(replyData)
|
||||
replyPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: int(r.MaxHeaderLength()),
|
||||
Data: replyVV,
|
||||
Payload: replyBuf,
|
||||
})
|
||||
defer replyPkt.DecRef()
|
||||
// Populate the network/transport headers in the packet buffer so the
|
||||
@@ -641,18 +641,20 @@ func (p *protocol) returnError(reason icmpReason, pkt *stack.PacketBuffer, deliv
|
||||
// view with the entire incoming IP packet reassembled and truncated as
|
||||
// required. This is now the payload of the new ICMP packet and no longer
|
||||
// considered a packet in its own right.
|
||||
newHeader := append(buffer.View(nil), origIPHdr...)
|
||||
|
||||
var newHeader []byte
|
||||
newHeader = append(newHeader, origIPHdr...)
|
||||
newHeader = append(newHeader, transportHeader...)
|
||||
payload := newHeader.ToVectorisedView()
|
||||
if dataCap := payloadLen - payload.Size(); dataCap > 0 {
|
||||
payload.AppendView(pkt.Data().AsRange().Capped(dataCap).ToOwnedView())
|
||||
payload := buffer.NewWithData(newHeader)
|
||||
if dataCap := payloadLen - int(payload.Size()); dataCap > 0 {
|
||||
payload.AppendOwned(pkt.Data().AsRange().Capped(dataCap).ToOwnedView())
|
||||
} else {
|
||||
payload.CapLength(payloadLen)
|
||||
payload.Truncate(int64(payloadLen))
|
||||
}
|
||||
|
||||
icmpPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: int(route.MaxHeaderLength()) + header.ICMPv4MinimumSize,
|
||||
Data: payload,
|
||||
Payload: payload,
|
||||
})
|
||||
defer icmpPkt.DecRef()
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ import (
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/atomicbitops"
|
||||
"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/network/internal/ip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
||||
@@ -312,14 +312,14 @@ func (igmp *igmpState) handleMembershipReport(groupAddress tcpip.Address) {
|
||||
//
|
||||
// +checklocksread:igmp.ep.mu
|
||||
func (igmp *igmpState) writePacket(destAddress tcpip.Address, groupAddress tcpip.Address, igmpType header.IGMPType) (bool, tcpip.Error) {
|
||||
igmpData := header.IGMP(buffer.NewView(header.IGMPReportMinimumSize))
|
||||
igmpData := header.IGMP(make([]byte, header.IGMPReportMinimumSize))
|
||||
igmpData.SetType(igmpType)
|
||||
igmpData.SetGroupAddress(groupAddress)
|
||||
igmpData.SetChecksum(header.IGMPCalculateChecksum(igmpData))
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: int(igmp.ep.MaxHeaderLength()),
|
||||
Data: buffer.View(igmpData).ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(igmpData),
|
||||
})
|
||||
defer pkt.DecRef()
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/refsvfs2"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/checker"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
@@ -110,7 +110,7 @@ func createAndInjectIGMPPacket(e *channel.Endpoint, igmpType header.IGMPType, ma
|
||||
&header.IPv4SerializableRouterAlertOption{},
|
||||
}
|
||||
}
|
||||
buf := buffer.NewView(header.IPv4MinimumSize + int(options.Length()) + header.IGMPQueryMinimumSize)
|
||||
buf := make([]byte, header.IPv4MinimumSize+int(options.Length())+header.IGMPQueryMinimumSize)
|
||||
|
||||
ip := header.IPv4(buf)
|
||||
ip.Encode(&header.IPv4Fields{
|
||||
@@ -129,7 +129,7 @@ func createAndInjectIGMPPacket(e *channel.Endpoint, igmpType header.IGMPType, ma
|
||||
igmp.SetGroupAddress(groupAddress)
|
||||
igmp.SetChecksum(header.IGMPCalculateChecksum(igmp))
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: buf.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(buf),
|
||||
})
|
||||
e.InjectInbound(ipv4.ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
|
||||
@@ -124,7 +124,7 @@ func (e *endpoint) HandleLinkResolutionFailure(pkt *stack.PacketBuffer) {
|
||||
// handleControl expects the entire offending packet to be in the packet
|
||||
// buffer's data field.
|
||||
pkt = stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: buffer.NewVectorisedView(pkt.Size(), pkt.Views()),
|
||||
Payload: pkt.Buffer(),
|
||||
})
|
||||
defer pkt.DecRef()
|
||||
pkt.NICID = e.nic.ID()
|
||||
@@ -1423,6 +1423,8 @@ func (p *protocol) MinimumPacketSize() int {
|
||||
}
|
||||
|
||||
// ParseAddresses implements stack.NetworkProtocol.
|
||||
// TODO(b/230896518): Remove buffer.View once stack.NetworkProtocol is changed
|
||||
// to use pkg/buffer.Buffer.
|
||||
func (*protocol) ParseAddresses(v buffer.View) (src, dst tcpip.Address) {
|
||||
h := header.IPv4(v)
|
||||
return h.SourceAddress(), h.DestinationAddress()
|
||||
|
||||
@@ -26,10 +26,11 @@ import (
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"gvisor.dev/gvisor/pkg/buffer"
|
||||
"gvisor.dev/gvisor/pkg/refsvfs2"
|
||||
"gvisor.dev/gvisor/pkg/sync"
|
||||
"gvisor.dev/gvisor/pkg/tcpip"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
tcpipbuffer "gvisor.dev/gvisor/pkg/tcpip/buffer"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/checker"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/faketime"
|
||||
"gvisor.dev/gvisor/pkg/tcpip/header"
|
||||
@@ -246,7 +247,7 @@ func newICMPEchoPacket(t *testing.T, srcAddr, dstAddr tcpip.Address, ttl uint8,
|
||||
t.Fatalf("ipHeaderLength = %d, want <= %d ", ipHeaderLength, header.IPv4MaximumHeaderSize)
|
||||
}
|
||||
totalLength := ipHeaderLength + header.ICMPv4MinimumSize + options.payloadLength
|
||||
hdr := buffer.NewPrependable(totalLength)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLength)
|
||||
hdr.Prepend(options.payloadLength)
|
||||
icmpH := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
|
||||
icmpH.SetIdent(randomIdent)
|
||||
@@ -1739,7 +1740,9 @@ func TestIPv4Sanity(t *testing.T) {
|
||||
t.Fatalf("IP header length too large: got = %d, want <= %d ", ipHeaderLength, header.IPv4MaximumHeaderSize)
|
||||
}
|
||||
totalLen := uint16(ipHeaderLength + header.ICMPv4MinimumSize)
|
||||
hdr := buffer.NewPrependable(int(totalLen))
|
||||
// TODO(b/230896518): tcpipbuffer is only needed for Prependable. Move
|
||||
// Prependable to outside pkg/tcpip/buffer.
|
||||
hdr := tcpipbuffer.NewPrependable(int(totalLen))
|
||||
icmpH := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
|
||||
|
||||
// Specify ident/seq to make sure we get the same in the response.
|
||||
@@ -1780,7 +1783,7 @@ func TestIPv4Sanity(t *testing.T) {
|
||||
}
|
||||
ip.SetChecksum(^ipHeaderChecksum)
|
||||
requestPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(hdr.View()),
|
||||
})
|
||||
defer requestPkt.DecRef()
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, requestPkt)
|
||||
@@ -1908,29 +1911,29 @@ func TestIPv4Sanity(t *testing.T) {
|
||||
func compareFragments(packets []*stack.PacketBuffer, sourcePacket *stack.PacketBuffer, mtu uint32, wantFragments []fragmentInfo, proto tcpip.TransportProtocolNumber, withIPHeader bool, expectedAvailableHeaderBytes int) error {
|
||||
// Make a complete array of the sourcePacket packet.
|
||||
var source header.IPv4
|
||||
vv := buffer.NewVectorisedView(sourcePacket.Size(), sourcePacket.Views())
|
||||
buf := sourcePacket.Buffer()
|
||||
|
||||
// If the packet to be fragmented contains an IPv4 header, use that header for
|
||||
// validating fragment headers. Else, use the header of the first fragment.
|
||||
if withIPHeader {
|
||||
source = header.IPv4(vv.ToView())
|
||||
source = header.IPv4(buf.Flatten())
|
||||
} else {
|
||||
source = header.IPv4(packets[0].NetworkHeader().View())
|
||||
source = append(source, vv.ToView()...)
|
||||
source = append(source, buf.Flatten()...)
|
||||
}
|
||||
|
||||
// Make a copy of the IP header, which will be modified in some fields to make
|
||||
// an expected header.
|
||||
sourceCopy := header.IPv4(append(buffer.View(nil), source[:source.HeaderLength()]...))
|
||||
sourceCopy := header.IPv4(append([]byte{}, source[:source.HeaderLength()]...))
|
||||
sourceCopy.SetChecksum(0)
|
||||
sourceCopy.SetFlagsFragmentOffset(0, 0)
|
||||
sourceCopy.SetTotalLength(0)
|
||||
// Build up an array of the bytes sent.
|
||||
var reassembledPayload buffer.VectorisedView
|
||||
var reassembledPayload buffer.Buffer
|
||||
for i, packet := range packets {
|
||||
// Confirm that the packet is valid.
|
||||
allBytes := buffer.NewVectorisedView(packet.Size(), packet.Views())
|
||||
fragmentIPHeader := header.IPv4(allBytes.ToView())
|
||||
allBytes := packet.Buffer()
|
||||
fragmentIPHeader := header.IPv4(allBytes.Flatten())
|
||||
if !fragmentIPHeader.IsValid(len(fragmentIPHeader)) {
|
||||
return fmt.Errorf("fragment #%d: IP packet is invalid:\n%s", i, hex.Dump(fragmentIPHeader))
|
||||
}
|
||||
@@ -1954,8 +1957,8 @@ func compareFragments(packets []*stack.PacketBuffer, sourcePacket *stack.PacketB
|
||||
} else {
|
||||
sourceCopy.SetFlagsFragmentOffset(sourceCopy.Flags()&^header.IPv4FlagMoreFragments, wantFragments[i].offset)
|
||||
}
|
||||
reassembledPayload.AppendView(packet.TransportHeader().View())
|
||||
reassembledPayload.AppendView(packet.Data().AsRange().ToOwnedView())
|
||||
reassembledPayload.Append(packet.TransportHeader().View())
|
||||
reassembledPayload.Append(packet.Data().AsRange().ToOwnedView())
|
||||
// Clear out the checksum and length from the ip because we can't compare
|
||||
// it.
|
||||
sourceCopy.SetTotalLength(wantFragments[i].payloadSize + header.IPv4MinimumSize)
|
||||
@@ -1974,8 +1977,8 @@ func compareFragments(packets []*stack.PacketBuffer, sourcePacket *stack.PacketB
|
||||
}
|
||||
}
|
||||
|
||||
expected := buffer.View(source[source.HeaderLength():])
|
||||
if diff := cmp.Diff(expected, reassembledPayload.ToView()); diff != "" {
|
||||
expected := []byte(source[source.HeaderLength():])
|
||||
if diff := cmp.Diff(expected, reassembledPayload.Flatten()); diff != "" {
|
||||
return fmt.Errorf("reassembledPayload mismatch (-want +got):\n%s", diff)
|
||||
}
|
||||
|
||||
@@ -2486,7 +2489,7 @@ func TestInvalidFragments(t *testing.T) {
|
||||
|
||||
for _, f := range test.fragments {
|
||||
pktSize := header.IPv4MinimumSize + len(f.payload)
|
||||
hdr := buffer.NewPrependable(pktSize)
|
||||
hdr := tcpipbuffer.NewPrependable(pktSize)
|
||||
|
||||
ip := header.IPv4(hdr.Prepend(pktSize))
|
||||
ip.Encode(&f.ipv4fields)
|
||||
@@ -2509,9 +2512,8 @@ func TestInvalidFragments(t *testing.T) {
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
}
|
||||
|
||||
vv := hdr.View().ToVectorisedView()
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv,
|
||||
Payload: buffer.NewWithData(hdr.View()),
|
||||
})
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
@@ -2718,10 +2720,10 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
||||
NIC: nicID,
|
||||
}})
|
||||
|
||||
var firstFragmentSent buffer.View
|
||||
var firstFragmentSent buffer.Buffer
|
||||
for _, f := range test.fragments {
|
||||
pktSize := header.IPv4MinimumSize
|
||||
hdr := buffer.NewPrependable(pktSize)
|
||||
hdr := tcpipbuffer.NewPrependable(pktSize)
|
||||
|
||||
ip := header.IPv4(hdr.Prepend(pktSize))
|
||||
ip.Encode(&f.ipv4fields)
|
||||
@@ -2729,15 +2731,15 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
||||
ip.SetChecksum(0)
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
|
||||
vv := hdr.View().ToVectorisedView()
|
||||
vv.AppendView(f.payload)
|
||||
buf := buffer.NewWithData(hdr.View())
|
||||
buf.Append(f.payload)
|
||||
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv,
|
||||
Payload: buf,
|
||||
})
|
||||
|
||||
if firstFragmentSent == nil && ip.FragmentOffset() == 0 {
|
||||
firstFragmentSent = stack.PayloadSince(pkt.NetworkHeader())
|
||||
if firstFragmentSent.Size() == 0 && ip.FragmentOffset() == 0 {
|
||||
firstFragmentSent = buffer.NewWithData(stack.PayloadSince(pkt.NetworkHeader()))
|
||||
}
|
||||
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, pkt)
|
||||
@@ -2756,7 +2758,7 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
||||
if reply == nil {
|
||||
t.Fatal("expected ICMP error message missing")
|
||||
}
|
||||
if firstFragmentSent == nil {
|
||||
if firstFragmentSent.Size() == 0 {
|
||||
t.Fatalf("unexpected ICMP error message received: %#v", reply)
|
||||
}
|
||||
|
||||
@@ -2769,7 +2771,7 @@ func TestFragmentReassemblyTimeout(t *testing.T) {
|
||||
checker.ICMPv4Type(header.ICMPv4TimeExceeded),
|
||||
checker.ICMPv4Code(header.ICMPv4ReassemblyTimeout),
|
||||
checker.ICMPv4Checksum(),
|
||||
checker.ICMPv4Payload(firstFragmentSent),
|
||||
checker.ICMPv4Payload(firstFragmentSent.Flatten()),
|
||||
),
|
||||
)
|
||||
reply.DecRef()
|
||||
@@ -2789,15 +2791,15 @@ func TestReceiveFragments(t *testing.T) {
|
||||
)
|
||||
|
||||
// Build and return a UDP header containing payload.
|
||||
udpGen := func(payloadLen int, multiplier uint8, src, dst tcpip.Address) buffer.View {
|
||||
payload := buffer.NewView(payloadLen)
|
||||
udpGen := func(payloadLen int, multiplier uint8, src, dst tcpip.Address) []byte {
|
||||
payload := make([]byte, payloadLen)
|
||||
for i := 0; i < len(payload); i++ {
|
||||
payload[i] = uint8(i) * multiplier
|
||||
}
|
||||
|
||||
udpLength := header.UDPMinimumSize + len(payload)
|
||||
|
||||
hdr := buffer.NewPrependable(udpLength)
|
||||
hdr := tcpipbuffer.NewPrependable(udpLength)
|
||||
u := header.UDP(hdr.Prepend(udpLength))
|
||||
u.Encode(&header.UDPFields{
|
||||
SrcPort: 5555,
|
||||
@@ -2834,7 +2836,7 @@ func TestReceiveFragments(t *testing.T) {
|
||||
id uint16
|
||||
flags uint8
|
||||
fragmentOffset uint16
|
||||
payload buffer.View
|
||||
payload []byte
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@@ -3210,7 +3212,7 @@ func TestReceiveFragments(t *testing.T) {
|
||||
|
||||
// Prepare and send the fragments.
|
||||
for _, frag := range test.fragments {
|
||||
hdr := buffer.NewPrependable(header.IPv4MinimumSize)
|
||||
hdr := tcpipbuffer.NewPrependable(header.IPv4MinimumSize)
|
||||
|
||||
// Serialize IPv4 fixed header.
|
||||
ip := header.IPv4(hdr.Prepend(header.IPv4MinimumSize))
|
||||
@@ -3226,10 +3228,10 @@ func TestReceiveFragments(t *testing.T) {
|
||||
})
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
|
||||
vv := hdr.View().ToVectorisedView()
|
||||
vv.AppendView(frag.payload)
|
||||
buf := buffer.NewWithData(hdr.View())
|
||||
buf.Append(frag.payload)
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: vv,
|
||||
Payload: buf,
|
||||
})
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
@@ -3398,7 +3400,7 @@ func TestWriteStats(t *testing.T) {
|
||||
for i := 0; i < nPackets; i++ {
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
ReserveHeaderBytes: header.UDPMinimumSize + int(rt.MaxHeaderLength()),
|
||||
Data: buffer.NewView(0).ToVectorisedView(),
|
||||
Payload: buffer.Buffer{},
|
||||
})
|
||||
defer pkt.DecRef()
|
||||
pkt.TransportHeader().Push(header.UDPMinimumSize)
|
||||
@@ -3509,7 +3511,7 @@ func TestPacketQueuing(t *testing.T) {
|
||||
{
|
||||
name: "ICMP Error",
|
||||
rxPkt: func(e *channel.Endpoint) {
|
||||
hdr := buffer.NewPrependable(header.IPv4MinimumSize + header.UDPMinimumSize)
|
||||
hdr := tcpipbuffer.NewPrependable(header.IPv4MinimumSize + header.UDPMinimumSize)
|
||||
u := header.UDP(hdr.Prepend(header.UDPMinimumSize))
|
||||
u.Encode(&header.UDPFields{
|
||||
SrcPort: 5555,
|
||||
@@ -3529,7 +3531,7 @@ func TestPacketQueuing(t *testing.T) {
|
||||
})
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(hdr.View()),
|
||||
})
|
||||
defer pkt.DecRef()
|
||||
e.InjectInbound(ipv4.ProtocolNumber, pkt)
|
||||
@@ -3559,7 +3561,7 @@ func TestPacketQueuing(t *testing.T) {
|
||||
name: "Ping",
|
||||
rxPkt: func(e *channel.Endpoint) {
|
||||
totalLen := header.IPv4MinimumSize + header.ICMPv4MinimumSize
|
||||
hdr := buffer.NewPrependable(totalLen)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLen)
|
||||
pkt := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
|
||||
pkt.SetType(header.ICMPv4Echo)
|
||||
pkt.SetCode(0)
|
||||
@@ -3575,7 +3577,7 @@ func TestPacketQueuing(t *testing.T) {
|
||||
})
|
||||
ip.SetChecksum(^ip.CalculateChecksum())
|
||||
echoPkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.View().ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(hdr.View()),
|
||||
})
|
||||
defer echoPkt.DecRef()
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, echoPkt)
|
||||
@@ -3661,7 +3663,7 @@ func TestPacketQueuing(t *testing.T) {
|
||||
|
||||
// Send an ARP reply to complete link address resolution.
|
||||
{
|
||||
hdr := buffer.View(make([]byte, header.ARPSize))
|
||||
hdr := make([]byte, header.ARPSize)
|
||||
packet := header.ARP(hdr)
|
||||
packet.SetIPv4OverEthernet()
|
||||
packet.SetOp(header.ARPReply)
|
||||
@@ -3670,7 +3672,7 @@ func TestPacketQueuing(t *testing.T) {
|
||||
copy(packet.HardwareAddressTarget(), host1NICLinkAddr)
|
||||
copy(packet.ProtocolAddressTarget(), host1IPv4Addr.AddressWithPrefix.Address)
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: hdr.ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(hdr),
|
||||
})
|
||||
e.InjectInbound(arp.ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
@@ -3851,14 +3853,14 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
})
|
||||
tests := []struct {
|
||||
name string
|
||||
createPacket func() buffer.View
|
||||
createPacket func() []byte
|
||||
check func(*testing.T, *channel.Endpoint, int)
|
||||
}{
|
||||
{
|
||||
name: "echo",
|
||||
createPacket: func() buffer.View {
|
||||
createPacket: func() []byte {
|
||||
totalLength := header.IPv4MinimumSize + header.ICMPv4MinimumSize
|
||||
hdr := buffer.NewPrependable(totalLength)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLength)
|
||||
icmpH := header.ICMPv4(hdr.Prepend(header.ICMPv4MinimumSize))
|
||||
icmpH.SetIdent(1)
|
||||
icmpH.SetSequence(1)
|
||||
@@ -3896,9 +3898,9 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "dst unreachable",
|
||||
createPacket: func() buffer.View {
|
||||
createPacket: func() []byte {
|
||||
totalLength := header.IPv4MinimumSize + header.UDPMinimumSize
|
||||
hdr := buffer.NewPrependable(totalLength)
|
||||
hdr := tcpipbuffer.NewPrependable(totalLength)
|
||||
udpH := header.UDP(hdr.Prepend(header.UDPMinimumSize))
|
||||
udpH.Encode(&header.UDPFields{
|
||||
SrcPort: 100,
|
||||
@@ -3942,7 +3944,7 @@ func TestIcmpRateLimit(t *testing.T) {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
for round := 0; round < icmpBurst+1; round++ {
|
||||
pkt := stack.NewPacketBuffer(stack.PacketBufferOptions{
|
||||
Data: testCase.createPacket().ToVectorisedView(),
|
||||
Payload: buffer.NewWithData(testCase.createPacket()),
|
||||
})
|
||||
e.InjectInbound(header.IPv4ProtocolNumber, pkt)
|
||||
pkt.DecRef()
|
||||
|
||||
@@ -15,6 +15,7 @@ go_library(
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//pkg/atomicbitops",
|
||||
"//pkg/buffer",
|
||||
"//pkg/sync",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
@@ -39,6 +40,7 @@ go_test(
|
||||
],
|
||||
library = ":ipv6",
|
||||
deps = [
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/tcpip",
|
||||
@@ -66,10 +68,10 @@ go_test(
|
||||
srcs = ["mld_test.go"],
|
||||
deps = [
|
||||
":ipv6",
|
||||
"//pkg/buffer",
|
||||
"//pkg/refs",
|
||||
"//pkg/refsvfs2",
|
||||
"//pkg/tcpip",
|
||||
"//pkg/tcpip/buffer",
|
||||
"//pkg/tcpip/checker",
|
||||
"//pkg/tcpip/faketime",
|
||||
"//pkg/tcpip/header",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user