Skip to content

Commit

Permalink
Remove dummy interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Apr 10, 2024
1 parent 29fbc73 commit 0f6dd8d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 68 deletions.
31 changes: 0 additions & 31 deletions test/test-manager/src/vm/network/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ pub const BRIDGE_NAME: &str = "br-mullvadtest";
/// TAP interface used by the guest
pub const TAP_NAME: &str = "tap-mullvadtest";

/// Pingable dummy LAN interface (name)
pub const DUMMY_LAN_INTERFACE_NAME: &str = "lan-mullvadtest";
/// Pingable dummy LAN interface (IP)
pub const DUMMY_LAN_INTERFACE_IP: Ipv4Addr = Ipv4Addr::new(172, 29, 1, 200);
/// Pingable dummy interface with public IP (name)
pub const DUMMY_INET_INTERFACE_NAME: &str = "net-mullvadtest";
/// Pingable dummy interface with public IP (IP)
pub const DUMMY_INET_INTERFACE_IP: Ipv4Addr = Ipv4Addr::new(1, 3, 3, 7);

// Private key of the wireguard remote peer on host.
const CUSTOM_TUN_REMOTE_PRIVKEY: &str = "gLvQuyqazziyf+pUCAFUgTnWIwn6fPE5MOReOqPEGHU=";
// Public key of the wireguard remote peer on host.
Expand Down Expand Up @@ -134,28 +125,6 @@ table ip mullvad_test_nat {{
))
.await?;

log::debug!("Set up pingable hosts");

run_ip_cmd(["link", "add", DUMMY_LAN_INTERFACE_NAME, "type", "dummy"]).await?;
run_ip_cmd([
"addr",
"add",
"dev",
DUMMY_LAN_INTERFACE_NAME,
&DUMMY_LAN_INTERFACE_IP.to_string(),
])
.await?;

run_ip_cmd(["link", "add", DUMMY_INET_INTERFACE_NAME, "type", "dummy"]).await?;
run_ip_cmd([
"addr",
"add",
"dev",
DUMMY_INET_INTERFACE_NAME,
&DUMMY_INET_INTERFACE_IP.to_string(),
])
.await?;

log::debug!("Create WireGuard peer");

create_local_wireguard_peer().await?;
Expand Down
35 changes: 0 additions & 35 deletions test/test-manager/src/vm/network/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ use anyhow::{anyhow, Context, Result};
use futures::future::{self, Either};
use tokio::{io::AsyncWriteExt, process::Command};

/// Pingable dummy LAN interface (IP)
pub const DUMMY_LAN_INTERFACE_IP: Ipv4Addr = Ipv4Addr::new(192, 168, 64, 254);

// Private key of the wireguard remote peer on host.
const CUSTOM_TUN_REMOTE_PRIVKEY: &str = "gLvQuyqazziyf+pUCAFUgTnWIwn6fPE5MOReOqPEGHU=";
// Public key of the wireguard remote peer on host.
Expand Down Expand Up @@ -50,41 +47,9 @@ pub async fn setup_test_network() -> Result<()> {
.await
.context("Failed to create WireGuard interface")?;

// A bit of trickery to detect when the bridge is available.
tokio::spawn(async move {
for _ in 0..30 {
let Ok(interface) = find_vm_bridge() else {
tokio::time::sleep(Duration::from_secs(1)).await;
continue;
};
match create_dummy_interface(interface).await {
Ok(_) => log::debug!("Created dummy interface"),
Err(error) => log::error!("Failed to create dummy interface: {error}"),
}
return;
}
log::error!("Failed to create dummy interface: timed out");
});

Ok(())
}

async fn create_dummy_interface(interface: String) -> Result<()> {
let mut cmd = Command::new("/usr/bin/sudo");
cmd.args([
"/sbin/ifconfig",
&interface,
"alias",
&DUMMY_LAN_INTERFACE_IP.to_string(),
]);
let output = cmd.output().await.context("Create dummy interface")?;
if output.status.success() {
Ok(())
} else {
Err(anyhow!("ifconfig failed: {:?}", output.status.code()))
}
}

/// 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.
Expand Down
3 changes: 1 addition & 2 deletions test/test-manager/src/vm/network/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ pub use macos as platform;
pub use platform::{
CUSTOM_TUN_GATEWAY, CUSTOM_TUN_INTERFACE_NAME, CUSTOM_TUN_LOCAL_PRIVKEY,
CUSTOM_TUN_LOCAL_TUN_ADDR, CUSTOM_TUN_REMOTE_PUBKEY, CUSTOM_TUN_REMOTE_REAL_ADDR,
CUSTOM_TUN_REMOTE_REAL_PORT, CUSTOM_TUN_REMOTE_TUN_ADDR, DUMMY_LAN_INTERFACE_IP,
NON_TUN_GATEWAY,
CUSTOM_TUN_REMOTE_REAL_PORT, CUSTOM_TUN_REMOTE_TUN_ADDR, NON_TUN_GATEWAY,
};

/// Port on NON_TUN_GATEWAY that hosts a SOCKS5 server
Expand Down

0 comments on commit 0f6dd8d

Please sign in to comment.