Fix TCP checksum calculation to include Ethernet header#1331
Closed
marcusb wants to merge 1 commit intoFreeRTOS:mainfrom
Closed
Fix TCP checksum calculation to include Ethernet header#1331marcusb wants to merge 1 commit intoFreeRTOS:mainfrom
marcusb wants to merge 1 commit intoFreeRTOS:mainfrom
Conversation
2cd0c98 to
0f41a12
Compare
When ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM is 0, the TCP checksum was calculated with xDataLength that did not include the Ethernet header size, resulting in incorrect checksums on outgoing TCP packets. This fix parallels the IPv6 implementation which already correctly includes the Ethernet header size (ipSIZE_OF_ETH_HEADER) in the checksum calculation. Add regression test that verifies usGenerateProtocolChecksum is called with the correct data length (ulLen + ipSIZE_OF_ETH_HEADER).
0f41a12 to
4ac168c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug in FreeRTOS+TCP where the TCP checksum was calculated with incorrect data length when
ipconfigDRIVER_INCLUDED_TX_IP_CHECKSUM == 0.Problem
In
prvTCPReturnPacket_IPV4(), the TCP checksum was calculated usingpxNetworkBuffer->xDataLengthwhich at that point did NOT include the Ethernet header size, resulting in incorrect checksums on outgoing TCP packets.Fix
The fix calculate the total length (ulLen + ipSIZE_OF_ETH_HEADER) before calling usGenerateProtocolChecksum(), paralleling the IPv6 implementation which already correctly includes the Ethernet header.
Test
Added regression test
test_prvTCPReturnPacket_TxChecksum_DataLengththat verifies usGenerateProtocolChecksum is called with the correct data length (ulLen + ipSIZE_OF_ETH_HEADER).