From e318cc4a80436fd9fa19c02886d682c49efca185 Mon Sep 17 00:00:00 2001 From: Asakura Mizu Date: Wed, 20 Nov 2024 16:14:36 +0800 Subject: [PATCH] feat(quinn-udp): support illumos --- .github/workflows/rust.yml | 18 ++++++++++++++++++ quinn-udp/build.rs | 6 ++++++ quinn-udp/src/unix.rs | 31 ++++++++++--------------------- quinn-udp/tests/tests.rs | 8 ++++---- quinn/src/tests.rs | 5 ++++- 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7a3b22cd6..552fae963 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -82,6 +82,24 @@ jobs: export PATH=$HOME/.rust_solaris/bin:$PATH cargo build --all-targets && cargo test && cargo test --manifest-path fuzz/Cargo.toml && cargo test -p quinn-udp --benches + test-illumos: + name: test on illumos + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: test on Illumos + uses: vmactions/omnios-vm@v1 + with: + usesh: true + mem: 4096 + copyback: false + prepare: | + pkg install gcc14 curl pkg-config glib2 + curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal + run: | + . "$HOME/.cargo/env" + cargo build --all-targets && cargo test && cargo test --manifest-path fuzz/Cargo.toml && cargo test -p quinn-udp --benches + test: strategy: matrix: diff --git a/quinn-udp/build.rs b/quinn-udp/build.rs index ef89ff70f..d9893ed94 100644 --- a/quinn-udp/build.rs +++ b/quinn-udp/build.rs @@ -19,6 +19,12 @@ fn main() { target_os = "netbsd" ) }, + solarish: { + any( + target_os = "solaris", + target_os = "illumos" + ) + }, // Convenience aliases apple_fast: { all(apple, feature = "fast-apple-datapath") }, apple_slow: { all(apple, not(feature = "fast-apple-datapath")) }, diff --git a/quinn-udp/src/unix.rs b/quinn-udp/src/unix.rs index 38b322e24..1b3515297 100644 --- a/quinn-udp/src/unix.rs +++ b/quinn-udp/src/unix.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(apple, target_os = "openbsd", target_os = "solaris")))] +#[cfg(not(any(apple, target_os = "openbsd", solarish)))] use std::ptr; use std::{ io::{self, IoSliceMut}, @@ -15,8 +15,7 @@ use std::{ use socket2::SockRef; use super::{ - cmsg, log::debug, log_sendmsg_error, EcnCodepoint, RecvMeta, Transmit, UdpSockRef, - IO_ERROR_LOG_INTERVAL, + cmsg, log_sendmsg_error, EcnCodepoint, RecvMeta, Transmit, UdpSockRef, IO_ERROR_LOG_INTERVAL, }; // Adapted from https://github.com/apple-oss-distributions/xnu/blob/8d741a5de7ff4191bf97d57b9f54c2f6d4a15585/bsd/sys/socket_private.h @@ -91,7 +90,7 @@ impl UdpSocketState { || cfg!(bsd) || cfg!(apple) || cfg!(target_os = "android") - || cfg!(target_os = "solaris") + || cfg!(solarish) { cmsg_platform_space += unsafe { libc::CMSG_SPACE(mem::size_of::() as _) as usize }; @@ -114,12 +113,12 @@ 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", target_os = "solaris")))] + #[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))] if is_ipv4 || !io.only_v6()? { if let Err(_err) = set_socket_option(&*io, libc::IPPROTO_IP, libc::IP_RECVTOS, OPTION_ON) { - debug!("Ignoring error setting IP_RECVTOS on socket: {_err:?}"); + crate::log::debug!("Ignoring error setting IP_RECVTOS on socket: {_err:?}"); } } @@ -162,7 +161,7 @@ impl UdpSocketState { )?; } } - #[cfg(any(bsd, apple, target_os = "solaris"))] + #[cfg(any(bsd, apple, solarish))] // IP_RECVDSTADDR == IP_SENDSRCADDR on FreeBSD // macOS uses only IP_RECVDSTADDR, no IP_SENDSRCADDR on macOS (the same on Solaris) // macOS also supports IP_PKTINFO @@ -446,12 +445,7 @@ fn send(state: &UdpSocketState, io: SockRef<'_>, transmit: &Transmit<'_>) -> io: Ok(()) } -#[cfg(not(any( - apple, - target_os = "openbsd", - target_os = "netbsd", - target_os = "solaris" -)))] +#[cfg(not(any(apple, target_os = "openbsd", target_os = "netbsd", solarish)))] fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> io::Result { let mut names = [MaybeUninit::::uninit(); BATCH_SIZE]; let mut ctrls = [cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit()); BATCH_SIZE]; @@ -518,12 +512,7 @@ fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> Ok(msg_count as usize) } -#[cfg(any( - target_os = "openbsd", - target_os = "netbsd", - target_os = "solaris", - apple_slow -))] +#[cfg(any(target_os = "openbsd", target_os = "netbsd", solarish, apple_slow))] fn recv(io: SockRef<'_>, bufs: &mut [IoSliceMut<'_>], meta: &mut [RecvMeta]) -> io::Result { let mut name = MaybeUninit::::uninit(); let mut ctrl = cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit()); @@ -616,7 +605,7 @@ fn prepare_msg( }; encoder.push(libc::IPPROTO_IP, libc::IP_PKTINFO, pktinfo); } - #[cfg(any(bsd, apple, target_os = "solaris"))] + #[cfg(any(bsd, apple, solarish))] { if encode_src_ip { let addr = libc::in_addr { @@ -693,7 +682,7 @@ fn decode_recv( ecn_bits = cmsg::decode::(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", target_os = "solaris")))] + #[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))] (libc::IPPROTO_IP, libc::IP_RECVTOS) => unsafe { ecn_bits = cmsg::decode::(cmsg); }, diff --git a/quinn-udp/tests/tests.rs b/quinn-udp/tests/tests.rs index 7169ed6ae..0ed020961 100644 --- a/quinn-udp/tests/tests.rs +++ b/quinn-udp/tests/tests.rs @@ -1,4 +1,4 @@ -#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))] +#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))] use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6}; use std::{ io::IoSliceMut, @@ -51,7 +51,7 @@ fn ecn_v6() { } #[test] -#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))] +#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))] fn ecn_v4() { let send = Socket::from(UdpSocket::bind((Ipv4Addr::LOCALHOST, 0)).unwrap()); let recv = Socket::from(UdpSocket::bind((Ipv4Addr::LOCALHOST, 0)).unwrap()); @@ -71,7 +71,7 @@ fn ecn_v4() { } #[test] -#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))] +#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))] fn ecn_v6_dualstack() { let recv = socket2::Socket::new( socket2::Domain::IPV6, @@ -117,7 +117,7 @@ fn ecn_v6_dualstack() { } #[test] -#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", target_os = "solaris")))] +#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))] fn ecn_v4_mapped_v6() { let send = socket2::Socket::new( socket2::Domain::IPV6, diff --git a/quinn/src/tests.rs b/quinn/src/tests.rs index ea5a65713..8887af1c2 100755 --- a/quinn/src/tests.rs +++ b/quinn/src/tests.rs @@ -387,7 +387,10 @@ async fn zero_rtt() { } #[test] -#[cfg_attr(target_os = "solaris", ignore = "Fails on Solaris")] +#[cfg_attr( + any(target_os = "solaris", target_os = "illumos"), + ignore = "Fails on Solaris and Illumos" +)] fn echo_v6() { run_echo(EchoArgs { client_addr: SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 0),