Skip to content

Commit

Permalink
Cfg's for IPV6_RECVTCLASS.
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Sep 27, 2023
1 parent 3f1a070 commit dc6ed1f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/backend/libc/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,25 @@ pub(crate) fn get_ip_recvtos(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::IPPROTO_IP, c::IP_RECVTOS).map(to_bool)
}

#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
#[inline]
pub(crate) fn set_ipv6_recvtclass(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
setsockopt(fd, c::IPPROTO_IPV6, c::IPV6_RECVTCLASS, from_bool(value))
}

#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
#[inline]
pub(crate) fn get_ipv6_recvtclass(fd: BorrowedFd<'_>) -> io::Result<bool> {
getsockopt(fd, c::IPPROTO_IPV6, c::IPV6_RECVTCLASS).map(to_bool)
Expand Down
14 changes: 14 additions & 0 deletions src/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,13 @@ pub fn get_ip_recvtos<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
#[inline]
#[doc(alias = "IPV6_RECVTCLASS")]
pub fn set_ipv6_recvtclass<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
Expand All @@ -869,6 +876,13 @@ pub fn set_ipv6_recvtclass<Fd: AsFd>(fd: Fd, value: bool) -> io::Result<()> {
/// See the [module-level documentation] for more.
///
/// [module-level documentation]: self#references-for-get_ipv6_-and-set_ipv6_-functions
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
#[inline]
#[doc(alias = "IPV6_RECVTCLASS")]
pub fn get_ipv6_recvtclass<Fd: AsFd>(fd: Fd) -> io::Result<bool> {
Expand Down
15 changes: 12 additions & 3 deletions tests/net/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,18 @@ fn test_sockopts_ipv6() {
assert_eq!(sockopt::get_ipv6_unicast_hops(&s).unwrap(), 8);

// Check the initial value of IPV6 RECVTCLASS, set it, and check it.
assert!(!sockopt::get_ipv6_recvtclass(&s).unwrap());
sockopt::set_ipv6_recvtclass(&s, true).unwrap();
assert!(sockopt::get_ipv6_recvtclass(&s).unwrap());
#[cfg(any(
bsd,
linux_like,
target_os = "aix",
target_os = "fuchsia",
target_os = "nto"
))]
{
assert!(!sockopt::get_ipv6_recvtclass(&s).unwrap());
sockopt::set_ipv6_recvtclass(&s, true).unwrap();
assert!(sockopt::get_ipv6_recvtclass(&s).unwrap());
}

test_sockopts_tcp(&s);
}

0 comments on commit dc6ed1f

Please sign in to comment.