Skip to content

Commit

Permalink
Workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
Razz4780 committed May 8, 2024
1 parent c2b5069 commit ffffafb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions changelog.d/+connect-bound.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed connect hook on bound sockets.
1 change: 1 addition & 0 deletions mirrord/layer/src/detour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
38 changes: 22 additions & 16 deletions mirrord/layer/src/socket/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<true>(
sockfd,
remote_address,
user_socket_info,
NetProtocol::Stream,
)
}

_ => Detour::Bypass(Bypass::DisabledOutgoing),
Expand Down

0 comments on commit ffffafb

Please sign in to comment.