From 3f817bfe8af732a29409039135220f6d7276eb20 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Mon, 25 Aug 2025 13:39:56 +0200 Subject: [PATCH] Expose UDP GSO/GRO on android --- Cargo.toml | 2 +- changelog/2666.added.md | 5 +++++ src/sys/socket/mod.rs | 14 +++++++------- src/sys/socket/sockopt.rs | 4 ++-- test/common/mod.rs | 2 +- test/sys/test_socket.rs | 2 +- 6 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 changelog/2666.added.md diff --git a/Cargo.toml b/Cargo.toml index 18aa5afcfa..bcca102820 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ targets = [ ] [dependencies] -libc = { version = "=0.2.172", features = ["extra_traits"] } +libc = { version = "=0.2.175", features = ["extra_traits"] } bitflags = "2.3.3" cfg-if = "1.0" pin-utils = { version = "0.1.0", optional = true } diff --git a/changelog/2666.added.md b/changelog/2666.added.md new file mode 100644 index 0000000000..c9b6fbef81 --- /dev/null +++ b/changelog/2666.added.md @@ -0,0 +1,5 @@ +Added the UDP GSO/GRO socket options and CMsgs on Android. This includes the following types: +- UdpGsoSegment +- UdpGroSegment +- ControlMessage::UdpGsoSegments +- ControlMessageOwned::UdpGroSegments diff --git a/src/sys/socket/mod.rs b/src/sys/socket/mod.rs index 30c4e0a082..e3a1eae934 100644 --- a/src/sys/socket/mod.rs +++ b/src/sys/socket/mod.rs @@ -912,7 +912,7 @@ pub enum ControlMessageOwned { /// /// `UdpGroSegment` socket option should be enabled on a socket /// to allow receiving GRO packets. - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] UdpGroSegments(i32), @@ -1087,7 +1087,7 @@ impl ControlMessageOwned { let dl = unsafe { ptr::read_unaligned(p as *const libc::sockaddr_in) }; ControlMessageOwned::Ipv4OrigDstAddr(dl) }, - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] (libc::SOL_UDP, libc::UDP_GRO) => { let gso_size: i32 = unsafe { ptr::read_unaligned(p as *const _) }; @@ -1265,7 +1265,7 @@ pub enum ControlMessage<'a> { /// passed through this control message. /// Send buffer should consist of multiple fixed-size wire payloads /// following one by one, and the last, possibly smaller one. - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] #[cfg_attr(docsrs, doc(cfg(feature = "net")))] UdpGsoSegments(&'a u16), @@ -1437,7 +1437,7 @@ impl ControlMessage<'_> { ControlMessage::AlgSetAeadAssoclen(len) => { len as *const _ as *const u8 }, - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] ControlMessage::UdpGsoSegments(gso_size) => { gso_size as *const _ as *const u8 @@ -1515,7 +1515,7 @@ impl ControlMessage<'_> { ControlMessage::AlgSetAeadAssoclen(len) => { mem::size_of_val(len) }, - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] ControlMessage::UdpGsoSegments(gso_size) => { mem::size_of_val(gso_size) @@ -1572,7 +1572,7 @@ impl ControlMessage<'_> { #[cfg(linux_android)] ControlMessage::AlgSetIv(_) | ControlMessage::AlgSetOp(_) | ControlMessage::AlgSetAeadAssoclen(_) => libc::SOL_ALG, - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] ControlMessage::UdpGsoSegments(_) => libc::SOL_UDP, #[cfg(any(linux_android, target_os = "netbsd", apple_targets))] @@ -1624,7 +1624,7 @@ impl ControlMessage<'_> { ControlMessage::AlgSetAeadAssoclen(_) => { libc::ALG_SET_AEAD_ASSOCLEN }, - #[cfg(target_os = "linux")] + #[cfg(linux_android)] #[cfg(feature = "net")] ControlMessage::UdpGsoSegments(_) => { libc::UDP_SEGMENT diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 8e00488617..49b305920f 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -1120,7 +1120,7 @@ sockopt_impl!( libc::IP_ORIGDSTADDR, bool ); -#[cfg(target_os = "linux")] +#[cfg(linux_android)] #[cfg(feature = "net")] sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] @@ -1132,7 +1132,7 @@ sockopt_impl!( libc::UDP_SEGMENT, libc::c_int ); -#[cfg(target_os = "linux")] +#[cfg(linux_android)] #[cfg(feature = "net")] sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] diff --git a/test/common/mod.rs b/test/common/mod.rs index ab0e746367..7dbdfbf454 100644 --- a/test/common/mod.rs +++ b/test/common/mod.rs @@ -111,7 +111,7 @@ cfg_if! { } cfg_if! { - if #[cfg(target_os = "linux")] { + if #[cfg(linux_android)] { #[macro_export] macro_rules! require_kernel_version { ($name:expr, $version_requirement:expr) => { use semver::{Version, VersionReq}; diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 42906a65e2..514e28d62b 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -462,7 +462,7 @@ mod recvfrom { assert_eq!(AddressFamily::Inet, from.unwrap().family().unwrap()); } - #[cfg(target_os = "linux")] + #[cfg(linux_android)] mod udp_offload { use super::*; use nix::sys::socket::sockopt::{UdpGroSegment, UdpGsoSegment};