Skip to content

Commit

Permalink
Merge branch 'main' into libc-recvmmsg-directly
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden authored Aug 20, 2024
2 parents 7680e38 + a003e10 commit bf31877
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ jobs:
uses: actions/checkout@v4

- name: Install JDK
uses: actions/setup-java@v3
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

- name: Install Android SDK
uses: android-actions/setup-android@v2
uses: android-actions/setup-android@v3

- name: Install Android NDK
run: sdkmanager --install "ndk;25.2.9519653"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ rustls-pemfile = "2"
rustls-platform-verifier = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1"
slab = "0.4"
slab = "0.4.6"
smol = "2"
socket2 = "0.5"
thiserror = "1.0.21"
Expand Down
2 changes: 1 addition & 1 deletion quinn-udp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ log = ["tracing/log"]
direct-log = ["dep:log"]

[dependencies]
libc = "0.2.113"
libc = "0.2.158"
log = { workspace = true, optional = true }
socket2 = { workspace = true }
tracing = { workspace = true, optional = true }
Expand Down
46 changes: 37 additions & 9 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
use std::ptr;
use std::{
io::{self, IoSliceMut},
Expand Down Expand Up @@ -62,6 +67,7 @@ impl UdpSocketState {
|| cfg!(target_os = "macos")
|| cfg!(target_os = "ios")
|| cfg!(target_os = "android")
|| cfg!(target_os = "solaris")
{
cmsg_platform_space +=
unsafe { libc::CMSG_SPACE(mem::size_of::<libc::in6_pktinfo>() as _) as usize };
Expand All @@ -84,7 +90,7 @@ impl UdpSocketState {

// mac and ios do not support IP_RECVTOS on dual-stack sockets :(
// older macos versions also don't have the flag and will error out if we don't ignore it
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
if is_ipv4 || !io.only_v6()? {
if let Err(_err) =
set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON)
Expand Down Expand Up @@ -138,10 +144,11 @@ impl UdpSocketState {
target_os = "openbsd",
target_os = "netbsd",
target_os = "macos",
target_os = "ios"
target_os = "ios",
target_os = "solaris",
))]
// IP_RECVDSTADDR == IP_SENDSRCADDR on FreeBSD
// macOS uses only IP_RECVDSTADDR, no IP_SENDSRCADDR on macOS
// macOS uses only IP_RECVDSTADDR, no IP_SENDSRCADDR on macOS (the same on Solaris)
// macOS also supports IP_PKTINFO
{
if is_ipv4 {
Expand Down Expand Up @@ -367,7 +374,12 @@ fn send(state: &UdpSocketState, io: SockRef<'_>, transmit: &Transmit<'_>) -> io:
Ok(())
}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> io::Result<usize> {
let mut names = [MaybeUninit::<libc::sockaddr_storage>::uninit(); BATCH_SIZE];
let mut ctrls = [cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit()); BATCH_SIZE];
Expand Down Expand Up @@ -404,7 +416,12 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
Ok(msg_count as usize)
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "openbsd"))]
#[cfg(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
))]
fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> io::Result<usize> {
let mut name = MaybeUninit::<libc::sockaddr_storage>::uninit();
let mut ctrl = cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit());
Expand Down Expand Up @@ -433,7 +450,12 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) ->
///
/// It uses [`libc::syscall`] instead of [`libc::recvmmsg`]
/// to avoid linking error on systems where libc does not contain `recvmmsg`.
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
unsafe fn recvmmsg_with_fallback(
sockfd: libc::c_int,
msgvec: *mut libc::mmsghdr,
Expand All @@ -460,7 +482,12 @@ unsafe fn recvmmsg_with_fallback(
/// Fallback implementation of `recvmmsg` using `recvmsg`
/// for systems which do not support `recvmmsg`
/// such as Linux <2.6.33.
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "openbsd")))]
#[cfg(not(any(
target_os = "macos",
target_os = "ios",
target_os = "openbsd",
target_os = "solaris",
)))]
unsafe fn recvmmsg_fallback(
sockfd: libc::c_int,
msgvec: *mut libc::mmsghdr,
Expand Down Expand Up @@ -551,6 +578,7 @@ fn prepare_msg(
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "solaris",
))]
{
if encode_src_ip {
Expand Down Expand Up @@ -609,7 +637,7 @@ fn decode_recv(
ecn_bits = cmsg::decode::<u8, libc::cmsghdr>(cmsg);
},
// FreeBSD uses IP_RECVTOS here, and we can be liberal because cmsgs are opt-in.
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
(libc::IPPROTO_IP, libc::IP_RECVTOS) => unsafe {
ecn_bits = cmsg::decode::<u8, libc::cmsghdr>(cmsg);
},
Expand Down
8 changes: 4 additions & 4 deletions quinn-udp/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
use std::{
io::IoSliceMut,
Expand Down Expand Up @@ -51,7 +51,7 @@ fn ecn_v6() {
}

#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
fn ecn_v4() {
let send = Socket::from(UdpSocket::bind("127.0.0.1:0").unwrap());
let recv = Socket::from(UdpSocket::bind("127.0.0.1:0").unwrap());
Expand All @@ -71,7 +71,7 @@ fn ecn_v4() {
}

#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
fn ecn_v6_dualstack() {
let recv = socket2::Socket::new(
socket2::Domain::IPV6,
Expand Down Expand Up @@ -114,7 +114,7 @@ fn ecn_v6_dualstack() {
}

#[test]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))]
fn ecn_v4_mapped_v6() {
let send = socket2::Socket::new(
socket2::Domain::IPV6,
Expand Down

0 comments on commit bf31877

Please sign in to comment.