From 3f62aabd2a1074de6da0397651e189093644b425 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Wed, 4 Dec 2024 00:17:32 +0800 Subject: [PATCH] feat: tun2 has been merged back to tun (meh/rust-tun) --- Cargo.lock | 12 +++---- crates/shadowsocks-service/Cargo.toml | 6 ++-- .../src/local/tun/fake_tun.rs | 32 +++++++++++-------- .../shadowsocks-service/src/local/tun/mod.rs | 4 +-- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27de2594c8e8..bd04c92f2da5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1880,7 +1880,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -3298,7 +3298,7 @@ dependencies = [ "tokio-native-tls", "tokio-rustls", "trait-variant", - "tun2", + "tun", "webpki-roots", "windows-sys 0.59.0", "zstd", @@ -3873,10 +3873,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] -name = "tun2" -version = "4.0.0" +name = "tun" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21afe73d3d42581a7400fbf5aec057a646ffe3f8bb5ae3f61d88c7e7f4ac77be" +checksum = "f3c3f82bccbec181c56278683da7d915cf875a6cf8a450b3bcf1367de222775e" dependencies = [ "bytes", "cfg-if", @@ -3886,7 +3886,7 @@ dependencies = [ "libc", "log", "nix", - "thiserror 1.0.69", + "thiserror 2.0.3", "tokio", "tokio-util", "windows-sys 0.59.0", diff --git a/crates/shadowsocks-service/Cargo.toml b/crates/shadowsocks-service/Cargo.toml index 714521441e05..c27fa095cbe6 100644 --- a/crates/shadowsocks-service/Cargo.toml +++ b/crates/shadowsocks-service/Cargo.toml @@ -96,7 +96,7 @@ local-tunnel = ["local"] # Enable socks4 protocol for sslocal local-socks4 = ["local"] # Enable Tun interface protocol for sslocal -local-tun = ["local", "etherparse", "tun2", "smoltcp"] +local-tun = ["local", "etherparse", "tun", "smoltcp"] # Enable Fake DNS local-fake-dns = ["local", "trust-dns", "sled", "bson"] # sslocal support online URL (SIP008 Online Configuration Delivery) @@ -195,9 +195,7 @@ flate2 = { version = "1.0", optional = true } brotli = { version = "7.0", optional = true } zstd = { version = "0.13", optional = true } -tun2 = { version = "4.0", optional = true, default-features = false, features = [ - "async", -] } +tun = { version = "0.7", optional = true, features = ["async"] } etherparse = { version = "0.16", optional = true } smoltcp = { version = "0.12", optional = true, default-features = false, features = [ "std", diff --git a/crates/shadowsocks-service/src/local/tun/fake_tun.rs b/crates/shadowsocks-service/src/local/tun/fake_tun.rs index 0e563f3e5b3c..a936cf53755c 100644 --- a/crates/shadowsocks-service/src/local/tun/fake_tun.rs +++ b/crates/shadowsocks-service/src/local/tun/fake_tun.rs @@ -9,7 +9,7 @@ use std::{ }; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; -use tun2::{AbstractDevice, Configuration, Error as TunError}; +use tun::{AbstractDevice, Configuration, Error as TunError}; pub struct FakeQueue; @@ -32,55 +32,59 @@ impl Write for FakeQueue { pub struct FakeDevice; impl AbstractDevice for FakeDevice { - fn tun_name(&self) -> tun2::Result { + fn tun_name(&self) -> tun::Result { Err(TunError::NotImplemented) } - fn set_tun_name(&mut self, _: &str) -> tun2::Result<()> { + fn tun_index(&self) -> tun::Result { Err(TunError::NotImplemented) } - fn enabled(&mut self, _: bool) -> tun2::Result<()> { + fn set_tun_name(&mut self, _: &str) -> tun::Result<()> { Err(TunError::NotImplemented) } - fn address(&self) -> tun2::Result { + fn enabled(&mut self, _: bool) -> tun::Result<()> { Err(TunError::NotImplemented) } - fn set_address(&mut self, _: IpAddr) -> tun2::Result<()> { + fn address(&self) -> tun::Result { Err(TunError::NotImplemented) } - fn destination(&self) -> tun2::Result { + fn set_address(&mut self, _: IpAddr) -> tun::Result<()> { Err(TunError::NotImplemented) } - fn set_destination(&mut self, _: IpAddr) -> tun2::Result<()> { + fn destination(&self) -> tun::Result { Err(TunError::NotImplemented) } - fn broadcast(&self) -> tun2::Result { + fn set_destination(&mut self, _: IpAddr) -> tun::Result<()> { Err(TunError::NotImplemented) } - fn set_broadcast(&mut self, _: IpAddr) -> tun2::Result<()> { + fn broadcast(&self) -> tun::Result { Err(TunError::NotImplemented) } - fn netmask(&self) -> tun2::Result { + fn set_broadcast(&mut self, _: IpAddr) -> tun::Result<()> { Err(TunError::NotImplemented) } - fn set_netmask(&mut self, _: IpAddr) -> tun2::Result<()> { + fn netmask(&self) -> tun::Result { Err(TunError::NotImplemented) } - fn mtu(&self) -> tun2::Result { + fn set_netmask(&mut self, _: IpAddr) -> tun::Result<()> { Err(TunError::NotImplemented) } - fn set_mtu(&mut self, _: u16) -> tun2::Result<()> { + fn mtu(&self) -> tun::Result { + Err(TunError::NotImplemented) + } + + fn set_mtu(&mut self, _: u16) -> tun::Result<()> { Err(TunError::NotImplemented) } diff --git a/crates/shadowsocks-service/src/local/tun/mod.rs b/crates/shadowsocks-service/src/local/tun/mod.rs index a60b089f4748..03536e7808f1 100644 --- a/crates/shadowsocks-service/src/local/tun/mod.rs +++ b/crates/shadowsocks-service/src/local/tun/mod.rs @@ -28,11 +28,11 @@ cfg_if! { target_os = "android", target_os = "windows", target_os = "freebsd"))] { - use tun2::{ + use tun::{ create_as_async, AsyncDevice, Configuration as TunConfiguration, AbstractDevice, Error as TunError, Layer, }; } else { - use tun2::{AbstractDevice, Configuration as TunConfiguration, Error as TunError, Layer}; + use tun::{AbstractDevice, Configuration as TunConfiguration, Error as TunError, Layer}; mod fake_tun; use self::fake_tun::{create_as_async, AsyncDevice};