From 95ebffa3f13903146ca1c1a0c0345e5ebf1b461b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Mon, 29 Jul 2024 11:46:18 +0200 Subject: [PATCH 1/3] Use std LazyLock instead of once_cell Lazy --- Cargo.lock | 12 -------- Cargo.toml | 2 +- android/translations-converter/Cargo.toml | 1 - .../src/android/string_value.rs | 7 +++-- .../translations-converter/src/normalize.rs | 14 ++++----- mullvad-api/Cargo.toml | 1 - mullvad-api/src/tls_stream.rs | 4 +-- mullvad-daemon/Cargo.toml | 1 - mullvad-daemon/src/account_history.rs | 5 ++-- mullvad-daemon/src/cli.rs | 6 ++-- mullvad-daemon/src/geoip.rs | 4 +-- .../src/migrations/account_history.rs | 5 ++-- mullvad-daemon/src/system_service.rs | 5 ++-- mullvad-daemon/src/tunnel.rs | 8 ++--- mullvad-daemon/src/version_check.rs | 8 ++--- mullvad-management-interface/Cargo.toml | 1 - mullvad-management-interface/src/lib.rs | 6 ++-- mullvad-problem-report/Cargo.toml | 1 - mullvad-problem-report/src/lib.rs | 8 ++--- mullvad-relay-selector/Cargo.toml | 1 - .../src/relay_selector/mod.rs | 5 ++-- .../tests/relay_selector.rs | 10 +++---- mullvad-setup/Cargo.toml | 1 - mullvad-setup/src/main.rs | 7 ++--- mullvad-types/Cargo.toml | 1 - mullvad-types/src/auth_failed.rs | 4 +-- mullvad-types/src/version.rs | 11 +++---- talpid-core/Cargo.toml | 2 +- talpid-core/src/firewall/linux.rs | 29 ++++++++++--------- talpid-core/src/firewall/mod.rs | 19 ++++++------ talpid-core/src/offline/mod.rs | 4 +-- talpid-core/src/resolver.rs | 4 +-- talpid-core/src/split_tunnel/macos/process.rs | 7 ++--- talpid-dbus/Cargo.toml | 1 - talpid-dbus/src/lib.rs | 6 ++-- talpid-dbus/src/systemd_resolved.rs | 11 +++++-- talpid-openvpn/Cargo.toml | 2 +- talpid-openvpn/src/lib.rs | 11 +++---- talpid-routing/Cargo.toml | 1 - talpid-routing/src/unix/linux.rs | 6 ++-- talpid-tunnel/Cargo.toml | 1 - talpid-tunnel/src/tun_provider/mod.rs | 14 +++++---- talpid-types/Cargo.toml | 1 - talpid-types/src/net/mod.rs | 7 ++--- talpid-wireguard/src/lib.rs | 8 ++--- talpid-wireguard/src/logging.rs | 5 ++-- talpid-wireguard/src/wireguard_nt/mod.rs | 24 ++++++++------- test/Cargo.lock | 6 ---- test/test-manager/src/logging.rs | 2 +- test/test-manager/src/package.rs | 10 ++++--- test/test-manager/src/vm/network/linux.rs | 6 ++-- test/test-rpc/Cargo.toml | 1 - test/test-rpc/src/net.rs | 5 ++-- test/test-runner/src/forward.rs | 7 ++--- test/test-runner/src/logging.rs | 4 +-- 55 files changed, 158 insertions(+), 185 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 26f0e8ac3dbd..9e5b30d1af42 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2147,7 +2147,6 @@ dependencies = [ "log", "mullvad-fs", "mullvad-types", - "once_cell", "rustls-pemfile", "serde", "serde_json", @@ -2208,7 +2207,6 @@ dependencies = [ "mullvad-version", "nix 0.23.2", "objc", - "once_cell", "regex", "serde", "serde_json", @@ -2296,7 +2294,6 @@ dependencies = [ "mullvad-paths", "mullvad-types", "nix 0.23.2", - "once_cell", "parity-tokio-ipc", "prost", "prost-types", @@ -2340,7 +2337,6 @@ dependencies = [ "mullvad-api", "mullvad-paths", "mullvad-version", - "once_cell", "regex", "talpid-platform-metadata", "talpid-types", @@ -2361,7 +2357,6 @@ dependencies = [ "itertools 0.12.1", "log", "mullvad-types", - "once_cell", "proptest", "rand 0.8.5", "serde_json", @@ -2381,7 +2376,6 @@ dependencies = [ "mullvad-paths", "mullvad-types", "mullvad-version", - "once_cell", "talpid-core", "talpid-future", "talpid-types", @@ -2399,7 +2393,6 @@ dependencies = [ "intersection-derive", "ipnetwork", "log", - "once_cell", "regex", "serde", "talpid-types", @@ -3931,7 +3924,6 @@ dependencies = [ "dbus", "libc", "log", - "once_cell", "thiserror", "tokio", ] @@ -4025,7 +4017,6 @@ dependencies = [ "netlink-packet-route", "netlink-sys", "nix 0.28.0", - "once_cell", "rtnetlink", "system-configuration", "talpid-types", @@ -4055,7 +4046,6 @@ dependencies = [ "jnix", "log", "nix 0.23.2", - "once_cell", "talpid-routing", "talpid-types", "talpid-windows", @@ -4093,7 +4083,6 @@ dependencies = [ "ipnetwork", "jnix", "log", - "once_cell", "serde", "thiserror", "x25519-dalek", @@ -4466,7 +4455,6 @@ name = "translations-converter" version = "0.0.0" dependencies = [ "htmlize", - "once_cell", "quick-xml", "regex", "serde", diff --git a/Cargo.toml b/Cargo.toml index 1317951f6549..90e8d75f0af4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,7 +83,7 @@ windows-sys = "0.52.0" chrono = { version = "0.4.26", default-features = false } clap = { version = "4.4.18", features = ["cargo", "derive"] } -once_cell = "1.13" +once_cell = "1.16" serde = "1.0.204" serde_json = "1.0.122" diff --git a/android/translations-converter/Cargo.toml b/android/translations-converter/Cargo.toml index 9bf902b17229..67704daf2c0c 100644 --- a/android/translations-converter/Cargo.toml +++ b/android/translations-converter/Cargo.toml @@ -13,7 +13,6 @@ workspace = true [dependencies] thiserror = { workspace = true } htmlize = { version = "1.0.2", features = ["unescape"] } -once_cell = { workspace = true } regex = "1" serde = { workspace = true, features = ["derive"] } quick-xml = { version = "0.27.1", features = ["serialize"] } diff --git a/android/translations-converter/src/android/string_value.rs b/android/translations-converter/src/android/string_value.rs index 9513f3e09642..9a01e9df86af 100644 --- a/android/translations-converter/src/android/string_value.rs +++ b/android/translations-converter/src/android/string_value.rs @@ -1,9 +1,9 @@ -use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Deserializer, Serialize}; use std::{ fmt::{self, Display, Formatter, Write}, ops::Deref, + sync::LazyLock, }; /// An Android string value @@ -32,7 +32,7 @@ impl StringValue { /// The input XML file might have line breaks inside the string, and they should be collapsed /// into a single whitespace character. fn collapse_line_breaks(original: String) -> String { - static LINE_BREAKS: Lazy = Lazy::new(|| Regex::new(r"\s*\n\s*").unwrap()); + static LINE_BREAKS: LazyLock = LazyLock::new(|| Regex::new(r"\s*\n\s*").unwrap()); LINE_BREAKS.replace_all(&original, " ").into_owned() } @@ -43,7 +43,8 @@ impl StringValue { /// would update the string so that all parameters have indices: `Things are %1$d, %3$s and /// %4$s`. fn ensure_parameters_are_indexed(original: String) -> String { - static PARAMETER_INDEX: Lazy = Lazy::new(|| Regex::new(r"^(\d+)\$").unwrap()); + static PARAMETER_INDEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\d+)\$").unwrap()); let mut parts = original.split('%'); let mut output = parts.next().unwrap().to_owned(); diff --git a/android/translations-converter/src/normalize.rs b/android/translations-converter/src/normalize.rs index 1ea0ae94404b..ace645570e04 100644 --- a/android/translations-converter/src/normalize.rs +++ b/android/translations-converter/src/normalize.rs @@ -1,5 +1,5 @@ -use once_cell::sync::Lazy; use regex::Regex; +use std::sync::LazyLock; pub trait Normalize { /// Normalize the string value into a common format. @@ -12,9 +12,9 @@ mod android { use super::*; use crate::android::StringValue; - static APOSTROPHES: Lazy = Lazy::new(|| Regex::new(r"\\'").unwrap()); - static DOUBLE_QUOTES: Lazy = Lazy::new(|| Regex::new(r#"\\""#).unwrap()); - static PARAMETERS: Lazy = Lazy::new(|| Regex::new(r"%[0-9]*\$").unwrap()); + static APOSTROPHES: LazyLock = LazyLock::new(|| Regex::new(r"\\'").unwrap()); + static DOUBLE_QUOTES: LazyLock = LazyLock::new(|| Regex::new(r#"\\""#).unwrap()); + static PARAMETERS: LazyLock = LazyLock::new(|| Regex::new(r"%[0-9]*\$").unwrap()); impl Normalize for StringValue { fn normalize(&self) -> String { @@ -35,9 +35,9 @@ mod gettext { use super::*; use crate::gettext::MsgString; - static ESCAPED_SINGLE_QUOTES: Lazy = Lazy::new(|| Regex::new(r"\\'").unwrap()); - static ESCAPED_DOUBLE_QUOTES: Lazy = Lazy::new(|| Regex::new(r#"\\""#).unwrap()); - static PARAMETERS: Lazy = Lazy::new(|| Regex::new(r"%\([^)]*\)").unwrap()); + static ESCAPED_SINGLE_QUOTES: LazyLock = LazyLock::new(|| Regex::new(r"\\'").unwrap()); + static ESCAPED_DOUBLE_QUOTES: LazyLock = LazyLock::new(|| Regex::new(r#"\\""#).unwrap()); + static PARAMETERS: LazyLock = LazyLock::new(|| Regex::new(r"%\([^)]*\)").unwrap()); impl Normalize for MsgString { fn normalize(&self) -> String { diff --git a/mullvad-api/Cargo.toml b/mullvad-api/Cargo.toml index 10b1cddce1ce..dacb6a79789a 100644 --- a/mullvad-api/Cargo.toml +++ b/mullvad-api/Cargo.toml @@ -29,7 +29,6 @@ tokio = { workspace = true, features = ["macros", "time", "rt-multi-thread", "ne tokio-rustls = "0.24.1" tokio-socks = "0.5.1" rustls-pemfile = "1.0.3" -once_cell = { workspace = true } mullvad-fs = { path = "../mullvad-fs" } mullvad-types = { path = "../mullvad-types" } diff --git a/mullvad-api/src/tls_stream.rs b/mullvad-api/src/tls_stream.rs index 74b6e9b27dce..bf4ff336f567 100644 --- a/mullvad-api/src/tls_stream.rs +++ b/mullvad-api/src/tls_stream.rs @@ -7,7 +7,7 @@ use std::{ }; use hyper::client::connect::{Connected, Connection}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio_rustls::{ rustls::{self, ClientConfig, ServerName}, @@ -25,7 +25,7 @@ where S: AsyncRead + AsyncWrite + Unpin, { pub async fn connect_https(stream: S, domain: &str) -> io::Result> { - static TLS_CONFIG: Lazy> = Lazy::new(|| { + static TLS_CONFIG: LazyLock> = LazyLock::new(|| { let config = ClientConfig::builder() .with_safe_default_cipher_suites() .with_safe_default_kx_groups() diff --git a/mullvad-daemon/Cargo.toml b/mullvad-daemon/Cargo.toml index 0aaa6565eee2..7a231ff69eb8 100644 --- a/mullvad-daemon/Cargo.toml +++ b/mullvad-daemon/Cargo.toml @@ -20,7 +20,6 @@ thiserror = { workspace = true } either = "1.11" fern = { version = "0.6", features = ["colored"] } futures = "0.3" -once_cell = { workspace = true } libc = "0.2" log = { workspace = true } regex = "1.0" diff --git a/mullvad-daemon/src/account_history.rs b/mullvad-daemon/src/account_history.rs index c03a84f0cc8a..09e0f47a38f2 100644 --- a/mullvad-daemon/src/account_history.rs +++ b/mullvad-daemon/src/account_history.rs @@ -1,7 +1,6 @@ use mullvad_types::account::AccountToken; -use once_cell::sync::Lazy; use regex::Regex; -use std::path::Path; +use std::{path::Path, sync::LazyLock}; use talpid_types::ErrorExt; use tokio::{ fs, @@ -32,7 +31,7 @@ pub struct AccountHistory { token: Option, } -static ACCOUNT_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[0-9]+$").unwrap()); +static ACCOUNT_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^[0-9]+$").unwrap()); impl AccountHistory { pub async fn new( diff --git a/mullvad-daemon/src/cli.rs b/mullvad-daemon/src/cli.rs index 4e9824aadaab..d702c443c581 100644 --- a/mullvad-daemon/src/cli.rs +++ b/mullvad-daemon/src/cli.rs @@ -1,7 +1,7 @@ use clap::{Args, Parser}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; -static ENV_DESC: Lazy = Lazy::new(|| { +static ENV_DESC: LazyLock = LazyLock::new(|| { format!( "ENV: @@ -119,7 +119,7 @@ impl From for Command { } pub fn get_config() -> &'static Config { - static CONFIG: Lazy = Lazy::new(create_config); + static CONFIG: LazyLock = LazyLock::new(create_config); &CONFIG } diff --git a/mullvad-daemon/src/geoip.rs b/mullvad-daemon/src/geoip.rs index af7db0cb2b02..da2fb3e8dbbf 100644 --- a/mullvad-daemon/src/geoip.rs +++ b/mullvad-daemon/src/geoip.rs @@ -3,7 +3,7 @@ use std::time::Duration; use futures::join; use mullvad_api::rest::{Error, RequestServiceHandle}; use mullvad_types::location::{AmIMullvad, GeoIpLocation, LocationEventData}; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use talpid_core::mpsc::Sender; use talpid_future::retry::{retry_future, ExponentialBackoff, Jittered}; use talpid_types::ErrorExt; @@ -19,7 +19,7 @@ use crate::{DaemonEventSender, InternalDaemonEvent}; // production build, a warning will be logged and the env variable *won´t* have // any effect on the api call. The default host name `am.i.mullvad.net` will // always be used in release mode. -static MULLVAD_CONNCHECK_HOST: Lazy = Lazy::new(|| { +static MULLVAD_CONNCHECK_HOST: LazyLock = LazyLock::new(|| { const DEFAULT_CONNCHECK_HOST: &str = "am.i.mullvad.net"; let conncheck_host_var = std::env::var("MULLVAD_CONNCHECK_HOST").ok(); let host = if cfg!(feature = "api-override") { diff --git a/mullvad-daemon/src/migrations/account_history.rs b/mullvad-daemon/src/migrations/account_history.rs index fb1691fb75c4..e367ffdce499 100644 --- a/mullvad-daemon/src/migrations/account_history.rs +++ b/mullvad-daemon/src/migrations/account_history.rs @@ -1,9 +1,8 @@ use super::{Error, Result}; use mullvad_types::account::AccountToken; -use once_cell::sync::Lazy; use regex::Regex; use serde::Deserialize; -use std::path::Path; +use std::{path::Path, sync::LazyLock}; use talpid_types::ErrorExt; use tokio::{ fs::{self, File}, @@ -17,7 +16,7 @@ use tokio::{ const ACCOUNT_HISTORY_FILE: &str = "account-history.json"; -static ACCOUNT_REGEX: Lazy = Lazy::new(|| Regex::new(r"^[0-9]+$").unwrap()); +static ACCOUNT_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^[0-9]+$").unwrap()); pub async fn migrate_location(old_dir: &Path, new_dir: &Path) { let old_path = old_dir.join(ACCOUNT_HISTORY_FILE); diff --git a/mullvad-daemon/src/system_service.rs b/mullvad-daemon/src/system_service.rs index a5a76e72b440..ccec49486b55 100644 --- a/mullvad-daemon/src/system_service.rs +++ b/mullvad-daemon/src/system_service.rs @@ -1,13 +1,12 @@ use crate::cli; use mullvad_daemon::{runtime::new_multi_thread, DaemonShutdownHandle}; -use once_cell::sync::Lazy; use std::{ env, ffi::{c_void, OsString}, ptr, slice, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering}, - mpsc, Arc, + mpsc, Arc, LazyLock, }, thread, time::{Duration, Instant}, @@ -39,7 +38,7 @@ static SERVICE_TYPE: ServiceType = ServiceType::OWN_PROCESS; const SERVICE_RECOVERY_LAST_RESTART_DELAY: Duration = Duration::from_secs(60 * 10); const SERVICE_FAILURE_RESET_PERIOD: Duration = Duration::from_secs(60 * 15); -static SERVICE_ACCESS: Lazy = Lazy::new(|| { +static SERVICE_ACCESS: LazyLock = LazyLock::new(|| { ServiceAccess::QUERY_CONFIG | ServiceAccess::CHANGE_CONFIG | ServiceAccess::START diff --git a/mullvad-daemon/src/tunnel.rs b/mullvad-daemon/src/tunnel.rs index 54bee64e7b5c..72ec5087fc8d 100644 --- a/mullvad-daemon/src/tunnel.rs +++ b/mullvad-daemon/src/tunnel.rs @@ -13,7 +13,7 @@ use mullvad_types::{ endpoint::MullvadWireguardEndpoint, location::GeoIpLocation, relay_list::Relay, settings::TunnelOptions, }; -use once_cell::sync::Lazy; +use std::sync::LazyLock; use talpid_core::tunnel_state_machine::TunnelParametersGenerator; #[cfg(not(target_os = "android"))] use talpid_types::net::{ @@ -31,9 +31,9 @@ use crate::device::{AccountManagerHandle, Error as DeviceError, PrivateAccountAn /// "Same IP" functionality. This means all clients have the same in-tunnel IP on these /// servers. This improves anonymity since the in-tunnel IP will not be unique to a specific /// peer. -static SAME_IP_V4: Lazy = - Lazy::new(|| Ipv4Addr::from_str("10.127.255.254").unwrap().into()); -static SAME_IP_V6: Lazy = Lazy::new(|| { +static SAME_IP_V4: LazyLock = + LazyLock::new(|| Ipv4Addr::from_str("10.127.255.254").unwrap().into()); +static SAME_IP_V6: LazyLock = LazyLock::new(|| { Ipv6Addr::from_str("fc00:bbbb:bbbb:bb01:ffff:ffff:ffff:ffff") .unwrap() .into() diff --git a/mullvad-daemon/src/version_check.rs b/mullvad-daemon/src/version_check.rs index d4274ec10d32..4aae30f574d3 100644 --- a/mullvad-daemon/src/version_check.rs +++ b/mullvad-daemon/src/version_check.rs @@ -6,7 +6,6 @@ use futures::{ }; use mullvad_api::{availability::ApiAvailabilityHandle, rest::MullvadRestHandle, AppVersionProxy}; use mullvad_types::version::{AppVersionInfo, ParsedAppVersion}; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; use std::{ cmp::max, @@ -15,6 +14,7 @@ use std::{ path::{Path, PathBuf}, pin::Pin, str::FromStr, + sync::LazyLock, time::{Duration, SystemTime}, }; use talpid_core::mpsc::Sender; @@ -24,9 +24,9 @@ use tokio::{fs::File, io::AsyncReadExt}; const VERSION_INFO_FILENAME: &str = "version-info.json"; -static APP_VERSION: Lazy = - Lazy::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); -static IS_DEV_BUILD: Lazy = Lazy::new(|| APP_VERSION.is_dev()); +static APP_VERSION: LazyLock = + LazyLock::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); +static IS_DEV_BUILD: LazyLock = LazyLock::new(|| APP_VERSION.is_dev()); const DOWNLOAD_TIMEOUT: Duration = Duration::from_secs(15); diff --git a/mullvad-management-interface/Cargo.toml b/mullvad-management-interface/Cargo.toml index 352b1e631c2f..75c6f1b0adc0 100644 --- a/mullvad-management-interface/Cargo.toml +++ b/mullvad-management-interface/Cargo.toml @@ -27,7 +27,6 @@ log = { workspace = true } [target.'cfg(unix)'.dependencies] nix = "0.23" -once_cell = { workspace = true } [build-dependencies] tonic-build = { workspace = true, default-features = false, features = ["transport", "prost"] } diff --git a/mullvad-management-interface/src/lib.rs b/mullvad-management-interface/src/lib.rs index 76564ff3db72..7abe9f761c08 100644 --- a/mullvad-management-interface/src/lib.rs +++ b/mullvad-management-interface/src/lib.rs @@ -24,10 +24,10 @@ pub type ManagementServiceClient = pub use types::management_service_server::{ManagementService, ManagementServiceServer}; #[cfg(unix)] -use once_cell::sync::Lazy; +use std::sync::LazyLock; #[cfg(unix)] -static MULLVAD_MANAGEMENT_SOCKET_GROUP: Lazy> = - Lazy::new(|| env::var("MULLVAD_MANAGEMENT_SOCKET_GROUP").ok()); +static MULLVAD_MANAGEMENT_SOCKET_GROUP: LazyLock> = + LazyLock::new(|| env::var("MULLVAD_MANAGEMENT_SOCKET_GROUP").ok()); pub const CUSTOM_LIST_LIST_NOT_FOUND_DETAILS: &[u8] = b"custom_list_list_not_found"; pub const CUSTOM_LIST_LIST_EXISTS_DETAILS: &[u8] = b"custom_list_list_exists"; diff --git a/mullvad-problem-report/Cargo.toml b/mullvad-problem-report/Cargo.toml index 53cc7a9d51d8..75360267b535 100644 --- a/mullvad-problem-report/Cargo.toml +++ b/mullvad-problem-report/Cargo.toml @@ -13,7 +13,6 @@ workspace = true [dependencies] dirs = "5.0.1" thiserror = { workspace = true } -once_cell = { workspace = true } log = { workspace = true } regex = "1.0" uuid = { version = "1.4.1", features = ["v4"] } diff --git a/mullvad-problem-report/src/lib.rs b/mullvad-problem-report/src/lib.rs index 74076a8b5a7b..270de55f9589 100644 --- a/mullvad-problem-report/src/lib.rs +++ b/mullvad-problem-report/src/lib.rs @@ -1,5 +1,4 @@ use mullvad_api::proxy::ApiConnectionMode; -use once_cell::sync::Lazy; use regex::Regex; use std::{ borrow::Cow, @@ -9,6 +8,7 @@ use std::{ fs::{self, File}, io::{self, BufWriter, Read, Seek, SeekFrom, Write}, path::{Path, PathBuf}, + sync::LazyLock, }; use talpid_types::ErrorExt; @@ -406,7 +406,7 @@ impl ProblemReport { } fn redact_account_number(input: &str) -> Cow<'_, str> { - static RE: Lazy = Lazy::new(|| Regex::new("\\d{16}").unwrap()); + static RE: LazyLock = LazyLock::new(|| Regex::new("\\d{16}").unwrap()); RE.replace_all(input, "[REDACTED ACCOUNT NUMBER]") } @@ -415,7 +415,7 @@ impl ProblemReport { } fn redact_network_info(input: &str) -> Cow<'_, str> { - static RE: Lazy = Lazy::new(|| { + static RE: LazyLock = LazyLock::new(|| { let boundary = "[^0-9a-zA-Z.:]"; let combined_pattern = format!( "(?P^|{})(?:{}|{}|{})", @@ -430,7 +430,7 @@ impl ProblemReport { } fn redact_guids(input: &str) -> Cow<'_, str> { - static RE: Lazy = Lazy::new(|| { + static RE: LazyLock = LazyLock::new(|| { Regex::new(r"(?i)\{?[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}?") .unwrap() }); diff --git a/mullvad-relay-selector/Cargo.toml b/mullvad-relay-selector/Cargo.toml index 7f8436bacb24..c113d401bad4 100644 --- a/mullvad-relay-selector/Cargo.toml +++ b/mullvad-relay-selector/Cargo.toml @@ -16,7 +16,6 @@ thiserror = { workspace = true } ipnetwork = { workspace = true } itertools = "0.12" log = { workspace = true } -once_cell = { workspace = true } rand = "0.8.5" serde_json = { workspace = true } diff --git a/mullvad-relay-selector/src/relay_selector/mod.rs b/mullvad-relay-selector/src/relay_selector/mod.rs index 7ee4d7bcd5a9..6e82252f14c6 100644 --- a/mullvad-relay-selector/src/relay_selector/mod.rs +++ b/mullvad-relay-selector/src/relay_selector/mod.rs @@ -8,12 +8,11 @@ pub mod query; use chrono::{DateTime, Local}; use itertools::Itertools; -use once_cell::sync::Lazy; use query::ObfuscationQuery; use rand::{seq::IteratorRandom, thread_rng}; use std::{ path::Path, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, time::SystemTime, }; @@ -52,7 +51,7 @@ use self::{ /// preferences. See [the documentation on `RelayQuery`][RelayQuery] for further details. /// /// This list should be kept in sync with the expected behavior defined in `docs/relay-selector.md` -pub static RETRY_ORDER: Lazy> = Lazy::new(|| { +pub static RETRY_ORDER: LazyLock> = LazyLock::new(|| { use query::builder::{IpVersion, RelayQueryBuilder}; vec![ // 1 diff --git a/mullvad-relay-selector/tests/relay_selector.rs b/mullvad-relay-selector/tests/relay_selector.rs index 9ee9e7371d99..9e7eb9c31ca7 100644 --- a/mullvad-relay-selector/tests/relay_selector.rs +++ b/mullvad-relay-selector/tests/relay_selector.rs @@ -1,9 +1,9 @@ //! Tests for verifying that the relay selector works as expected. -use once_cell::sync::Lazy; use std::{ collections::HashSet, net::{IpAddr, Ipv4Addr, Ipv6Addr}, + sync::LazyLock, }; use talpid_types::net::{ obfuscation::ObfuscatorConfig, @@ -32,7 +32,7 @@ use mullvad_types::{ }, }; -static RELAYS: Lazy = Lazy::new(|| RelayList { +static RELAYS: LazyLock = LazyLock::new(|| RelayList { etag: None, countries: vec![RelayListCountry { name: "Sweden".to_string(), @@ -185,7 +185,7 @@ static RELAYS: Lazy = Lazy::new(|| RelayList { }); /// A Shadowsocks relay with additional addresses -static SHADOWSOCKS_RELAY: Lazy = Lazy::new(|| Relay { +static SHADOWSOCKS_RELAY: LazyLock = LazyLock::new(|| Relay { hostname: SHADOWSOCKS_RELAY_LOCATION .get_hostname() .unwrap() @@ -212,8 +212,8 @@ const SHADOWSOCKS_RELAY_EXTRA_ADDRS: &[IpAddr; 2] = &[ IpAddr::V4(Ipv4Addr::new(123, 123, 123, 2)), IpAddr::V6(Ipv6Addr::new(0x123, 0, 0, 0, 0, 0, 0, 2)), ]; -static SHADOWSOCKS_RELAY_LOCATION: Lazy = - Lazy::new(|| GeographicLocationConstraint::hostname("se", "got", "se1337-wireguard")); +static SHADOWSOCKS_RELAY_LOCATION: LazyLock = + LazyLock::new(|| GeographicLocationConstraint::hostname("se", "got", "se1337-wireguard")); // Helper functions fn unwrap_relay(get_result: GetRelay) -> Relay { diff --git a/mullvad-setup/Cargo.toml b/mullvad-setup/Cargo.toml index f8a8239f43d0..0b526b8ff6d4 100644 --- a/mullvad-setup/Cargo.toml +++ b/mullvad-setup/Cargo.toml @@ -18,7 +18,6 @@ path = "src/main.rs" clap = { workspace = true } env_logger = { workspace = true } thiserror = { workspace = true } -once_cell = { workspace = true } mullvad-management-interface = { path = "../mullvad-management-interface" } diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs index 34155fbb7195..f937f04e7edf 100644 --- a/mullvad-setup/src/main.rs +++ b/mullvad-setup/src/main.rs @@ -1,6 +1,5 @@ use clap::Parser; -use once_cell::sync::Lazy; -use std::{path::PathBuf, process, str::FromStr, time::Duration}; +use std::{path::PathBuf, process, str::FromStr, sync::LazyLock, time::Duration}; use mullvad_api::{proxy::ApiConnectionMode, DEVICE_NOT_FOUND}; use mullvad_management_interface::MullvadProxyClient; @@ -9,8 +8,8 @@ use talpid_core::firewall::{self, Firewall}; use talpid_future::retry::{retry_future, ConstantInterval}; use talpid_types::ErrorExt; -static APP_VERSION: Lazy = - Lazy::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); +static APP_VERSION: LazyLock = + LazyLock::new(|| ParsedAppVersion::from_str(mullvad_version::VERSION).unwrap()); const DEVICE_REMOVAL_STRATEGY: ConstantInterval = ConstantInterval::new(Duration::ZERO, Some(5)); diff --git a/mullvad-types/Cargo.toml b/mullvad-types/Cargo.toml index 4e53931b302b..adddfef0f555 100644 --- a/mullvad-types/Cargo.toml +++ b/mullvad-types/Cargo.toml @@ -15,7 +15,6 @@ either = "1.11" chrono = { workspace = true, features = ["clock", "serde"] } thiserror = { workspace = true } ipnetwork = { workspace = true } -once_cell = { workspace = true } log = { workspace = true } regex = "1" serde = { workspace = true, features = ["derive"] } diff --git a/mullvad-types/src/auth_failed.rs b/mullvad-types/src/auth_failed.rs index 6c118ff0ebfa..335f8463f334 100644 --- a/mullvad-types/src/auth_failed.rs +++ b/mullvad-types/src/auth_failed.rs @@ -1,5 +1,5 @@ -use once_cell::sync::Lazy; use regex::Regex; +use std::sync::LazyLock; use talpid_types::tunnel::ErrorStateCause; /// Used to parse [`talpid_types::tunnel::ErrorStateCause::AuthFailed`], which may be returned @@ -68,7 +68,7 @@ impl TryFrom<&ErrorStateCause> for AuthFailed { // * "This is not a valid Mullvad account" - human-readable message (ignored). // In the case that the message has preceding whitespace, it will be trimmed. fn parse_string(reason: &str) -> Option<&str> { - static REASON_REGEX: Lazy = Lazy::new(|| Regex::new(r"^\[(\w+)\]\s*").unwrap()); + static REASON_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^\[(\w+)\]\s*").unwrap()); let captures = REASON_REGEX.captures(reason)?; captures.get(1).map(|m| m.as_str()) } diff --git a/mullvad-types/src/version.rs b/mullvad-types/src/version.rs index 682070735add..1ca578514787 100644 --- a/mullvad-types/src/version.rs +++ b/mullvad-types/src/version.rs @@ -1,16 +1,17 @@ -use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; use std::{ cmp::Ordering, fmt::{self, Formatter}, str::FromStr, + sync::LazyLock, }; -static STABLE_REGEX: Lazy = Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)$").unwrap()); -static BETA_REGEX: Lazy = Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)-beta(\d+)$").unwrap()); -static DEV_REGEX: Lazy = - Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)(\.\d+)?(-beta(\d+))?-dev-(\w+)$").unwrap()); +static STABLE_REGEX: LazyLock = LazyLock::new(|| Regex::new(r"^(\d{4})\.(\d+)$").unwrap()); +static BETA_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\d{4})\.(\d+)-beta(\d+)$").unwrap()); +static DEV_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"^(\d{4})\.(\d+)(\.\d+)?(-beta(\d+))?-dev-(\w+)$").unwrap()); /// AppVersionInfo represents the current stable and the current latest release versions of the /// Mullvad VPN app. diff --git a/talpid-core/Cargo.toml b/talpid-core/Cargo.toml index 20b69e8afca6..be8d6ca39b20 100644 --- a/talpid-core/Cargo.toml +++ b/talpid-core/Cargo.toml @@ -17,7 +17,6 @@ futures = "0.3.15" ipnetwork = { workspace = true } libc = "0.2" log = { workspace = true } -once_cell = { workspace = true } parking_lot = "0.12.0" rand = "0.8.5" talpid-routing = { path = "../talpid-routing" } @@ -67,6 +66,7 @@ bitflags = "1.2" widestring = "1.0" winreg = { version = "0.51", features = ["transactions"] } memoffset = "0.6" +once_cell = { workspace = true } windows-service = "0.6.0" talpid-windows = { path = "../talpid-windows" } diff --git a/talpid-core/src/firewall/linux.rs b/talpid-core/src/firewall/linux.rs index accac083c327..c226b803e69d 100644 --- a/talpid-core/src/firewall/linux.rs +++ b/talpid-core/src/firewall/linux.rs @@ -5,12 +5,12 @@ use nftnl::{ expr::{self, IcmpCode, Payload, RejectionType, Verdict}, nft_expr, table, Batch, Chain, FinalizedBatch, ProtoFamily, Rule, Table, }; -use once_cell::sync::Lazy; use std::{ env, ffi::{CStr, CString}, fs, io, net::{IpAddr, Ipv4Addr}, + sync::LazyLock, }; use talpid_types::net::{ AllowedEndpoint, AllowedTunnelTraffic, Endpoint, TransportProtocol, ALLOWED_LAN_MULTICAST_NETS, @@ -55,23 +55,24 @@ pub enum Error { /// TODO(linus): This crate is not supposed to be Mullvad-aware. So at some point this should be /// replaced by allowing the table name to be configured from the public API of this crate. -static TABLE_NAME: Lazy = Lazy::new(|| CString::new("mullvad").unwrap()); -static IN_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("input").unwrap()); -static OUT_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("output").unwrap()); -static FORWARD_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("forward").unwrap()); -static PREROUTING_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("prerouting").unwrap()); -static MANGLE_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("mangle").unwrap()); -static NAT_CHAIN_NAME: Lazy = Lazy::new(|| CString::new("nat").unwrap()); +static TABLE_NAME: LazyLock = LazyLock::new(|| CString::new("mullvad").unwrap()); +static IN_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("input").unwrap()); +static OUT_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("output").unwrap()); +static FORWARD_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("forward").unwrap()); +static PREROUTING_CHAIN_NAME: LazyLock = + LazyLock::new(|| CString::new("prerouting").unwrap()); +static MANGLE_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("mangle").unwrap()); +static NAT_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("nat").unwrap()); /// Allows controlling whether firewall rules should have packet counters or not from an env /// variable. Useful for debugging the rules. -static ADD_COUNTERS: Lazy = Lazy::new(|| { +static ADD_COUNTERS: LazyLock = LazyLock::new(|| { env::var("TALPID_FIREWALL_DEBUG") .map(|v| v != "0") .unwrap_or(false) }); -static DONT_SET_SRC_VALID_MARK: Lazy = Lazy::new(|| { +static DONT_SET_SRC_VALID_MARK: LazyLock = LazyLock::new(|| { env::var("TALPID_FIREWALL_DONT_SET_SRC_VALID_MARK") .map(|v| v != "0") .unwrap_or(false) @@ -1066,10 +1067,10 @@ fn set_src_valid_mark_sysctl() -> io::Result<()> { /// Tables that are no longer used but need to be deleted due to upgrades. /// This can be removed when upgrades from 2023.3 are no longer supported. fn batch_deprecated_tables(batch: &mut Batch) { - static MANGLE_TABLE_NAME_V4: Lazy = - Lazy::new(|| CString::new("mullvadmangle4").unwrap()); - static MANGLE_TABLE_NAME_V6: Lazy = - Lazy::new(|| CString::new("mullvadmangle6").unwrap()); + static MANGLE_TABLE_NAME_V4: LazyLock = + LazyLock::new(|| CString::new("mullvadmangle4").unwrap()); + static MANGLE_TABLE_NAME_V6: LazyLock = + LazyLock::new(|| CString::new("mullvadmangle6").unwrap()); let tables = [ Table::new(&*MANGLE_TABLE_NAME_V4, ProtoFamily::Ipv4), Table::new(&*MANGLE_TABLE_NAME_V6, ProtoFamily::Ipv6), diff --git a/talpid-core/src/firewall/mod.rs b/talpid-core/src/firewall/mod.rs index 1ef8fd7af701..c9c351bb590d 100644 --- a/talpid-core/src/firewall/mod.rs +++ b/talpid-core/src/firewall/mod.rs @@ -1,8 +1,8 @@ use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; -use once_cell::sync::Lazy; use std::{ fmt, net::{IpAddr, Ipv4Addr, Ipv6Addr}, + sync::LazyLock, }; use talpid_types::net::{AllowedEndpoint, AllowedTunnelTraffic, ALLOWED_LAN_NETS}; @@ -25,23 +25,24 @@ mod imp; pub use self::imp::Error; #[cfg(any(target_os = "linux", target_os = "macos"))] -static IPV6_LINK_LOCAL: Lazy = - Lazy::new(|| Ipv6Network::new(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0), 10).unwrap()); +static IPV6_LINK_LOCAL: LazyLock = + LazyLock::new(|| Ipv6Network::new(Ipv6Addr::new(0xfe80, 0, 0, 0, 0, 0, 0, 0), 10).unwrap()); /// The allowed target addresses of outbound DHCPv6 requests #[cfg(any(target_os = "linux", target_os = "macos"))] -static DHCPV6_SERVER_ADDRS: Lazy<[Ipv6Addr; 2]> = Lazy::new(|| { +static DHCPV6_SERVER_ADDRS: LazyLock<[Ipv6Addr; 2]> = LazyLock::new(|| { [ Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 1, 2), Ipv6Addr::new(0xff05, 0, 0, 0, 0, 0, 1, 3), ] }); #[cfg(any(target_os = "linux", target_os = "macos"))] -static ROUTER_SOLICITATION_OUT_DST_ADDR: Lazy = - Lazy::new(|| Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 0, 2)); +static ROUTER_SOLICITATION_OUT_DST_ADDR: LazyLock = + LazyLock::new(|| Ipv6Addr::new(0xff02, 0, 0, 0, 0, 0, 0, 2)); #[cfg(any(target_os = "linux", target_os = "macos"))] -static SOLICITED_NODE_MULTICAST: Lazy = - Lazy::new(|| Ipv6Network::new(Ipv6Addr::new(0xff02, 0, 0, 0, 0, 1, 0xFF00, 0), 104).unwrap()); -static LOOPBACK_NETS: Lazy<[IpNetwork; 2]> = Lazy::new(|| { +static SOLICITED_NODE_MULTICAST: LazyLock = LazyLock::new(|| { + Ipv6Network::new(Ipv6Addr::new(0xff02, 0, 0, 0, 0, 1, 0xFF00, 0), 104).unwrap() +}); +static LOOPBACK_NETS: LazyLock<[IpNetwork; 2]> = LazyLock::new(|| { [ IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(127, 0, 0, 0), 8).unwrap()), IpNetwork::V6(Ipv6Network::new(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1), 128).unwrap()), diff --git a/talpid-core/src/offline/mod.rs b/talpid-core/src/offline/mod.rs index cb3d1d8b29ed..0e1d55c27375 100644 --- a/talpid-core/src/offline/mod.rs +++ b/talpid-core/src/offline/mod.rs @@ -1,5 +1,5 @@ use futures::channel::mpsc::UnboundedSender; -use once_cell::sync::Lazy; +use std::sync::LazyLock; #[cfg(not(target_os = "android"))] use talpid_routing::RouteManagerHandle; #[cfg(target_os = "android")] @@ -23,7 +23,7 @@ mod imp; mod imp; /// Disables offline monitor -static FORCE_DISABLE_OFFLINE_MONITOR: Lazy = Lazy::new(|| { +static FORCE_DISABLE_OFFLINE_MONITOR: LazyLock = LazyLock::new(|| { std::env::var("TALPID_DISABLE_OFFLINE_MONITOR") .map(|v| v != "0") .unwrap_or(false) diff --git a/talpid-core/src/resolver.rs b/talpid-core/src/resolver.rs index 30942d34fecc..97f1f4b79c00 100644 --- a/talpid-core/src/resolver.rs +++ b/talpid-core/src/resolver.rs @@ -28,12 +28,12 @@ use hickory_server::{ server::{Request, RequestHandler, ResponseHandler, ResponseInfo}, ServerFuture, }; -use once_cell::sync::Lazy; +use std::sync::LazyLock; const ALLOWED_RECORD_TYPES: &[RecordType] = &[RecordType::A, RecordType::CNAME]; const CAPTIVE_PORTAL_DOMAINS: &[&str] = &["captive.apple.com", "netcts.cdn-apple.com"]; -static ALLOWED_DOMAINS: Lazy> = Lazy::new(|| { +static ALLOWED_DOMAINS: LazyLock> = LazyLock::new(|| { CAPTIVE_PORTAL_DOMAINS .iter() .map(|domain| LowerName::from(Name::from_str(domain).unwrap())) diff --git a/talpid-core/src/split_tunnel/macos/process.rs b/talpid-core/src/split_tunnel/macos/process.rs index b5db9ac7081c..52e0fb1862b0 100644 --- a/talpid-core/src/split_tunnel/macos/process.rs +++ b/talpid-core/src/split_tunnel/macos/process.rs @@ -7,7 +7,6 @@ use futures::channel::oneshot; use libc::{proc_listallpids, proc_pidpath}; -use once_cell::sync::Lazy; use serde::Deserialize; use std::{ collections::{HashMap, HashSet}, @@ -16,7 +15,7 @@ use std::{ path::PathBuf, process::Stdio, ptr, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, time::Duration, }; use talpid_platform_metadata::MacosVersion; @@ -26,8 +25,8 @@ use tokio::io::{AsyncBufReadExt, BufReader}; const SHUTDOWN_TIMEOUT: Duration = Duration::from_secs(3); const EARLY_FAIL_TIMEOUT: Duration = Duration::from_millis(500); -static MIN_OS_VERSION: Lazy = - Lazy::new(|| MacosVersion::from_raw_version("13.0.0").unwrap()); +static MIN_OS_VERSION: LazyLock = + LazyLock::new(|| MacosVersion::from_raw_version("13.0.0").unwrap()); #[derive(thiserror::Error, Debug)] pub enum Error { diff --git a/talpid-dbus/Cargo.toml b/talpid-dbus/Cargo.toml index b81af1360220..4e5880bdb818 100644 --- a/talpid-dbus/Cargo.toml +++ b/talpid-dbus/Cargo.toml @@ -12,7 +12,6 @@ workspace = true [target.'cfg(target_os = "linux")'.dependencies] dbus = "0.9" thiserror = { workspace = true } -once_cell = { workspace = true } log = { workspace = true } libc = "0.2" tokio = { workspace = true, features = ["rt"] } diff --git a/talpid-dbus/src/lib.rs b/talpid-dbus/src/lib.rs index d077c245e57d..e2c8a64d709a 100644 --- a/talpid-dbus/src/lib.rs +++ b/talpid-dbus/src/lib.rs @@ -2,13 +2,13 @@ //! DBus system connection pub use dbus; use dbus::blocking::SyncConnection; -use once_cell::sync::Lazy; -use std::sync::{Arc, Mutex}; +use std::sync::{Arc, LazyLock, Mutex}; pub mod network_manager; pub mod systemd; pub mod systemd_resolved; -static DBUS_CONNECTION: Lazy>>> = Lazy::new(|| Mutex::new(None)); +static DBUS_CONNECTION: LazyLock>>> = + LazyLock::new(|| Mutex::new(None)); /// Reuse or create a system DBus connection. pub fn get_connection() -> Result, dbus::Error> { diff --git a/talpid-dbus/src/systemd_resolved.rs b/talpid-dbus/src/systemd_resolved.rs index 31e24008df6f..b678d5bf20a6 100644 --- a/talpid-dbus/src/systemd_resolved.rs +++ b/talpid-dbus/src/systemd_resolved.rs @@ -7,8 +7,13 @@ use dbus::{ message::{MatchRule, SignalArgs}, }; use libc::{AF_INET, AF_INET6}; -use once_cell::sync::Lazy; -use std::{fs, io, net::IpAddr, path::Path, sync::Arc, time::Duration}; +use std::{ + fs, io, + net::IpAddr, + path::Path, + sync::{Arc, LazyLock}, + time::Duration, +}; pub type Result = std::result::Result; @@ -57,7 +62,7 @@ pub enum Error { AsyncTaskError(#[source] tokio::task::JoinError), } -static RESOLVED_STUB_PATHS: Lazy> = Lazy::new(|| { +static RESOLVED_STUB_PATHS: LazyLock> = LazyLock::new(|| { vec![ Path::new("/run/systemd/resolve/stub-resolv.conf"), Path::new("/run/systemd/resolve/resolv.conf"), diff --git a/talpid-openvpn/Cargo.toml b/talpid-openvpn/Cargo.toml index dcdbfafdac4d..4450d56a039d 100644 --- a/talpid-openvpn/Cargo.toml +++ b/talpid-openvpn/Cargo.toml @@ -14,7 +14,6 @@ workspace = true async-trait = "0.1" thiserror = { workspace = true } futures = "0.3.15" -once_cell = { workspace = true } log = { workspace = true } shell-escape = "0.1" talpid-routing = { path = "../talpid-routing" } @@ -34,6 +33,7 @@ prost = { workspace = true } widestring = "1.0" winreg = { version = "0.51", features = ["transactions"] } talpid-windows = { path = "../talpid-windows" } +once_cell = { workspace = true } [target.'cfg(windows)'.dependencies.windows-sys] workspace = true diff --git a/talpid-openvpn/src/lib.rs b/talpid-openvpn/src/lib.rs index d665c54c5d33..f9d9393994e7 100644 --- a/talpid-openvpn/src/lib.rs +++ b/talpid-openvpn/src/lib.rs @@ -3,11 +3,11 @@ #![deny(missing_docs)] use crate::proxy::ProxyMonitor; -#[cfg(windows)] -use once_cell::sync::Lazy; use process::openvpn::{OpenVpnCommand, OpenVpnProcHandle}; #[cfg(target_os = "linux")] use std::collections::{HashMap, HashSet}; +#[cfg(windows)] +use std::sync::LazyLock; #[cfg(target_os = "windows")] use std::{ffi::OsString, sync::Arc}; use std::{ @@ -39,10 +39,11 @@ mod process; mod proxy; #[cfg(windows)] -static ADAPTER_ALIAS: Lazy = Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_ALIAS: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); #[cfg(windows)] -static ADAPTER_TUNNEL_TYPE: Lazy = - Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_TUNNEL_TYPE: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); #[cfg(windows)] const ADAPTER_GUID: GUID = GUID { diff --git a/talpid-routing/Cargo.toml b/talpid-routing/Cargo.toml index 94e9b3cc8f49..2c8b99a00b09 100644 --- a/talpid-routing/Cargo.toml +++ b/talpid-routing/Cargo.toml @@ -22,7 +22,6 @@ talpid-types = { path = "../talpid-types" } [target.'cfg(target_os = "linux")'.dependencies] libc = "0.2" -once_cell = { workspace = true } rtnetlink = "0.11" netlink-packet-route = { version = "0.13", features = ["rich_nlas"] } netlink-sys = "0.8.3" diff --git a/talpid-routing/src/unix/linux.rs b/talpid-routing/src/unix/linux.rs index 785105ad56fa..92b4513301d3 100644 --- a/talpid-routing/src/unix/linux.rs +++ b/talpid-routing/src/unix/linux.rs @@ -31,14 +31,14 @@ use netlink_packet_route::{ rule::{nlas::Nla as RuleNla, RuleHeader, RuleMessage}, NetlinkMessage, NetlinkPayload, RtnlMessage, }; -use once_cell::sync::Lazy; use rtnetlink::{ constants::{RTMGRP_IPV4_ROUTE, RTMGRP_IPV6_ROUTE, RTMGRP_LINK, RTMGRP_NOTIFY}, sys::SocketAddr, Handle, IpVersion, }; +use std::sync::LazyLock; -static SUPPRESS_RULE_V4: Lazy = Lazy::new(|| RuleMessage { +static SUPPRESS_RULE_V4: LazyLock = LazyLock::new(|| RuleMessage { header: RuleHeader { family: AF_INET as u8, action: FR_ACT_TO_TBL, @@ -49,7 +49,7 @@ static SUPPRESS_RULE_V4: Lazy = Lazy::new(|| RuleMessage { RuleNla::Table(RT_TABLE_MAIN as u32), ], }); -static SUPPRESS_RULE_V6: Lazy = Lazy::new(|| { +static SUPPRESS_RULE_V6: LazyLock = LazyLock::new(|| { let mut v6_rule = SUPPRESS_RULE_V4.clone(); v6_rule.header.family = AF_INET6 as u8; v6_rule diff --git a/talpid-tunnel/Cargo.toml b/talpid-tunnel/Cargo.toml index d452b2c20fa1..21312912f4eb 100644 --- a/talpid-tunnel/Cargo.toml +++ b/talpid-tunnel/Cargo.toml @@ -11,7 +11,6 @@ rust-version.workspace = true workspace = true [dependencies] -once_cell = { workspace = true } thiserror = { workspace = true } cfg-if = "1.0" ipnetwork = { workspace = true } diff --git a/talpid-tunnel/src/tun_provider/mod.rs b/talpid-tunnel/src/tun_provider/mod.rs index 20497ab1bb41..4eca1c32455e 100644 --- a/talpid-tunnel/src/tun_provider/mod.rs +++ b/talpid-tunnel/src/tun_provider/mod.rs @@ -1,7 +1,9 @@ use cfg_if::cfg_if; use ipnetwork::IpNetwork; -use once_cell::sync::Lazy; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::{ + net::{IpAddr, Ipv4Addr, Ipv6Addr}, + sync::LazyLock, +}; cfg_if! { if #[cfg(target_os = "android")] { @@ -85,13 +87,13 @@ pub fn blocking_config() -> TunConfig { } } -static DEFAULT_ROUTES: Lazy> = - Lazy::new(|| vec![*IPV4_DEFAULT_ROUTE, *IPV6_DEFAULT_ROUTE]); -static IPV4_DEFAULT_ROUTE: Lazy = Lazy::new(|| { +static DEFAULT_ROUTES: LazyLock> = + LazyLock::new(|| vec![*IPV4_DEFAULT_ROUTE, *IPV6_DEFAULT_ROUTE]); +static IPV4_DEFAULT_ROUTE: LazyLock = LazyLock::new(|| { IpNetwork::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0) .expect("Invalid IP network prefix for IPv4 address") }); -static IPV6_DEFAULT_ROUTE: Lazy = Lazy::new(|| { +static IPV6_DEFAULT_ROUTE: LazyLock = LazyLock::new(|| { IpNetwork::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 0) .expect("Invalid IP network prefix for IPv6 address") }); diff --git a/talpid-types/Cargo.toml b/talpid-types/Cargo.toml index ffca93f1a848..d6e9ddc69f7c 100644 --- a/talpid-types/Cargo.toml +++ b/talpid-types/Cargo.toml @@ -12,7 +12,6 @@ workspace = true [dependencies] serde = { workspace = true, features = ["derive"] } -once_cell = { workspace = true } ipnetwork = { workspace = true } base64 = "0.22.0" x25519-dalek = { version = "2.0.1", features = ["static_secrets", "zeroize", "getrandom"] } diff --git a/talpid-types/src/net/mod.rs b/talpid-types/src/net/mod.rs index 5875f3348201..1ec8ba46c574 100644 --- a/talpid-types/src/net/mod.rs +++ b/talpid-types/src/net/mod.rs @@ -1,6 +1,5 @@ use ipnetwork::{IpNetwork, Ipv4Network, Ipv6Network}; use obfuscation::ObfuscatorConfig; -use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; #[cfg(windows)] use std::path::PathBuf; @@ -8,6 +7,7 @@ use std::{ fmt, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, str::FromStr, + sync::LazyLock, }; use self::proxy::{CustomProxy, Socks5Local}; @@ -18,7 +18,7 @@ pub mod proxy; pub mod wireguard; /// When "allow local network" is enabled the app will allow traffic to and from these networks. -pub static ALLOWED_LAN_NETS: Lazy<[IpNetwork; 6]> = Lazy::new(|| { +pub static ALLOWED_LAN_NETS: LazyLock<[IpNetwork; 6]> = LazyLock::new(|| { [ IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(10, 0, 0, 0), 8).unwrap()), IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(172, 16, 0, 0), 12).unwrap()), @@ -28,9 +28,8 @@ pub static ALLOWED_LAN_NETS: Lazy<[IpNetwork; 6]> = Lazy::new(|| { IpNetwork::V6(Ipv6Network::new(Ipv6Addr::new(0xfc00, 0, 0, 0, 0, 0, 0, 0), 7).unwrap()), ] }); - /// When "allow local network" is enabled the app will allow traffic to these networks. -pub static ALLOWED_LAN_MULTICAST_NETS: Lazy<[IpNetwork; 8]> = Lazy::new(|| { +pub static ALLOWED_LAN_MULTICAST_NETS: LazyLock<[IpNetwork; 8]> = LazyLock::new(|| { [ // Local network broadcast. Not routable IpNetwork::V4(Ipv4Network::new(Ipv4Addr::new(255, 255, 255, 255), 32).unwrap()), diff --git a/talpid-wireguard/src/lib.rs b/talpid-wireguard/src/lib.rs index ca59e014ff54..0ab83b326236 100644 --- a/talpid-wireguard/src/lib.rs +++ b/talpid-wireguard/src/lib.rs @@ -6,12 +6,8 @@ use self::config::Config; #[cfg(windows)] use futures::channel::mpsc; use futures::future::{BoxFuture, Future}; -#[cfg(target_os = "linux")] -use once_cell::sync::Lazy; #[cfg(target_os = "android")] use std::borrow::Cow; -#[cfg(target_os = "linux")] -use std::env; #[cfg(windows)] use std::io; use std::{ @@ -22,6 +18,8 @@ use std::{ sync::{mpsc as sync_mpsc, Arc, Mutex}, time::Duration, }; +#[cfg(target_os = "linux")] +use std::{env, sync::LazyLock}; use talpid_routing as routing; use talpid_routing::{self, RequiredRoute}; #[cfg(not(windows))] @@ -192,7 +190,7 @@ impl Drop for ObfuscatorHandle { #[cfg(target_os = "linux")] /// Overrides the preference for the kernel module for WireGuard. -static FORCE_USERSPACE_WIREGUARD: Lazy = Lazy::new(|| { +static FORCE_USERSPACE_WIREGUARD: LazyLock = LazyLock::new(|| { env::var("TALPID_FORCE_USERSPACE_WIREGUARD") .map(|v| v != "0") .unwrap_or(false) diff --git a/talpid-wireguard/src/logging.rs b/talpid-wireguard/src/logging.rs index a4d8c7f240b8..dcb33b11e303 100644 --- a/talpid-wireguard/src/logging.rs +++ b/talpid-wireguard/src/logging.rs @@ -1,8 +1,7 @@ -use once_cell::sync::Lazy; use parking_lot::Mutex; -use std::{collections::HashMap, fmt, fs, io::Write, path::Path}; +use std::{collections::HashMap, fmt, fs, io::Write, path::Path, sync::LazyLock}; -static LOG_MUTEX: Lazy> = Lazy::new(|| Mutex::new(LogState::default())); +static LOG_MUTEX: LazyLock> = LazyLock::new(|| Mutex::new(LogState::default())); #[derive(Default)] struct LogState { diff --git a/talpid-wireguard/src/wireguard_nt/mod.rs b/talpid-wireguard/src/wireguard_nt/mod.rs index 254c503dcff8..35937bcb8c24 100644 --- a/talpid-wireguard/src/wireguard_nt/mod.rs +++ b/talpid-wireguard/src/wireguard_nt/mod.rs @@ -7,7 +7,7 @@ use super::{ use bitflags::bitflags; use futures::SinkExt; use ipnetwork::IpNetwork; -use once_cell::sync::{Lazy, OnceCell}; +use once_cell::sync::OnceCell; #[cfg(daita)] use std::{ffi::c_uchar, path::PathBuf}; use std::{ @@ -21,7 +21,7 @@ use std::{ path::Path, pin::Pin, ptr, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, }; use talpid_types::{BoxedError, ErrorExt}; use talpid_windows::net; @@ -42,8 +42,10 @@ use windows_sys::{ mod daita; static WG_NT_DLL: OnceCell = OnceCell::new(); -static ADAPTER_TYPE: Lazy = Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); -static ADAPTER_ALIAS: Lazy = Lazy::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_TYPE: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); +static ADAPTER_ALIAS: LazyLock = + LazyLock::new(|| U16CString::from_str("Mullvad").unwrap()); const ADAPTER_GUID: GUID = GUID { data1: 0x514a3988, @@ -553,7 +555,7 @@ impl Drop for WgNtTunnel { } } -static LOG_CONTEXT: Lazy>> = Lazy::new(|| Mutex::new(None)); +static LOG_CONTEXT: LazyLock>> = LazyLock::new(|| Mutex::new(None)); struct LoggerHandle { dll: &'static WgNtDll, @@ -1159,11 +1161,11 @@ mod tests { p0_allowed_ip_0: WgAllowedIp, } - static WG_PRIVATE_KEY: Lazy = - Lazy::new(wireguard::PrivateKey::new_from_random); - static WG_PUBLIC_KEY: Lazy = - Lazy::new(|| wireguard::PrivateKey::new_from_random().public_key()); - static WG_CONFIG: Lazy = Lazy::new(|| Config { + static WG_PRIVATE_KEY: LazyLock = + LazyLock::new(wireguard::PrivateKey::new_from_random); + static WG_PUBLIC_KEY: LazyLock = + LazyLock::new(|| wireguard::PrivateKey::new_from_random().public_key()); + static WG_CONFIG: LazyLock = LazyLock::new(|| Config { tunnel: wireguard::TunnelConfig { private_key: WG_PRIVATE_KEY.clone(), addresses: vec![], @@ -1185,7 +1187,7 @@ mod tests { quantum_resistant: false, }); - static WG_STRUCT_CONFIG: Lazy = Lazy::new(|| Interface { + static WG_STRUCT_CONFIG: LazyLock = LazyLock::new(|| Interface { interface: WgInterface { flags: WgInterfaceFlag::HAS_PRIVATE_KEY | WgInterfaceFlag::REPLACE_PEERS, listen_port: 0, diff --git a/test/Cargo.lock b/test/Cargo.lock index 998176ab5a14..66b1924b74d8 100644 --- a/test/Cargo.lock +++ b/test/Cargo.lock @@ -1838,7 +1838,6 @@ dependencies = [ "log", "mullvad-fs", "mullvad-types", - "once_cell", "rustls-pemfile 1.0.4", "serde", "serde_json", @@ -1872,7 +1871,6 @@ dependencies = [ "mullvad-paths", "mullvad-types", "nix 0.23.2", - "once_cell", "parity-tokio-ipc", "prost", "prost-types", @@ -1905,7 +1903,6 @@ dependencies = [ "itertools 0.12.1", "log", "mullvad-types", - "once_cell", "rand 0.8.5", "serde_json", "talpid-types", @@ -1921,7 +1918,6 @@ dependencies = [ "intersection-derive", "ipnetwork", "log", - "once_cell", "regex", "serde", "talpid-types", @@ -3222,7 +3218,6 @@ dependencies = [ "ipnetwork", "jnix", "log", - "once_cell", "serde", "thiserror", "x25519-dalek", @@ -3349,7 +3344,6 @@ dependencies = [ "hyper", "hyper-rustls", "log", - "once_cell", "rustls-pemfile 0.2.1", "serde", "serde_json", diff --git a/test/test-manager/src/logging.rs b/test/test-manager/src/logging.rs index 7484c7833d5b..ce7477cd69e9 100644 --- a/test/test-manager/src/logging.rs +++ b/test/test-manager/src/logging.rs @@ -26,7 +26,7 @@ struct StoredRecord { impl Logger { pub fn get_or_init() -> Self { - static LOGGER: once_cell::sync::Lazy = once_cell::sync::Lazy::new(|| { + static LOGGER: std::sync::LazyLock = std::sync::LazyLock::new(|| { let mut logger = env_logger::Builder::new(); logger.filter_module("h2", log::LevelFilter::Info); logger.filter_module("tower", log::LevelFilter::Info); diff --git a/test/test-manager/src/package.rs b/test/test-manager/src/package.rs index c644d60b72e8..295557907e19 100644 --- a/test/test-manager/src/package.rs +++ b/test/test-manager/src/package.rs @@ -1,9 +1,11 @@ use crate::config::{Architecture, OsType, PackageType, VmConfig}; use anyhow::{Context, Result}; use itertools::Itertools; -use once_cell::sync::Lazy; use regex::Regex; -use std::path::{Path, PathBuf}; +use std::{ + path::{Path, PathBuf}, + sync::LazyLock, +}; #[derive(Debug, Clone)] pub struct Manifest { @@ -70,8 +72,8 @@ pub fn get_app_manifest( } pub fn get_version_from_path(app_package_path: &Path) -> Result { - static VERSION_REGEX: Lazy = - Lazy::new(|| Regex::new(r"\d{4}\.\d+((-beta\d+)?(-dev)?-([0-9a-z])+)?").unwrap()); + static VERSION_REGEX: LazyLock = + LazyLock::new(|| Regex::new(r"\d{4}\.\d+((-beta\d+)?(-dev)?-([0-9a-z])+)?").unwrap()); VERSION_REGEX .captures(app_package_path.to_str().unwrap()) diff --git a/test/test-manager/src/vm/network/linux.rs b/test/test-manager/src/vm/network/linux.rs index 34e8438b92fd..f81131119cea 100644 --- a/test/test-manager/src/vm/network/linux.rs +++ b/test/test-manager/src/vm/network/linux.rs @@ -1,11 +1,11 @@ use ipnetwork::Ipv4Network; -use once_cell::sync::Lazy; use std::{ ffi::OsStr, io, net::{IpAddr, Ipv4Addr}, process::Stdio, str::FromStr, + sync::LazyLock, }; use tokio::{ io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, @@ -13,8 +13,8 @@ use tokio::{ }; /// (Contained) test subnet for the test runner: 172.29.1.1/24 -pub static TEST_SUBNET: Lazy = - Lazy::new(|| Ipv4Network::new(Ipv4Addr::new(172, 29, 1, 1), 24).unwrap()); +pub static TEST_SUBNET: LazyLock = + LazyLock::new(|| Ipv4Network::new(Ipv4Addr::new(172, 29, 1, 1), 24).unwrap()); /// Range of IPs returned by the DNS server: TEST_SUBNET_DHCP_FIRST to TEST_SUBNET_DHCP_LAST pub const TEST_SUBNET_DHCP_FIRST: Ipv4Addr = Ipv4Addr::new(172, 29, 1, 2); /// Range of IPs returned by the DNS server: TEST_SUBNET_DHCP_FIRST to TEST_SUBNET_DHCP_LAST diff --git a/test/test-rpc/Cargo.toml b/test/test-rpc/Cargo.toml index 24596a09afde..c39a2a19756a 100644 --- a/test/test-rpc/Cargo.toml +++ b/test/test-rpc/Cargo.toml @@ -17,7 +17,6 @@ tokio-serde = { workspace = true } tarpc = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } -once_cell = { workspace = true } bytes = { workspace = true } thiserror = { workspace = true } log = { workspace = true } diff --git a/test/test-rpc/src/net.rs b/test/test-rpc/src/net.rs index 124b4f9ad36f..c867ccf0d0e1 100644 --- a/test/test-rpc/src/net.rs +++ b/test/test-rpc/src/net.rs @@ -1,15 +1,14 @@ use futures::channel::oneshot; use hyper::{Client, Uri}; -use once_cell::sync::Lazy; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use std::{net::SocketAddr, time::Duration}; +use std::{net::SocketAddr, sync::LazyLock, time::Duration}; use tokio_rustls::rustls::ClientConfig; use crate::{AmIMullvad, Error}; const LE_ROOT_CERT: &[u8] = include_bytes!("../../../mullvad-api/le_root_cert.pem"); -static CLIENT_CONFIG: Lazy = Lazy::new(|| { +static CLIENT_CONFIG: LazyLock = LazyLock::new(|| { ClientConfig::builder() .with_safe_default_cipher_suites() .with_safe_default_kx_groups() diff --git a/test/test-runner/src/forward.rs b/test/test-runner/src/forward.rs index a4c80ae18900..01b48e647a00 100644 --- a/test/test-runner/src/forward.rs +++ b/test/test-runner/src/forward.rs @@ -1,17 +1,16 @@ -use once_cell::sync::Lazy; use std::{ collections::HashMap, net::SocketAddr, sync::{ atomic::{AtomicUsize, Ordering}, - Arc, Mutex, + Arc, LazyLock, Mutex, }, }; use test_rpc::net::SockHandleId; use tokio::net::{TcpListener, TcpStream}; -static SERVERS: Lazy>> = - Lazy::new(|| Mutex::new(HashMap::new())); +static SERVERS: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::new())); /// Spawn a TCP forwarder that sends TCP via `via_addr` pub async fn start_server( diff --git a/test/test-runner/src/logging.rs b/test/test-runner/src/logging.rs index ffe21de9855b..2fb893900278 100644 --- a/test/test-runner/src/logging.rs +++ b/test/test-runner/src/logging.rs @@ -1,8 +1,8 @@ use log::{Level, LevelFilter, Metadata, Record, SetLoggerError}; -use once_cell::sync::Lazy; use std::{ ffi::OsStr, path::{Path, PathBuf}, + sync::LazyLock, }; use test_rpc::logging::{Error, LogFile, LogOutput, Output}; use tokio::{ @@ -22,7 +22,7 @@ const EXCLUDE_LOG_FILE_CONTAIN: &str = ".old"; /// Maximum number of lines that each log file may contain const TRUNCATE_LOG_FILE_LINES: usize = 100; -pub static LOGGER: Lazy = Lazy::new(|| { +pub static LOGGER: LazyLock = LazyLock::new(|| { let (sender, listener) = channel(MAX_OUTPUT_BUFFER); StdOutBuffer(Mutex::new(listener), sender) }); From 6d6b4e73faf3d214c128c5fc8f75b32188661bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Tue, 30 Jul 2024 16:00:22 +0200 Subject: [PATCH 2/3] Use CStr literals instead of LazyLock --- talpid-core/src/firewall/linux.rs | 46 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 24 deletions(-) diff --git a/talpid-core/src/firewall/linux.rs b/talpid-core/src/firewall/linux.rs index c226b803e69d..5f3489649a25 100644 --- a/talpid-core/src/firewall/linux.rs +++ b/talpid-core/src/firewall/linux.rs @@ -7,7 +7,7 @@ use nftnl::{ }; use std::{ env, - ffi::{CStr, CString}, + ffi::CStr, fs, io, net::{IpAddr, Ipv4Addr}, sync::LazyLock, @@ -55,14 +55,13 @@ pub enum Error { /// TODO(linus): This crate is not supposed to be Mullvad-aware. So at some point this should be /// replaced by allowing the table name to be configured from the public API of this crate. -static TABLE_NAME: LazyLock = LazyLock::new(|| CString::new("mullvad").unwrap()); -static IN_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("input").unwrap()); -static OUT_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("output").unwrap()); -static FORWARD_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("forward").unwrap()); -static PREROUTING_CHAIN_NAME: LazyLock = - LazyLock::new(|| CString::new("prerouting").unwrap()); -static MANGLE_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("mangle").unwrap()); -static NAT_CHAIN_NAME: LazyLock = LazyLock::new(|| CString::new("nat").unwrap()); +const TABLE_NAME: &CStr = c"mullvad"; +const IN_CHAIN_NAME: &CStr = c"input"; +const OUT_CHAIN_NAME: &CStr = c"output"; +const FORWARD_CHAIN_NAME: &CStr = c"forward"; +const PREROUTING_CHAIN_NAME: &CStr = c"prerouting"; +const MANGLE_CHAIN_NAME: &CStr = c"mangle"; +const NAT_CHAIN_NAME: &CStr = c"nat"; /// Allows controlling whether firewall rules should have packet counters or not from an env /// variable. Useful for debugging the rules. @@ -105,15 +104,15 @@ impl Firewall { } pub fn apply_policy(&mut self, policy: FirewallPolicy) -> Result<()> { - let table = Table::new(&*TABLE_NAME, ProtoFamily::Inet); + let table = Table::new(&TABLE_NAME, ProtoFamily::Inet); let batch = PolicyBatch::new(&table).finalize(&policy, self.fwmark)?; Self::send_and_process(&batch)?; Self::apply_kernel_config(&policy); - self.verify_tables(&[&TABLE_NAME]) + self.verify_tables(&[TABLE_NAME]) } pub fn reset_policy(&mut self) -> Result<()> { - let table = Table::new(&*TABLE_NAME, ProtoFamily::Inet); + let table = Table::new(&TABLE_NAME, ProtoFamily::Inet); let mut batch = Batch::new(); // Our batch will add and remove the table even though the goal is just to remove @@ -236,33 +235,33 @@ impl<'a> PolicyBatch<'a> { batch.add(table, nftnl::MsgType::Del); batch.add(table, nftnl::MsgType::Add); - let mut prerouting_chain = Chain::new(&*PREROUTING_CHAIN_NAME, table); + let mut prerouting_chain = Chain::new(&PREROUTING_CHAIN_NAME, table); prerouting_chain.set_hook(nftnl::Hook::PreRouting, PREROUTING_CHAIN_PRIORITY); prerouting_chain.set_type(nftnl::ChainType::Filter); batch.add(&prerouting_chain, nftnl::MsgType::Add); - let mut out_chain = Chain::new(&*OUT_CHAIN_NAME, table); + let mut out_chain = Chain::new(&OUT_CHAIN_NAME, table); out_chain.set_hook(nftnl::Hook::Out, 0); out_chain.set_policy(nftnl::Policy::Drop); batch.add(&out_chain, nftnl::MsgType::Add); - let mut in_chain = Chain::new(&*IN_CHAIN_NAME, table); + let mut in_chain = Chain::new(&IN_CHAIN_NAME, table); in_chain.set_hook(nftnl::Hook::In, 0); in_chain.set_policy(nftnl::Policy::Drop); batch.add(&in_chain, nftnl::MsgType::Add); - let mut forward_chain = Chain::new(&*FORWARD_CHAIN_NAME, table); + let mut forward_chain = Chain::new(&FORWARD_CHAIN_NAME, table); forward_chain.set_hook(nftnl::Hook::Forward, 0); forward_chain.set_policy(nftnl::Policy::Drop); batch.add(&forward_chain, nftnl::MsgType::Add); - let mut mangle_chain = Chain::new(&*MANGLE_CHAIN_NAME, table); + let mut mangle_chain = Chain::new(&MANGLE_CHAIN_NAME, table); mangle_chain.set_hook(nftnl::Hook::Out, MANGLE_CHAIN_PRIORITY); mangle_chain.set_type(nftnl::ChainType::Route); mangle_chain.set_policy(nftnl::Policy::Accept); batch.add(&mangle_chain, nftnl::MsgType::Add); - let mut nat_chain = Chain::new(&*NAT_CHAIN_NAME, table); + let mut nat_chain = Chain::new(&NAT_CHAIN_NAME, table); nat_chain.set_hook(nftnl::Hook::PostRouting, libc::NF_IP_PRI_NAT_SRC); nat_chain.set_type(nftnl::ChainType::Nat); nat_chain.set_policy(nftnl::Policy::Accept); @@ -1067,13 +1066,12 @@ fn set_src_valid_mark_sysctl() -> io::Result<()> { /// Tables that are no longer used but need to be deleted due to upgrades. /// This can be removed when upgrades from 2023.3 are no longer supported. fn batch_deprecated_tables(batch: &mut Batch) { - static MANGLE_TABLE_NAME_V4: LazyLock = - LazyLock::new(|| CString::new("mullvadmangle4").unwrap()); - static MANGLE_TABLE_NAME_V6: LazyLock = - LazyLock::new(|| CString::new("mullvadmangle6").unwrap()); + const MANGLE_TABLE_NAME_V4: &CStr = c"mullvadmangle4"; + const MANGLE_TABLE_NAME_V6: &CStr = c"mullvadmangle6"; + let tables = [ - Table::new(&*MANGLE_TABLE_NAME_V4, ProtoFamily::Ipv4), - Table::new(&*MANGLE_TABLE_NAME_V6, ProtoFamily::Ipv6), + Table::new(&MANGLE_TABLE_NAME_V4, ProtoFamily::Ipv4), + Table::new(&MANGLE_TABLE_NAME_V6, ProtoFamily::Ipv6), ]; for table in &tables { batch.add(table, nftnl::MsgType::Add); From cd409ea27b19285ea394a6adb75421a425f7886e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Tue, 30 Jul 2024 16:03:39 +0200 Subject: [PATCH 3/3] Update MSRV --- Cargo.toml | 2 +- test/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 90e8d75f0af4..9ff2ac27844c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Mullvad VPN"] repository = "https://github.com/mullvad/mullvadvpn-app/" license = "GPL-3.0" edition = "2021" -rust-version = "1.77.0" +rust-version = "1.80.0" [workspace] resolver = "2" diff --git a/test/Cargo.toml b/test/Cargo.toml index 4f8b1931be84..d0c734620cd0 100644 --- a/test/Cargo.toml +++ b/test/Cargo.toml @@ -3,7 +3,7 @@ authors = ["Mullvad VPN"] repository = "https://github.com/mullvad/mullvadvpn-app/" license = "GPL-3.0" edition = "2021" -rust-version = "1.77.0" +rust-version = "1.80.0" [workspace] resolver = "2"