From 6f186e30dd62a59d8278a6ffaea1dad356293740 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Fri, 24 May 2024 23:19:45 +0800 Subject: [PATCH] fix: missing Read + Write --- .../src/local/tun/sys/mod.rs | 3 +++ .../src/local/tun/sys/others.rs | 21 +++++++++++++++-- .../src/local/tun/sys/unix/android.rs | 5 +++- .../src/local/tun/sys/unix/apple/others.rs | 2 +- .../src/local/tun/sys/unix/bsd.rs | 2 +- .../src/local/tun/sys/unix/linux.rs | 5 +++- .../src/local/tun/sys/unix/mod.rs | 3 +++ .../src/local/tun/sys/unix/others.rs | 23 +++++++++++++++++++ .../src/local/tun/sys/windows/mod.rs | 5 +++- 9 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 crates/shadowsocks-service/src/local/tun/sys/unix/others.rs diff --git a/crates/shadowsocks-service/src/local/tun/sys/mod.rs b/crates/shadowsocks-service/src/local/tun/sys/mod.rs index 27507266f1a0..c44ea91faab0 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/mod.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/mod.rs @@ -9,5 +9,8 @@ cfg_if! { } else if #[cfg(windows)] { mod windows; pub use self::windows::*; + } else { + mod others; + pub use self::others::*; } } diff --git a/crates/shadowsocks-service/src/local/tun/sys/others.rs b/crates/shadowsocks-service/src/local/tun/sys/others.rs index cdf996940b52..fb966718fbb3 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/others.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/others.rs @@ -1,6 +1,23 @@ -//! Other platforms +use std::{ + io::{self, Read, Write}, + marker::Unpin, +}; + +use tokio::io::{AsyncWrite, AsyncWriteExt}; +use tun::Device; + +/// Packet Information length in bytes +pub const IFF_PI_PREFIX_LEN: usize = 0; + +/// Writing packet with packet information +pub async fn write_packet_with_pi(writer: &mut W, packet: &[u8]) -> io::Result<()> { + writer.write_all(packet).await +} /// Set platform specific route configuration -pub async fn set_route_configuration(_: &mut TunDevice) -> io::Result<()> { +pub async fn set_route_configuration(_: &mut (dyn Device + Send)) -> io::Result<()> +where + Q: Read + Write, +{ Ok(()) } diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/android.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/android.rs index 02c66f8b9eb1..e2937c234f21 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/unix/android.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/android.rs @@ -1,4 +1,7 @@ -use std::{io, marker::Unpin}; +use std::{ + io::{self, Read, Write}, + marker::Unpin, +}; use tokio::io::{AsyncWrite, AsyncWriteExt}; use tun::Device; diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/apple/others.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/apple/others.rs index 21d66a51cc7c..d74444b2cb85 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/unix/apple/others.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/apple/others.rs @@ -1,4 +1,4 @@ -use std::io; +use std::io::{self, Read, Write}; use tun::Device; diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/bsd.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/bsd.rs index 396c2b8d512b..34e23a7c8986 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/unix/bsd.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/bsd.rs @@ -1,5 +1,5 @@ use std::{ - io::{self, ErrorKind, IoSlice}, + io::{self, ErrorKind, IoSlice, Read, Write}, marker::Unpin, }; diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/linux.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/linux.rs index 35728beeaeee..58fa8185fafa 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/unix/linux.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/linux.rs @@ -1,4 +1,7 @@ -use std::{io, marker::Unpin}; +use std::{ + io::{self, Read, Write}, + marker::Unpin, +}; use tokio::io::{AsyncWrite, AsyncWriteExt}; use tun::Device; diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/mod.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/mod.rs index e618d6650f16..fce535d6cfe7 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/unix/mod.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/mod.rs @@ -13,5 +13,8 @@ cfg_if! { } else if #[cfg(target_os = "android")] { mod android; pub use self::android::*; + } else { + mod others; + pub use self::others::*; } } diff --git a/crates/shadowsocks-service/src/local/tun/sys/unix/others.rs b/crates/shadowsocks-service/src/local/tun/sys/unix/others.rs new file mode 100644 index 000000000000..fb966718fbb3 --- /dev/null +++ b/crates/shadowsocks-service/src/local/tun/sys/unix/others.rs @@ -0,0 +1,23 @@ +use std::{ + io::{self, Read, Write}, + marker::Unpin, +}; + +use tokio::io::{AsyncWrite, AsyncWriteExt}; +use tun::Device; + +/// Packet Information length in bytes +pub const IFF_PI_PREFIX_LEN: usize = 0; + +/// Writing packet with packet information +pub async fn write_packet_with_pi(writer: &mut W, packet: &[u8]) -> io::Result<()> { + writer.write_all(packet).await +} + +/// Set platform specific route configuration +pub async fn set_route_configuration(_: &mut (dyn Device + Send)) -> io::Result<()> +where + Q: Read + Write, +{ + Ok(()) +} diff --git a/crates/shadowsocks-service/src/local/tun/sys/windows/mod.rs b/crates/shadowsocks-service/src/local/tun/sys/windows/mod.rs index 5e203f38049a..62f48860c0f3 100644 --- a/crates/shadowsocks-service/src/local/tun/sys/windows/mod.rs +++ b/crates/shadowsocks-service/src/local/tun/sys/windows/mod.rs @@ -1,4 +1,7 @@ -use std::{io, marker::Unpin}; +use std::{ + io::{self, Read, Write}, + marker::Unpin, +}; use tokio::io::{AsyncWrite, AsyncWriteExt}; use tun::Device;