local-tun also obey "mode" configuration

This commit is contained in:
zonyitoo
2022-01-16 04:24:51 +08:00
parent 9c9cde4156
commit 7db23b38f4
2 changed files with 10 additions and 9 deletions
-9
View File
@@ -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
@@ -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) => {