From 7db23b38f4680903267a45d0bbc845ffd8d3bfa4 Mon Sep 17 00:00:00 2001 From: zonyitoo Date: Sun, 16 Jan 2022 04:24:51 +0800 Subject: [PATCH] local-tun also obey "mode" configuration --- README.md | 9 --------- crates/shadowsocks-service/src/local/tun/mod.rs | 10 ++++++++++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 292542f6..c9f5b48c 100644 --- a/README.md +++ b/README.md @@ -385,15 +385,6 @@ sslocal --protocol tun -s "[::1]:8388" -m "aes-256-gcm" -k "hello-kitty" --outbo It will create a Tun interface with address `10.255.0.1` and netmask `255.255.255.0`. -(OPTIONAL) macOS requires adding a route entry to redirect packets that destinated to `10.155.0.1` (the address of the Tun interface) to the Tun interface itself. - -```bash -# 10.255.0.1 address -# 255.255.255.0 netmask -# utun8 tun's interface name -route add -net 10.255.0.1 -netmask 255.255.255.0 -interface utun8 -``` - ### Server ```bash diff --git a/crates/shadowsocks-service/src/local/tun/mod.rs b/crates/shadowsocks-service/src/local/tun/mod.rs index a18136bc..814112c0 100644 --- a/crates/shadowsocks-service/src/local/tun/mod.rs +++ b/crates/shadowsocks-service/src/local/tun/mod.rs @@ -192,6 +192,11 @@ impl Tun { match packet.protocol() { IpProtocol::Tcp => { + if !self.mode.enable_tcp() { + trace!("received TCP packet but mode is {}, throwing away", self.mode); + return Ok(()); + } + let tcp_packet = match TcpPacket::new_checked(packet.payload()) { Ok(p) => p, Err(err) => { @@ -225,6 +230,11 @@ impl Tun { self.tcp.drive_interface_state(frame); } IpProtocol::Udp => { + if !self.mode.enable_udp() { + trace!("received UDP packet but mode is {}, throwing away", self.mode); + return Ok(()); + } + let udp_packet = match UdpPacket::new_checked(packet.payload()) { Ok(p) => p, Err(err) => {