Skip to content

Commit

Permalink
feat: tun2 has been merged back to tun (meh/rust-tun)
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Dec 3, 2024
1 parent f21869a commit 3f62aab
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/shadowsocks-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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",
Expand Down
32 changes: 18 additions & 14 deletions crates/shadowsocks-service/src/local/tun/fake_tun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,55 +32,59 @@ impl Write for FakeQueue {
pub struct FakeDevice;

impl AbstractDevice for FakeDevice {
fn tun_name(&self) -> tun2::Result<String> {
fn tun_name(&self) -> tun::Result<String> {
Err(TunError::NotImplemented)
}

fn set_tun_name(&mut self, _: &str) -> tun2::Result<()> {
fn tun_index(&self) -> tun::Result<i32> {
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<IpAddr> {
fn enabled(&mut self, _: bool) -> tun::Result<()> {
Err(TunError::NotImplemented)
}

fn set_address(&mut self, _: IpAddr) -> tun2::Result<()> {
fn address(&self) -> tun::Result<IpAddr> {
Err(TunError::NotImplemented)
}

fn destination(&self) -> tun2::Result<IpAddr> {
fn set_address(&mut self, _: IpAddr) -> tun::Result<()> {
Err(TunError::NotImplemented)
}

fn set_destination(&mut self, _: IpAddr) -> tun2::Result<()> {
fn destination(&self) -> tun::Result<IpAddr> {
Err(TunError::NotImplemented)
}

fn broadcast(&self) -> tun2::Result<IpAddr> {
fn set_destination(&mut self, _: IpAddr) -> tun::Result<()> {
Err(TunError::NotImplemented)
}

fn set_broadcast(&mut self, _: IpAddr) -> tun2::Result<()> {
fn broadcast(&self) -> tun::Result<IpAddr> {
Err(TunError::NotImplemented)
}

fn netmask(&self) -> tun2::Result<IpAddr> {
fn set_broadcast(&mut self, _: IpAddr) -> tun::Result<()> {
Err(TunError::NotImplemented)
}

fn set_netmask(&mut self, _: IpAddr) -> tun2::Result<()> {
fn netmask(&self) -> tun::Result<IpAddr> {
Err(TunError::NotImplemented)
}

fn mtu(&self) -> tun2::Result<u16> {
fn set_netmask(&mut self, _: IpAddr) -> tun::Result<()> {
Err(TunError::NotImplemented)
}

fn set_mtu(&mut self, _: u16) -> tun2::Result<()> {
fn mtu(&self) -> tun::Result<u16> {
Err(TunError::NotImplemented)
}

fn set_mtu(&mut self, _: u16) -> tun::Result<()> {
Err(TunError::NotImplemented)
}

Expand Down
4 changes: 2 additions & 2 deletions crates/shadowsocks-service/src/local/tun/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 3f62aab

Please sign in to comment.