Skip to content

Commit

Permalink
Merge pull request #7 from shutton/optional-gro
Browse files Browse the repository at this point in the history
Make enabling GRO optional
  • Loading branch information
leshow authored Jul 30, 2024
2 parents 14e36a3 + ab4575b commit f9c2dca
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A: ToSocketAddrs>(&self, addrs: A) -> io::Result<()> {
self.io.connect(addrs).await
}
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f9c2dca

Please sign in to comment.