From f026ca7cca68b8a7f4905215d9bc2ac8e2557863 Mon Sep 17 00:00:00 2001 From: Keith Mattix II Date: Wed, 11 Sep 2024 19:10:35 +0000 Subject: [PATCH 1/8] Implement original_dst for windows Signed-off-by: Keith Mattix II --- Cargo.toml | 2 +- src/sys/windows.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++-- tests/socket.rs | 42 +++++++++++++++++++++++++++++- 3 files changed, 104 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8ef85ebc..024ee548 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ include = [ [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] -targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"] +targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"] [package.metadata.playground] features = ["all"] diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 11f2b7b0..3db91483 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -20,14 +20,16 @@ use std::time::{Duration, Instant}; use std::{process, ptr, slice}; use windows_sys::Win32::Foundation::{SetHandleInformation, HANDLE, HANDLE_FLAG_INHERIT}; -#[cfg(feature = "all")] -use windows_sys::Win32::Networking::WinSock::SO_PROTOCOL_INFOW; use windows_sys::Win32::Networking::WinSock::{ self, tcp_keepalive, FIONBIO, IN6_ADDR, IN6_ADDR_0, INVALID_SOCKET, IN_ADDR, IN_ADDR_0, POLLERR, POLLHUP, POLLRDNORM, POLLWRNORM, SD_BOTH, SD_RECEIVE, SD_SEND, SIO_KEEPALIVE_VALS, SOCKET_ERROR, WSABUF, WSAEMSGSIZE, WSAESHUTDOWN, WSAPOLLFD, WSAPROTOCOL_INFOW, WSA_FLAG_NO_HANDLE_INHERIT, WSA_FLAG_OVERLAPPED, }; +#[cfg(feature = "all")] +use windows_sys::Win32::Networking::WinSock::{ + IP6T_SO_ORIGINAL_DST, SOL_IP, SO_ORIGINAL_DST, SO_PROTOCOL_INFOW, +}; use windows_sys::Win32::System::Threading::INFINITE; use crate::{MsgHdr, RecvFlags, SockAddr, TcpKeepalive, Type}; @@ -927,6 +929,64 @@ impl crate::Socket { } } + /// Get the value for the `SO_ORIGINAL_DST` option on this socket. + /// Only valid for sockets in accepting mode. + /// + /// Note: if using this function in a proxy context, you must query the + /// redirect records for this socket and set them on the outbound socket + /// created by your proxy in order for any OS level firewall rules to be + /// applied. Read more in the Windows bind and connect redirection + /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). + #[cfg(feature = "all")] + #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] + pub fn original_dst(&self) -> io::Result { + unsafe { + SockAddr::try_init(|storage, len| { + syscall!( + getsockopt( + self.as_raw(), + SOL_IP as i32, + SO_ORIGINAL_DST as i32, + storage.cast(), + len, + ), + PartialEq::eq, + SOCKET_ERROR + ) + }) + } + .map(|(_, addr)| addr) + } + + /// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. + /// Only valid for sockets in accepting mode. + /// + /// Note: if using this function in a proxy context, you must query the + /// redirect records for this socket and set them on the outbound socket + /// created by your proxy in order for any OS level firewall rules to be + /// applied. Read more in the Windows bind and connect redirection + /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). + #[cfg(feature = "all")] + #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] + pub fn original_dst_ipv6(&self) -> io::Result { + unsafe { + SockAddr::try_init(|storage, len| { + syscall!( + getsockopt( + self.as_raw(), + SOL_IP as i32, + IP6T_SO_ORIGINAL_DST as i32, + storage.cast(), + len, + ), + PartialEq::eq, + SOCKET_ERROR + ) + }) + } + .map(|(_, addr)| addr) + } + /// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW` /// option on this socket. /// diff --git a/tests/socket.rs b/tests/socket.rs index c87ca0e0..3047d644 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -42,6 +42,9 @@ use std::num::NonZeroUsize; use std::os::unix::io::AsRawFd; #[cfg(windows)] use std::os::windows::io::AsRawSocket; +#[cfg(windows)] +use windows_sys::Win32::Networking::WinSock::WSAEINVAL; + #[cfg(unix)] use std::path::Path; use std::str; @@ -1617,7 +1620,27 @@ fn original_dst() { } #[test] -#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))] +#[cfg(all(feature = "all", target_os = "windows"))] +fn original_dst() { + let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); + match socket.original_dst() { + Ok(_) => panic!("original_dst on non-redirected socket should fail"), + Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + } + + // Not supported on IPv6 socket. + let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); + match socket.original_dst_ipv6() { + Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), + Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + } +} + +#[test] +#[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") +))] fn original_dst_ipv6() { let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); match socket.original_dst_ipv6() { @@ -1633,6 +1656,23 @@ fn original_dst_ipv6() { } } +#[test] +#[cfg(all(feature = "all", target_os = "windows"))] +fn original_dst_ipv6() { + let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); + match socket.original_dst_ipv6() { + Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), + Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + } + + // Not supported on IPv4 socket. + let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap(); + match socket.original_dst_ipv6() { + Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), + Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + } +} + #[test] #[cfg(all(feature = "all", any(target_os = "freebsd", target_os = "linux")))] fn tcp_congestion() { From c278b9c8319ef33571653c6d969608b7ea581e69 Mon Sep 17 00:00:00 2001 From: Keith Mattix II Date: Mon, 7 Oct 2024 20:25:55 +0000 Subject: [PATCH 2/8] Generalize original_dst funcs Signed-off-by: Keith Mattix II --- src/socket.rs | 42 ++++++++++++++++ src/sys/unix.rs | 108 ++++++++++++++++++++--------------------- src/sys/windows.rs | 116 ++++++++++++++++++++++----------------------- tests/socket.rs | 62 +++++++++--------------- 4 files changed, 174 insertions(+), 154 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index 3d9d44af..4e41793c 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -2225,6 +2225,48 @@ impl Socket { ) } } + + /// Get the value for the `SO_ORIGINAL_DST` option on this socket. + #[cfg(all( + feature = "all", + any( + target_os = "android", + target_os = "fuchsia", + target_os = "linux", + target_os = "windows", + ) + ))] + #[cfg_attr( + docsrs, + doc(cfg(all( + feature = "all", + any( + target_os = "android", + target_os = "fuchsia", + target_os = "linux", + target_os = "windows", + ) + ))) + )] + pub fn original_dst(&self) -> io::Result { + sys::original_dst(self.as_raw()) + } + + /// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. + #[cfg(all( + feature = "all", + any(target_os = "android", target_os = "linux", target_os = "windows") + ))] + #[cfg_attr( + docsrs, + doc(cfg(all( + feature = "all", + any(target_os = "android", target_os = "linux", target_os = "windows") + ))) + )] + pub fn original_dst_ipv6(&self) -> io::Result { + sys::original_dst_ipv6(self.as_raw()) + } } impl Read for Socket { diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 3a898bc3..da1ff078 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -1406,6 +1406,58 @@ pub(crate) const fn to_mreqn( } } +#[cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") +))] +#[cfg_attr( + docsrs, + doc(cfg(all( + feature = "all", + any(target_os = "android", target_os = "fuchsia", target_os = "linux") + ))) +)] +pub(crate) fn original_dst(fd: Socket) -> io::Result { + // Safety: `getsockopt` initialises the `SockAddr` for us. + unsafe { + SockAddr::try_init(|storage, len| { + syscall!(getsockopt( + fd, + libc::SOL_IP, + libc::SO_ORIGINAL_DST, + storage.cast(), + len + )) + }) + } + .map(|(_, addr)| addr) +} + +/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. +/// +/// This value contains the original destination IPv6 address of the connection +/// redirected using `ip6tables` `REDIRECT` or `TPROXY`. +#[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))] +#[cfg_attr( + docsrs, + doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))) +)] +pub(crate) fn original_dst_ipv6(fd: Socket) -> io::Result { + // Safety: `getsockopt` initialises the `SockAddr` for us. + unsafe { + SockAddr::try_init(|storage, len| { + syscall!(getsockopt( + fd, + libc::SOL_IPV6, + libc::IP6T_SO_ORIGINAL_DST, + storage.cast(), + len + )) + }) + } + .map(|(_, addr)| addr) +} + /// Unix only API. impl crate::Socket { /// Accept a new incoming connection from this listener. @@ -2402,62 +2454,6 @@ impl crate::Socket { } } - /// Get the value for the `SO_ORIGINAL_DST` option on this socket. - /// - /// This value contains the original destination IPv4 address of the connection - /// redirected using `iptables` `REDIRECT` or `TPROXY`. - #[cfg(all( - feature = "all", - any(target_os = "android", target_os = "fuchsia", target_os = "linux") - ))] - #[cfg_attr( - docsrs, - doc(cfg(all( - feature = "all", - any(target_os = "android", target_os = "fuchsia", target_os = "linux") - ))) - )] - pub fn original_dst(&self) -> io::Result { - // Safety: `getsockopt` initialises the `SockAddr` for us. - unsafe { - SockAddr::try_init(|storage, len| { - syscall!(getsockopt( - self.as_raw(), - libc::SOL_IP, - libc::SO_ORIGINAL_DST, - storage.cast(), - len - )) - }) - } - .map(|(_, addr)| addr) - } - - /// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. - /// - /// This value contains the original destination IPv6 address of the connection - /// redirected using `ip6tables` `REDIRECT` or `TPROXY`. - #[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))] - #[cfg_attr( - docsrs, - doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))) - )] - pub fn original_dst_ipv6(&self) -> io::Result { - // Safety: `getsockopt` initialises the `SockAddr` for us. - unsafe { - SockAddr::try_init(|storage, len| { - syscall!(getsockopt( - self.as_raw(), - libc::SOL_IPV6, - libc::IP6T_SO_ORIGINAL_DST, - storage.cast(), - len - )) - }) - } - .map(|(_, addr)| addr) - } - /// Copies data between a `file` and this socket using the `sendfile(2)` /// system call. Because this copying is done within the kernel, /// `sendfile()` is more efficient than the combination of `read(2)` and diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 3db91483..c233c600 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -859,6 +859,64 @@ pub(crate) fn to_mreqn( } } +/// Get the value for the `SO_ORIGINAL_DST` option on this socket. +/// Only valid for sockets in accepting mode. +/// +/// Note: if using this function in a proxy context, you must query the +/// redirect records for this socket and set them on the outbound socket +/// created by your proxy in order for any OS level firewall rules to be +/// applied. Read more in the Windows bind and connect redirection +/// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). +#[cfg(feature = "all")] +#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] +pub(crate) fn original_dst(socket: Socket) -> io::Result { + unsafe { + SockAddr::try_init(|storage, len| { + syscall!( + getsockopt( + socket, + SOL_IP as i32, + SO_ORIGINAL_DST as i32, + storage.cast(), + len, + ), + PartialEq::eq, + SOCKET_ERROR + ) + }) + } + .map(|(_, addr)| addr) +} + +/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. +/// Only valid for sockets in accepting mode. +/// +/// Note: if using this function in a proxy context, you must query the +/// redirect records for this socket and set them on the outbound socket +/// created by your proxy in order for any OS level firewall rules to be +/// applied. Read more in the Windows bind and connect redirection +/// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). +#[cfg(feature = "all")] +#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] +pub(crate) fn original_dst_ipv6(socket: Socket) -> io::Result { + unsafe { + SockAddr::try_init(|storage, len| { + syscall!( + getsockopt( + socket, + SOL_IP as i32, + IP6T_SO_ORIGINAL_DST as i32, + storage.cast(), + len, + ), + PartialEq::eq, + SOCKET_ERROR + ) + }) + } + .map(|(_, addr)| addr) +} + #[allow(unsafe_op_in_unsafe_fn)] pub(crate) fn unix_sockaddr(path: &Path) -> io::Result { // SAFETY: a `sockaddr_storage` of all zeros is valid. @@ -929,64 +987,6 @@ impl crate::Socket { } } - /// Get the value for the `SO_ORIGINAL_DST` option on this socket. - /// Only valid for sockets in accepting mode. - /// - /// Note: if using this function in a proxy context, you must query the - /// redirect records for this socket and set them on the outbound socket - /// created by your proxy in order for any OS level firewall rules to be - /// applied. Read more in the Windows bind and connect redirection - /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). - #[cfg(feature = "all")] - #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] - pub fn original_dst(&self) -> io::Result { - unsafe { - SockAddr::try_init(|storage, len| { - syscall!( - getsockopt( - self.as_raw(), - SOL_IP as i32, - SO_ORIGINAL_DST as i32, - storage.cast(), - len, - ), - PartialEq::eq, - SOCKET_ERROR - ) - }) - } - .map(|(_, addr)| addr) - } - - /// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. - /// Only valid for sockets in accepting mode. - /// - /// Note: if using this function in a proxy context, you must query the - /// redirect records for this socket and set them on the outbound socket - /// created by your proxy in order for any OS level firewall rules to be - /// applied. Read more in the Windows bind and connect redirection - /// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). - #[cfg(feature = "all")] - #[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] - pub fn original_dst_ipv6(&self) -> io::Result { - unsafe { - SockAddr::try_init(|storage, len| { - syscall!( - getsockopt( - self.as_raw(), - SOL_IP as i32, - IP6T_SO_ORIGINAL_DST as i32, - storage.cast(), - len, - ), - PartialEq::eq, - SOCKET_ERROR - ) - }) - } - .map(|(_, addr)| addr) - } - /// Returns the [`Protocol`] of this socket by checking the `SO_PROTOCOL_INFOW` /// option on this socket. /// diff --git a/tests/socket.rs b/tests/socket.rs index 3047d644..c58b1a0d 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -42,8 +42,6 @@ use std::num::NonZeroUsize; use std::os::unix::io::AsRawFd; #[cfg(windows)] use std::os::windows::io::AsRawSocket; -#[cfg(windows)] -use windows_sys::Win32::Networking::WinSock::WSAEINVAL; #[cfg(unix)] use std::path::Path; @@ -1603,36 +1601,29 @@ fn header_included_ipv6() { #[test] #[cfg(all( feature = "all", - any(target_os = "android", target_os = "fuchsia", target_os = "linux") + any( + target_os = "android", + target_os = "fuchsia", + target_os = "linux", + target_os = "windows" + ) ))] fn original_dst() { let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap(); - match socket.original_dst() { - Ok(_) => panic!("original_dst on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(libc::ENOENT)), - } + #[cfg(not(target_os = "windows"))] + let expected = Some(libc::ENOENT); + #[cfg(target_os = "windows")] + let expected = Some(windows_sys::Win32::Networking::WinSock::WSAEINVAL); - let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); match socket.original_dst() { Ok(_) => panic!("original_dst on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(libc::ENOENT)), + Err(err) => assert_eq!(err.raw_os_error(), expected), } -} -#[test] -#[cfg(all(feature = "all", target_os = "windows"))] -fn original_dst() { let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); match socket.original_dst() { Ok(_) => panic!("original_dst on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), - } - - // Not supported on IPv6 socket. - let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); - match socket.original_dst_ipv6() { - Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + Err(err) => assert_eq!(err.raw_os_error(), expected), } } @@ -1643,33 +1634,24 @@ fn original_dst() { ))] fn original_dst_ipv6() { let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); + #[cfg(not(target_os = "windows"))] + let expected = Some(libc::ENOENT); + #[cfg(target_os = "windows")] + let expected = Some(windows_sys::Win32::Networking::WinSock::WSAEINVAL); + #[cfg(not(target_os = "windows"))] + let expected_v4 = Some(libc::EOPNOTSUPP); + #[cfg(target_os = "windows")] + let expected_v4 = Some(windows_sys::Win32::Networking::WinSock::WSAEINVAL); match socket.original_dst_ipv6() { Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(libc::ENOENT)), - } - - // Not supported on IPv4 socket. - let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap(); - match socket.original_dst_ipv6() { - Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(libc::EOPNOTSUPP)), - } -} - -#[test] -#[cfg(all(feature = "all", target_os = "windows"))] -fn original_dst_ipv6() { - let socket = Socket::new(Domain::IPV6, Type::STREAM, None).unwrap(); - match socket.original_dst_ipv6() { - Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + Err(err) => assert_eq!(err.raw_os_error(), expected), } // Not supported on IPv4 socket. let socket = Socket::new(Domain::IPV4, Type::STREAM, None).unwrap(); match socket.original_dst_ipv6() { Ok(_) => panic!("original_dst_ipv6 on non-redirected socket should fail"), - Err(err) => assert_eq!(err.raw_os_error(), Some(WSAEINVAL)), + Err(err) => assert_eq!(err.raw_os_error(), expected_v4), } } From 128d5dce7cdf2a5d2cf262729c70b10ee2c419ef Mon Sep 17 00:00:00 2001 From: Keith Mattix II Date: Mon, 25 Nov 2024 14:55:21 +0000 Subject: [PATCH 3/8] Remove windows-gnu as target due to failure Signed-off-by: Keith Mattix II --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 024ee548..8ef85ebc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,7 +29,7 @@ include = [ [package.metadata.docs.rs] all-features = true rustdoc-args = ["--cfg", "docsrs"] -targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-windows-gnu", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"] +targets = ["aarch64-apple-ios", "aarch64-linux-android", "x86_64-apple-darwin", "x86_64-unknown-fuchsia", "x86_64-pc-windows-msvc", "x86_64-pc-solaris", "x86_64-unknown-freebsd", "x86_64-unknown-illumos", "x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl", "x86_64-unknown-netbsd", "x86_64-unknown-redox", "armv7-linux-androideabi", "i686-linux-android"] [package.metadata.playground] features = ["all"] From 65df97ab196657c703f43f5c9b9df6d113fbc651 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 27 Nov 2024 17:04:41 +0100 Subject: [PATCH 4/8] Remove unused docsrs cfg --- src/sys/unix.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/sys/unix.rs b/src/sys/unix.rs index da1ff078..7807dbdc 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -1410,13 +1410,6 @@ pub(crate) const fn to_mreqn( feature = "all", any(target_os = "android", target_os = "fuchsia", target_os = "linux") ))] -#[cfg_attr( - docsrs, - doc(cfg(all( - feature = "all", - any(target_os = "android", target_os = "fuchsia", target_os = "linux") - ))) -)] pub(crate) fn original_dst(fd: Socket) -> io::Result { // Safety: `getsockopt` initialises the `SockAddr` for us. unsafe { From f5e9f8b8cd5b2bc4ad737b0a4f3308693a152e9a Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 27 Nov 2024 17:04:47 +0100 Subject: [PATCH 5/8] Remove unused docsrs cfg --- src/sys/unix.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 7807dbdc..1451b1f4 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -1431,10 +1431,6 @@ pub(crate) fn original_dst(fd: Socket) -> io::Result { /// This value contains the original destination IPv6 address of the connection /// redirected using `ip6tables` `REDIRECT` or `TPROXY`. #[cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))] -#[cfg_attr( - docsrs, - doc(cfg(all(feature = "all", any(target_os = "android", target_os = "linux")))) -)] pub(crate) fn original_dst_ipv6(fd: Socket) -> io::Result { // Safety: `getsockopt` initialises the `SockAddr` for us. unsafe { From f527aa7dd3df580e2bcb0c75fceb7f0f3d73401b Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 27 Nov 2024 17:04:57 +0100 Subject: [PATCH 6/8] Remove unused docs --- src/sys/windows.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/sys/windows.rs b/src/sys/windows.rs index c233c600..98e43028 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -859,16 +859,7 @@ pub(crate) fn to_mreqn( } } -/// Get the value for the `SO_ORIGINAL_DST` option on this socket. -/// Only valid for sockets in accepting mode. -/// -/// Note: if using this function in a proxy context, you must query the -/// redirect records for this socket and set them on the outbound socket -/// created by your proxy in order for any OS level firewall rules to be -/// applied. Read more in the Windows bind and connect redirection -/// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). #[cfg(feature = "all")] -#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] pub(crate) fn original_dst(socket: Socket) -> io::Result { unsafe { SockAddr::try_init(|storage, len| { From c3b788283e109ce019321de85a5a0149602563df Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 27 Nov 2024 17:05:04 +0100 Subject: [PATCH 7/8] Remove unused docs --- src/sys/windows.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/sys/windows.rs b/src/sys/windows.rs index 98e43028..8cf27b53 100644 --- a/src/sys/windows.rs +++ b/src/sys/windows.rs @@ -879,16 +879,7 @@ pub(crate) fn original_dst(socket: Socket) -> io::Result { .map(|(_, addr)| addr) } -/// Get the value for the `IP6T_SO_ORIGINAL_DST` option on this socket. -/// Only valid for sockets in accepting mode. -/// -/// Note: if using this function in a proxy context, you must query the -/// redirect records for this socket and set them on the outbound socket -/// created by your proxy in order for any OS level firewall rules to be -/// applied. Read more in the Windows bind and connect redirection -/// [documentation](https://learn.microsoft.com/en-us/windows-hardware/drivers/network/using-bind-or-connect-redirection). #[cfg(feature = "all")] -#[cfg_attr(docsrs, doc(cfg(all(windows, feature = "all"))))] pub(crate) fn original_dst_ipv6(socket: Socket) -> io::Result { unsafe { SockAddr::try_init(|storage, len| { From 08d6ca0eef2ca6996822b611c43fc385ed4de6c5 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Wed, 27 Nov 2024 17:05:13 +0100 Subject: [PATCH 8/8] Remove extra line --- tests/socket.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/socket.rs b/tests/socket.rs index c58b1a0d..0959ef39 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -42,7 +42,6 @@ use std::num::NonZeroUsize; use std::os::unix::io::AsRawFd; #[cfg(windows)] use std::os::windows::io::AsRawSocket; - #[cfg(unix)] use std::path::Path; use std::str;