diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-07-22 15:46:11 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-07-22 15:46:11 +0200 |
| commit | bcd90f658557b7a01e03eb97d9d21ef817e4b07a (patch) | |
| tree | 31aa45cc64467ff30a4c40db7bd6e2b3263af04e | |
| parent | 5dd98f4417e7c69f32f2368086926989526d09ff (diff) | |
| parent | e69d04d1a7df0a5dcd64db8a9fd9676acaa9d0fd (diff) | |
| download | mullvadvpn-bcd90f658557b7a01e03eb97d9d21ef817e4b07a.tar.xz mullvadvpn-bcd90f658557b7a01e03eb97d9d21ef817e4b07a.zip | |
Merge branch 'win-wg-ipv6-issue'
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/mod.rs | 22 | ||||
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/wireguard_go.rs | 9 | ||||
| -rw-r--r-- | wireguard/libwg/libwg_windows.go | 35 |
4 files changed, 39 insertions, 29 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index ace301a14c..f3fe19b7a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,8 @@ Line wrap the file at 100 chars. Th #### Windows - Fix window flickering by disabling window animations. +- Fix WireGuard not connecting if IPv6 is disabled in the adapter or OS. `libwg` would time out + waiting for an IPv6 interface to become available. #### Android - Fix Connect screen sometimes becoming unusually tall. This ended up causing the screen to be diff --git a/talpid-core/src/tunnel/mod.rs b/talpid-core/src/tunnel/mod.rs index 9926116a48..37d64c85f2 100644 --- a/talpid-core/src/tunnel/mod.rs +++ b/talpid-core/src/tunnel/mod.rs @@ -10,8 +10,6 @@ use std::{ #[cfg(not(target_os = "android"))] use talpid_types::net::openvpn as openvpn_types; use talpid_types::net::{wireguard as wireguard_types, TunnelParameters}; -#[cfg(target_os = "windows")] -use talpid_types::ErrorExt; #[cfg(target_os = "android")] pub use self::tun_provider::TunConfig; @@ -241,22 +239,10 @@ impl TunnelMonitor { let options = tunnel_parameters.get_generic_options(); #[cfg(target_os = "windows")] - match tunnel_parameters { - TunnelParameters::OpenVpn(..) => { - if options.enable_ipv6 { - try_enabling_ipv6(tunnel_parameters) - } else { - Ok(()) - } - } - TunnelParameters::Wireguard(..) => { - // WireGuard always waits on an IPv6 interface, - // even if it's not in use - if let Err(e) = try_enabling_ipv6(tunnel_parameters) { - log::error!("{}", e.display_chain_with_msg("Failed to enable IPv6")); - } - Ok(()) - } + if options.enable_ipv6 { + try_enabling_ipv6(tunnel_parameters) + } else { + Ok(()) } #[cfg(not(target_os = "windows"))] diff --git a/talpid-core/src/tunnel/wireguard/wireguard_go.rs b/talpid-core/src/tunnel/wireguard/wireguard_go.rs index 058735536a..761276dcdf 100644 --- a/talpid-core/src/tunnel/wireguard/wireguard_go.rs +++ b/talpid-core/src/tunnel/wireguard/wireguard_go.rs @@ -126,10 +126,18 @@ impl WgGoTunnel { .map(LoggingContext) .map_err(TunnelError::LoggingError)?; + let wait_on_ipv6 = config.ipv6_gateway.is_some() + || config.tunnel.addresses.iter().any(|ip| ip.is_ipv6()) + || config + .peers + .iter() + .any(|config| config.allowed_ips.iter().any(|ip| ip.is_ipv6())); + let handle = unsafe { wgTurnOn( cstr_iface_name.as_ptr(), config.mtu as i64, + wait_on_ipv6 as u8, wg_config_str.as_ptr(), Some(logging_callback), logging_context.0 as *mut libc::c_void, @@ -350,6 +358,7 @@ extern "C" { fn wgTurnOn( iface_name: *const i8, mtu: i64, + wait_on_ipv6: u8, settings: *const i8, logging_callback: Option<LoggingCallback>, logging_context: *mut libc::c_void, diff --git a/wireguard/libwg/libwg_windows.go b/wireguard/libwg/libwg_windows.go index ba47c46f2b..5b245be71c 100644 --- a/wireguard/libwg/libwg_windows.go +++ b/wireguard/libwg/libwg_windows.go @@ -28,8 +28,30 @@ import ( type LogSink = unsafe.Pointer type LogContext = unsafe.Pointer +func createInterfaceWatcherEvents(waitOnIpv6 bool, tunLuid uint64) []interfacewatcher.Event { + if waitOnIpv6 { + return []interfacewatcher.Event{ + { + Luid: winipcfg.LUID(tunLuid), + Family: windows.AF_INET, + }, + interfacewatcher.Event { + Luid: winipcfg.LUID(tunLuid), + Family: windows.AF_INET6, + }, + } + } else { + return []interfacewatcher.Event{ + { + Luid: winipcfg.LUID(tunLuid), + Family: windows.AF_INET, + }, + } + } +} + //export wgTurnOn -func wgTurnOn(cIfaceName *C.char, mtu int, cSettings *C.char, logSink LogSink, logContext LogContext) int32 { +func wgTurnOn(cIfaceName *C.char, mtu int, waitOnIpv6 bool, cSettings *C.char, logSink LogSink, logContext LogContext) int32 { logger := logging.NewLogger(logSink, logContext) if cIfaceName == nil { @@ -91,16 +113,7 @@ func wgTurnOn(cIfaceName *C.char, mtu int, cSettings *C.char, logSink LogSink, l device.Up() - interfaces := []interfacewatcher.Event{ - { - Luid: winipcfg.LUID(nativeTun.LUID()), - Family: windows.AF_INET, - }, - { - Luid: winipcfg.LUID(nativeTun.LUID()), - Family: windows.AF_INET6, - }, - } + interfaces := createInterfaceWatcherEvents(waitOnIpv6, nativeTun.LUID()) logger.Debug.Println("Waiting for interfaces to attach") |
