From ac5031fd95743802676b163d576c9e6afb124530 Mon Sep 17 00:00:00 2001 From: ospab Date: Thu, 28 May 2026 16:40:49 +0300 Subject: [PATCH] Fix Windows TUN routing loop for SIM modems (0.0.0.0 NextHop) --- ostp-client/src/tunnel/native_handler.rs | 7 +++++-- ostp-client/src/tunnel/wintun_handler.rs | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ostp-client/src/tunnel/native_handler.rs b/ostp-client/src/tunnel/native_handler.rs index 76de492..d446ab2 100644 --- a/ostp-client/src/tunnel/native_handler.rs +++ b/ostp-client/src/tunnel/native_handler.rs @@ -58,8 +58,11 @@ pub async fn run_native_tunnel( if ($route) {{\n\ $gw = $route.NextHop\n\ $ifIndex = $route.InterfaceIndex\n\ - # Route server IP and gateway directly via real interface (bypass TUN)\n\ - New-NetRoute -DestinationPrefix \"$remote_ip/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ + if ($gw -eq '0.0.0.0' -or $gw -eq '::') {{\n\ + New-NetRoute -DestinationPrefix \"$remote_ip/32\" -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ + }} else {{\n\ + New-NetRoute -DestinationPrefix \"$remote_ip/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ + }}\n\ if ($gw -ne '0.0.0.0') {{\n\ New-NetRoute -DestinationPrefix \"$gw/32\" -NextHop '0.0.0.0' -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ }}\n\ diff --git a/ostp-client/src/tunnel/wintun_handler.rs b/ostp-client/src/tunnel/wintun_handler.rs index b23d849..158dc33 100644 --- a/ostp-client/src/tunnel/wintun_handler.rs +++ b/ostp-client/src/tunnel/wintun_handler.rs @@ -93,7 +93,11 @@ pub async fn run_wintun_tunnel( if ($route) {{\n\ $gw = $route.NextHop\n\ $ifIndex = $route.InterfaceIndex\n\ - New-NetRoute -DestinationPrefix \"$remote_ip/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ + if ($gw -eq '0.0.0.0' -or $gw -eq '::') {{\n\ + New-NetRoute -DestinationPrefix \"$remote_ip/32\" -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ + }} else {{\n\ + New-NetRoute -DestinationPrefix \"$remote_ip/32\" -NextHop $gw -InterfaceIndex $ifIndex -RouteMetric 1 -ErrorAction SilentlyContinue\n\ + }}\n\ }}\n\ New-NetFirewallRule -DisplayName 'OSTP Tunnel In' -Direction Inbound -Program $exe_path -Action Allow -Enabled True -ErrorAction SilentlyContinue\n\ New-NetFirewallRule -DisplayName 'OSTP Tunnel Out' -Direction Outbound -Program $exe_path -Action Allow -Enabled True -ErrorAction SilentlyContinue\n",