Skip to content

Commit

Permalink
More fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Sep 29, 2023
1 parent ad8c225 commit c54b57e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
2 changes: 1 addition & 1 deletion ci/more-sockopts.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions src/backend/libc/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -778,13 +778,13 @@ pub(crate) fn get_ipv6_original_dst(fd: BorrowedFd<'_>) -> io::Result<SocketAddr
}
}

#[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 set_ipv6_tclass(fd: BorrowedFd<'_>, 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<u32> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_TCLASS)
Expand Down Expand Up @@ -864,7 +864,12 @@ pub(crate) fn get_tcp_quickack(fd: BorrowedFd<'_>) -> io::Result<bool> {
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;
Expand All @@ -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<String> {
let level = c::IPPROTO_TCP;
Expand Down
18 changes: 14 additions & 4 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ pub fn get_ipv6_original_dst<Fd: AsFd>(fd: Fd) -> io::Result<SocketAddrV6> {
/// 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: AsFd>(fd: Fd, value: u32) -> io::Result<()> {
Expand All @@ -1104,7 +1104,7 @@ pub fn set_ipv6_tclass<Fd: AsFd>(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: AsFd>(fd: Fd) -> io::Result<u32> {
Expand Down Expand Up @@ -1262,7 +1262,12 @@ pub fn get_tcp_quickack<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
/// 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: AsFd>(fd: Fd, value: &str) -> io::Result<()> {
Expand All @@ -1275,7 +1280,12 @@ pub fn set_tcp_congestion<Fd: AsFd>(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: AsFd>(fd: Fd) -> io::Result<String> {
Expand Down
16 changes: 12 additions & 4 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit c54b57e

Please sign in to comment.