mirror of
https://github.com/soypat/lneto.git
synced 2026-08-21 06:59:04 +00:00
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:
+1
-37
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/soypat/lneto"
|
||||
)
|
||||
|
||||
// NewUDPFrame returns a new UDPFrame with data set to buf.
|
||||
// NewFrame returns a new udp.Frame with data set to buf.
|
||||
// An error is returned if the buffer size is smaller than 8.
|
||||
// Users should still call [Frame.ValidateSize] before working
|
||||
// with payload/options of frames to avoid panics.
|
||||
@@ -79,42 +79,6 @@ func (ufrm Frame) Payload() []byte {
|
||||
return ufrm.buf[sizeHeader:l]
|
||||
}
|
||||
|
||||
func (ufrm Frame) CRCWriteIPv4(crc *lneto.CRC791) {
|
||||
crc.AddUint16(ufrm.Length())
|
||||
crc.AddUint16(ufrm.SourcePort())
|
||||
crc.AddUint16(ufrm.DestinationPort())
|
||||
crc.AddUint16(ufrm.Length()) // Length double tap for IPv4.
|
||||
crc.Write(ufrm.Payload())
|
||||
}
|
||||
|
||||
func (ufrm Frame) CRCWriteIPv6(crc *lneto.CRC791) {
|
||||
crc.AddUint16(ufrm.SourcePort())
|
||||
crc.AddUint16(ufrm.DestinationPort())
|
||||
crc.AddUint16(ufrm.Length())
|
||||
crc.Write(ufrm.Payload())
|
||||
}
|
||||
|
||||
// func (ufrm Frame) CalculateIPv4Checksum(ifrm IPv4Frame) uint16 {
|
||||
// var crc lneto.CRC791
|
||||
// ifrm.crcWriteUDPPseudo(&crc)
|
||||
// crc.AddUint16(ufrm.Length())
|
||||
// crc.AddUint16(ufrm.SourcePort())
|
||||
// crc.AddUint16(ufrm.DestinationPort())
|
||||
// crc.AddUint16(ufrm.Length()) // Length double tap.
|
||||
// crc.Write(ufrm.Payload())
|
||||
// return crc.Sum16()
|
||||
// }
|
||||
|
||||
// func (ufrm Frame) CalculateIPv6Checksum(ifrm IPv6Frame) uint16 {
|
||||
// var crc lneto.CRC791
|
||||
// ifrm.crcWritePseudo(&crc)
|
||||
// crc.AddUint16(ufrm.SourcePort())
|
||||
// crc.AddUint16(ufrm.DestinationPort())
|
||||
// crc.AddUint16(ufrm.Length()) // Length double tap.
|
||||
// crc.Write(ufrm.Payload())
|
||||
// return crc.Sum16()
|
||||
// }
|
||||
|
||||
// ClearHeader zeros out the header contents.
|
||||
func (frm Frame) ClearHeader() {
|
||||
for i := range frm.buf[:sizeHeader] {
|
||||
|
||||
Reference in New Issue
Block a user