From ffffafb70223f3409b016f8516db324799fb317d Mon Sep 17 00:00:00 2001 From: Razz4780 Date: Wed, 8 May 2024 12:59:46 +0200 Subject: [PATCH] Workaround --- changelog.d/+connect-bound.fixed.md | 1 + mirrord/layer/src/detour.rs | 1 + mirrord/layer/src/socket/ops.rs | 38 +++++++++++++++++------------ 3 files changed, 24 insertions(+), 16 deletions(-) create mode 100644 changelog.d/+connect-bound.fixed.md diff --git a/changelog.d/+connect-bound.fixed.md b/changelog.d/+connect-bound.fixed.md new file mode 100644 index 00000000000..f8be9c0609b --- /dev/null +++ b/changelog.d/+connect-bound.fixed.md @@ -0,0 +1 @@ +Fixed connect hook on bound sockets. \ No newline at end of file diff --git a/mirrord/layer/src/detour.rs b/mirrord/layer/src/detour.rs index a1bccd66938..343032c538c 100644 --- a/mirrord/layer/src/detour.rs +++ b/mirrord/layer/src/detour.rs @@ -196,6 +196,7 @@ pub(crate) enum Bypass { BindWhenTargetless, /// Hooked connect from a bound mirror socket. + #[allow(unused)] MirrorConnect, /// Hooked a `connect` to a target that is disabled in the configuration. diff --git a/mirrord/layer/src/socket/ops.rs b/mirrord/layer/src/socket/ops.rs index 3c566a11da0..d6f49f9cd9f 100644 --- a/mirrord/layer/src/socket/ops.rs +++ b/mirrord/layer/src/socket/ops.rs @@ -610,22 +610,28 @@ pub(super) fn connect( ) } - SocketState::Bound(Bound { address, .. }) => { - trace!("connect -> SocketState::Bound {:#?}", user_socket_info); - - let address = SockAddr::from(address); - let bind_result = unsafe { FN_BIND(sockfd, address.as_ptr(), address.len()) }; - - if bind_result != 0 { - error!( - "connect -> Failed to bind socket result {:?}, address: {:?}, sockfd: {:?}!", - bind_result, address, sockfd - ); - - Err(io::Error::last_os_error())? - } else { - Detour::Bypass(Bypass::MirrorConnect) - } + SocketState::Bound(Bound { .. }) => { + // trace!("connect -> SocketState::Bound {:#?}", user_socket_info); + + // let address = SockAddr::from(address); + // let bind_result = unsafe { FN_BIND(sockfd, address.as_ptr(), address.len()) }; + + // if bind_result != 0 { + // error!( + // "connect -> Failed to bind socket result {:?}, address: {:?}, sockfd: + // {:?}!", bind_result, address, sockfd + // ); + + // Err(io::Error::last_os_error())? + // } else { + // Detour::Bypass(Bypass::MirrorConnect) + // } + connect_outgoing::( + sockfd, + remote_address, + user_socket_info, + NetProtocol::Stream, + ) } _ => Detour::Bypass(Bypass::DisabledOutgoing),