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
+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;