diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-07-13 13:29:34 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2018-07-18 09:12:26 -0300 |
| commit | a31b9ff86be652a11ef69ae88699d78e9a9c9c8a (patch) | |
| tree | 6730a26271c91d0e4cbb939adf27c14a645e2d17 /talpid-core/src | |
| parent | 8e3708da9a4f87d779e8a0ef5c04f1668f301ad3 (diff) | |
| download | mullvadvpn-a31b9ff86be652a11ef69ae88699d78e9a9c9c8a.tar.xz mullvadvpn-a31b9ff86be652a11ef69ae88699d78e9a9c9c8a.zip | |
Set `ip` command path on Linux
Use the `which` crate to find the location of the binary file.
Diffstat (limited to 'talpid-core/src')
| -rw-r--r-- | talpid-core/src/lib.rs | 4 | ||||
| -rw-r--r-- | talpid-core/src/process/openvpn.rs | 13 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 16 |
3 files changed, 33 insertions, 0 deletions
diff --git a/talpid-core/src/lib.rs b/talpid-core/src/lib.rs index fd26752fac..de3bd84ea6 100644 --- a/talpid-core/src/lib.rs +++ b/talpid-core/src/lib.rs @@ -17,6 +17,8 @@ extern crate log; #[macro_use] extern crate error_chain; +#[cfg(target_os = "linux")] +extern crate failure; #[cfg(unix)] extern crate ipnetwork; extern crate jsonrpc_core; @@ -28,6 +30,8 @@ extern crate lazy_static; extern crate libc; extern crate shell_escape; extern crate uuid; +#[cfg(target_os = "linux")] +extern crate which; extern crate openvpn_plugin; extern crate talpid_ipc; diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs index 0a5e93a084..409cc605a7 100644 --- a/talpid-core/src/process/openvpn.rs +++ b/talpid-core/src/process/openvpn.rs @@ -48,6 +48,7 @@ pub struct OpenVpnCommand { user_pass_path: Option<PathBuf>, ca: Option<PathBuf>, crl: Option<PathBuf>, + iproute_bin: Option<OsString>, plugin: Option<(PathBuf, Vec<String>)>, log: Option<PathBuf>, tunnel_options: net::OpenVpnTunnelOptions, @@ -65,6 +66,7 @@ impl OpenVpnCommand { user_pass_path: None, ca: None, crl: None, + iproute_bin: None, plugin: None, log: None, tunnel_options: net::OpenVpnTunnelOptions::default(), @@ -103,6 +105,12 @@ impl OpenVpnCommand { self } + /// Sets the path to the ip route command. + pub fn iproute_bin<S: Into<OsString>>(&mut self, iproute_bin: S) -> &mut Self { + self.iproute_bin = Some(iproute_bin.into()); + self + } + /// Sets a plugin and its arguments that OpenVPN will be started with. pub fn plugin<P: AsRef<Path>>(&mut self, path: P, args: Vec<String>) -> &mut Self { self.plugin = Some((path.as_ref().to_path_buf(), args)); @@ -146,6 +154,11 @@ impl OpenVpnCommand { args.extend(self.remote_arguments().iter().map(OsString::from)); args.extend(self.authentication_arguments()); + if let Some(ref iproute_bin) = self.iproute_bin { + args.push(OsString::from("--iproute")); + args.push(iproute_bin.clone()); + } + if let Some(ref ca) = self.ca { args.push(OsString::from("--ca")); args.push(OsString::from(ca.as_os_str())); diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index cd90924ac1..932279c0a0 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -11,6 +11,11 @@ use std::io::{self, Write}; use std::net::Ipv4Addr; use std::path::{Path, PathBuf}; +#[cfg(target_os = "linux")] +use failure::ResultExt as FailureResultExt; +#[cfg(target_os = "linux")] +use which; + use talpid_types::net::{ Endpoint, OpenVpnTunnelOptions, TunnelEndpoint, TunnelEndpointData, TunnelOptions, }; @@ -43,6 +48,11 @@ error_chain!{ description("No OpenVPN binary found") display("No OpenVPN binary found at {}", path.display()) } + /// The IP routing program was not found. + #[cfg(target_os = "linux")] + IpRouteNotFound { + description("The IP routing program `ip` was not found.") + } /// The OpenVPN plugin was not found. PluginNotFound(path: PathBuf) { description("No OpenVPN plugin found") @@ -192,6 +202,12 @@ impl TunnelMonitor { if let Some(config) = Self::get_config_path(resource_dir) { cmd.config(config); } + #[cfg(target_os = "linux")] + cmd.iproute_bin( + which::which("ip") + .compat() + .chain_err(|| ErrorKind::IpRouteNotFound)?, + ); cmd.remote(remote) .user_pass(user_pass_file) .tunnel_options(&options) |
