Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make enabling GRO optional #7

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading