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:
Chenx Dust
2026-02-14 14:54:36 +08:00
committed by GitHub
parent 5a777959e3
commit 7a26640c26
15 changed files with 180 additions and 42 deletions
+9 -3
View File
@@ -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",
+2 -2
View File
@@ -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"
)))]
+12 -5
View File
@@ -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;