Skip to content

Commit

Permalink
Merge pull request #188 from NordSecurity/LLT-4409-fix
Browse files Browse the repository at this point in the history
When disabling meshnet, don't wait for wg listen port
  • Loading branch information
tomaszklak authored Oct 26, 2023
2 parents d918bff + 17d8b93 commit c9e20e0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<br>

Expand Down
51 changes: 46 additions & 5 deletions src/device/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(),
Expand Down Expand Up @@ -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());
}
}

0 comments on commit c9e20e0

Please sign in to comment.