From 5d07ad6f30e6d92ab7e9b2f5c8c47eb9cb144905 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sat, 2 Jul 2022 12:37:24 -0700 Subject: [PATCH] Fix Linux DF bit setting for IPv6-mapped IPv4 addresses --- quinn-udp/src/unix.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/quinn-udp/src/unix.rs b/quinn-udp/src/unix.rs index b68e91f70f..88fe35aaff 100644 --- a/quinn-udp/src/unix.rs +++ b/quinn-udp/src/unix.rs @@ -147,20 +147,21 @@ fn init(io: &std::net::UdpSocket) -> io::Result<()> { ) }; - if addr.is_ipv4() { - let rc = unsafe { - libc::setsockopt( - io.as_raw_fd(), - libc::IPPROTO_IP, - libc::IP_MTU_DISCOVER, - &libc::IP_PMTUDISC_PROBE as *const _ as _, - mem::size_of_val(&libc::IP_PMTUDISC_PROBE) as _, - ) - }; - if rc == -1 { - return Err(io::Error::last_os_error()); - } + // Forbid IPv4 fragmentation. Set even for IPv6 to account for IPv6 mapped IPv4 addresses. + let rc = unsafe { + libc::setsockopt( + io.as_raw_fd(), + libc::IPPROTO_IP, + libc::IP_MTU_DISCOVER, + &libc::IP_PMTUDISC_PROBE as *const _ as _, + mem::size_of_val(&libc::IP_PMTUDISC_PROBE) as _, + ) + }; + if rc == -1 { + return Err(io::Error::last_os_error()); + } + if addr.is_ipv4() { let on: libc::c_int = 1; let rc = unsafe { libc::setsockopt(