diff options
author | Ting-Yu Wang <anivia@google.com> | 2021-03-03 16:03:04 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-03-03 16:05:16 -0800 |
commit | 1cd76d958a9b3eb29f6b55a8bea71fbe464e67d3 (patch) | |
tree | 1f4df3b516c62a2aa630ffaf9c6ecba99482e3d3 /test | |
parent | cfd2c31962a4358d7d05a4bd04dde271dc238339 (diff) |
Make dedicated methods for data operations in PacketBuffer
One of the preparation to decouple underlying buffer implementation.
There are still some methods that tie to VectorisedView, and they will be
changed gradually in later CLs.
This CL also introduce a new ICMPv6ChecksumParams to replace long list of
parameters when calling ICMPv6Checksum, aiming to be more descriptive.
PiperOrigin-RevId: 360778149
Diffstat (limited to 'test')
4 files changed, 23 insertions, 21 deletions
diff --git a/test/packetimpact/testbench/layers.go b/test/packetimpact/testbench/layers.go index 19e6b8d7d..64a7a171a 100644 --- a/test/packetimpact/testbench/layers.go +++ b/test/packetimpact/testbench/layers.go @@ -852,7 +852,13 @@ func (l *ICMPv6) ToBytes() ([]byte, error) { if err != nil { return nil, err } - h.SetChecksum(header.ICMPv6Checksum(h, *ipv6.SrcAddr, *ipv6.DstAddr, payload)) + h.SetChecksum(header.ICMPv6Checksum(header.ICMPv6ChecksumParams{ + Header: h, + Src: *ipv6.SrcAddr, + Dst: *ipv6.DstAddr, + PayloadCsum: header.ChecksumVV(payload, 0 /* initial */), + PayloadLen: payload.Size(), + })) break } } @@ -974,7 +980,7 @@ func (l *ICMPv4) ToBytes() ([]byte, error) { var vv buffer.VectorisedView vv.AppendView(buffer.View(l.Payload)) vv.Append(payload) - h.SetChecksum(header.ICMPv4Checksum(h, vv)) + h.SetChecksum(header.ICMPv4Checksum(h, header.ChecksumVV(vv, 0 /* initial */))) } return h, nil diff --git a/test/packetimpact/tests/ipv4_fragment_reassembly_test.go b/test/packetimpact/tests/ipv4_fragment_reassembly_test.go index ee050e2c6..707f0f1f5 100644 --- a/test/packetimpact/tests/ipv4_fragment_reassembly_test.go +++ b/test/packetimpact/tests/ipv4_fragment_reassembly_test.go @@ -21,7 +21,6 @@ import ( "time" "github.com/google/go-cmp/cmp" - "gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/test/packetimpact/testbench" ) @@ -118,10 +117,7 @@ func TestIPv4FragmentReassembly(t *testing.T) { if _, err := rand.Read(originalPayload); err != nil { t.Fatalf("rand.Read: %s", err) } - cksum := header.ICMPv4Checksum( - icmp, - buffer.NewVectorisedView(len(originalPayload), []buffer.View{originalPayload}), - ) + cksum := header.ICMPv4Checksum(icmp, header.Checksum(originalPayload, 0 /* initial */)) icmp.SetChecksum(cksum) for _, fragment := range test.fragments { diff --git a/test/packetimpact/tests/ipv6_fragment_icmp_error_test.go b/test/packetimpact/tests/ipv6_fragment_icmp_error_test.go index e0b2a2178..4034a128e 100644 --- a/test/packetimpact/tests/ipv6_fragment_icmp_error_test.go +++ b/test/packetimpact/tests/ipv6_fragment_icmp_error_test.go @@ -21,7 +21,6 @@ import ( "github.com/google/go-cmp/cmp" "gvisor.dev/gvisor/pkg/tcpip" - "gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/pkg/tcpip/network/ipv6" "gvisor.dev/gvisor/test/packetimpact/testbench" @@ -45,12 +44,13 @@ func fragmentedICMPEchoRequest(t *testing.T, n *testbench.DUTTestNet, conn *test icmpv6Header.SetCode(header.ICMPv6UnusedCode) icmpv6Header.SetIdent(0) icmpv6Header.SetSequence(0) - cksum := header.ICMPv6Checksum( - icmpv6Header, - tcpip.Address(n.LocalIPv6), - tcpip.Address(n.RemoteIPv6), - buffer.NewVectorisedView(len(payload), []buffer.View{payload}), - ) + cksum := header.ICMPv6Checksum(header.ICMPv6ChecksumParams{ + Header: icmpv6Header, + Src: tcpip.Address(n.LocalIPv6), + Dst: tcpip.Address(n.RemoteIPv6), + PayloadCsum: header.Checksum(payload, 0 /* initial */), + PayloadLen: len(payload), + }) icmpv6Header.SetChecksum(cksum) icmpv6Bytes := append([]byte(icmpv6Header), payload...) diff --git a/test/packetimpact/tests/ipv6_fragment_reassembly_test.go b/test/packetimpact/tests/ipv6_fragment_reassembly_test.go index dd98ee7a1..db6195dc9 100644 --- a/test/packetimpact/tests/ipv6_fragment_reassembly_test.go +++ b/test/packetimpact/tests/ipv6_fragment_reassembly_test.go @@ -22,7 +22,6 @@ import ( "github.com/google/go-cmp/cmp" "gvisor.dev/gvisor/pkg/tcpip" - "gvisor.dev/gvisor/pkg/tcpip/buffer" "gvisor.dev/gvisor/pkg/tcpip/header" "gvisor.dev/gvisor/test/packetimpact/testbench" ) @@ -121,12 +120,13 @@ func TestIPv6FragmentReassembly(t *testing.T) { t.Fatalf("rand.Read: %s", err) } - cksum := header.ICMPv6Checksum( - icmp, - lIP, - rIP, - buffer.NewVectorisedView(len(originalPayload), []buffer.View{originalPayload}), - ) + cksum := header.ICMPv6Checksum(header.ICMPv6ChecksumParams{ + Header: icmp, + Src: lIP, + Dst: rIP, + PayloadCsum: header.Checksum(originalPayload, 0 /* initial */), + PayloadLen: len(originalPayload), + }) icmp.SetChecksum(cksum) for _, fragment := range test.fragments { |