dotpcap / packetnet

Official repository - High performance .Net assembly for dissecting and constructing network packets such as ethernet, ip, tcp, udp etc.
Mozilla Public License 2.0
483 stars 104 forks source link

Large UDP packet: Length field get overwritten with length of first IP fragment #203

Open arvindpdmn opened 1 year ago

arvindpdmn commented 1 year ago

Using iperf we send large UDP packets, say 2000 bytes. The networking stack will send the packet as two IPv4 fragments.

At the receiver we use this .NET library. When the receiver gets the first fragment, it decodes the IPv4 packet/fragment correctly. But then it also proceeds to decode the UDP header in the first fragment. Because only part of the UDP payload has come in, it updates the Length field of UDP packet to the smaller value. This is wrong. Higher layer decoding should be deferred until all IP fragments are received.

In our application, the receiver is an intermediate node. It's meant to transparently pass on IP and higher layer content.

If this library had used ReadOnlySpan<byte>, this bug could have been avoided. Library should not modify packet contents that it receives.