summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-09-10 15:03:44 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-09-10 15:39:57 +0000
commit510163fb57f89818a666a5ea5b762860fa41fc3e (patch)
tree31069a5bef5387781b46c99065ecf3304247e0e9
parent3dca23fb570294b0d83464826de5feca0e6f33f9 (diff)
downloadmullvadvpn-510163fb57f89818a666a5ea5b762860fa41fc3e.tar.xz
mullvadvpn-510163fb57f89818a666a5ea5b762860fa41fc3e.zip
Add `create_tun_if_closed` method to `TunProvider`
-rw-r--r--mullvad-jni/src/vpn_service_tun_provider.rs9
-rw-r--r--talpid-core/src/tunnel/tun_provider/mod.rs4
-rw-r--r--talpid-core/src/tunnel/tun_provider/stub.rs5
3 files changed, 18 insertions, 0 deletions
diff --git a/mullvad-jni/src/vpn_service_tun_provider.rs b/mullvad-jni/src/vpn_service_tun_provider.rs
index afb9ca8970..152f3caea9 100644
--- a/mullvad-jni/src/vpn_service_tun_provider.rs
+++ b/mullvad-jni/src/vpn_service_tun_provider.rs
@@ -160,6 +160,15 @@ impl TunProvider for VpnServiceTunProvider {
}))
}
+ fn create_tun_if_closed(&mut self) -> Result<(), BoxedError> {
+ if self.active_tun.is_none() {
+ self.prepare_tun(self.last_tun_config.clone())
+ .map_err(BoxedError::new)?;
+ }
+
+ Ok(())
+ }
+
fn close_tun(&mut self) {
self.active_tun = None;
}
diff --git a/talpid-core/src/tunnel/tun_provider/mod.rs b/talpid-core/src/tunnel/tun_provider/mod.rs
index d11f245626..3cac459c51 100644
--- a/talpid-core/src/tunnel/tun_provider/mod.rs
+++ b/talpid-core/src/tunnel/tun_provider/mod.rs
@@ -52,6 +52,10 @@ pub trait TunProvider: Send + 'static {
/// Retrieve a tunnel device with the provided configuration.
fn get_tun(&mut self, config: TunConfig) -> Result<Box<dyn Tun>, BoxedError>;
+ /// Open a tunnel device using the previous or the default configuration.
+ #[cfg(target_os = "android")]
+ fn create_tun_if_closed(&mut self) -> Result<(), BoxedError>;
+
/// Close currently active tunnel device.
#[cfg(target_os = "android")]
fn close_tun(&mut self);
diff --git a/talpid-core/src/tunnel/tun_provider/stub.rs b/talpid-core/src/tunnel/tun_provider/stub.rs
index 055bb8156e..be985c8045 100644
--- a/talpid-core/src/tunnel/tun_provider/stub.rs
+++ b/talpid-core/src/tunnel/tun_provider/stub.rs
@@ -16,6 +16,11 @@ impl TunProvider for StubTunProvider {
}
#[cfg(target_os = "android")]
+ fn create_tun_if_closed(&mut self) -> Result<(), BoxedError> {
+ unimplemented!();
+ }
+
+ #[cfg(target_os = "android")]
fn close_tun(&mut self) {
unimplemented!();
}