From 45ffd2cfe6a4a223d7f5889cc2ed0603992bd78e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 29 Sep 2023 07:43:58 -0700 Subject: [PATCH] More fixes. --- ci/more-sockopts.patch | 2 +- src/backend/libc/net/sockopt.rs | 39 +++++++++++++++++++++++++++------ src/net/sockopt.rs | 25 ++++++++++++++++----- tests/net/sockopt.rs | 16 ++++++++++---- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/ci/more-sockopts.patch b/ci/more-sockopts.patch index ec9f62cb8..54eaab5e9 100644 --- a/ci/more-sockopts.patch +++ b/ci/more-sockopts.patch @@ -48,7 +48,7 @@ diff -ur -x roms -x build a/linux-user/syscall.c b/linux-user/syscall.c + goto int_case; + case TARGET_SO_COOKIE: + optname = SO_COOKIE; -+ if (get_user_u64(len, optlen)) ++ if (get_user_u32(len, optlen)) + return -TARGET_EFAULT; + if (len < 0) + return -TARGET_EINVAL; diff --git a/src/backend/libc/net/sockopt.rs b/src/backend/libc/net/sockopt.rs index 04694125b..2319c7cda 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -5,7 +5,12 @@ use crate::backend::c; use crate::backend::conv::{borrowed_fd, ret}; use crate::fd::BorrowedFd; #[cfg(feature = "alloc")] -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] use crate::ffi::CStr; use crate::io; use crate::net::sockopt::Timeout; @@ -46,10 +51,20 @@ use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; use crate::net::{SocketAddrAny, SocketAddrStorage, SocketAddrV4}; use crate::utils::as_mut_ptr; #[cfg(feature = "alloc")] -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] use alloc::borrow::ToOwned; #[cfg(feature = "alloc")] -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] use alloc::string::String; #[cfg(apple)] use c::TCP_KEEPALIVE as TCP_KEEPIDLE; @@ -778,13 +793,13 @@ pub(crate) fn get_ipv6_original_dst(fd: BorrowedFd<'_>) -> io::Result, value: u32) -> io::Result<()> { setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_TCLASS, value) } -#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] +#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] #[inline] pub(crate) fn get_ipv6_tclass(fd: BorrowedFd<'_>) -> io::Result { getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_TCLASS) @@ -864,7 +879,12 @@ pub(crate) fn get_tcp_quickack(fd: BorrowedFd<'_>) -> io::Result { getsockopt(fd, c::IPPROTO_TCP, c::TCP_QUICKACK).map(to_bool) } -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] #[inline] pub(crate) fn set_tcp_congestion(fd: BorrowedFd<'_>, value: &str) -> io::Result<()> { let level = c::IPPROTO_TCP; @@ -874,7 +894,12 @@ pub(crate) fn set_tcp_congestion(fd: BorrowedFd<'_>, value: &str) -> io::Result< } #[cfg(feature = "alloc")] -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] #[inline] pub(crate) fn get_tcp_congestion(fd: BorrowedFd<'_>) -> io::Result { let level = c::IPPROTO_TCP; diff --git a/src/net/sockopt.rs b/src/net/sockopt.rs index 72420c09a..05e407f78 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -171,7 +171,12 @@ use crate::net::SocketAddrV6; use crate::net::{Ipv4Addr, Ipv6Addr, SocketType}; use crate::{backend, io}; #[cfg(feature = "alloc")] -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] use alloc::string::String; use backend::c; use backend::fd::AsFd; @@ -1092,7 +1097,7 @@ pub fn get_ipv6_original_dst(fd: Fd) -> io::Result { /// See the [module-level documentation] for more. /// /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions -#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] +#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] #[inline] #[doc(alias = "IPV6_TCLASS")] pub fn set_ipv6_tclass(fd: Fd, value: u32) -> io::Result<()> { @@ -1104,7 +1109,7 @@ pub fn set_ipv6_tclass(fd: Fd, value: u32) -> io::Result<()> { /// See the [module-level documentation] for more. /// /// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions -#[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] +#[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] #[inline] #[doc(alias = "IPV6_TCLASS")] pub fn get_ipv6_tclass(fd: Fd) -> io::Result { @@ -1262,7 +1267,12 @@ pub fn get_tcp_quickack(fd: Fd) -> io::Result { /// See the [module-level documentation] for more. /// /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] #[inline] #[doc(alias = "TCP_CONGESTION")] pub fn set_tcp_congestion(fd: Fd, value: &str) -> io::Result<()> { @@ -1275,7 +1285,12 @@ pub fn set_tcp_congestion(fd: Fd, value: &str) -> io::Result<()> { /// /// [module-level documentation]: self#references-for-get_tcp_-and-set_tcp_-functions #[cfg(feature = "alloc")] -#[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] +#[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" +))] #[inline] #[doc(alias = "TCP_CONGESTION")] pub fn get_tcp_congestion(fd: Fd) -> io::Result { diff --git a/tests/net/sockopt.rs b/tests/net/sockopt.rs index ba06e798f..c4406bd07 100644 --- a/tests/net/sockopt.rs +++ b/tests/net/sockopt.rs @@ -235,13 +235,21 @@ fn test_sockopts_tcp(s: &OwnedFd) { // Temporarily disable this test on non-x86 as qemu isn't yet aware of // TCP_CONGESTION. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] - #[cfg(any(linux_like, solarish, target_os = "freebsd", target_os = "fuchsia"))] + #[cfg(any( + linux_like, + target_os = "freebsd", + target_os = "fuchsia", + target_os = "illumos" + ))] #[cfg(feature = "alloc")] { let algo = sockopt::get_tcp_congestion(&s).unwrap(); assert!(!algo.is_empty()); - sockopt::set_tcp_congestion(&s, "reno").unwrap(); - assert_eq!(sockopt::get_tcp_congestion(&s).unwrap(), "reno"); + #[cfg(linux_like)] + { + sockopt::set_tcp_congestion(&s, "reno").unwrap(); + assert_eq!(sockopt::get_tcp_congestion(&s).unwrap(), "reno"); + } } // Check the initial value of TCP_THIN_LINEAR_TIMEOUTS, set it, and check @@ -447,7 +455,7 @@ fn test_sockopts_ipv6() { } // Check the initial value of IPV6_TCLASS, set it, and check it. - #[cfg(not(any(solarish, target_os = "espidf", target_os = "haiku")))] + #[cfg(not(any(solarish, windows, target_os = "espidf", target_os = "haiku")))] { assert_eq!(sockopt::get_ipv6_tclass(&s).unwrap(), 0); sockopt::set_ipv6_tclass(&s, 12).unwrap();