Skip to content

Commit

Permalink
don't re-resolve when connecting to loopback on outgoing filter (#2390)
Browse files Browse the repository at this point in the history
  • Loading branch information
aviramha authored Apr 22, 2024
1 parent 81230fa commit accf0bf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/2389.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
don't re-resolve when connecting to loopback on outgoing filter
9 changes: 8 additions & 1 deletion mirrord/layer/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,14 @@ impl OutgoingSelector {
/// 2. `address` is **NOT** in [`REMOTE_DNS_REVERSE_MAPPING`]: return the `address` as is;
#[mirrord_layer_macro::instrument(level = "trace", ret)]
fn get_local_address_to_connect(address: SocketAddr) -> HookResult<SocketAddr> {
// Aviram: I think this whole function and logic is weird but I really need to get
// https://github.com/metalbear-co/mirrord/issues/2389 fixed and I don't have time to
// fully understand or refactor, and the logic is sound (if it's loopback, just connect to
// it)
if address.ip().is_loopback() {
return Ok(address);
}

let cached = REMOTE_DNS_REVERSE_MAPPING
.get(&address.ip())
.map(|entry| entry.value().clone());
Expand All @@ -324,7 +332,6 @@ impl OutgoingSelector {
};

let _guard = DetourGuard::new();

(hostname, address.port())
.to_socket_addrs()?
.next()
Expand Down

0 comments on commit accf0bf

Please sign in to comment.