diff options
| author | David Lönnhager <david.l@mullvad.net> | 2024-05-03 09:03:55 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2024-05-03 09:03:55 +0200 |
| commit | 8c671c1e4936c9b33cbd0cd3e86bee5d5b6828ad (patch) | |
| tree | cae9bf9581a6fa26d95704d5aa78cb179a6c56b6 | |
| parent | d93c3a5e0b69cb891062d10af8990aa03459ec34 (diff) | |
| parent | b9c5501e24ca3957c994ecbc5ed5ebcd1de1cbfd (diff) | |
| download | mullvadvpn-8c671c1e4936c9b33cbd0cd3e86bee5d5b6828ad.tar.xz mullvadvpn-8c671c1e4936c9b33cbd0cd3e86bee5d5b6828ad.zip | |
Merge branch 'fix-clippy-lints'
| -rw-r--r-- | mullvad-relay-selector/src/relay_selector/query.rs | 24 | ||||
| -rw-r--r-- | mullvad-types/src/version.rs | 13 | ||||
| -rw-r--r-- | talpid-core/src/split_tunnel/macos/bindings.rs | 42 | ||||
| -rw-r--r-- | talpid-core/src/split_tunnel/macos/bpf.rs | 4 | ||||
| -rwxr-xr-x | talpid-core/src/split_tunnel/macos/generate-bindings.sh | 3 | ||||
| -rw-r--r-- | talpid-types/src/error.rs | 6 |
6 files changed, 41 insertions, 51 deletions
diff --git a/mullvad-relay-selector/src/relay_selector/query.rs b/mullvad-relay-selector/src/relay_selector/query.rs index ff68407051..f37013a5b2 100644 --- a/mullvad-relay-selector/src/relay_selector/query.rs +++ b/mullvad-relay-selector/src/relay_selector/query.rs @@ -109,6 +109,12 @@ impl RelayQuery { } } +impl Default for RelayQuery { + fn default() -> Self { + Self::new() + } +} + impl From<RelayQuery> for RelayConstraints { /// The mapping from [`RelayQuery`] to [`RelayConstraints`]. fn from(value: RelayQuery) -> Self { @@ -163,6 +169,12 @@ impl WireguardRelayQuery { } } +impl Default for WireguardRelayQuery { + fn default() -> Self { + Self::new() + } +} + impl From<WireguardRelayQuery> for WireguardConstraints { /// The mapping from [`WireguardRelayQuery`] to [`WireguardConstraints`]. fn from(value: WireguardRelayQuery) -> Self { @@ -207,6 +219,12 @@ impl OpenVpnRelayQuery { } } +impl Default for OpenVpnRelayQuery { + fn default() -> Self { + Self::new() + } +} + /// This is the reflection of [`BridgeState`] + [`BridgeSettings`] in the "universe of relay /// queries". /// @@ -387,6 +405,12 @@ pub mod builder { } } + impl Default for RelayQueryBuilder<Any> { + fn default() -> Self { + Self::new() + } + } + // Type-safe builder for Wireguard relay constraints. /// Internal builder state for a [`WireguardRelayQuery`] configuration. diff --git a/mullvad-types/src/version.rs b/mullvad-types/src/version.rs index 02b47b3dc3..523e995b7f 100644 --- a/mullvad-types/src/version.rs +++ b/mullvad-types/src/version.rs @@ -3,6 +3,7 @@ use jnix::IntoJava; use once_cell::sync::Lazy; use regex::Regex; use serde::{Deserialize, Serialize}; +use std::fmt::{self, Formatter}; use std::{cmp::Ordering, str::FromStr}; static STABLE_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(\d{4})\.(\d+)$").unwrap()); @@ -133,18 +134,18 @@ impl PartialOrd for ParsedAppVersion { } } -impl ToString for ParsedAppVersion { - fn to_string(&self) -> String { +impl fmt::Display for ParsedAppVersion { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { match self { - Self::Stable(year, version) => format!("{year}.{version}"), + Self::Stable(year, version) => write!(f, "{year}.{version}"), Self::Beta(year, version, beta_version) => { - format!("{year}.{version}-beta{beta_version}") + write!(f, "{year}.{version}-beta{beta_version}") } Self::Dev(year, version, beta_version, hash) => { if let Some(beta_version) = beta_version { - format!("{year}.{version}-beta{beta_version}-dev-{hash}") + write!(f, "{year}.{version}-beta{beta_version}-dev-{hash}") } else { - format!("{year}.{version}-dev-{hash}") + write!(f, "{year}.{version}-dev-{hash}") } } } diff --git a/talpid-core/src/split_tunnel/macos/bindings.rs b/talpid-core/src/split_tunnel/macos/bindings.rs index 1ff1727892..69aabfc0e9 100644 --- a/talpid-core/src/split_tunnel/macos/bindings.rs +++ b/talpid-core/src/split_tunnel/macos/bindings.rs @@ -5,7 +5,6 @@ pub const PCAP_ERRBUF_SIZE: u32 = 256; pub type __int32_t = ::std::os::raw::c_int; pub type __darwin_pid_t = __int32_t; pub type __darwin_uuid_t = [::std::os::raw::c_uchar; 16usize]; -pub type u_int = ::std::os::raw::c_uint; pub type pid_t = __darwin_pid_t; #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -290,47 +289,6 @@ fn bindgen_test_layout_pktap_header() { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct bpf_stat { - pub bs_recv: u_int, - pub bs_drop: u_int, -} -#[test] -fn bindgen_test_layout_bpf_stat() { - const UNINIT: ::std::mem::MaybeUninit<bpf_stat> = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::<bpf_stat>(), - 8usize, - concat!("Size of: ", stringify!(bpf_stat)) - ); - assert_eq!( - ::std::mem::align_of::<bpf_stat>(), - 4usize, - concat!("Alignment of ", stringify!(bpf_stat)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bs_recv) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(bpf_stat), - "::", - stringify!(bs_recv) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).bs_drop) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(bpf_stat), - "::", - stringify!(bs_drop) - ) - ); -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] pub struct pcap { _unused: [u8; 0], } diff --git a/talpid-core/src/split_tunnel/macos/bpf.rs b/talpid-core/src/split_tunnel/macos/bpf.rs index d2cd42bdcc..ec3f8fc62d 100644 --- a/talpid-core/src/split_tunnel/macos/bpf.rs +++ b/talpid-core/src/split_tunnel/macos/bpf.rs @@ -318,7 +318,9 @@ impl<'a> BpfIterMut<'a> { } // SAFETY: The buffer is large enough to contain a BPF header - let hdr = unsafe { &*(&self.data[offset] as *const u8 as *const bpf_hdr) }; + let hdr = unsafe { + &*(self.data[offset..offset + mem::size_of::<bpf_hdr>()].as_ptr() as *const bpf_hdr) + }; if offset + hdr.bh_hdrlen as usize + hdr.bh_caplen as usize > self.data.len() { return None; diff --git a/talpid-core/src/split_tunnel/macos/generate-bindings.sh b/talpid-core/src/split_tunnel/macos/generate-bindings.sh index a56fe69d2d..9cfa5c1b62 100755 --- a/talpid-core/src/split_tunnel/macos/generate-bindings.sh +++ b/talpid-core/src/split_tunnel/macos/generate-bindings.sh @@ -18,5 +18,4 @@ bindgen "include/bindings.h" -o ./bindings.rs \ --allowlist-item "^pktap_header" \ --allowlist-item "PCAP_ERRBUF_SIZE" \ --allowlist-item "^BIOCSWANTPKTAP" \ - --allowlist-item "^PTH_FLAG_DIR_OUT" \ - --allowlist-item "^bpf_stat" + --allowlist-item "^PTH_FLAG_DIR_OUT" diff --git a/talpid-types/src/error.rs b/talpid-types/src/error.rs index e4471eff29..70bdaba19b 100644 --- a/talpid-types/src/error.rs +++ b/talpid-types/src/error.rs @@ -102,6 +102,12 @@ pub mod flood { counter: usize, } + impl Default for DetectFlood { + fn default() -> Self { + DetectFlood::new() + } + } + impl DetectFlood { pub const fn new() -> Self { DetectFlood { |
