summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock1
-rw-r--r--mullvad-daemon/Cargo.toml1
-rw-r--r--mullvad-daemon/src/migrations/mod.rs21
-rw-r--r--mullvad-daemon/src/migrations/v1.rs17
-rw-r--r--mullvad-daemon/src/migrations/v2.rs10
-rw-r--r--mullvad-daemon/src/migrations/v3.rs52
-rw-r--r--mullvad-daemon/src/migrations/v4.rs32
7 files changed, 124 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index a3fdecbf56..0203e5b11c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1333,6 +1333,7 @@ dependencies = [
"fern",
"futures",
"ipnetwork",
+ "jnix",
"lazy_static",
"libc",
"log",
diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml
index e9c3d75839..b2df8ce051 100644
--- a/mullvad-daemon/Cargo.toml
+++ b/mullvad-daemon/Cargo.toml
@@ -41,6 +41,7 @@ mullvad-management-interface = { path = "../mullvad-management-interface" }
[target.'cfg(target_os="android")'.dependencies]
android_logger = "0.8"
+jnix = { version = "0.4", features = ["derive"] }
[target.'cfg(unix)'.dependencies]
nix = "0.22.2"
diff --git a/mullvad-daemon/src/migrations/mod.rs b/mullvad-daemon/src/migrations/mod.rs
index 2e20e3cc36..3ba962aaea 100644
--- a/mullvad-daemon/src/migrations/mod.rs
+++ b/mullvad-daemon/src/migrations/mod.rs
@@ -1,3 +1,24 @@
+//! Code for migrating between different versions of the settings.
+//! Migration only supports migrating forward, to newer formats.
+//!
+//! A settings migration module is responsible for converting
+//! from its own version to the next version. So `v3::migrate`
+//! migrates from settings version `V3` to `V4` etc.
+//!
+//! Migration modules may NOT import and use structs that may
+//! change. Because then a later change to the current code can break
+//! old migrations. The only items a settings migration module may import
+//! are anything from `std`, `jnix` and the following:
+//!
+//! ```ignore
+//! use super::{Error, Result};
+//! use mullvad_types::relay_constraints::Constraint;
+//! use mullvad_types::settings::SettingsVersion;
+//! ```
+//!
+//! Any other type must be vendored into the migration module so the format
+//! it has is locked over time.
+
use std::path::Path;
use tokio::{
fs,
diff --git a/mullvad-daemon/src/migrations/v1.rs b/mullvad-daemon/src/migrations/v1.rs
index 82b6df3935..7f2a656c04 100644
--- a/mullvad-daemon/src/migrations/v1.rs
+++ b/mullvad-daemon/src/migrations/v1.rs
@@ -1,6 +1,21 @@
use super::Result;
use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
-use talpid_types::net::TunnelType;
+
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
+
+/// The tunnel protocol used by a [`TunnelEndpoint`].
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename = "tunnel_type")]
+pub enum TunnelType {
+ #[serde(rename = "openvpn")]
+ OpenVpn,
+ #[serde(rename = "wireguard")]
+ Wireguard,
+}
+
+// ======================================================
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
diff --git a/mullvad-daemon/src/migrations/v2.rs b/mullvad-daemon/src/migrations/v2.rs
index 46973f06b7..585bc16cc1 100644
--- a/mullvad-daemon/src/migrations/v2.rs
+++ b/mullvad-daemon/src/migrations/v2.rs
@@ -1,8 +1,16 @@
use super::{Error, Result};
-use crate::wireguard::{MAX_ROTATION_INTERVAL, MIN_ROTATION_INTERVAL};
use mullvad_types::settings::SettingsVersion;
use std::time::Duration;
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
+
+pub const MIN_ROTATION_INTERVAL: Duration = Duration::from_secs(1 * 24 * 60 * 60);
+pub const MAX_ROTATION_INTERVAL: Duration = Duration::from_secs(7 * 24 * 60 * 60);
+
+// ======================================================
+
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
return Ok(());
diff --git a/mullvad-daemon/src/migrations/v3.rs b/mullvad-daemon/src/migrations/v3.rs
index b7f12f6714..d4c94443ff 100644
--- a/mullvad-daemon/src/migrations/v3.rs
+++ b/mullvad-daemon/src/migrations/v3.rs
@@ -1,7 +1,53 @@
use super::{Error, Result};
-use mullvad_types::settings::{
- CustomDnsOptions, DefaultDnsOptions, DnsOptions, DnsState, SettingsVersion,
-};
+#[cfg(target_os = "android")]
+use jnix::IntoJava;
+use mullvad_types::settings::SettingsVersion;
+use std::net::IpAddr;
+
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
+
+#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+#[serde(rename_all = "snake_case")]
+pub enum DnsState {
+ Default,
+ Custom,
+}
+
+impl Default for DnsState {
+ fn default() -> Self {
+ Self::Default
+ }
+}
+
+/// DNS config
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+#[cfg_attr(target_os = "android", derive(IntoJava))]
+#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))]
+pub struct DnsOptions {
+ #[cfg_attr(target_os = "android", jnix(map = "|state| state == DnsState::Custom"))]
+ pub state: DnsState,
+ #[cfg_attr(target_os = "android", jnix(skip))]
+ pub default_options: DefaultDnsOptions,
+ #[cfg_attr(target_os = "android", jnix(map = "|opts| opts.addresses"))]
+ pub custom_options: CustomDnsOptions,
+}
+
+/// Default DNS config
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+pub struct DefaultDnsOptions {
+ pub block_ads: bool,
+ pub block_trackers: bool,
+}
+
+/// Custom DNS config
+#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize, Hash)]
+pub struct CustomDnsOptions {
+ pub addresses: Vec<IpAddr>,
+}
+
+// ======================================================
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
diff --git a/mullvad-daemon/src/migrations/v4.rs b/mullvad-daemon/src/migrations/v4.rs
index 865b4bbfa6..4a27b352fb 100644
--- a/mullvad-daemon/src/migrations/v4.rs
+++ b/mullvad-daemon/src/migrations/v4.rs
@@ -1,13 +1,35 @@
use super::{Error, Result};
-use mullvad_types::{
- relay_constraints::{Constraint, TransportPort},
- settings::SettingsVersion,
-};
-use talpid_types::net::TransportProtocol;
+#[cfg(target_os = "android")]
+use jnix::IntoJava;
+use mullvad_types::{relay_constraints::Constraint, settings::SettingsVersion};
+
+// ======================================================
+// Section for vendoring types and values that
+// this settings version depend on. See `mod.rs`.
const WIREGUARD_TCP_PORTS: [u16; 3] = [80, 443, 5001];
const OPENVPN_TCP_PORTS: [u16; 2] = [80, 443];
+/// Representation of a transport protocol, either UDP or TCP.
+#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
+#[serde(rename_all = "snake_case")]
+#[cfg_attr(target_os = "android", derive(IntoJava))]
+#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.talpid.net"))]
+pub enum TransportProtocol {
+ /// Represents the UDP transport protocol.
+ Udp,
+ /// Represents the TCP transport protocol.
+ Tcp,
+}
+
+#[derive(Debug, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)]
+pub struct TransportPort {
+ pub protocol: TransportProtocol,
+ pub port: Constraint<u16>,
+}
+
+// ======================================================
+
pub fn migrate(settings: &mut serde_json::Value) -> Result<()> {
if !version_matches(settings) {
return Ok(());