summaryrefslogtreecommitdiffhomepage
path: root/pkg
diff options
context:
space:
mode:
authorBhasker Hariharan <bhaskerh@google.com>2019-03-29 12:04:42 -0700
committerShentubot <shentubot@google.com>2019-03-29 12:05:43 -0700
commit45c54b1f4e2bb6fcad14b8b7734d6a1847329901 (patch)
treeedcb16a05eb4799210f2a1308677f24e64517186 /pkg
parentcc0e96a4bd3348ecc2a636fd90118b8e5cce672c (diff)
Fix incorrect checksums in TCP and UDP tests.
PiperOrigin-RevId: 241025361 Change-Id: I292e7aea9a4b294b11e4f736e107010d9524586b
Diffstat (limited to 'pkg')
-rw-r--r--pkg/tcpip/transport/tcp/testing/context/context.go8
-rw-r--r--pkg/tcpip/transport/udp/udp_test.go8
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)