Checksum simplification proposal (#29)

* Simplified checksum calculation and verification

* Fixed tests

* UDP: using NewBoundedFrame to create a Frame instance limited to the actual frame size.

* Minor: renamed some functions

* Commented and made more readable consecutive SetCRC calls.

* Fixed icmp checksum calculation after rebase

* Replaced NewBoundedFrame with explicit validation
This commit is contained in:
ddirect
2026-02-05 22:35:42 +02:00
committed by GitHub
parent cd51bd6c3f
commit fba97c990a
13 changed files with 139 additions and 228 deletions
+5 -2
View File
@@ -88,6 +88,10 @@ func (i6frm Frame) SetHopLimit(hop uint8) {
i6frm.buf[7] = hop
}
func (i6frm Frame) sourceAndDestinationAddr() []byte {
return i6frm.buf[8:40]
}
// SourceAddr returns pointer to the sending node unicast IPv6 address in the IP header.
func (i6frm Frame) SourceAddr() *[16]byte {
return (*[16]byte)(i6frm.buf[8:24])
@@ -99,8 +103,7 @@ func (i6frm Frame) DestinationAddr() *[16]byte {
}
func (i6frm Frame) CRCWritePseudo(crc *lneto.CRC791) {
crc.Write(i6frm.SourceAddr()[:])
crc.Write(i6frm.DestinationAddr()[:])
crc.WriteEven(i6frm.sourceAndDestinationAddr())
crc.AddUint32(uint32(i6frm.PayloadLength()))
crc.AddUint32(uint32(i6frm.NextHeader()))
}