Apply Tailscale TUN offload APIs

This commit is contained in:
世界 2026-05-17 20:15:11 +08:00
parent 414291f6d6
commit 824e7573c0
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
5 changed files with 277 additions and 13 deletions

View file

@ -92,6 +92,11 @@ func checksum(b []byte, initial uint64) uint16 {
return uint16(ac)
}
// Checksum computes an IP checksum starting with the provided initial value.
func Checksum(data []byte, initial uint16) uint16 {
return checksum(data, uint64(initial))
}
func pseudoHeaderChecksumNoFold(protocol uint8, srcAddr, dstAddr []byte, totalLen uint16) uint64 {
sum := checksumNoFold(srcAddr, 0)
sum = checksumNoFold(dstAddr, sum)
@ -100,3 +105,9 @@ func pseudoHeaderChecksumNoFold(protocol uint8, srcAddr, dstAddr []byte, totalLe
binary.BigEndian.PutUint16(tmp, totalLen)
return checksumNoFold(tmp, sum)
}
// PseudoHeaderChecksum computes an IP pseudo-header checksum. srcAddr and
// dstAddr must be 4 or 16 bytes in length.
func PseudoHeaderChecksum(protocol uint8, srcAddr, dstAddr []byte, totalLen uint16) uint16 {
return checksum([]byte{}, pseudoHeaderChecksumNoFold(protocol, srcAddr, dstAddr, totalLen))
}