From c54b57e9ccf85ac8654a6ffa8e532c9a954bcd3f 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 | 18 ++++++++++++++---- src/net/sockopt.rs | 18 ++++++++++++++---- tests/net/sockopt.rs | 16 ++++++++++++---- 4 files changed, 41 insertions(+), 13 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..b6dadd0f1 100644 --- a/src/backend/libc/net/sockopt.rs +++ b/src/backend/libc/net/sockopt.rs @@ -778,13 +778,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 +864,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 +879,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..c0fab2b23 100644 --- a/src/net/sockopt.rs +++ b/src/net/sockopt.rs @@ -1092,7 +1092,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 +1104,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 +1262,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 +1280,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();