summaryrefslogtreecommitdiffhomepage
path: root/talpid-core/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2020-09-15 15:36:05 +0200
committerDavid Lönnhager <david.l@mullvad.net>2020-09-18 10:32:58 +0200
commit06c9a4c3ec587e09935dbfbcd69f6b627e5e8370 (patch)
tree41b053f53a1a1849fa198b0c79c53ed2ce3e75a6 /talpid-core/src
parent0e24a2d3ffd3c8530f6ae6449c6e08f12dbf5908 (diff)
downloadmullvadvpn-06c9a4c3ec587e09935dbfbcd69f6b627e5e8370.tar.xz
mullvadvpn-06c9a4c3ec587e09935dbfbcd69f6b627e5e8370.zip
Add an environment variable for overriding the preference for the WireGuard kernel module
Diffstat (limited to 'talpid-core/src')
-rw-r--r--talpid-core/src/tunnel/wireguard/mod.rs44
1 files changed, 30 insertions, 14 deletions
diff --git a/talpid-core/src/tunnel/wireguard/mod.rs b/talpid-core/src/tunnel/wireguard/mod.rs
index 06bbd74fa3..6f5546aa74 100644
--- a/talpid-core/src/tunnel/wireguard/mod.rs
+++ b/talpid-core/src/tunnel/wireguard/mod.rs
@@ -3,6 +3,10 @@ use self::config::Config;
use super::tun_provider;
use super::{tun_provider::TunProvider, TunnelEvent, TunnelMetadata};
use crate::routing::{self, RequiredRoute};
+#[cfg(target_os = "linux")]
+use lazy_static::lazy_static;
+#[cfg(target_os = "linux")]
+use std::env;
use std::{
collections::HashSet,
path::Path,
@@ -55,6 +59,14 @@ pub struct WireguardMonitor {
pinger_stop_sender: mpsc::Sender<()>,
}
+#[cfg(target_os = "linux")]
+lazy_static! {
+ /// Overrides the preference for the kernel module for WireGuard.
+ static ref FORCE_USERSPACE_WIREGUARD: bool = env::var("TALPID_FORCE_USERSPACE_WIREGUARD")
+ .map(|v| v != "0")
+ .unwrap_or(false);
+}
+
impl WireguardMonitor {
/// Starts a WireGuard tunnel with the given config
pub fn start<F: Fn(TunnelEvent) + Send + Sync + Clone + 'static>(
@@ -130,20 +142,24 @@ impl WireguardMonitor {
route_manager: &mut routing::RouteManager,
) -> Result<Box<dyn Tunnel>> {
#[cfg(target_os = "linux")]
- match wireguard_kernel::KernelTunnel::new(route_manager.runtime_handle(), config) {
- Ok(tunnel) => {
- log::debug!("Using kernel WireGuard implementation");
- return Ok(Box::new(tunnel));
- }
- Err(error) => {
- log::error!(
- "{}",
- error.display_chain_with_msg(
- "Failed to setup kernel WireGuard device, falling back to userspace"
- )
- );
- }
- };
+ if !*FORCE_USERSPACE_WIREGUARD {
+ match wireguard_kernel::KernelTunnel::new(route_manager.runtime_handle(), config) {
+ Ok(tunnel) => {
+ log::debug!("Using kernel WireGuard implementation");
+ return Ok(Box::new(tunnel));
+ }
+ Err(error) => {
+ log::error!(
+ "{}",
+ error.display_chain_with_msg(
+ "Failed to setup kernel WireGuard device, falling back to userspace"
+ )
+ );
+ }
+ };
+ } else {
+ log::debug!("Using userspace WireGuard implementation");
+ }
Ok(Box::new(WgGoTunnel::start_tunnel(
&config,