Skip to content

Commit 1abf457

Browse files
committed
fix: wintun already add default route automatically
1 parent 1aad70e commit 1abf457

File tree

9 files changed

+13
-73
lines changed

9 files changed

+13
-73
lines changed

.github/workflows/build-nightly-release.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
./build-release -t ${{ matrix.target }} $compile_features $compile_compress
5454
5555
- name: Upload Artifacts
56-
uses: actions/upload-artifact@v3
56+
uses: actions/upload-artifact@v4
5757
with:
5858
name: ${{ matrix.target }}
5959
path: build/release/*
@@ -94,7 +94,7 @@ jobs:
9494
./build/build-host-release -t ${{ matrix.target }}
9595
9696
- name: Upload Artifacts
97-
uses: actions/upload-artifact@v3
97+
uses: actions/upload-artifact@v4
9898
with:
9999
name: ${{ matrix.target }}
100100
path: build/release/*
@@ -119,7 +119,7 @@ jobs:
119119
pwsh ./build/build-host-release.ps1
120120
121121
- name: Upload Artifacts
122-
uses: actions/upload-artifact@v3
122+
uses: actions/upload-artifact@v4
123123
with:
124124
name: windows-native
125125
path: build/release/*

crates/shadowsocks-service/src/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1630,7 +1630,8 @@ impl Config {
16301630
match tun_interface_destination.parse::<IpNet>() {
16311631
Ok(addr) => local_config.tun_interface_destination = Some(addr),
16321632
Err(..) => {
1633-
let err = Error::new(ErrorKind::Malformed, "`tun_interface_destination` invalid", None);
1633+
let err =
1634+
Error::new(ErrorKind::Malformed, "`tun_interface_destination` invalid", None);
16341635
return Err(err);
16351636
}
16361637
}

crates/shadowsocks-service/src/local/tun/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Tun {
183183
);
184184

185185
// Set default route
186-
if let Err(err) = sys::set_route_configuration(&self.device.get_ref()).await {
186+
if let Err(err) = sys::set_route_configuration(self.device.get_mut()).await {
187187
warn!("[TUN] tun device set route failed, error: {}", err);
188188
}
189189

crates/shadowsocks-service/src/local/tun/sys/unix/android.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet:
1616
}
1717

1818
/// Set platform specific route configuration
19-
pub async fn set_route_configuration(_device: &TunDevice) -> io::Result<()> {
19+
pub async fn set_route_configuration(_device: &mut TunDevice) -> io::Result<()> {
2020
Ok(())
2121
}

crates/shadowsocks-service/src/local/tun/sys/unix/apple/macos.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct rt_msg {
5858
}
5959

6060
/// Set platform specific route configuration
61-
pub async fn set_route_configuration(device: &TunDevice) -> io::Result<()> {
61+
pub async fn set_route_configuration(device: &mut TunDevice) -> io::Result<()> {
6262
let tun_address = match device.address() {
6363
Ok(t) => t,
6464
Err(err) => {

crates/shadowsocks-service/src/local/tun/sys/unix/apple/others.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ use std::io;
33
use tun::platform::Device as TunDevice;
44

55
/// Set platform specific route configuration
6-
pub async fn set_route_configuration(_device: &TunDevice) -> io::Result<()> {
6+
pub async fn set_route_configuration(_device: &mut TunDevice) -> io::Result<()> {
77
Ok(())
88
}

crates/shadowsocks-service/src/local/tun/sys/unix/bsd.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,6 @@ pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet:
5454
}
5555

5656
/// Set platform specific route configuration
57-
pub async fn set_route_configuration(_device: &TunDevice) -> io::Result<()> {
57+
pub async fn set_route_configuration(_device: &mut TunDevice) -> io::Result<()> {
5858
Ok(())
5959
}

crates/shadowsocks-service/src/local/tun/sys/unix/linux.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet:
1616
}
1717

1818
/// Set platform specific route configuration
19-
pub async fn set_route_configuration(_device: &TunDevice) -> io::Result<()> {
19+
pub async fn set_route_configuration(_device: &mut TunDevice) -> io::Result<()> {
2020
Ok(())
2121
}
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
1-
use std::{
2-
io::{self, ErrorKind},
3-
marker::Unpin,
4-
mem,
5-
};
1+
use std::{io, marker::Unpin};
62

7-
use log::{error, trace};
83
use tokio::io::{AsyncWrite, AsyncWriteExt};
94
use tun::{platform::Device as TunDevice, Device};
10-
use windows_sys::Win32::{
11-
Foundation::NO_ERROR,
12-
NetworkManagement::IpHelper::{
13-
CreateIpForwardEntry,
14-
GetBestInterface,
15-
MIB_IPFORWARDROW,
16-
MIB_IPROUTE_TYPE_INDIRECT,
17-
},
18-
Networking::WinSock::MIB_IPPROTO_NETMGMT,
19-
};
205

216
/// Packet Information length in bytes
227
///
@@ -31,52 +16,6 @@ pub async fn write_packet_with_pi<W: AsyncWrite + Unpin>(writer: &mut W, packet:
3116
}
3217

3318
/// Set platform specific route configuration
34-
pub async fn set_route_configuration(device: &TunDevice) -> io::Result<()> {
35-
let tun_address = match device.address() {
36-
Ok(t) => t,
37-
Err(err) => {
38-
error!("tun device doesn't have address, error: {}", err);
39-
return Err(io::Error::new(ErrorKind::Other, err));
40-
}
41-
};
42-
43-
let tun_netmask = match device.netmask() {
44-
Ok(m) => m,
45-
Err(err) => {
46-
error!("tun device doesn't have netmask, error: {}", err);
47-
return Err(io::Error::new(ErrorKind::Other, err));
48-
}
49-
};
50-
51-
unsafe {
52-
// https://learn.microsoft.com/en-us/windows/win32/api/ipmib/ns-ipmib-mib_ipforwardrow
53-
let mut ipfrow: MIB_IPFORWARDROW = mem::zeroed();
54-
55-
ipfrow.dwForwardDest = u32::from(tun_address);
56-
ipfrow.dwForwardMask = u32::from(tun_netmask);
57-
58-
// Get ifindex of this inteface
59-
// https://learn.microsoft.com/en-us/windows/win32/api/iphlpapi/nf-iphlpapi-getbestinterface
60-
let mut if_index: u32 = 0;
61-
let ret = GetBestInterface(ipfrow.dwForwardDest, &mut if_index);
62-
if ret != NO_ERROR {
63-
error!("GetBestInterface failed, ret: {}, destination: {}", ret, tun_address);
64-
return Err(io::Error::new(ErrorKind::Other, format!("GetBestInterface {}", ret)));
65-
}
66-
ipfrow.dwForwardIfIndex = if_index;
67-
68-
ipfrow.Anonymous1.dwForwardType = MIB_IPROUTE_TYPE_INDIRECT as u32;
69-
ipfrow.Anonymous2.dwForwardProto = MIB_IPPROTO_NETMGMT as u32;
70-
71-
let status = CreateIpForwardEntry(&ipfrow);
72-
if status != NO_ERROR {
73-
error!("CreateIpForwardEntry failed, status: {}", status);
74-
return Err(io::Error::new(
75-
ErrorKind::Other,
76-
format!("CreateIpForwardEntry {}", status),
77-
));
78-
}
79-
}
80-
19+
pub async fn set_route_configuration(_device: &mut TunDevice) -> io::Result<()> {
8120
Ok(())
8221
}

0 commit comments

Comments
 (0)