support ohos (#974)
* support ohos --------- Co-authored-by: FrankHan <2777926911@qq.com>
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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()))?;
|
||||
|
||||
Reference in New Issue
Block a user