Skip to content

Commit

Permalink
Use bridge interface IP from tart
Browse files Browse the repository at this point in the history
  • Loading branch information
Serock3 committed Jan 8, 2025
1 parent a4bd7cc commit 621042c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion test/test-manager/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ async fn main() -> Result<()> {
.await
.context("Failed to run provisioning for VM")?;

let bridge_ip = instance.get_ip().to_owned();
TEST_CONFIG.init(tests::config::TestConfig::new(
account,
artifacts_dir,
Expand All @@ -311,7 +312,11 @@ async fn main() -> Result<()> {
.gui_package_path
.map(|path| path.file_name().unwrap().to_string_lossy().into_owned()),
mullvad_host,
vm::network::bridge()?,
vm::network::bridge(
#[cfg(target_os = "macos")]
&bridge_ip,
)?,
bridge_ip,
test_rpc::meta::Os::from(vm_config.os_type),
openvpn_certificate,
));
Expand Down
5 changes: 4 additions & 1 deletion test/test-manager/src/tests/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::net::IpAddr;
use std::sync::OnceLock;
use std::{ops::Deref, path::Path};
use test_rpc::meta::Os;
Expand Down Expand Up @@ -35,7 +36,7 @@ pub struct TestConfig {
pub mullvad_host: String,

pub host_bridge_name: String,

pub host_bridge_ip: IpAddr,
pub os: Os,
/// The OpenVPN CA certificate to use with the the installed Mullvad App.
pub openvpn_certificate: OpenVPNCertificate,
Expand All @@ -52,6 +53,7 @@ impl TestConfig {
ui_e2e_tests_filename: Option<String>,
mullvad_host: String,
host_bridge_name: String,
host_bridge_ip: IpAddr,
os: Os,
openvpn_certificate: OpenVPNCertificate,
) -> Self {
Expand All @@ -63,6 +65,7 @@ impl TestConfig {
ui_e2e_tests_filename,
mullvad_host,
host_bridge_name,
host_bridge_ip,
os,
openvpn_certificate,
}
Expand Down
6 changes: 3 additions & 3 deletions test/test-manager/src/vm/network/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ pub async fn setup_test_network() -> Result<()> {
/// A hack to find the Tart bridge interface using `NON_TUN_GATEWAY`.
/// It should be possible to retrieve this using the virtualization framework instead,
/// but that requires an entitlement.
pub(crate) fn find_vm_bridge() -> Result<String> {
pub(crate) fn find_vm_bridge(bridge_ip: &IpAddr) -> Result<String> {
for addr in nix::ifaddrs::getifaddrs().unwrap() {
if !addr.interface_name.starts_with("bridge") {
continue;
}
if let Some(address) = addr.address.as_ref().and_then(|addr| addr.as_sockaddr_in()) {
let interface_ip = *SocketAddrV4::from(*address).ip();
if interface_ip == NON_TUN_GATEWAY {
let interface_ip = SocketAddrV4::from(*address).ip();
if interface_ip == bridge_ip {
return Ok(addr.interface_name.to_owned());
}
}
Expand Down
7 changes: 5 additions & 2 deletions test/test-manager/src/vm/network/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// #[cfg(target_os = "linux")]
pub mod linux;
#[cfg(target_os = "macos")]
use std::net::IpAddr;

#[cfg(target_os = "linux")]
pub use linux as platform;

Expand All @@ -19,10 +22,10 @@ pub use platform::{
pub const SOCKS5_PORT: u16 = 54321;

/// Get the name of the bridge interface between the test-manager and the test-runner.
pub fn bridge() -> anyhow::Result<String> {
pub fn bridge(#[cfg(target_os = "macos")] bridge_ip: &IpAddr) -> anyhow::Result<String> {
#[cfg(target_os = "macos")]
{
crate::vm::network::macos::find_vm_bridge()
crate::vm::network::macos::find_vm_bridge(bridge_ip)
}
#[cfg(not(target_os = "macos"))]
Ok(platform::BRIDGE_NAME.to_owned())
Expand Down

0 comments on commit 621042c

Please sign in to comment.