UDP packet fragmentation problem

Greg Corson
Posts: 35
Joined: Sun May 20, 2018 9:16 pm

UDP packet fragmentation problem

Postby Greg Corson » Thu Apr 25, 2019 11:00 pm

I found this using the ESP32 arduino setup, but I think it will apply to the ESP IDF as well so I posted it here.

The issue is how large UDP packets are being handled. When a UDP packet is bigger than the MTU (around 1.4k) it is supposed to be broken into fragments, sent over the net, and reassembled on the receiving end. It is still lossy, that is if any of the fragments are lost, the whole packet is lost.

So for example a 2000 byte packet would get broken into 2 IP fragments and if both fragments didn't make it to the receiving end, you would get nothing.

Now I understand that packet fragmentation is DISABLED in the lwip configuration for ESP32, nothing really wrong with that but the way lwip is handling large UDP packets in this mode seems bad.

What it seems to be doing is breaking the one large packet into several smaller ones and sending them as independent UDP packets.

This can be bad because, for example, if you send a 2000 byte UDP packet it will get broken into two pieces, but if one piece is lost the other will still be delivered, leaving you with less than 2000 bytes of data on the receiving end and an odd amount of missing data.

It seems like what should happen is that if IP fragmentation is disabled and you try to send a UDP packet bigger than the MTU, you should get an error and/or the packet should not be sent. But that's not what's happening.

Can anyone comment on this? Should it be considered a bug and fixed?

I didn't notice what was going on right away because the UDP messages were going to a black-box data logger that was just taking the UDP messages assuming each one was complete and writing it to a file. A dropped packet wouldn't be a problem because you would lose the COMPLETE message. But the way lwip handles things, you could lose part of a message which corrupts the log.

Who is online

Users browsing this forum: Gaston1980, Google [Bot] and 83 guests