mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-07 02:09:06 +00:00
feat: support macOS Network Extension (#1902)
* feat: support macOS Network Extension * fix: disable macOS NE feature in cargo hack check
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
||||
#[cfg(any(
|
||||
all(target_os = "macos", not(feature = "macos-ne")),
|
||||
target_os = "freebsd"
|
||||
))]
|
||||
mod darwin;
|
||||
#[cfg(target_os = "linux")]
|
||||
mod netlink;
|
||||
@@ -144,14 +147,17 @@ impl IfConfiguerTrait for DummyIfConfiger {}
|
||||
#[cfg(target_os = "linux")]
|
||||
pub type IfConfiger = netlink::NetlinkIfConfiger;
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
||||
#[cfg(any(
|
||||
all(target_os = "macos", not(feature = "macos-ne")),
|
||||
target_os = "freebsd"
|
||||
))]
|
||||
pub type IfConfiger = darwin::MacIfConfiger;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
pub type IfConfiger = windows::WindowsIfConfiger;
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "macos",
|
||||
all(target_os = "macos", not(feature = "macos-ne")),
|
||||
target_os = "linux",
|
||||
target_os = "windows",
|
||||
target_os = "freebsd",
|
||||
|
||||
@@ -120,7 +120,7 @@ pub fn get_machine_id() -> uuid::Uuid {
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
all(target_os = "macos", not(feature = "macos-ne")),
|
||||
target_os = "windows",
|
||||
target_os = "freebsd"
|
||||
))]
|
||||
@@ -137,7 +137,7 @@ pub fn get_machine_id() -> uuid::Uuid {
|
||||
|
||||
#[cfg(not(any(
|
||||
target_os = "linux",
|
||||
target_os = "macos",
|
||||
all(target_os = "macos", not(feature = "macos-ne")),
|
||||
target_os = "windows",
|
||||
target_os = "freebsd"
|
||||
)))]
|
||||
|
||||
@@ -16,7 +16,11 @@ struct InterfaceFilter {
|
||||
iface: NetworkInterface,
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "android", target_os = "ios", target_env = "ohos"))]
|
||||
#[cfg(any(
|
||||
target_os = "android",
|
||||
any(target_os = "ios", feature = "macos-ne"),
|
||||
target_env = "ohos"
|
||||
))]
|
||||
impl InterfaceFilter {
|
||||
async fn filter_iface(&self) -> bool {
|
||||
true
|
||||
@@ -60,13 +64,16 @@ impl InterfaceFilter {
|
||||
}
|
||||
|
||||
// Cache for networksetup command output
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(all(target_os = "macos", not(feature = "macos-ne")))]
|
||||
static NETWORKSETUP_CACHE: std::sync::OnceLock<Mutex<(String, std::time::Instant)>> =
|
||||
std::sync::OnceLock::new();
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "freebsd"))]
|
||||
#[cfg(any(
|
||||
all(target_os = "macos", not(feature = "macos-ne")),
|
||||
target_os = "freebsd"
|
||||
))]
|
||||
impl InterfaceFilter {
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(all(target_os = "macos", not(feature = "macos-ne")))]
|
||||
async fn get_networksetup_output() -> String {
|
||||
use anyhow::Context;
|
||||
use std::time::{Duration, Instant};
|
||||
@@ -101,7 +108,7 @@ impl InterfaceFilter {
|
||||
stdout
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[cfg(all(target_os = "macos", not(feature = "macos-ne")))]
|
||||
async fn is_interface_physical(&self) -> bool {
|
||||
let interface_name = &self.iface.name;
|
||||
let stdout = Self::get_networksetup_output().await;
|
||||
|
||||
Reference in New Issue
Block a user