diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-09-22 11:41:38 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-09-23 12:45:22 +0200 |
| commit | eaffbee181f2180ba3607fe85af9ca6c338d4bba (patch) | |
| tree | 6876ab824e6805d13b76c710caf9ab062599dbd8 /talpid-core | |
| parent | 4c78b71821233da8cbe9de9f877ad2eb097abea4 (diff) | |
| download | mullvadvpn-eaffbee181f2180ba3607fe85af9ca6c338d4bba.tar.xz mullvadvpn-eaffbee181f2180ba3607fe85af9ca6c338d4bba.zip | |
Wait for SetTunnelLink to finish
Diffstat (limited to 'talpid-core')
| -rw-r--r-- | talpid-core/src/routing/linux.rs | 3 | ||||
| -rw-r--r-- | talpid-core/src/routing/unix.rs | 16 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/openvpn.rs | 8 |
3 files changed, 22 insertions, 5 deletions
diff --git a/talpid-core/src/routing/linux.rs b/talpid-core/src/routing/linux.rs index 328ce161f2..bd7fd0c33d 100644 --- a/talpid-core/src/routing/linux.rs +++ b/talpid-core/src/routing/linux.rs @@ -633,12 +633,13 @@ impl RouteManagerImpl { RouteManagerCommand::DisableExclusionsRoutes => { self.disable_exclusions_routes().await; } - RouteManagerCommand::SetTunnelLink(interface_name) => { + RouteManagerCommand::SetTunnelLink(interface_name, result_tx) => { log::debug!( "Exclusions: Ignoring route changes for dev {}", &interface_name ); self.split_ignored_interface = Some(interface_name); + let _ = result_tx.send(()); } RouteManagerCommand::RouteExclusionsDns(tunnel_alias, dns_servers, result_rx) => { let _ = diff --git a/talpid-core/src/routing/unix.rs b/talpid-core/src/routing/unix.rs index 433f2d8efa..c766fbfbe8 100644 --- a/talpid-core/src/routing/unix.rs +++ b/talpid-core/src/routing/unix.rs @@ -67,7 +67,7 @@ pub enum RouteManagerCommand { DisableExclusionsRoutes, /// Adds link to ignore in the exclusions table. #[cfg(target_os = "linux")] - SetTunnelLink(String), + SetTunnelLink(String, oneshot::Sender<()>), /// Adds exclusions table route for sending DNS requests via the tunnel. #[cfg(target_os = "linux")] RouteExclusionsDns( @@ -208,13 +208,23 @@ impl RouteManager { #[cfg(target_os = "linux")] pub fn set_tunnel_link(&mut self, tunnel_alias: &str) -> Result<(), Error> { if let Some(tx) = &self.manage_tx { + let (result_tx, result_rx) = oneshot::channel(); if tx - .unbounded_send(RouteManagerCommand::SetTunnelLink(tunnel_alias.to_string())) + .unbounded_send(RouteManagerCommand::SetTunnelLink( + tunnel_alias.to_string(), + result_tx, + )) .is_err() { return Err(Error::RouteManagerDown); } - Ok(()) + match self.runtime.block_on(result_rx) { + Ok(()) => Ok(()), + Err(error) => { + log::trace!("{}", error.display_chain_with_msg("channel is closed")); + Ok(()) + } + } } else { Err(Error::RouteManagerDown) } diff --git a/talpid-core/src/tunnel/openvpn.rs b/talpid-core/src/tunnel/openvpn.rs index df39a9d5df..8730eadeeb 100644 --- a/talpid-core/src/tunnel/openvpn.rs +++ b/talpid-core/src/tunnel/openvpn.rs @@ -8,6 +8,8 @@ use crate::{ proxy::{self, ProxyMonitor, ProxyResourceData}, routing, }; +#[cfg(target_os = "linux")] +use futures::channel::oneshot; use std::{ collections::HashMap, fs, @@ -175,10 +177,14 @@ impl OpenVpnMonitor<OpenVpnCommand> { let on_openvpn_event = move |event, env: HashMap<String, String>| { #[cfg(target_os = "linux")] if event == openvpn_plugin::EventType::Up { + let (tx, rx) = oneshot::channel(); let interface = env.get("dev").unwrap().to_owned(); route_manager_tx - .unbounded_send(routing::RouteManagerCommand::SetTunnelLink(interface)) + .unbounded_send(routing::RouteManagerCommand::SetTunnelLink(interface, tx)) .unwrap(); + tokio::task::block_in_place(move || { + futures::executor::block_on(rx).unwrap(); + }); return; } if event == openvpn_plugin::EventType::RouteUp { |
