AK+Userland+Kernel+Tests: Deduplicate IPv4 header checksumming #26482
+117
−131
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.
Previously, there were two slightly different implementations of this in the Kernel and in LibCrypto.
This patch removes those, and replaces them with an implementation that seeks to combine the best aspects of both while not being a drop-in replacement for either.
Two new tests are also included.
FWIW I'm not sure why the old kernel-side implementation had this logic in the core loop:
That kind of looks like an attempt to prevent unsigned 32-bit integer overflow, but I can't see that realistically happening (you'd have to sum up at least 131075 (
UINT32_MAX/UINT16_MAX*2+1) bytes before that'd happen, and even that's a worst-case scenario). The example C implementation in RFC1071 does no such thing either. It seems like this part originated from the old LibCinternet_checksumfunction, so I guess it can go.This also gets rid of all the endianness conversions in the checksumming process (since the checksum is actually byte-order independent, see 2.B of the aforementioned RFC).