Skip to content

Commit

Permalink
feat(quinn-udp): support illumos
Browse files Browse the repository at this point in the history
  • Loading branch information
AsakuraMizu authored and djc committed Nov 29, 2024
1 parent f188909 commit e318cc4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions quinn-udp/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")) },
Expand Down
31 changes: 10 additions & 21 deletions quinn-udp/src/unix.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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
Expand Down Expand Up @@ -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::<libc::in6_pktinfo>() as _) as usize };
Expand All @@ -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:?}");
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<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 @@ -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<usize> {
let mut name = MaybeUninit::<libc::sockaddr_storage>::uninit();
let mut ctrl = cmsg::Aligned(MaybeUninit::<[u8; CMSG_LEN]>::uninit());
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -693,7 +682,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", target_os = "solaris")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))]
(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", target_os = "solaris")))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd", solarish)))]
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", 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());
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion quinn/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit e318cc4

Please sign in to comment.