Skip to content

Commit 7db2688

Browse files
committed
feat: Add UDP GRO option
1 parent 3a93893 commit 7db2688

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/socket.rs

+30
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,36 @@ impl Socket {
10681068
}
10691069
}
10701070

1071+
/// Get the value of the `UDP_GRO` option on this socket.
1072+
///
1073+
/// For more information about this option, see [`set_udp_gro`].
1074+
///
1075+
/// [`set_udp_gro`]: Socket::set_udp_gro
1076+
#[cfg(all(feature = "all", target_os = "linux"))]
1077+
pub fn udp_gro(&self) -> io::Result<bool> {
1078+
unsafe {
1079+
getsockopt::<c_int>(self.as_raw(), sys::SOL_UDP, sys::UDP_GRO)
1080+
.map(|reuse| reuse != 0)
1081+
}
1082+
}
1083+
1084+
/// Set value for the `UDP_GRO` option on this socket.
1085+
///
1086+
/// This indicates that the kernel can combine multiple datagrams into a
1087+
/// single buffer, this needs to be used in combination with [`Self::recvmsg`]
1088+
/// to get the number of segments in the buffer from the [`MsgHdr`].
1089+
#[cfg(all(feature = "all", target_os = "linux"))]
1090+
pub fn set_udp_gro(&self, reuse: bool) -> io::Result<()> {
1091+
unsafe {
1092+
setsockopt(
1093+
self.as_raw(),
1094+
sys::SOL_UDP,
1095+
sys::UDP_GRO,
1096+
reuse as c_int,
1097+
)
1098+
}
1099+
}
1100+
10711101
/// Get the value of the `SO_SNDBUF` option on this socket.
10721102
///
10731103
/// For more information about this option, see [`set_send_buffer_size`].

src/sys/unix.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub(crate) use libc::SO_LINGER;
179179
))]
180180
pub(crate) use libc::SO_LINGER_SEC as SO_LINGER;
181181
#[cfg(target_os = "linux")]
182-
pub(crate) use libc::SO_PASSCRED;
182+
pub(crate) use libc::{SO_PASSCRED, SOL_UDP, UDP_GRO};
183183
pub(crate) use libc::{
184184
ip_mreq as IpMreq, linger, IPPROTO_IP, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, IPV6_MULTICAST_IF,
185185
IPV6_MULTICAST_LOOP, IPV6_UNICAST_HOPS, IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP,

0 commit comments

Comments
 (0)