forked from metalbear-co/mirrord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hook gethosbyname to resolve DNS for erlang/elixir. (metalbear-co#2071)
* Hook gethosbyname for elixir outgoing requests (it uses a deprecated getaddrinfo-like function). * pointer slice trickery * convert the right address to h_addr_list * just return global reference * deal with the crazy h_aliases * always v4 * null end of list * length at 4 * redoxify * less unwrapping * more logs * woo * .. * logs * integration test * remove unused * refactor + docs * fix changelog * remove unused features * fix logs * more log changes * force pointer cast * explicit type * node -> name // cast --------- Co-authored-by: Aviram Hassan <[email protected]>
- Loading branch information
Showing
7 changed files
with
243 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add a hook for [gethostbyname](https://www.man7.org/linux/man-pages/man3/gethostbyname.3.html) to allow erlang/elixir to resolve DNS. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <stdio.h> | ||
#include <netdb.h> | ||
#include <strings.h> | ||
#include <arpa/inet.h> | ||
|
||
void try_gethostbyname(const char name[]) { | ||
struct hostent *result = gethostbyname(name); | ||
|
||
if (result) { | ||
printf("result %p\n\t", result); | ||
printf("h_name %s\n\t", result->h_name); | ||
printf("h_length %i\n\t", result->h_length); | ||
printf("h_addrtype %i\n\t", result->h_addrtype); | ||
|
||
for (int i = 0; result->h_addr_list[i]; i++) { | ||
char str[INET6_ADDRSTRLEN]; | ||
struct in_addr address = {}; | ||
bcopy(result->h_addr_list[i], (char *)&address, sizeof(address)); | ||
printf("h_addresses[%i] %s\n\t", i, inet_ntoa(address)); | ||
} | ||
|
||
for (int i = 0; result->h_aliases[i]; i++) { | ||
printf("h_aliases[%i] %s\n\t", i, result->h_aliases[i]); | ||
} | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
printf("test issue 2055: START\n"); | ||
try_gethostbyname("www.mirrord.dev"); | ||
try_gethostbyname("www.invalid.dev"); | ||
printf("test issue 2055: SUCCESS\n"); | ||
printf("\n"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#![feature(assert_matches)] | ||
use std::{net::IpAddr, path::PathBuf, time::Duration}; | ||
|
||
use mirrord_protocol::{ | ||
dns::{DnsLookup, GetAddrInfoRequest, GetAddrInfoResponse, LookupRecord}, | ||
ClientMessage, DaemonMessage, DnsLookupError, | ||
ResolveErrorKindInternal::NoRecordsFound, | ||
ResponseError, | ||
}; | ||
use rstest::rstest; | ||
|
||
mod common; | ||
pub use common::*; | ||
|
||
/// Verify that issue [#2055](https://github.com/metalbear-co/mirrord/issues/2055) is fixed. | ||
/// "DNS Issue on Elixir macOS" | ||
#[rstest] | ||
#[tokio::test] | ||
#[timeout(Duration::from_secs(60))] | ||
async fn issue_2055(dylib_path: &PathBuf) { | ||
let application = Application::CIssue2055; | ||
let (mut test_process, mut intproxy) = application | ||
.start_process_with_layer(dylib_path, Default::default(), None) | ||
.await; | ||
|
||
println!("Application started, waiting for `GetAddrInfoRequest`."); | ||
|
||
let msg = intproxy.recv().await; | ||
let ClientMessage::GetAddrInfoRequest(GetAddrInfoRequest { node }) = msg else { | ||
panic!("Invalid message received from layer: {msg:?}"); | ||
}; | ||
|
||
intproxy | ||
.send(DaemonMessage::GetAddrInfoResponse(GetAddrInfoResponse(Ok( | ||
DnsLookup(vec![LookupRecord { | ||
name: node, | ||
ip: "93.184.216.34".parse::<IpAddr>().unwrap(), | ||
}]), | ||
)))) | ||
.await; | ||
|
||
let msg = intproxy.recv().await; | ||
let ClientMessage::GetAddrInfoRequest(GetAddrInfoRequest { node: _ }) = msg else { | ||
panic!("Invalid message received from layer: {msg:?}"); | ||
}; | ||
|
||
intproxy | ||
.send(DaemonMessage::GetAddrInfoResponse(GetAddrInfoResponse( | ||
Err(ResponseError::DnsLookup(DnsLookupError { | ||
kind: NoRecordsFound(3), | ||
})), | ||
))) | ||
.await; | ||
|
||
test_process.wait_assert_success().await; | ||
test_process | ||
.assert_stdout_contains("test issue 2055: START") | ||
.await; | ||
test_process | ||
.assert_stdout_contains("test issue 2055: SUCCESS") | ||
.await; | ||
} |