tun: export optimized IP checksum funcs

External implementers of tun.Device may support GRO, requiring checksum
offload.

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited 2024-07-23 13:34:34 -07:00 committed by Jordan Whited
parent 60eeedfd62
commit 6c039a188c
5 changed files with 23 additions and 18 deletions

View file

@ -2,12 +2,15 @@ package tun
import "golang.org/x/sys/cpu"
// checksum computes an IP checksum starting with the provided initial value.
// The length of data should be at least 128 bytes for best performance. Smaller
// buffers will still compute a correct result. For best performance with
// smaller buffers, use shortChecksum().
var checksum = checksumAMD64
// Checksum computes an IP checksum starting with the provided initial value.
// The length of data should be at least 128 bytes for best performance. Smaller
// buffers will still compute a correct result.
func Checksum(data []byte, initial uint16) uint16 {
return checksum(data, initial)
}
func init() {
if cpu.X86.HasAVX && cpu.X86.HasAVX2 && cpu.X86.HasBMI2 {
checksum = checksumAVX2