Skip to content

Commit e914a36

Browse files
committed
Use regular default route for the tunnel interface on Windows instead of /1 routes
This is done for two reasons: 1. This mitigates an issue in our fork of wireguard-nt, which intentionally allows routes back to the tunnel interface. The fork explicitly disallows this only for routes with a prefix 0, which means that the /1 routes are not exempted. This can result in an infinite routing loop if the non-tunnel route to the relay is removed (e.g., if the default interface or its routes disappear). 2. This simplifies the code and routes. The /1 routes are unnecessary since we're setting metric on the default route to lowest value anyway, so the OS should always prefer the tunnel default route. Even when it doesn't, the firewall will prevent leaks.
1 parent 66e2c86 commit e914a36

File tree

1 file changed

+1
-22
lines changed

1 file changed

+1
-22
lines changed

talpid-wireguard/src/lib.rs

+1-22
Original file line numberDiff line numberDiff line change
@@ -746,9 +746,7 @@ impl WireguardMonitor {
746746
#[cfg(target_os = "android")] cancel_receiver: connectivity::CancelReceiver,
747747
) -> Result<WgGoTunnel> {
748748
#[cfg(all(unix, not(target_os = "android")))]
749-
let routes = config
750-
.get_tunnel_destinations()
751-
.flat_map(Self::replace_default_prefixes);
749+
let routes = config.get_tunnel_destinations();
752750

753751
#[cfg(all(unix, not(target_os = "android")))]
754752
let tunnel = WgGoTunnel::start_tunnel(config, log_path, tun_provider, routes)
@@ -925,7 +923,6 @@ impl WireguardMonitor {
925923
let iter = config
926924
.get_tunnel_destinations()
927925
.filter(|allowed_ip| allowed_ip.prefix() == 0)
928-
.flat_map(Self::replace_default_prefixes)
929926
.map(move |allowed_ip| {
930927
if allowed_ip.is_ipv4() {
931928
RequiredRoute::new(allowed_ip, node_v4.clone())
@@ -965,24 +962,6 @@ impl WireguardMonitor {
965962
}
966963
}
967964

968-
/// Replace default (0-prefix) routes with more specific routes.
969-
#[cfg(not(target_os = "android"))]
970-
fn replace_default_prefixes(network: ipnetwork::IpNetwork) -> Vec<ipnetwork::IpNetwork> {
971-
#[cfg(windows)]
972-
if network.prefix() == 0 {
973-
if network.is_ipv4() {
974-
vec!["0.0.0.0/1".parse().unwrap(), "128.0.0.0/1".parse().unwrap()]
975-
} else {
976-
vec!["8000::/1".parse().unwrap(), "::/1".parse().unwrap()]
977-
}
978-
} else {
979-
vec![network]
980-
}
981-
982-
#[cfg(not(windows))]
983-
vec![network]
984-
}
985-
986965
fn tunnel_metadata(interface_name: &str, config: &Config) -> TunnelMetadata {
987966
TunnelMetadata {
988967
interface: interface_name.to_string(),

0 commit comments

Comments
 (0)