diff options
author | gVisor bot <gvisor-bot@google.com> | 2020-01-27 13:48:30 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2020-01-27 13:48:30 +0000 |
commit | ca9d6769b598f18a1d2daa354a44f4785518cea3 (patch) | |
tree | f03d1f6c604ad5b3a77bbe9a9e23dbcfea6ce7de /pkg/tcpip | |
parent | 3c0af1c3cf8ef2072cf633881553acc9ccf51749 (diff) | |
parent | 6b43cf791a74a746443f70f98d859c1246f87e2a (diff) |
Merge release-20200115.0-102-g6b43cf7 (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r-- | pkg/tcpip/header/checksum.go | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/pkg/tcpip/header/checksum.go b/pkg/tcpip/header/checksum.go index ce57b581a..204285576 100644 --- a/pkg/tcpip/header/checksum.go +++ b/pkg/tcpip/header/checksum.go @@ -160,20 +160,23 @@ func unrolledCalculateChecksum(buf []byte, odd bool, initial uint32) (uint16, bo return ChecksumCombine(uint16(v), uint16(v>>16)), odd } -// Checksum calculates the checksum (as defined in RFC 1071) of the bytes in the -// given byte array. +// ChecksumOld calculates the checksum (as defined in RFC 1071) of the bytes in +// the given byte array. This function uses a non-optimized implementation. Its +// only retained for reference and to use as a benchmark/test. Most code should +// use the header.Checksum function. // // The initial checksum must have been computed on an even number of bytes. -func Checksum(buf []byte, initial uint16) uint16 { +func ChecksumOld(buf []byte, initial uint16) uint16 { s, _ := calculateChecksum(buf, false, uint32(initial)) return s } -// UnrolledChecksum calculates the checksum (as defined in RFC 1071) of the -// bytes in the given byte array. +// Checksum calculates the checksum (as defined in RFC 1071) of the bytes in the +// given byte array. This function uses an optimized unrolled version of the +// checksum algorithm. // // The initial checksum must have been computed on an even number of bytes. -func UnrolledChecksum(buf []byte, initial uint16) uint16 { +func Checksum(buf []byte, initial uint16) uint16 { s, _ := unrolledCalculateChecksum(buf, false, uint32(initial)) return s } |