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

feat: Add UDP GRO option #536

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
30 changes: 30 additions & 0 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3097,6 +3097,36 @@ impl crate::Socket {
)
}
}

/// Get the value of the `UDP_GRO` option on this socket.
///
/// For more information about this option, see [`set_udp_gro`].
///
/// [`set_udp_gro`]: Socket::set_udp_gro
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
pub fn udp_gro(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO).map(|reuse| reuse != 0)
}
}

/// Set value for the `UDP_GRO` option on this socket.
///
/// This indicates that the kernel can combine multiple datagrams into a
/// single buffer, this needs to be used in combination with [`Self::recvmsg`]
/// to get the number of segments in the buffer from the [`MsgHdr`].
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
pub fn set_udp_gro(&self, reuse: bool) -> io::Result<()> {
unsafe { setsockopt(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO, reuse as c_int) }
}
}

/// See [`Socket::dccp_available_ccids`].
Expand Down
6 changes: 6 additions & 0 deletions tests/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,12 @@ test!(reuse_address, set_reuse_address(true));
not(any(windows, target_os = "solaris", target_os = "illumos"))
))]
test!(reuse_port, set_reuse_port(true));
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
#[cfg_attr(
docsrs,
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
)]
test!(udp_gro, set_udp_gro(true));
#[cfg(all(feature = "all", target_os = "freebsd"))]
test!(reuse_port_lb, set_reuse_port_lb(true));
#[cfg(all(feature = "all", unix, not(target_os = "redox")))]
Expand Down
Loading