summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mullvad-daemon/src/lib.rs27
-rw-r--r--mullvad-daemon/src/management_interface.rs8
-rw-r--r--mullvad-daemon/src/settings/mod.rs2
-rw-r--r--mullvad-management-interface/proto/management_interface.proto1
-rw-r--r--mullvad-management-interface/src/client.rs5
-rw-r--r--test/test-manager/src/tests/mod.rs108
6 files changed, 32 insertions, 119 deletions
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index c2c7002377..2e685d778f 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -273,6 +273,8 @@ pub enum DaemonCommand {
SetWireguardRotationInterval(ResponseTx<(), settings::Error>, Option<RotationInterval>),
/// Get the daemon settings
GetSettings(oneshot::Sender<Settings>),
+ /// Reset all daemon settings to the defaults
+ ResetSettings(ResponseTx<(), settings::Error>),
/// Generate new wireguard key
RotateWireguardKey(ResponseTx<(), Error>),
/// Return a public key of the currently set wireguard private key, if there is one
@@ -1189,6 +1191,7 @@ where
self.on_set_wireguard_rotation_interval(tx, interval).await
}
GetSettings(tx) => self.on_get_settings(tx),
+ ResetSettings(tx) => self.on_reset_settings(tx).await,
RotateWireguardKey(tx) => self.on_rotate_wireguard_key(tx),
GetWireguardKey(tx) => self.on_get_wireguard_key(tx).await,
CreateCustomList(tx, name) => self.on_create_custom_list(tx, name).await,
@@ -2256,18 +2259,10 @@ where
{
Ok(settings_changed) => {
Self::oneshot_send(tx, Ok(()), "set_daita_settings response");
- if settings_changed {
- self.parameters_generator
- .set_tunnel_options(&self.settings.tunnel_options)
- .await;
- self.event_listener
- .notify_settings(self.settings.to_settings());
- self.relay_selector
- .set_config(new_selector_config(&self.settings));
- if self.get_target_tunnel_type() == Some(TunnelType::Wireguard) {
- log::info!("Reconnecting because DAITA settings changed");
- self.reconnect_tunnel();
- }
+ if settings_changed && self.get_target_tunnel_type() == Some(TunnelType::Wireguard)
+ {
+ log::info!("Reconnecting because DAITA settings changed");
+ self.reconnect_tunnel();
}
}
Err(e) => {
@@ -2617,6 +2612,12 @@ where
Self::oneshot_send(tx, self.settings.to_settings(), "get_settings response");
}
+ async fn on_reset_settings(&mut self, tx: ResponseTx<(), settings::Error>) {
+ self.disconnect_tunnel();
+ let result = self.settings.reset().await;
+ Self::oneshot_send(tx, result, "reset_settings response");
+ }
+
fn oneshot_send<T>(tx: oneshot::Sender<T>, t: T, msg: &'static str) {
if tx.send(t).is_err() {
log::warn!("Unable to send {} to the daemon command sender", msg);
@@ -2741,7 +2742,7 @@ where
self.send_tunnel_command(TunnelCommand::Connect);
}
- fn disconnect_tunnel(&mut self) {
+ fn disconnect_tunnel(&self) {
self.send_tunnel_command(TunnelCommand::Disconnect);
}
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs
index 62a353dcc6..bc6ebe8287 100644
--- a/mullvad-daemon/src/management_interface.rs
+++ b/mullvad-daemon/src/management_interface.rs
@@ -246,6 +246,14 @@ impl ManagementService for ManagementServiceImpl {
.map(|settings| Response::new(types::Settings::from(&settings)))
}
+ async fn reset_settings(&self, _: Request<()>) -> ServiceResult<()> {
+ log::debug!("reset_settings");
+ let (tx, rx) = oneshot::channel();
+ self.send_command_to_daemon(DaemonCommand::ResetSettings(tx))?;
+ self.wait_for_result(rx).await??;
+ Ok(Response::new(()))
+ }
+
async fn set_allow_lan(&self, request: Request<bool>) -> ServiceResult<()> {
let allow_lan = request.into_inner();
log::debug!("set_allow_lan({})", allow_lan);
diff --git a/mullvad-daemon/src/settings/mod.rs b/mullvad-daemon/src/settings/mod.rs
index f16a777b54..d5a222cd02 100644
--- a/mullvad-daemon/src/settings/mod.rs
+++ b/mullvad-daemon/src/settings/mod.rs
@@ -1,4 +1,3 @@
-#[cfg(not(target_os = "android"))]
use futures::TryFutureExt;
use mullvad_types::{
custom_list::Error as CustomListError,
@@ -220,7 +219,6 @@ impl SettingsPersister {
}
/// Resets default settings
- #[cfg(not(target_os = "android"))]
pub async fn reset(&mut self) -> Result<(), Error> {
self.settings = Self::default_settings();
let path = self.path.clone();
diff --git a/mullvad-management-interface/proto/management_interface.proto b/mullvad-management-interface/proto/management_interface.proto
index aa279070f0..798e3a3bee 100644
--- a/mullvad-management-interface/proto/management_interface.proto
+++ b/mullvad-management-interface/proto/management_interface.proto
@@ -39,6 +39,7 @@ service ManagementService {
// Settings
rpc GetSettings(google.protobuf.Empty) returns (Settings) {}
+ rpc ResetSettings(google.protobuf.Empty) returns (google.protobuf.Empty) {}
rpc SetAllowLan(google.protobuf.BoolValue) returns (google.protobuf.Empty) {}
rpc SetShowBetaReleases(google.protobuf.BoolValue) returns (google.protobuf.Empty) {}
rpc SetBlockWhenDisconnected(google.protobuf.BoolValue) returns (google.protobuf.Empty) {}
diff --git a/mullvad-management-interface/src/client.rs b/mullvad-management-interface/src/client.rs
index 14ed66ea97..4db40cac52 100644
--- a/mullvad-management-interface/src/client.rs
+++ b/mullvad-management-interface/src/client.rs
@@ -313,6 +313,11 @@ impl MullvadProxyClient {
Settings::try_from(settings).map_err(Error::InvalidResponse)
}
+ pub async fn reset_settings(&mut self) -> Result<()> {
+ self.0.reset_settings(()).await.map_err(Error::Rpc)?;
+ Ok(())
+ }
+
pub async fn set_allow_lan(&mut self, state: bool) -> Result<()> {
self.0.set_allow_lan(state).await.map_err(Error::Rpc)?;
Ok(())
diff --git a/test/test-manager/src/tests/mod.rs b/test/test-manager/src/tests/mod.rs
index 23a3976ef2..0a9a6913df 100644
--- a/test/test-manager/src/tests/mod.rs
+++ b/test/test-manager/src/tests/mod.rs
@@ -79,115 +79,15 @@ pub async fn cleanup_after_test(
rpc: ServiceClient,
rpc_provider: &RpcClientProvider,
) -> anyhow::Result<()> {
- log::debug!("Cleaning up daemon in test cleanup");
+ log::debug!("Resetting daemon settings after test");
// Check if daemon should be restarted
restart_daemon(rpc).await?;
let mut mullvad_client = rpc_provider.new_client().await;
-
- helpers::disconnect_and_wait(&mut mullvad_client).await?;
-
- // Bring all the settings into scope so we remember to reset them.
- let mullvad_types::settings::Settings {
- relay_settings,
- bridge_settings,
- obfuscation_settings,
- bridge_state,
- custom_lists,
- api_access_methods,
- allow_lan,
- block_when_disconnected,
- auto_connect,
- tunnel_options,
- relay_overrides,
- show_beta_releases,
- #[cfg(target_os = "macos")]
- split_tunnel: _,
- settings_version: _, // N/A
- } = Default::default();
-
mullvad_client
- .clear_custom_access_methods()
+ .reset_settings()
.await
- .context("Could not clear custom api access methods")?;
- for access_method in api_access_methods.iter() {
- mullvad_client
- .update_access_method(access_method.clone())
- .await
- .context("Could not reset default access method")?;
- }
-
- mullvad_client
- .set_relay_settings(relay_settings)
- .await
- .context("Could not set relay settings")?;
-
- let _ = relay_overrides;
- mullvad_client
- .clear_all_relay_overrides()
- .await
- .context("Could not set relay overrides")?;
-
- mullvad_client
- .set_auto_connect(auto_connect)
- .await
- .context("Could not set auto connect in cleanup")?;
-
- mullvad_client
- .set_allow_lan(allow_lan)
- .await
- .context("Could not set allow lan in cleanup")?;
-
- mullvad_client
- .set_show_beta_releases(show_beta_releases)
- .await
- .context("Could not set show beta releases in cleanup")?;
-
- mullvad_client
- .set_bridge_state(bridge_state)
- .await
- .context("Could not set bridge state in cleanup")?;
-
- mullvad_client
- .set_bridge_settings(bridge_settings.clone())
- .await
- .context("Could not set bridge settings in cleanup")?;
-
- mullvad_client
- .set_obfuscation_settings(obfuscation_settings.clone())
- .await
- .context("Could set obfuscation settings in cleanup")?;
-
- mullvad_client
- .set_block_when_disconnected(block_when_disconnected)
- .await
- .context("Could not set block when disconnected setting in cleanup")?;
-
- mullvad_client
- .clear_split_tunnel_apps()
- .await
- .context("Could not clear split tunnel apps in cleanup")?;
-
- mullvad_client
- .clear_split_tunnel_processes()
- .await
- .context("Could not clear split tunnel processes in cleanup")?;
-
- mullvad_client
- .set_dns_options(tunnel_options.dns_options.clone())
- .await
- .context("Could not clear dns options in cleanup")?;
-
- mullvad_client
- .set_quantum_resistant_tunnel(tunnel_options.wireguard.quantum_resistant)
- .await
- .context("Could not clear PQ options in cleanup")?;
-
- let _ = custom_lists;
- mullvad_client
- .clear_custom_lists()
- .await
- .context("Could not remove custom list")?;
-
+ .context("Failed to reset settings")?;
+ helpers::disconnect_and_wait(&mut mullvad_client).await?;
Ok(())
}