-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix IP fragmentation checks for big-endian CPUs #2919
Conversation
src/net_builtin.c
Outdated
ip->ver = 0x45; // Version 4, header length 5 words | ||
ip->frag = 0x40; // Don't fragment | ||
ip->ver = 0x45; // Version 4, header length 5 words | ||
ip->frag = mg_htons(0x40); // Don't fragment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be mg_htons(0x4000) instead.
We want to set the first byte at the &ip->frag offset.
Thus, on a little endian mg_htons(0x4000) results in 0x0040, which means the first byte will be written with value 0x40.
On a big endian system instead, mg_htons(0x4000) would still be 0x4000, which means the first byte will be written with 0x40.
In both cases, we set the 'don't fragment' bit correctly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, fixed
@@ -784,7 +784,8 @@ static void rx_tcp(struct mg_tcpip_if *ifp, struct pkt *pkt) { | |||
} | |||
|
|||
static void rx_ip(struct mg_tcpip_if *ifp, struct pkt *pkt) { | |||
if (pkt->ip->frag & IP_MORE_FRAGS_MSK || pkt->ip->frag & IP_FRAG_OFFSET_MSK) { | |||
uint16_t frag = mg_ntohs(pkt->ip->frag); | |||
if (frag & IP_MORE_FRAGS_MSK || frag & IP_FRAG_OFFSET_MSK) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The masks should also be in big endian order.
#define IP_FRAG_OFFSET_MSK 0x1FFF
#define IP_MORE_FRAGS_MSK 0x2000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
No description provided.