From f90045055529aaa3f3847c7cac60af2b251b9ac6 Mon Sep 17 00:00:00 2001 From: Andrew Hauck Date: Fri, 27 Sep 2024 15:37:47 -0700 Subject: Add windows compatibility for get_original_dest() --- .bleep | 2 +- pingora-core/src/protocols/digest.rs | 13 +++++++++++++ pingora-core/src/protocols/l4/ext.rs | 7 ++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/.bleep b/.bleep index 1ac3b4f..4611476 100644 --- a/.bleep +++ b/.bleep @@ -1 +1 @@ -73cbdf49b1e1279ebba51525cad01952d4dc04d2 \ No newline at end of file +9d8254e966aca99eeb6623f2bcf5fc93facbb05a \ No newline at end of file diff --git a/pingora-core/src/protocols/digest.rs b/pingora-core/src/protocols/digest.rs index 9e23741..19dc78d 100644 --- a/pingora-core/src/protocols/digest.rs +++ b/pingora-core/src/protocols/digest.rs @@ -162,6 +162,7 @@ impl SocketDigest { } } + #[cfg(unix)] pub fn original_dst(&self) -> Option<&SocketAddr> { self.original_dst .get_or_init(|| { @@ -172,6 +173,18 @@ impl SocketDigest { }) .as_ref() } + + #[cfg(windows)] + pub fn original_dst(&self) -> Option<&SocketAddr> { + self.original_dst + .get_or_init(|| { + get_original_dest(self.raw_sock) + .ok() + .flatten() + .map(SocketAddr::Inet) + }) + .as_ref() + } } /// The interface to return timing information diff --git a/pingora-core/src/protocols/l4/ext.rs b/pingora-core/src/protocols/l4/ext.rs index fae93f7..b687cc4 100644 --- a/pingora-core/src/protocols/l4/ext.rs +++ b/pingora-core/src/protocols/l4/ext.rs @@ -413,11 +413,16 @@ pub fn get_original_dest(fd: RawFd) -> Result> { .map(Some) } -#[cfg(not(target_os = "linux"))] +#[cfg(all(unix, not(target_os = "linux")))] pub fn get_original_dest(_fd: RawFd) -> Result> { Ok(None) } +#[cfg(windows)] +pub fn get_original_dest(_sock: RawSocket) -> Result> { + Ok(None) +} + /// connect() to the given address while optionally binding to the specific source address and port range. /// /// The `set_socket` callback can be used to tune the socket before `connect()` is called. -- cgit v1.2.3