diff options
| author | David Lönnhager <david.l@mullvad.net> | 2020-07-21 17:36:26 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2020-07-22 13:55:31 +0200 |
| commit | c7d943071e4575e8bd1c05fb2f674271c139c306 (patch) | |
| tree | 0b4449b01e919397ef4e43ed97ab8d2a1580ef00 | |
| parent | 5dd98f4417e7c69f32f2368086926989526d09ff (diff) | |
| download | mullvadvpn-c7d943071e4575e8bd1c05fb2f674271c139c306.tar.xz mullvadvpn-c7d943071e4575e8bd1c05fb2f674271c139c306.zip | |
Prevent infinite wait on non-existent IPv6 interface on Windows
| -rw-r--r-- | talpid-core/src/tunnel/wireguard/wireguard_go.rs | 6 | ||||
| -rw-r--r-- | wireguard/libwg/libwg_windows.go | 35 |
2 files changed, 30 insertions, 11 deletions
diff --git a/talpid-core/src/tunnel/wireguard/wireguard_go.rs b/talpid-core/src/tunnel/wireguard/wireguard_go.rs index 058735536a..61e722d442 100644 --- a/talpid-core/src/tunnel/wireguard/wireguard_go.rs +++ b/talpid-core/src/tunnel/wireguard/wireguard_go.rs @@ -126,10 +126,15 @@ 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 +355,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") |
