diff options
| author | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-02-02 16:14:53 +0100 |
|---|---|---|
| committer | Markus Pettersson <markus.pettersson@mullvad.net> | 2024-02-09 13:04:06 +0100 |
| commit | a6a26bf92ddd690c85e7cefbca1c8e5bb7fe7683 (patch) | |
| tree | ea5b784ceca66b772e8065ce6686a9cefdc3faeb /mullvad-daemon/src | |
| parent | 7fe5f5fe63621a448623ee53c651ed2dd50b9d4a (diff) | |
| download | mullvadvpn-a6a26bf92ddd690c85e7cefbca1c8e5bb7fe7683.tar.xz mullvadvpn-a6a26bf92ddd690c85e7cefbca1c8e5bb7fe7683.zip | |
Detect available IP versions
Try to detect available IP versions by looking at the available routes
on the host. On Linux, we check if there exists IPv4 and/or IPv6 routes
to some public IP addresses. On macOS and Windows, we check if there
exists default routes for IPv4 and/or IPv6. On Android, we check if
there is any connectivity at all.
The intention is to be able to generate better default constraints for
tunnel endpoints. If we can detect "working" IPv4 and/or IPv6 and
forward this information to a `TunnelParametersGenerator`, we may choose
to connect to a Wireguard relay using IPv6 as part of our
retry-strategy. This has not been possible before.
Diffstat (limited to 'mullvad-daemon/src')
| -rw-r--r-- | mullvad-daemon/src/api.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/mullvad-daemon/src/api.rs b/mullvad-daemon/src/api.rs index 588068810e..a493b532d1 100644 --- a/mullvad-daemon/src/api.rs +++ b/mullvad-daemon/src/api.rs @@ -21,7 +21,9 @@ use mullvad_types::access_method::{ }; use std::{net::SocketAddr, path::PathBuf}; use talpid_core::mpsc::Sender; -use talpid_types::net::{AllowedClients, AllowedEndpoint, Endpoint, TransportProtocol}; +use talpid_types::net::{ + AllowedClients, AllowedEndpoint, Connectivity, Endpoint, TransportProtocol, +}; pub enum Message { Get(ResponseTx<ResolvedConnectionMode>), @@ -527,18 +529,26 @@ pub fn allowed_clients(connection_mode: &ApiConnectionMode) -> AllowedClients { } } +/// Forwards the received values from `offline_state_rx` to the [`ApiAvailabilityHandle`]. pub(crate) fn forward_offline_state( api_availability: ApiAvailabilityHandle, - mut offline_state_rx: mpsc::UnboundedReceiver<bool>, + mut offline_state_rx: mpsc::UnboundedReceiver<Connectivity>, ) { tokio::spawn(async move { - let initial_state = offline_state_rx + let is_offline = offline_state_rx .next() .await - .expect("missing initial offline state"); - api_availability.set_offline(initial_state); - while let Some(is_offline) = offline_state_rx.next().await { - api_availability.set_offline(is_offline); + .expect("missing initial offline state") + .is_offline(); + log::info!( + "Initial offline state - {state}", + state = if is_offline { "offline" } else { "online" }, + ); + api_availability.set_offline(is_offline); + + while let Some(state) = offline_state_rx.next().await { + log::info!("Detecting changes to offline state - {state:?}"); + api_availability.set_offline(state.is_offline()); } }); } |
