Skip to content

Commit

Permalink
Allows build on Solaris (quinn-rs#1877)
Browse files Browse the repository at this point in the history
  • Loading branch information
psumbera committed Jul 11, 2024
1 parent 36407fe commit 2bd44e6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
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 @@ -61,6 +66,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 @@ -83,7 +89,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 @@ -136,10 +142,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 @@ -365,7 +372,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 @@ -402,7 +414,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 @@ -431,7 +448,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 Down Expand Up @@ -474,7 +496,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 @@ -565,6 +592,7 @@ fn prepare_msg(
target_os = "netbsd",
target_os = "macos",
target_os = "ios",
target_os = "solaris",
))]
{
if encode_src_ip {
Expand Down Expand Up @@ -623,7 +651,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 2bd44e6

Please sign in to comment.