From 45c54b1f4e2bb6fcad14b8b7734d6a1847329901 Mon Sep 17 00:00:00 2001 From: Bhasker Hariharan Date: Fri, 29 Mar 2019 12:04:42 -0700 Subject: Fix incorrect checksums in TCP and UDP tests. PiperOrigin-RevId: 241025361 Change-Id: I292e7aea9a4b294b11e4f736e107010d9524586b --- pkg/tcpip/transport/tcp/testing/context/context.go | 8 ++------ pkg/tcpip/transport/udp/udp_test.go | 8 ++------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/pkg/tcpip/transport/tcp/testing/context/context.go b/pkg/tcpip/transport/tcp/testing/context/context.go index 5cef8ee97..8ac411b1d 100644 --- a/pkg/tcpip/transport/tcp/testing/context/context.go +++ b/pkg/tcpip/transport/tcp/testing/context/context.go @@ -327,9 +327,7 @@ func (c *Context) BuildSegment(payload []byte, h *Headers) buffer.VectorisedView }) // Calculate the TCP pseudo-header checksum. - xsum := header.Checksum([]byte(TestAddr), 0) - xsum = header.Checksum([]byte(StackAddr), xsum) - xsum = header.Checksum([]byte{0, uint8(tcp.ProtocolNumber)}, xsum) + xsum := header.PseudoHeaderChecksum(tcp.ProtocolNumber, TestAddr, StackAddr, uint16(len(t))) // Calculate the TCP checksum and set it. xsum = header.Checksum(payload, xsum) @@ -481,9 +479,7 @@ func (c *Context) SendV6Packet(payload []byte, h *Headers) { }) // Calculate the TCP pseudo-header checksum. - xsum := header.Checksum([]byte(TestV6Addr), 0) - xsum = header.Checksum([]byte(StackV6Addr), xsum) - xsum = header.Checksum([]byte{0, uint8(tcp.ProtocolNumber)}, xsum) + xsum := header.PseudoHeaderChecksum(tcp.ProtocolNumber, TestV6Addr, StackV6Addr, uint16(len(t))) // Calculate the TCP checksum and set it. xsum = header.Checksum(payload, xsum) diff --git a/pkg/tcpip/transport/udp/udp_test.go b/pkg/tcpip/transport/udp/udp_test.go index 0d5871615..2f4e94c58 100644 --- a/pkg/tcpip/transport/udp/udp_test.go +++ b/pkg/tcpip/transport/udp/udp_test.go @@ -195,9 +195,7 @@ func (c *testContext) sendV6Packet(payload []byte, h *headers) { }) // Calculate the UDP pseudo-header checksum. - xsum := header.Checksum([]byte(testV6Addr), 0) - xsum = header.Checksum([]byte(stackV6Addr), xsum) - xsum = header.Checksum([]byte{0, uint8(udp.ProtocolNumber)}, xsum) + xsum := header.PseudoHeaderChecksum(udp.ProtocolNumber, testV6Addr, stackV6Addr, uint16(len(u))) // Calculate the UDP checksum and set it. xsum = header.Checksum(payload, xsum) @@ -233,9 +231,7 @@ func (c *testContext) sendPacket(payload []byte, h *headers) { }) // Calculate the UDP pseudo-header checksum. - xsum := header.Checksum([]byte(testAddr), 0) - xsum = header.Checksum([]byte(stackAddr), xsum) - xsum = header.Checksum([]byte{0, uint8(udp.ProtocolNumber)}, xsum) + xsum := header.PseudoHeaderChecksum(udp.ProtocolNumber, testAddr, stackAddr, uint16(len(u))) // Calculate the UDP checksum and set it. xsum = header.Checksum(payload, xsum) -- cgit v1.2.3