fix: ethernet frame header is 14 not 18 #3025
Open
+1
−1
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.
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
ETHERNET_HEADER_FRAME_SIZE
= 18 in the following codeesp-hal/esp-wifi/src/wifi/mod.rs
Line 76 in f247b40
is only used here
esp-hal/esp-wifi/src/wifi/mod.rs
Line 950 in f247b40
which is only used here
esp-hal/esp-wifi/src/wifi/mod.rs
Line 2715 in f247b40
I thought maybe the extra 4 bytes were for the fcs at the end but the buffer is passed with the length given by caller here
esp-hal/esp-wifi/src/wifi/mod.rs
Lines 2717 to 2721 in f247b40
so that can't be it.
The only reason I noticed this is because smoltcp doesn't support ipv6 fragmentation and ignores if the given MTU is too large (see here) and I tried to send a max MTU UDP packet. It panicked indexing
[..len]
so I calculated what the max non-fragmenting size would be like so:but was surprised to find the calculated MTU seemed to be 4 bytes less than the panic message implied was valid. I believe I tracked down the source of this discrepancy to the changed line in the PR. As seen here and here an ethernet header is 14 bytes not 18.
I don't know if this would be considered public facing enough to warrant a change log entry, but I'm pretty sure it's a bug.
If my analysis is wrong and the fcs is included in that sizing, then there should at least be an assert that the passed length matches the configured MTU and not config.MTU+4 as it does now. The index check of
[..len]
should optimize out if the assert occurs before it.Sidenote: It's a good thing the buffer index was checked and panicked in the esp-wifi code or I probably would never have figured this out. Also, I'll file an issue with smoltcp to at least warn when a packet which is too large and can't be fragmented needs to be sent.
Testing
See above.