diff options
| author | David Lönnhager <david.l@mullvad.net> | 2021-02-01 18:25:26 +0100 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2021-02-02 13:09:23 +0100 |
| commit | 9a700fffa07eccccc4fe5400a7e74f68f434038e (patch) | |
| tree | 7eaf65c065d2f487481130cb38ff3bb5fb410587 /talpid-core | |
| parent | 0258346401f1512fd1bc6007a64d5a369de0ae49 (diff) | |
| download | mullvadvpn-9a700fffa07eccccc4fe5400a7e74f68f434038e.tar.xz mullvadvpn-9a700fffa07eccccc4fe5400a7e74f68f434038e.zip | |
Only unload wintun.dll when the daemon exits
Diffstat (limited to 'talpid-core')
| -rw-r--r-- | talpid-core/src/tunnel/openvpn/mod.rs | 20 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/openvpn/windows.rs | 1 |
2 files changed, 18 insertions, 3 deletions
diff --git a/talpid-core/src/tunnel/openvpn/mod.rs b/talpid-core/src/tunnel/openvpn/mod.rs index fd186026d4..38a1d26d22 100644 --- a/talpid-core/src/tunnel/openvpn/mod.rs +++ b/talpid-core/src/tunnel/openvpn/mod.rs @@ -30,7 +30,7 @@ use std::{ #[cfg(target_os = "linux")] use std::{collections::HashSet, net::IpAddr}; #[cfg(windows)] -use std::{ffi::OsStr, os::windows::ffi::OsStrExt, time::Instant}; +use std::{ffi::OsStr, os::windows::ffi::OsStrExt, sync::Mutex, time::Instant}; use talpid_types::net::openvpn; #[cfg(any(windows, target_os = "linux"))] use talpid_types::ErrorExt; @@ -60,12 +60,27 @@ mod windows; #[cfg(windows)] lazy_static! { + static ref WINTUN_DLL: Mutex<Option<Arc<windows::WintunDll>>> = Mutex::new(None); static ref ADAPTER_ALIAS: U16CString = U16CString::from_str("Mullvad").unwrap(); static ref ADAPTER_POOL: U16CString = U16CString::from_str("Mullvad").unwrap(); static ref ADAPTER_GUID_STR: String = windows::string_from_guid(&ADAPTER_GUID); } #[cfg(windows)] +fn get_wintun_dll(resource_dir: &Path) -> Result<Arc<windows::WintunDll>> { + let mut dll = (*WINTUN_DLL).lock().expect("Wintun mutex poisoned"); + match &*dll { + Some(dll) => Ok(dll.clone()), + None => { + let new_dll = + Arc::new(windows::WintunDll::new(resource_dir).map_err(Error::WintunDllError)?); + *dll = Some(new_dll.clone()); + Ok(new_dll) + } + } +} + +#[cfg(windows)] const ADAPTER_GUID: GUID = GUID { Data1: 0xAFE43773, Data2: 0xE1F8, @@ -347,8 +362,7 @@ impl OpenVpnMonitor<OpenVpnCommand> { #[cfg(windows)] let wintun_adapter = { - let dll = - Arc::new(windows::WintunDll::new(resource_dir).map_err(Error::WintunDllError)?); + let dll = get_wintun_dll(resource_dir)?; { match windows::WintunAdapter::open(dll.clone(), &*ADAPTER_ALIAS, &*ADAPTER_POOL) { diff --git a/talpid-core/src/tunnel/openvpn/windows.rs b/talpid-core/src/tunnel/openvpn/windows.rs index 1c691794e0..f87efc3967 100644 --- a/talpid-core/src/tunnel/openvpn/windows.rs +++ b/talpid-core/src/tunnel/openvpn/windows.rs @@ -50,6 +50,7 @@ pub struct WintunDll { func_delete: WintunDeleteAdapterFn, } +unsafe impl Send for WintunDll {} unsafe impl Sync for WintunDll {} type RebootRequired = bool; |
