Setting the Don't Fragment (DF) bit on OSX

288 views
Skip to first unread message

Marten Seemann

unread,
Apr 23, 2021, 2:20:15 AM4/23/21
to golang-nuts
For my QUIC implementation, I'm trying to set the DF bit on outgoing packets.

The following code works fine on Linux:
addr, _ := net.ResolveUDPAddr("udp", ":0")
conn, _ := net.ListenUDP("udp", addr)
rawConn, _ := conn.SyscallConn()
rawConn.Control(func(fd uintptr) {
    unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_MTU_DISCOVER, 1)
})

On OSX, the sockopt doesn't have a named constant, the correct value to use here is 28. The code above only works if I'm listening on an address that's unambiguously IPv4, e.g. 127.0.0.1:0.
If I listen on an address that allows me to send and receive both IPv4 and IPv6 (like :0), it doesn't work anymore: SetsockoptInt now returns error 22 (invalid argument). That's unfortunate as users of the library often listen on :0.

Is there any way to make this work analogously to how it works on Linux?

Stefan Beke

unread,
Apr 24, 2021, 4:37:26 PM4/24/21
to golang-nuts
I'm curious, why do you need to set DF bit? I'm asking, because as a network engineer I'm often experiencing broken apps with this setting. It usually ends up network pointing to app and vice versa.
New tunnel along the path, either GRE or IPSec is lowering MTU, new technologies like Cisco SD-WAN are all tunnel inside tunnel inside MPLS and MTU can go as low as 1260.
Different workarounds are configured on routers as dynamic mss size adjustment.
In your case you are at least trying to discover MTU, but path could be in many cases asymmetric.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages