UDP maximum packet size through loopback interface

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


UDP maximum packet size through loopback interface



I want to use UDP to do Interprocesses communication, I know the maximum size for a UDP datagram is ~64K. but whether is that true for loopback?




1 Answer
1



TL;DR: 64k, if you don't care about IP fragmentation. MTU if you do.



Even though UDP max packet size is 64k, the actual transfer size is governed by the interface's MTU.



Any packet larger than the MTU (including IP and UDP overhead) will be fragmented to multiple layer-2 packets.



So, while you can always send a 64k UDP packet, you may end up with more than one IP packet, which add latency and increase the chance of packet drop (if one fragment is lost - all the datagram is lost).



The good news is that you don't have to worry about fragmentation yourself - the kernel will take care of fragmentation and reassembly so your application will see a single datagram of 64k in size.



Since you're asking about the loopback interface, packet drop is not an issue, so you're only bound by UDP's size field.



If you would like to avoid IP fragmentation, you need to query the interface's MTU and make sure your datagrams are smaller (again, including IP and UDP overhead).



On my Mac the loopback interface default MTU is 16384:


$ ifconfig lo0
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
...



On Linux, you can get/set an interface MTU programmatically with SIOCGIFMTU/SIOCSIFMTU ioctl (man 7 netdevice).


SIOCGIFMTU


SIOCSIFMTU






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

Visual Studio Code: How to configure includePath for better IntelliSense results