Skip to content

Commit 337665d

Browse files
committed
feat: Add UDP GRO option
1 parent 3a93893 commit 337665d

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/sys/unix.rs

+38
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,44 @@ impl SockAddr {
896896
#[cfg(not(any(target_os = "linux", target_os = "android")))]
897897
None
898898
}
899+
900+
/// Get the value of the `UDP_GRO` option on this socket.
901+
///
902+
/// For more information about this option, see [`set_udp_gro`].
903+
///
904+
/// [`set_udp_gro`]: Socket::set_udp_gro
905+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
906+
#[cfg_attr(
907+
docsrs,
908+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
909+
)]
910+
pub fn udp_gro(&self) -> io::Result<bool> {
911+
unsafe {
912+
getsockopt::<c_int>(self.as_raw(), libc::SOL_UDP, libc::UDP_GRO)
913+
.map(|reuse| reuse != 0)
914+
}
915+
}
916+
917+
/// Set value for the `UDP_GRO` option on this socket.
918+
///
919+
/// This indicates that the kernel can combine multiple datagrams into a
920+
/// single buffer, this needs to be used in combination with [`Self::recvmsg`]
921+
/// to get the number of segments in the buffer from the [`MsgHdr`].
922+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
923+
#[cfg_attr(
924+
docsrs,
925+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
926+
)]
927+
pub fn set_udp_gro(&self, reuse: bool) -> io::Result<()> {
928+
unsafe {
929+
setsockopt(
930+
self.as_raw(),
931+
sys::SOL_UDP,
932+
sys::UDP_GRO,
933+
reuse as c_int,
934+
)
935+
}
936+
}
899937
}
900938

901939
pub(crate) type Socket = c_int;

tests/socket.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,12 @@ test!(reuse_address, set_reuse_address(true));
13551355
not(any(windows, target_os = "solaris", target_os = "illumos"))
13561356
))]
13571357
test!(reuse_port, set_reuse_port(true));
1358+
#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))]
1359+
#[cfg_attr(
1360+
docsrs,
1361+
doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux"))))
1362+
)]
1363+
test!(udp_gro, set_udp_gro(true));
13581364
#[cfg(all(feature = "all", target_os = "freebsd"))]
13591365
test!(reuse_port_lb, set_reuse_port_lb(true));
13601366
#[cfg(all(feature = "all", unix, not(target_os = "redox")))]

0 commit comments

Comments
 (0)