summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--talpid-core/src/process/openvpn.rs17
-rw-r--r--talpid-core/src/tunnel/mod.rs5
2 files changed, 22 insertions, 0 deletions
diff --git a/talpid-core/src/process/openvpn.rs b/talpid-core/src/process/openvpn.rs
index 527e45f3f3..ba0e5f20e4 100644
--- a/talpid-core/src/process/openvpn.rs
+++ b/talpid-core/src/process/openvpn.rs
@@ -16,7 +16,10 @@ use talpid_types::net;
static BASE_ARGUMENTS: &[&[&str]] = &[
&["--client"],
&["--nobind"],
+ #[cfg(not(windows))]
&["--dev", "tun"],
+ #[cfg(windows)]
+ &["--dev-type", "tun"],
&["--ping", "3"],
&["--ping-exit", "15"],
&["--connect-retry", "0", "0"],
@@ -48,6 +51,7 @@ pub struct OpenVpnCommand {
plugin: Option<(PathBuf, Vec<String>)>,
log: Option<PathBuf>,
tunnel_options: net::OpenVpnTunnelOptions,
+ tunnel_alias: Option<OsString>,
}
impl OpenVpnCommand {
@@ -64,6 +68,7 @@ impl OpenVpnCommand {
plugin: None,
log: None,
tunnel_options: net::OpenVpnTunnelOptions::default(),
+ tunnel_alias: None,
}
}
@@ -122,6 +127,13 @@ impl OpenVpnCommand {
self
}
+ /// Sets the tunnel alias which will be used to identify a tunnel device that will be used by
+ /// OpenVPN.
+ pub fn set_tunnel_alias(&mut self, tunnel_alias: Option<OsString>) -> &mut Self {
+ self.tunnel_alias = tunnel_alias;
+ self
+ }
+
/// Returns all arguments that the subprocess would be spawned with.
pub fn get_arguments(&self) -> Vec<OsString> {
let mut args: Vec<OsString> = Self::base_arguments().iter().map(OsString::from).collect();
@@ -159,6 +171,11 @@ impl OpenVpnCommand {
args.push(OsString::from(mssfix.to_string()));
}
+ if let Some(ref tunnel_device) = self.tunnel_alias {
+ args.push(OsString::from("--dev-node"));
+ args.push(tunnel_device.clone());
+ }
+
args.extend(Self::security_arguments().iter().map(OsString::from));
args
diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs
index 3c3e9979f2..3d56eb6e79 100644
--- a/talpid-core/src/tunnel/mod.rs
+++ b/talpid-core/src/tunnel/mod.rs
@@ -5,6 +5,7 @@ use openvpn_plugin::types::OpenVpnPluginEvent;
use process::openvpn::OpenVpnCommand;
use std::collections::HashMap;
+use std::ffi::OsString;
use std::fs;
use std::io::{self, Write};
use std::net::Ipv4Addr;
@@ -132,6 +133,7 @@ impl TunnelMonitor {
pub fn new<L>(
tunnel_endpoint: TunnelEndpoint,
tunnel_options: &TunnelOptions,
+ tunnel_alias: Option<OsString>,
account_token: &str,
log: Option<&Path>,
resource_dir: &Path,
@@ -148,6 +150,7 @@ impl TunnelMonitor {
.chain_err(|| ErrorKind::CredentialsWriteError)?;
let cmd = Self::create_openvpn_cmd(
tunnel_endpoint.to_endpoint(),
+ tunnel_alias,
&tunnel_options.openvpn,
user_pass_file.as_ref(),
log,
@@ -179,6 +182,7 @@ impl TunnelMonitor {
fn create_openvpn_cmd(
remote: Endpoint,
+ tunnel_alias: Option<OsString>,
options: &OpenVpnTunnelOptions,
user_pass_file: &Path,
log: Option<&Path>,
@@ -193,6 +197,7 @@ impl TunnelMonitor {
.set_tunnel_options(&options)
.ca(resource_dir.join("ca.crt"))
.crl(resource_dir.join("crl.pem"));
+ cmd.set_tunnel_alias(tunnel_alias);
if let Some(log) = log {
cmd.log(log);
}