Page 1 of 1

how to properly implment path MTU discovery?

Posted: Sat Jul 16, 2016 7:28 am
by mariuszp
does path MTU discovery have to be implemented separately for each transport-layer protocol?

I can see that for example for ICMP this is never necessary since all valid packets are below or at minimum PMTU.

for TCP it's easy, since whenever I receive a "packet too big" or "fragmentation needed" message, all I have to do is make the TCP segment smaller and retransmit.

but what about UDP? am i supposed keep outbound UDP packets in a "possible retransmit list" for a bit and wait for "packet too big" messages to potentially arrive? or do i just not keep track of outbound packets and simply decrease the PMTU when i get such a message, and simply tolerate the loss of the larger packets?

or is there a specific protocol to detect the PMTU before beginning communication with a socket?

Re: how to properly implment path MTU discovery?

Posted: Mon Jul 18, 2016 8:01 pm
by Brendan
Hi,

I think the basic idea is reasonably well covered by the corresponding wikipiedia article.....


Cheers,

Brendan

Re: how to properly implment path MTU discovery?

Posted: Tue Jul 19, 2016 2:12 am
by mariuszp
I have read the article but what I don't understand is whether, for example, for UDP i'm supposed to retransmit the packets in fragments after I already sent them and discovered the size was too large; or do I simply accept that the packet was dropped (which would in theory work since UDP tolerates loss).

Re: how to properly implment path MTU discovery?

Posted: Tue Jul 19, 2016 7:25 am
by onlyonemac
Don't retransmit UDP packets, the other machine has no way to know that they have been retransmitted. If you get a "too large" response, reduce the packet size and continue with the next packet.

Re: how to properly implment path MTU discovery?

Posted: Tue Jul 19, 2016 8:34 am
by iansjack
mariuszp wrote:I have read the article but what I don't understand is whether, for example, for UDP i'm supposed to retransmit the packets in fragments after I already sent them and discovered the size was too large; or do I simply accept that the packet was dropped (which would in theory work since UDP tolerates loss).
You can do either. The packet will have been dropped at some point, so it's as if it was never transmitted. As far as the client listening on the remote computer is concerned the first time that you send it, suitably fragmented, using the correct MTU is the first time it has been sent.

Re: how to properly implment path MTU discovery?

Posted: Tue Jul 19, 2016 4:52 pm
by Brendan
Hi,

Also note that it's probably better to consider it "continuous MTU adjustment" (and not "once only MTU discovery"). There can be many different paths between 2 computers (each with a different MTU), and no guarantee that all packets will travel the same path.

Basically; whenever you're told "packet too big" reduce your packet size to suit; and then maybe for long running connections consider sending an occasional/rare "deliberately slightly over-sized" packet to determine if MTU could be increased.


Cheers,

Brendan

Re: how to properly implment path MTU discovery?

Posted: Tue Jul 19, 2016 5:23 pm
by mariuszp
that makes sense thanks

Re: how to properly implment path MTU discovery?

Posted: Fri Jul 22, 2016 8:54 am
by jbemmel
Unlike TCP, for UDP the OS cannot choose the packet size, it must deliver the UDP packet as requested by the application. Only if your OS would offer a higher-level interface ( like "streamvideo" ) you could consider to implement dynamic tuning of the packet size based on PMTU discovery ( i.e. setting the DF flag ). Normally, the Internet will fragment UDP packets that are too large ( and they might arrive, or might not, depending on firewalls and the likes )

See https://lists.opensuse.org/opensuse-bug ... 02451.html