diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-04-03 13:50:50 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-04-03 13:50:50 -0300 |
| commit | 5ea3c63fb2c174502bc0dfff96e655b499286474 (patch) | |
| tree | a2ba50128845d202664f62d1dd298d9bc3770ee0 | |
| parent | 5d5392d39cc00696cd42c547587bbd7d767dd1c9 (diff) | |
| parent | 7bfa99d4106b28d46506081c4690d76292920f54 (diff) | |
| download | mullvadvpn-5ea3c63fb2c174502bc0dfff96e655b499286474.tar.xz mullvadvpn-5ea3c63fb2c174502bc0dfff96e655b499286474.zip | |
Merge branch 'compile-for-android'
| -rw-r--r-- | README.md | 7 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 2 | ||||
| -rw-r--r-- | mullvad-paths/src/cache.rs | 24 | ||||
| -rw-r--r-- | mullvad-paths/src/lib.rs | 4 | ||||
| -rw-r--r-- | mullvad-paths/src/logs.rs | 19 | ||||
| -rw-r--r-- | mullvad-paths/src/resources.rs | 29 | ||||
| -rw-r--r-- | mullvad-paths/src/rpc_socket.rs | 6 | ||||
| -rw-r--r-- | mullvad-paths/src/settings.rs | 19 | ||||
| -rw-r--r-- | mullvad-problem-report/src/metadata.rs | 21 | ||||
| -rw-r--r-- | mullvad-tests/src/bin/mock_openvpn.rs | 124 | ||||
| -rw-r--r-- | mullvad-tests/src/lib.rs | 2 | ||||
| -rw-r--r-- | talpid-core/Cargo.toml | 3 | ||||
| -rw-r--r-- | talpid-core/src/dns/android.rs | 24 | ||||
| -rw-r--r-- | talpid-core/src/dns/mod.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/firewall/android.rs | 25 | ||||
| -rw-r--r-- | talpid-core/src/firewall/mod.rs | 5 | ||||
| -rw-r--r-- | talpid-core/src/lib.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/offline/dummy.rs | 2 | ||||
| -rw-r--r-- | talpid-core/src/routing/android.rs | 32 | ||||
| -rw-r--r-- | talpid-core/src/routing/mod.rs | 5 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 24 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/openvpn.rs | 2 |
22 files changed, 279 insertions, 106 deletions
@@ -341,7 +341,8 @@ The settings directory can be changed by setting the `MULLVAD_SETTINGS_DIR` envi |----------|------| | Linux | `/etc/mullvad-vpn/` | | macOS | `/etc/mullvad-vpn/` | -| Windows | `%LOCALAPPDATA%\Mullvad VPN\` +| Windows | `%LOCALAPPDATA%\Mullvad VPN\` | +| Android | `/data/data/net.mullvad.mullvadvpn/` | #### Logs @@ -352,6 +353,7 @@ The log directory can be changed by setting the `MULLVAD_LOG_DIR` environment va | Linux | `/var/log/mullvad-vpn/` + systemd | | macOS | `/var/log/mullvad-vpn/` | | Windows | `C:\ProgramData\Mullvad VPN\` | +| Android | `/data/data/net.mullvad.mullvadvpn/` | #### Cache @@ -362,6 +364,7 @@ The cache directory can be changed by setting the `MULLVAD_CACHE_DIR` environmen | Linux | `/var/cache/mullvad-vpn/` | | macOS | `/var/root/Library/Caches/mullvad-vpn/` | | Windows | `%LOCALAPPDATA%\Mullvad VPN\` | +| Android | `/data/data/net.mullvad.mullvadvpn/cache` | #### RPC address file @@ -373,6 +376,7 @@ environment variable. | Linux | `/var/run/mullvad-vpn` | | macOS | `/var/run/mullvad-vpn` | | Windows | `//./pipe/Mullvad VPN` | +| Android | `/data/data/net.mullvad.mullvadvpn/rpc-socket` | ### GUI @@ -384,6 +388,7 @@ The GUI has a specific settings file that is configured for each user. The path | Linux | `$XDG_CONFIG_HOME/Mullvad VPN/gui_settings.json` | | macOS | `~/Library/Application Support/Mullvad VPN/gui_settings.json` | | Windows | `%LOCALAPPDATA%\Mullvad VPN\gui_settings.json` | +| Android | Present in Android's `logcat` | ## Audits, pentests and external security reviews diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 37b69e2a13..96ebae7ff9 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -645,6 +645,8 @@ impl Daemon { const PLATFORM: &str = "macos"; #[cfg(target_os = "windows")] const PLATFORM: &str = "windows"; + #[cfg(target_os = "android")] + const PLATFORM: &str = "android"; let fut = self .version_proxy diff --git a/mullvad-paths/src/cache.rs b/mullvad-paths/src/cache.rs index dd4307572c..50f11167f2 100644 --- a/mullvad-paths/src/cache.rs +++ b/mullvad-paths/src/cache.rs @@ -1,5 +1,8 @@ use crate::Result; -use std::{env, path::PathBuf}; +use std::{ + env, + path::{Path, PathBuf}, +}; /// Creates and returns the cache directory pointed to by `MULLVAD_CACHE_DIR`, or the default /// one if that variable is unset. @@ -15,14 +18,21 @@ fn get_cache_dir() -> Result<PathBuf> { } pub fn get_default_cache_dir() -> Result<PathBuf> { - let dir; - #[cfg(target_os = "linux")] + #[cfg(not(target_os = "android"))] { - dir = Ok(PathBuf::from("/var/cache")) + let dir; + #[cfg(target_os = "linux")] + { + dir = Ok(PathBuf::from("/var/cache")) + } + #[cfg(any(target_os = "macos", windows))] + { + dir = dirs::cache_dir().ok_or_else(|| crate::Error::FindDirError) + } + dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } - #[cfg(any(target_os = "macos", windows))] + #[cfg(target_os = "android")] { - dir = dirs::cache_dir().ok_or(crate::Error::FindDirError) + Ok(Path::new(crate::APP_PATH).join("cache")) } - dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } diff --git a/mullvad-paths/src/lib.rs b/mullvad-paths/src/lib.rs index 1d829e1145..863119a261 100644 --- a/mullvad-paths/src/lib.rs +++ b/mullvad-paths/src/lib.rs @@ -19,12 +19,14 @@ pub enum Error { NoProgramDataDir, } -#[cfg(unix)] +#[cfg(any(target_os = "linux", target_os = "macos"))] const PRODUCT_NAME: &str = "mullvad-vpn"; #[cfg(windows)] const PRODUCT_NAME: &str = "Mullvad VPN"; +#[cfg(target_os = "android")] +const APP_PATH: &str = "/data/data/net.mullvad.mullvadvpn"; #[cfg(windows)] fn get_allusersprofile_dir() -> Result<PathBuf> { diff --git a/mullvad-paths/src/logs.rs b/mullvad-paths/src/logs.rs index 48c0ff1f2c..91f229f489 100644 --- a/mullvad-paths/src/logs.rs +++ b/mullvad-paths/src/logs.rs @@ -23,14 +23,21 @@ pub fn get_log_dir() -> Result<PathBuf> { } pub fn get_default_log_dir() -> Result<PathBuf> { - let dir; - #[cfg(unix)] + #[cfg(not(target_os = "android"))] { - dir = Ok(PathBuf::from("/var/log")); + let dir; + #[cfg(unix)] + { + dir = Ok(PathBuf::from("/var/log")); + } + #[cfg(windows)] + { + dir = crate::get_allusersprofile_dir(); + } + dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } - #[cfg(windows)] + #[cfg(target_os = "android")] { - dir = crate::get_allusersprofile_dir(); + Ok(PathBuf::from(crate::APP_PATH)) } - dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } diff --git a/mullvad-paths/src/resources.rs b/mullvad-paths/src/resources.rs index 6b8e1383af..2ae2e5e2b6 100644 --- a/mullvad-paths/src/resources.rs +++ b/mullvad-paths/src/resources.rs @@ -10,19 +10,26 @@ pub fn get_resource_dir() -> PathBuf { } pub fn get_default_resource_dir() -> PathBuf { - match env::current_exe() { - Ok(mut path) => { - path.pop(); - path - } - Err(e) => { - log::error!( - "Failed finding the install directory. Using working directory: {}", - e - ); - PathBuf::from(".") + #[cfg(not(target_os = "android"))] + { + match env::current_exe() { + Ok(mut path) => { + path.pop(); + path + } + Err(e) => { + log::error!( + "Failed finding the install directory. Using working directory: {}", + e + ); + PathBuf::from(".") + } } } + #[cfg(target_os = "android")] + { + PathBuf::from(crate::APP_PATH) + } } pub fn get_api_ca_path() -> PathBuf { diff --git a/mullvad-paths/src/rpc_socket.rs b/mullvad-paths/src/rpc_socket.rs index 50765cf7ee..1398db93d2 100644 --- a/mullvad-paths/src/rpc_socket.rs +++ b/mullvad-paths/src/rpc_socket.rs @@ -8,7 +8,7 @@ pub fn get_rpc_socket_path() -> PathBuf { } pub fn get_default_rpc_socket_path() -> PathBuf { - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] { PathBuf::from("/var/run/mullvad-vpn") } @@ -16,4 +16,8 @@ pub fn get_default_rpc_socket_path() -> PathBuf { { PathBuf::from("//./pipe/Mullvad VPN") } + #[cfg(target_os = "android")] + { + PathBuf::from(format!("{}/rpc-socket", crate::APP_PATH)) + } } diff --git a/mullvad-paths/src/settings.rs b/mullvad-paths/src/settings.rs index 0645a38a6e..8eff863677 100644 --- a/mullvad-paths/src/settings.rs +++ b/mullvad-paths/src/settings.rs @@ -15,14 +15,21 @@ fn get_settings_dir() -> Result<PathBuf> { } pub fn get_default_settings_dir() -> Result<PathBuf> { - let dir; - #[cfg(unix)] + #[cfg(not(target_os = "android"))] { - dir = Ok(PathBuf::from("/etc")); + let dir; + #[cfg(unix)] + { + dir = Ok(PathBuf::from("/etc")); + } + #[cfg(windows)] + { + dir = dirs::data_local_dir().ok_or_else(|| crate::Error::FindDirError); + } + dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } - #[cfg(windows)] + #[cfg(target_os = "android")] { - dir = dirs::data_local_dir().ok_or(crate::Error::FindDirError); + Ok(PathBuf::from(crate::APP_PATH)) } - dir.map(|dir| dir.join(crate::PRODUCT_NAME)) } diff --git a/mullvad-problem-report/src/metadata.rs b/mullvad-problem-report/src/metadata.rs index d45c344c83..8153e7671f 100644 --- a/mullvad-problem-report/src/metadata.rs +++ b/mullvad-problem-report/src/metadata.rs @@ -109,6 +109,27 @@ mod os { } } +#[cfg(target_os = "android")] +mod os { + pub fn version() -> String { + let manufacturer = get_prop("ro.product.manufacturer").unwrap_or_else(String::new); + let product = get_prop("ro.product.model").unwrap_or_else(String::new); + let build = get_prop("ro.build.display.id").unwrap_or_else(String::new); + let api_level = get_prop("ro.build.version.sdk") + .map(|api| format!("(API level: {})", api)) + .unwrap_or_else(String::new); + + format!( + "Android {} {} {} {}", + manufacturer, product, build, api_level + ) + } + + fn get_prop(property: &str) -> Option<String> { + super::command_stdout_lossy("getprop", &[property]) + } +} + /// Helper for getting stdout of some command as a String. Ignores the exit code of the command. fn command_stdout_lossy(cmd: &str, args: &[&str]) -> Option<String> { Command::new(cmd) diff --git a/mullvad-tests/src/bin/mock_openvpn.rs b/mullvad-tests/src/bin/mock_openvpn.rs index 042065d3be..03d38a4a09 100644 --- a/mullvad-tests/src/bin/mock_openvpn.rs +++ b/mullvad-tests/src/bin/mock_openvpn.rs @@ -1,70 +1,84 @@ -use mullvad_tests::{watch_event, PathWatcher}; -use std::{ - env, - fs::{self, File}, - io::{self, Read, Write}, - path::PathBuf, - sync::mpsc, - thread, - time::Duration, -}; +use crate::mock_openvpn::run; +fn main() { + run(); +} -const MAX_EVENT_TIME: Duration = Duration::from_secs(60); +#[cfg(target_os = "android")] +mod mock_openvpn { + pub fn run() {} +} -fn main() { - let (file, path) = create_args_file(); - let (finished_tx, finished_rx) = mpsc::channel(); - let watcher = PathWatcher::watch(&path).expect("Failed to watch file for events"); +#[cfg(not(target_os = "android"))] +mod mock_openvpn { + use mullvad_tests::{watch_event, PathWatcher}; + use std::{ + env, + fs::{self, File}, + io::{self, Read, Write}, + path::PathBuf, + sync::mpsc, + thread, + time::Duration, + }; - write_command_line(file); + const MAX_EVENT_TIME: Duration = Duration::from_secs(60); - wait_thread(wait_for_stdin_to_be_closed, finished_tx.clone()); - wait_thread( - move || wait_for_file_to_be_deleted(watcher, MAX_EVENT_TIME), - finished_tx, - ); + pub fn run() { + let (file, path) = create_args_file(); + let (finished_tx, finished_rx) = mpsc::channel(); + let watcher = PathWatcher::watch(&path).expect("Failed to watch file for events"); - let _ = finished_rx.recv(); - let _ = fs::remove_file(path); -} + write_command_line(file); -fn create_args_file() -> (File, PathBuf) { - let path = PathBuf::from( - env::var_os("MOCK_OPENVPN_ARGS_FILE").expect("Missing mock OpenVPN arguments file path"), - ); - let file = File::create(&path).expect("Failed to create mock OpenVPN arguments file"); + wait_thread(wait_for_stdin_to_be_closed, finished_tx.clone()); + wait_thread( + move || wait_for_file_to_be_deleted(watcher, MAX_EVENT_TIME), + finished_tx, + ); - (file, path) -} + let _ = finished_rx.recv(); + let _ = fs::remove_file(path); + } -fn write_command_line(mut file: File) { - for argument in env::args() { - let escaped_argument = argument - .replace("\\", "\\\\") - .replace("\n", "\\n") - .replace("\r", "\\r"); + fn create_args_file() -> (File, PathBuf) { + let path = PathBuf::from( + env::var_os("MOCK_OPENVPN_ARGS_FILE") + .expect("Missing mock OpenVPN arguments file path"), + ); + let file = File::create(&path).expect("Failed to create mock OpenVPN arguments file"); - writeln!(file, "{}", escaped_argument).expect("Failed to write argument to file"); + (file, path) } -} -fn wait_thread<F>(function: F, finished_tx: mpsc::Sender<()>) -where - F: FnOnce() + Send + 'static, -{ - thread::spawn(move || { - function(); - let _ = finished_tx.send(()); - }); -} + fn write_command_line(mut file: File) { + for argument in env::args() { + let escaped_argument = argument + .replace("\\", "\\\\") + .replace("\n", "\\n") + .replace("\r", "\\r"); -fn wait_for_stdin_to_be_closed() { - let _ignore_bytes = io::stdin().bytes().last(); -} + writeln!(file, "{}", escaped_argument).expect("Failed to write argument to file"); + } + } + + fn wait_thread<F>(function: F, finished_tx: mpsc::Sender<()>) + where + F: FnOnce() + Send + 'static, + { + thread::spawn(move || { + function(); + let _ = finished_tx.send(()); + }); + } + + fn wait_for_stdin_to_be_closed() { + let _ignore_bytes = io::stdin().bytes().last(); + } -fn wait_for_file_to_be_deleted(mut watcher: PathWatcher, timeout: Duration) { - let _ignore_event = watcher - .set_timeout(timeout) - .find(|&event| event == watch_event::REMOVE); + fn wait_for_file_to_be_deleted(mut watcher: PathWatcher, timeout: Duration) { + let _ignore_event = watcher + .set_timeout(timeout) + .find(|&event| event == watch_event::REMOVE); + } } diff --git a/mullvad-tests/src/lib.rs b/mullvad-tests/src/lib.rs index 243b0e3d99..fccb1354ca 100644 --- a/mullvad-tests/src/lib.rs +++ b/mullvad-tests/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_os = "android"))] + use self::{mock_openvpn::MOCK_OPENVPN_ARGS_FILE, platform_specific::*}; use futures::sync::oneshot; use jsonrpc_client_core::{Future, Transport}; diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 5d577d1c46..b27c509fcb 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -32,7 +32,6 @@ uuid = { version = "0.7", features = ["v4"] } hex = "0.3" ipnetwork = "0.14" lazy_static = "1.0" -tun = { git = "https://github.com/pinkisemils/rust-tun", branch = "add-raw-fd-traits" } nix = "0.13" @@ -48,12 +47,14 @@ nftnl = { git = "https://github.com/mullvad/nftnl-rs", rev = "29651f4370fdf22cc2 mnl = { git = "https://github.com/mullvad/mnl-rs", rev = "f0d19501b9b85be9a1ffaec8317a378bcbdf4fa6", features = ["mnl-1-0-4"] } which = "2.0" err-derive = "0.1.5" +tun = { git = "https://github.com/pinkisemils/rust-tun", branch = "add-raw-fd-traits" } [target.'cfg(target_os = "macos")'.dependencies] # TODO: Specify 0.2.1 once the crate gets published pfctl = { git = "https://github.com/mullvad/pfctl-rs", rev = "9f31b5ddcab941862470075eab83bb398195f3d6" } system-configuration = "0.2" +tun = { git = "https://github.com/pinkisemils/rust-tun", branch = "add-raw-fd-traits" } [target.'cfg(windows)'.dependencies] diff --git a/talpid-core/src/dns/android.rs b/talpid-core/src/dns/android.rs new file mode 100644 index 0000000000..032960ae1e --- /dev/null +++ b/talpid-core/src/dns/android.rs @@ -0,0 +1,24 @@ +use std::{net::IpAddr, path::Path}; + +/// Stub error type for DNS errors on Android. +#[derive(Debug, err_derive::Error)] +#[error(display = "Unknown Android DNS error")] +pub struct Error; + +pub struct DnsMonitor; + +impl super::DnsMonitorT for DnsMonitor { + type Error = Error; + + fn new(_cache_dir: impl AsRef<Path>) -> Result<Self, Self::Error> { + Ok(DnsMonitor) + } + + fn set(&mut self, _interface: &str, _servers: &[IpAddr]) -> Result<(), Self::Error> { + Ok(()) + } + + fn reset(&mut self) -> Result<(), Self::Error> { + Ok(()) + } +} diff --git a/talpid-core/src/dns/mod.rs b/talpid-core/src/dns/mod.rs index 5353167ea9..138caac58a 100644 --- a/talpid-core/src/dns/mod.rs +++ b/talpid-core/src/dns/mod.rs @@ -12,6 +12,10 @@ mod imp; #[path = "windows/mod.rs"] mod imp; +#[cfg(target_os = "android")] +#[path = "android.rs"] +mod imp; + pub use self::imp::Error; /// Sets and monitors system DNS settings. Makes sure the desired DNS servers are being used. diff --git a/talpid-core/src/firewall/android.rs b/talpid-core/src/firewall/android.rs new file mode 100644 index 0000000000..eb5d8574f9 --- /dev/null +++ b/talpid-core/src/firewall/android.rs @@ -0,0 +1,25 @@ +use super::{FirewallPolicy, FirewallT}; + +/// Stub error type for Firewall errors on Android. +#[derive(Debug, err_derive::Error)] +#[error(display = "Unknown Android Firewall error")] +pub struct Error; + +/// The Android stub implementation for the firewall. +pub struct Firewall; + +impl FirewallT for Firewall { + type Error = Error; + + fn new() -> Result<Self, Self::Error> { + Ok(Firewall) + } + + fn apply_policy(&mut self, _policy: FirewallPolicy) -> Result<(), Self::Error> { + Ok(()) + } + + fn reset_policy(&mut self) -> Result<(), Self::Error> { + Ok(()) + } +} diff --git a/talpid-core/src/firewall/mod.rs b/talpid-core/src/firewall/mod.rs index e7b388245f..af29d0739c 100644 --- a/talpid-core/src/firewall/mod.rs +++ b/talpid-core/src/firewall/mod.rs @@ -22,8 +22,11 @@ mod imp; #[path = "windows.rs"] mod imp; -pub use self::imp::Error; +#[cfg(target_os = "android")] +#[path = "android.rs"] +mod imp; +pub use self::imp::Error; #[cfg(unix)] lazy_static! { diff --git a/talpid-core/src/lib.rs b/talpid-core/src/lib.rs index 8de9002c1a..a636a22466 100644 --- a/talpid-core/src/lib.rs +++ b/talpid-core/src/lib.rs @@ -21,7 +21,7 @@ mod ffi; #[cfg(windows)] mod winnet; -#[cfg(unix)] +#[cfg(any(target_os = "linux", target_os = "macos"))] /// Working with IP interface devices pub mod network_interface; #[cfg(unix)] diff --git a/talpid-core/src/offline/dummy.rs b/talpid-core/src/offline/dummy.rs index 1c2da77819..e36ad8c4ee 100644 --- a/talpid-core/src/offline/dummy.rs +++ b/talpid-core/src/offline/dummy.rs @@ -1,5 +1,5 @@ +use crate::tunnel_state_machine::TunnelCommand; use futures::sync::mpsc::UnboundedSender; -use tunnel_state_machine::TunnelCommand; error_chain! {} diff --git a/talpid-core/src/routing/android.rs b/talpid-core/src/routing/android.rs new file mode 100644 index 0000000000..fa5c5c8f8e --- /dev/null +++ b/talpid-core/src/routing/android.rs @@ -0,0 +1,32 @@ +use super::{ + subprocess::{Exec, RunExpr}, + NetNode, RequiredRoutes, +}; +use std::{ + collections::HashSet, + net::{IpAddr, Ipv4Addr}, +}; + +error_chain! {} + +pub struct RouteManager; + +impl super::RoutingT for RouteManager { + type Error = Error; + + fn new() -> Result<Self> { + Ok(RouteManager) + } + + fn add_routes(&mut self, _required_routes: RequiredRoutes) -> Result<()> { + Ok(()) + } + + fn delete_routes(&mut self) -> Result<()> { + Ok(()) + } + + fn get_default_route_node(&mut self) -> Result<IpAddr> { + Ok(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0))) + } +} diff --git a/talpid-core/src/routing/mod.rs b/talpid-core/src/routing/mod.rs index 50385a436f..612c0b2396 100644 --- a/talpid-core/src/routing/mod.rs +++ b/talpid-core/src/routing/mod.rs @@ -9,8 +9,11 @@ mod imp; #[path = "linux.rs"] mod imp; -mod subprocess; +#[cfg(target_os = "android")] +#[path = "android.rs"] +mod imp; +mod subprocess; /// A single route #[derive(Hash, Eq, PartialEq)] diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index cc7bcdb325..04332908c4 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -6,14 +6,14 @@ use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, path::{Path, PathBuf}, }; -#[cfg(unix)] +#[cfg(any(target_os = "linux", target_os = "macos"))] use talpid_types::net::wireguard as wireguard_types; use talpid_types::net::{openvpn as openvpn_types, GenericTunnelOptions, TunnelParameters}; /// A module for all OpenVPN related tunnel management. pub mod openvpn; -#[cfg(unix)] +#[cfg(any(target_os = "linux", target_os = "macos"))] pub mod wireguard; const OPENVPN_LOG_FILENAME: &str = "openvpn.log"; @@ -46,7 +46,7 @@ error_chain! { ; WirguardTunnelMonitoringError(wireguard::Error, wireguard::ErrorKind) /// There was an error listening for events from the OpenVPN tunnel - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] ; } } @@ -146,16 +146,16 @@ impl TunnelMonitor { TunnelParameters::OpenVpn(config) => { Self::start_openvpn_tunnel(&config, tunnel_alias, log_file, resource_dir, on_event) } - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] TunnelParameters::Wireguard(config) => { Self::start_wireguard_tunnel(&config, log_file, on_event) } - #[cfg(windows)] + #[cfg(any(windows, target_os = "android"))] TunnelParameters::Wireguard(_) => bail!(ErrorKind::UnsupportedPlatform), } } - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] fn start_wireguard_tunnel<L>( params: &wireguard_types::TunnelParameters, log: Option<PathBuf>, @@ -237,7 +237,7 @@ impl TunnelMonitor { pub enum CloseHandle { /// OpenVpn close handle OpenVpn(openvpn::OpenVpnCloseHandle), - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] /// Wireguard close handle Wireguard(wireguard::CloseHandle), } @@ -247,7 +247,7 @@ impl CloseHandle { pub fn close(self) -> io::Result<()> { match self { CloseHandle::OpenVpn(handle) => handle.close(), - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] CloseHandle::Wireguard(mut handle) => { handle.close(); Ok(()) @@ -258,7 +258,7 @@ impl CloseHandle { enum InternalTunnelMonitor { OpenVpn(openvpn::OpenVpnMonitor), - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] Wireguard(wireguard::WireguardMonitor), } @@ -266,7 +266,7 @@ impl InternalTunnelMonitor { fn close_handle(&self) -> CloseHandle { match self { InternalTunnelMonitor::OpenVpn(tun) => CloseHandle::OpenVpn(tun.close_handle()), - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] InternalTunnelMonitor::Wireguard(tun) => CloseHandle::Wireguard(tun.close_handle()), } } @@ -274,7 +274,7 @@ impl InternalTunnelMonitor { fn wait(self) -> Result<()> { match self { InternalTunnelMonitor::OpenVpn(tun) => tun.wait()?, - #[cfg(unix)] + #[cfg(any(target_os = "linux", target_os = "macos"))] InternalTunnelMonitor::Wireguard(tun) => tun.wait()?, } @@ -316,7 +316,7 @@ fn is_ipv6_enabled_in_os() -> bool { .map(|disable_ipv6| disable_ipv6.trim() == "0") .unwrap_or(false) } - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "android"))] { true } diff --git a/talpid-core/src/tunnel/openvpn.rs b/talpid-core/src/tunnel/openvpn.rs index d3e2b9858f..8e0de74430 100644 --- a/talpid-core/src/tunnel/openvpn.rs +++ b/talpid-core/src/tunnel/openvpn.rs @@ -85,7 +85,7 @@ static OPENVPN_DIE_TIMEOUT: Duration = Duration::from_secs(30); #[cfg(target_os = "macos")] const OPENVPN_PLUGIN_FILENAME: &str = "libtalpid_openvpn_plugin.dylib"; -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "linux", target_os = "android"))] const OPENVPN_PLUGIN_FILENAME: &str = "libtalpid_openvpn_plugin.so"; #[cfg(windows)] const OPENVPN_PLUGIN_FILENAME: &str = "talpid_openvpn_plugin.dll"; |
