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 /talpid-core/src | |
| parent | 5d5392d39cc00696cd42c547587bbd7d767dd1c9 (diff) | |
| parent | 7bfa99d4106b28d46506081c4690d76292920f54 (diff) | |
| download | mullvadvpn-5ea3c63fb2c174502bc0dfff96e655b499286474.tar.xz mullvadvpn-5ea3c63fb2c174502bc0dfff96e655b499286474.zip | |
Merge branch 'compile-for-android'
Diffstat (limited to 'talpid-core/src')
| -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 |
10 files changed, 108 insertions, 17 deletions
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"; |
