IP_MTU_DISCOVER(2const)
π IP_MTU_DISCOVER(2const) π
okay bestie so this is a page from the IP_MTU_DISCOVER(2const) section of the Linux manual, and it's all about path maximum transfer unit size discovery β aka figuring out how big your packets can actually be before the network starts throwing hands. π¦
π LIBRARY
The standard C library, duh: libc, -lc. π
β¨ SYNOPSIS β¨
like, the include situation first:
#include <netinet/in.h> /* Definition of IP* constants */
#include <sys/socket.h>
and then the actual calls:
int setsockopt(int sockfd, IPPROTO_IP, IP_MTU_DISCOVER,
const int *val, sizeof(int));
int getsockopt(int sockfd, IPPROTO_IP, IP_MTU_DISCOVER,
int *val, sizeof(int));
πΈ DESCRIPTION πΈ
So basically you use this to set or receive the Path MTU Discovery setting for a socket. That's the whole vibe.
When it's enabled, Linux will do Path MTU Discovery exactly as defined in RFC 1191 on SOCK_STREAM sockets. slay.
Now for the non-SOCK_STREAM girlies: IP_PMTUDISC_DO forces the don't-fragment flag to be set on all outgoing packets. And no, the kernel is not gonna hold your hand here β it is the user's responsibility to packetize the data into MTU-sized chunks and to do the retransmits if necessary. π The kernel will reject with EMSGSIZE any datagrams that are bigger than the known path MTU. Meanwhile IP_PMTUDISC_WANT will fragment a datagram if it needs to, according to the path MTU, or it'll set the don't-fragment flag otherwise.
The system-wide default can be toggled between IP_PMTUDISC_WANT and IP_PMTUDISC_DONT by writing zero and nonzero values (respectively) to the /proc/sys/net/ipv4/ip_no_pmtu_disc file.
Here's the β¨ value cheat sheet β¨ β the path MTU discovery value on the left, what it actually means on the right:
IP_PMTUDISC_WANTβ Use per-route settings.IP_PMTUDISC_DONTβ Never do Path MTU Discovery.IP_PMTUDISC_DOβ Always do Path MTU Discovery.IP_PMTUDISC_PROBEβ Set DF but ignore Path MTU.
When PMTU discovery is enabled, the kernel automatically keeps track of the path MTU per destination host. Obsessed. And when it's connected to a specific peer with connect(2), you can conveniently retrieve the currently known path MTU using the IP_MTU(2const) socket option β like, say, after an EMSGSIZE error happened. π«Ά
Plot twist though: the path MTU may change over time. For connectionless sockets with many destinations, the new MTU for a given destination can also be accessed using the error queue (see IP_RECVERR(2const)). And a new error will be queued for every incoming MTU update. every single one. π
β οΈ While MTU discovery is in progress, initial packets from datagram sockets may be dropped. Applications using UDP should be aware of this and not take it into account for their packet retransmit strategy. fr fr, don't do it.
To bootstrap the path MTU discovery process on unconnected sockets, it's possible to start with a big datagram size (headers up to 64 kilobytes long) and let it shrink by updates of the path MTU. iconic behavior honestly.
And to get an initial estimate of the path MTU: connect a datagram socket to the destination address using connect(2) and retrieve the MTU by calling getsockopt(2) with the IP_MTU(2const) option. easy.
Oh and β you can implement RFC 4821 MTU probing with SOCK_DGRAM or SOCK_RAW sockets by setting a value of IP_PMTUDISC_PROBE. This is also particularly useful for diagnostic tools such as tracepath(8) that wish to deliberately send probe packets larger than the observed Path MTU. main character energy for real. π
π¨ ERRORS π¨
See IPPROTO_IP(2const). See setsockopt(2). See ip(7). that's it, that's the whole section bestie.
π STANDARDS π
Linux. periodt. π
π°οΈ HISTORY π°οΈ
- Linux 2.2.
IP_PMTUDISC_PROBEβ Linux 2.6.22.
π SEE ALSO π
okay that's the whole page!! π this was from Linux man-pages 6.20, dated 2025-11-25, and it's the IP_MTU_DISCOVER(2const) page mwah π go set some socket options responsibly bestie, and remember: packetize your own chunks, the kernel is not your mom π¦β¨
π¦ where this page comes from
- arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- π the page's license: Linux-man-pages-copyleft
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms