From 17d8b93c4d47daa67965d13d0153b50b6da98e4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20K=C5=82ak?= Date: Wed, 25 Oct 2023 13:35:48 +0200 Subject: [PATCH] When disabling meshnet, don't wait for wg listen port Before this change, failing call to wait_for_listen_port could make the disabling of meshnet (set_config with None) fail. There is no reason for that so the call to wait_for_listen_port is moved to the part executed only when the meshnet is enabled. --- changelog.md | 1 + src/device/mod.rs | 51 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 85929df9e..2c440c7a9 100644 --- a/changelog.md +++ b/changelog.md @@ -36,6 +36,7 @@ * LLT-4286: Add icmp error packet handling to firewall * LLT-4432: Use forked system-configuration crate to prevent iOS linking errors * LLT-3951: IPv6 analytics. +* LLT-4409: Wait for listen port only if meshnet is enabled
diff --git a/src/device/mod.rs b/src/device/mod.rs index a77e6b5b0..7c9ab9a17 100644 --- a/src/device/mod.rs +++ b/src/device/mod.rs @@ -1212,11 +1212,6 @@ impl Runtime { self.requested_state.meshnet_config = config.clone(); let wg_itf = self.entities.wireguard_interface.get_interface().await?; - let wg_port = self - .entities - .wireguard_interface - .wait_for_listen_port(Duration::from_secs(1)) - .await?; let secret_key = if let Some(secret_key) = wg_itf.private_key { secret_key } else { @@ -1232,6 +1227,12 @@ impl Runtime { // Update for proxy and derp config if let Some(config) = config { + let wg_port = self + .entities + .wireguard_interface + .wait_for_listen_port(Duration::from_secs(1)) + .await?; + let proxy_config = ProxyConfig { wg_port: Some(wg_port), peers: peers.clone(), @@ -2328,4 +2329,44 @@ mod tests { Error::BadPublicKey )); } + + #[cfg(not(windows))] + #[tokio::test(start_paused = true)] + async fn test_disabling_meshnet_will_not_fail_if_wg_has_not_listen_port() { + let sender = tokio::sync::broadcast::channel(1).0; + + let pk = SecretKey::gen(); + let mut rt = Runtime::start( + sender, + &DeviceConfig { + private_key: pk, + ..Default::default() + }, + Default::default(), + None, + ) + .await + .unwrap(); + + rt.test_env + .adapter + .lock() + .await + .expect_send_uapi_cmd() + .returning(|_| { + Ok(uapi::Response { + errno: 0, + interface: Some(Interface::default()), + }) + }); + assert!(rt + .entities + .wireguard_interface + .wait_for_listen_port(Duration::from_secs(1)) + .await + .is_err()); + + assert!(rt.set_private_key(&pk).await.is_ok()); + assert!(rt.set_config(&None).await.is_ok()); + } }