From ab4575b37ab7333c85769d278164c56090903ab8 Mon Sep 17 00:00:00 2001 From: Scott Hutton Date: Thu, 25 Jul 2024 09:47:53 -0700 Subject: [PATCH] Make enabling GRO optional --- src/unix.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/unix.rs b/src/unix.rs index 89be2cd..fa6b43f 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -116,6 +116,17 @@ impl UdpSocket { self.io.set_broadcast(broadcast) } + /// Opportunistically try to enable GRO support for this socket. This is + /// only supported on Linux platforms. + #[cfg(target_os = "linux")] + pub fn set_gro(&self, enable: bool) -> io::Result<()> { + // See gro::gro_segments(). + const OPTION_OFF: libc::c_int = 0; + + let value = if enable { OPTION_ON } else { OPTION_OFF }; + set_socket_option(&self.io, libc::SOL_UDP, libc::UDP_GRO, value) + } + pub async fn connect(&self, addrs: A) -> io::Result<()> { self.io.connect(addrs).await } @@ -609,9 +620,6 @@ fn init(io: SockRef<'_>) -> io::Result<()> { } #[cfg(target_os = "linux")] { - // opportunistically try to enable GRO. See gro::gro_segments(). - let _ = set_socket_option(&*io, libc::SOL_UDP, libc::UDP_GRO, OPTION_ON); - // Forbid IPv4 fragmentation. Set even for IPv6 to account for IPv6 mapped IPv4 addresses. set_socket_option( &*io,