diff --git a/Cargo.lock b/Cargo.lock index 6f27b9917d98..5ad9214f1b6a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4644,7 +4644,6 @@ dependencies = [ "ipnetwork", "jnix", "log", - "nix 0.23.2", "talpid-routing", "talpid-types", "talpid-windows", @@ -5178,11 +5177,15 @@ checksum = "5b5ea2466ffcdd0be0831f7d3981daa0b953586c0062f6d33398cb374689b090" dependencies = [ "bytes", "cfg-if", + "futures", + "futures-core", "ipnet", "libc", "log", "nix 0.29.0", "thiserror 2.0.9", + "tokio", + "tokio-util 0.7.10", "windows-sys 0.59.0", "wintun-bindings", ] diff --git a/talpid-tunnel/Cargo.toml b/talpid-tunnel/Cargo.toml index f60615fef9ca..a3400889e041 100644 --- a/talpid-tunnel/Cargo.toml +++ b/talpid-tunnel/Cargo.toml @@ -19,15 +19,12 @@ talpid-types = { path = "../talpid-types" } futures = { workspace = true } tokio = { workspace = true, features = ["process", "rt-multi-thread", "fs"] } -[target.'cfg(all(unix, not(target_os = "android")))'.dependencies] -nix = "0.23" - [target.'cfg(target_os = "android")'.dependencies] jnix = { version = "0.5.1", features = ["derive"] } log = { workspace = true } [target.'cfg(any(target_os = "linux", target_os = "macos"))'.dependencies] -tun = "0.7" +tun = { version = "0.7", features = ["async"] } [target.'cfg(windows)'.dependencies] talpid-windows = { path = "../talpid-windows" } diff --git a/talpid-tunnel/src/tun_provider/unix.rs b/talpid-tunnel/src/tun_provider/unix.rs index 588cb7a35929..69605a841e77 100644 --- a/talpid-tunnel/src/tun_provider/unix.rs +++ b/talpid-tunnel/src/tun_provider/unix.rs @@ -1,11 +1,10 @@ use super::TunConfig; -use nix::fcntl; #[cfg(target_os = "macos")] use std::io; use std::{ net::IpAddr, ops::Deref, - os::unix::io::{AsRawFd, IntoRawFd, RawFd}, + os::unix::io::{AsRawFd, RawFd}, }; use tun::{AbstractDevice, Configuration}; @@ -20,10 +19,6 @@ pub enum Error { #[error("Unable to open a tunnel device")] CreateDevice(#[source] tun::Error), - /// Failed to apply async flags to tunnel device - #[error("Failed to apply async flags to tunnel device")] - SetDeviceAsync(#[source] nix::Error), - /// Failed to enable/disable link device #[error("Failed to enable/disable link device")] ToggleDevice(#[source] tun::Error), @@ -111,7 +106,7 @@ impl Deref for UnixTun { /// A tunnel device pub struct TunnelDevice { - dev: tun::Device, + dev: tun::AsyncDevice, } /// A tunnel device builder. @@ -125,15 +120,7 @@ pub struct TunnelDeviceBuilder { impl TunnelDeviceBuilder { /// Create a [`TunnelDevice`] from this builder. pub fn create(self) -> Result { - fn apply_async_flags(fd: RawFd) -> Result<(), nix::Error> { - fcntl::fcntl(fd, fcntl::FcntlArg::F_GETFL)?; - let arg = fcntl::FcntlArg::F_SETFL(fcntl::OFlag::O_RDWR | fcntl::OFlag::O_NONBLOCK); - fcntl::fcntl(fd, arg)?; - Ok(()) - } - - let dev = tun::create(&self.config).map_err(Error::CreateDevice)?; - apply_async_flags(dev.as_raw_fd()).map_err(Error::SetDeviceAsync)?; + let dev = tun::create_as_async(&self.config).map_err(Error::CreateDevice)?; Ok(TunnelDevice { dev }) } @@ -164,12 +151,6 @@ impl AsRawFd for TunnelDevice { } } -impl IntoRawFd for TunnelDevice { - fn into_raw_fd(self) -> RawFd { - self.dev.into_raw_fd() - } -} - impl TunnelDevice { #[cfg(target_os = "linux")] fn set_ip(&mut self, ip: IpAddr) -> Result<(), Error> {