support ohos (#974)

* support ohos

---------

Co-authored-by: FrankHan <2777926911@qq.com>
This commit is contained in:
韩嘉乐
2025-07-02 09:44:45 +08:00
committed by GitHub
parent bf021a9ead
commit 01e491ec07
22 changed files with 668 additions and 21 deletions
+1 -1
View File
@@ -85,7 +85,7 @@ http = { version = "1", default-features = false, features = [
tokio-rustls = { version = "0.26", default-features = false, optional = true }
# for tap device
tun = { package = "tun-easytier", version = "1.1.1", features = [
tun = { package = "tun-easytier", git="https://github.com/EasyTier/rust-tun", features = [
"async",
], optional = true }
# for net ns
+1 -1
View File
@@ -107,7 +107,7 @@ impl GlobalCtx {
let stun_info_collection = Arc::new(StunInfoCollector::new_with_default_servers());
let enable_exit_node = config_fs.get_flags().enable_exit_node;
let enable_exit_node = config_fs.get_flags().enable_exit_node || cfg!(target_env= "ohos");
let proxy_forward_by_system = config_fs.get_flags().proxy_forward_by_system;
let no_tun = config_fs.get_flags().no_tun;
+2 -2
View File
@@ -16,14 +16,14 @@ struct InterfaceFilter {
iface: NetworkInterface,
}
#[cfg(target_os = "android")]
#[cfg(any(target_os = "android", target_env = "ohos"))]
impl InterfaceFilter {
async fn filter_iface(&self) -> bool {
true
}
}
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", not(target_env = "ohos")))]
impl InterfaceFilter {
async fn is_tun_tap_device(&self) -> bool {
let path = format!("/sys/class/net/{}/tun_flags", self.iface.name);
+1 -1
View File
@@ -29,7 +29,7 @@ async fn set_bind_addr_for_peer_connector(
is_ipv4: bool,
ip_collector: &Arc<IPCollector>,
) {
if cfg!(target_os = "android") {
if cfg!(any(target_os = "android", target_env = "ohos")) {
return;
}
+1 -1
View File
@@ -520,7 +520,7 @@ impl<C: NatDstConnector> TcpProxy<C> {
#[cfg(feature = "smoltcp")]
if self.global_ctx.get_flags().use_smoltcp
|| self.global_ctx.no_tun()
|| cfg!(target_os = "android")
|| cfg!(any(target_os = "android", target_env = "ohos"))
{
// use smoltcp network stack
self.local_port
+5 -5
View File
@@ -89,8 +89,8 @@ impl IpProxy {
self.tcp_proxy.start(true).await?;
if let Err(e) = self.icmp_proxy.start().await {
tracing::error!("start icmp proxy failed: {:?}", e);
if cfg!(not(target_os = "android")) {
// android may not support icmp proxy
if cfg!(not(any(target_os = "android", target_env = "ohos"))) {
// android and ohos not support icmp proxy
return Err(e);
}
}
@@ -477,7 +477,7 @@ impl Instance {
continue;
}
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
{
let mut new_nic_ctx = NicCtx::new(
global_ctx_c.clone(),
@@ -531,7 +531,7 @@ impl Instance {
Self::clear_nic_ctx(self.nic_ctx.clone(), self.peer_packet_receiver.clone()).await;
if !self.global_ctx.config.get_flags().no_tun {
#[cfg(not(target_os = "android"))]
#[cfg(not(any(target_os = "android", target_env = "ohos")))]
if let Some(ipv4_addr) = self.global_ctx.get_ipv4() {
let mut new_nic_ctx = NicCtx::new(
self.global_ctx.clone(),
@@ -796,7 +796,7 @@ impl Instance {
self.peer_packet_receiver.clone()
}
#[cfg(target_os = "android")]
#[cfg(any(target_os = "android", target_env = "ohos"))]
pub async fn setup_nic_ctx_for_android(
nic_ctx: ArcNicCtx,
global_ctx: ArcGlobalCtx,
+3 -3
View File
@@ -110,7 +110,7 @@ enum PacketProtocol {
// Note: the protocol in the packet information header is platform dependent.
impl PacketProtocol {
#[cfg(any(target_os = "linux", target_os = "android"))]
#[cfg(any(target_os = "linux", target_os = "android", target_env = "ohos"))]
fn into_pi_field(self) -> Result<u16, io::Error> {
use nix::libc;
match self {
@@ -328,7 +328,7 @@ impl VirtualNic {
Ok(tun::create(&config)?)
}
#[cfg(target_os = "android")]
#[cfg(any(target_os = "android", target_env = "ohos"))]
pub async fn create_dev_for_android(
&mut self,
tun_fd: std::os::fd::RawFd,
@@ -690,7 +690,7 @@ impl NicCtx {
Ok(())
}
#[cfg(target_os = "android")]
#[cfg(any(target_os = "android", target_env = "ohos"))]
pub async fn run_for_android(&mut self, tun_fd: std::os::fd::RawFd) -> Result<(), Error> {
let tunnel = {
let mut nic = self.nic.lock().await;
+2 -2
View File
@@ -94,7 +94,7 @@ impl EasyTierLauncher {
}
}
#[cfg(target_os = "android")]
#[cfg(any(target_os = "android", target_env = "ohos"))]
async fn run_routine_for_android(
instance: &Instance,
data: &EasyTierData,
@@ -199,7 +199,7 @@ impl EasyTierLauncher {
});
}
#[cfg(target_os = "android")]
#[cfg(any(target_os = "android", target_env = "ohos"))]
Self::run_routine_for_android(&instance, &data, &mut tasks).await;
instance.run().await?;
+8 -1
View File
@@ -862,7 +862,14 @@ impl PeerManager {
}
}
}
#[cfg(target_env = "ohos")]
{
if dst_peers.is_empty() {
tracing::info!("no peer id for ipv4: {}, set exit_node for ohos", ipv4_addr);
dst_peers.push(self.my_peer_id.clone());
is_exit_node = true;
}
}
(dst_peers, is_exit_node)
}
+1 -1
View File
@@ -388,7 +388,7 @@ pub(crate) fn setup_sokcet2_ext(
}
}
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
#[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux", target_env = "ohos"))]
if let Some(dev_name) = bind_dev {
tracing::trace!(dev_name = ?dev_name, "bind device");
socket2_socket.bind_device(Some(dev_name.as_bytes()))?;