#3186·mihomo

[Bug] Windows: IPv4 forwarding on the bound outbound interface causes TUN self-reentry (latest Alpha)

Author: zanzhz1101Created Sep 5, 2026Updated Sep 23, 2026
Labelsbug

Verify steps

  • I have read the documentation and understand the meaning of all the configuration items I have written, rather than just piling up seemingly useful options or default values.
  • I have carefully reviewed the documentation and have not resolved the issue.
  • I have searched the Issue Tracker for the issue I want to raise and did not find it.
  • I am a non-Chinese user.
  • I have tested with the latest Alpha branch version, and the issue still persists.
  • I have provided the server and client configuration files and processes that can reproduce the issue locally, rather than a sanitized complex client configuration file.
  • I provided the simplest configuration that can be used to reproduce the errors in my report, rather than relying on remote servers or piling on a lot of unnecessary configurations for reproduction.
  • I have provided complete logs, rather than just the parts I think are useful out of confidence in my own intelligence.
  • I have directly reproduced the error using the Mihomo command-line program, rather than using other tools or scripts.

Operating System

Windows

System Version

Windows 11 Pro 25H2, OS build 26200.9168, x64

Mihomo Version

Mihomo Meta alpha-fd74ecb windows amd64 with go1.26.8 Sat Sep  5 02:03:57 UTC 2026
Use tags: with_gvisor

Tested on 2026-09-06 (UTC+08:00) using the latest official rolling Alpha available at test time: mihomo-windows-amd64-alpha-fd74ecb.zip.

Archive SHA256, verified against the release's checksums.txt: f8e247e80c13f048f32bdf6c23810e5203a1c33ef175fe739789527e5ad225e9.

Extracted executable SHA256: 152f4b633ddfe9988328644d1df35487ca4be78561e0dc9e9ff7428d2812f295. The executable was copied, byte-for-byte, to mihomo-alpha-probe.exe so that the diagnostic process rule targets only this test instance. No source modification or GUI-generated configuration was used for this instance.

Configuration File

yaml
mode: rule
log-level: debug
ipv6: false
find-process-mode: always
interface-name: 以太网
tun:
  enable: true
  device: MihomoAlphaProbe
  stack: system
  auto-route: true
  auto-detect-interface: false
  strict-route: false
  route-address:
  - 203.0.113.10/32
  dns-hijack: []
  mtu: 1420
dns:
  enable: false
  enhanced-mode: fake-ip
  fake-ip-range: 198.19.0.1/16
rules:
- PROCESS-NAME,mihomo-alpha-probe.exe,REJECT
- MATCH,DIRECT

Description

Enabling IPv4 Forwarding on the explicitly selected physical outbound interface causes Mihomo's own DIRECT TCP connections to enter its TUN again. This reproduces with the latest official Alpha, auto-detect-interface: false, and an explicit, correct interface-name.

The reproduction uses only 203.0.113.10:18080 (TEST-NET-3), one TUN /32 route, and DIRECT. It needs no subscription, proxy server, credentials, working Internet destination, DNS resolution, or HTTP server. The observation is self-reentry, not failure to obtain an HTTP response from a reserved address.

Expected: Mihomo's outbound connection should stay outside its own TUN when explicitly bound to the physical interface. If Windows cannot support that combination, a clear diagnostic and bounded failure would help.

Actual: With physical-interface forwarding enabled, the log contains an incoming connection attributed to mihomo-alpha-probe.exe, immediately after the original client is routed DIRECT. A first-match PROCESS-NAME,...,REJECT rule deliberately stops that connection from recursing. The empty response / EOF is the guard's consequence, not an independent failure criterion. The guard was retained throughout the experiment; no unbounded loop was induced with this Alpha build.

Controlled A/B/A result

Only IPv4 Forwarding on interface index 10 changed between phases. The Alpha process, configuration, TUN route, physical outbound interface, weak-host settings, and global registry setting remained unchanged.

Phase / local start time (UTC+08:00) Physical forwarding Unbound curl client Explicitly interface-bound Python socket Core self-reentry in complete log
A1 / 02:32:24.504 Disabled Timeout, exit 28, 3.036 s Timeout, 2.003 s None
B / 02:32:30.784 Enabled Empty reply, exit 52, 0.026 s EOF, 0.020 s Two core connections, both caught by the guard
A2 / 02:32:32.049 Disabled Timeout, exit 28, 3.033 s Timeout, 2.011 s None

The unbound client normally enters TUN in all phases. In phase B the explicitly bound Python client also enters TUN, despite getsockopt(IP_UNICAST_IF) returning the requested physical index 10. It is absent from the TUN TCP log in A1/A2. A timeout in the disabled phases is expected for the chosen reserved destination and does not imply a successful remote connection.

Host and routing context

  • Windows 11 Pro 25H2, build 26200.9168, x64; elevated CLI.
  • Physical outbound: Intel(R) Ethernet Controller (3) I225-V, driver 1.1.4.43 dated 2024-02-15; index 10; address 192.168.8.130; gateway 192.168.8.1; interface metric 25.
  • The adapter's literal local name is 以太网 (Ethernet). It is preserved in the exact configuration/logs below; replace it with the correct physical adapter name on another machine.
  • WeakHostSend=Disabled and WeakHostReceive=Disabled on the physical interface throughout.
  • HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\IPEnableRouter=1 throughout. Whether this global setting is necessary on a clean machine was not separately tested.
  • Another Remote NDIS interface (index 11) has 192.168.10.2/24, gateway 192.168.10.1, metric 5000, forwarding enabled, and both weak-host flags disabled; it was unchanged.
  • The test TUN was MihomoAlphaProbe, index 50, 198.19.0.1/30. The destination route was 203.0.113.10/32 -> 198.19.0.2, interface 50, route metric 0.
  • To preserve this machine's working network, an existing Clash Verge Rev 2.5.2 / Mihomo v1.19.29 instance remained running. Its TUN routes were temporarily restricted to 198.18.0.0/16 on interface 47; it did not own the test destination route. Its configuration was not used by the Alpha instance. This is a direct CLI reproduction, but not a clean-machine / single-process environment; that limitation is stated explicitly.

The full-public TUN symptom was originally observed with v1.19.29. Disabling forwarding on the physical interface restored normal QQ login and Bilibili playback on this host. The current report narrows the directly demonstrated Alpha behavior to IPv4 TCP self-reentry; it does not claim a separately captured Alpha UDP reproduction or a specific Windows kernel/driver defect.

Investigation direction

The Windows dialer at the tested commit uses IP_UNICAST_IF for IPv4 binding. The independent socket control below makes a Windows routing interaction plausible, but does not establish the exact layer responsible. Could Mihomo detect this combination and either keep egress out of TUN using a supported mechanism, or warn clearly and prevent self-recursion? Globally disabling forwarding without consent would also affect legitimate routing/tethering use cases.

I reviewed the TUN documentation and outbound-interface setting; explicit physical-interface selection is already applied here.

Related reports and checklist clarification

I searched existing reports and found the related items above, so the optional checklist statement saying I found none is intentionally unchecked. I prefer to report in English; the optional statement that I am a non-Chinese user is also left unchecked.

Reproduction Steps

Use an elevated PowerShell terminal. This example's physical index is 10; select your own physical outbound index with Get-NetIPInterface and use the matching interface-name in the YAML. Use a local console or an isolated test machine, and keep the test route limited to the reserved /32. Do not enable forwarding while an unrelated full-public TUN still captures your working network.

  1. Extract the official Alpha above into an otherwise empty test directory. Copy its executable to mihomo-alpha-probe.exe. Save the exact YAML from the Configuration File field as config.yaml. The process name in the guard must match the actual executable name.

  2. Verify the binary and configuration, then invoke the core directly in terminal A:

powershell
.\mihomo-alpha-probe.exe -v
.\mihomo-alpha-probe.exe -t -d . -f .\config.yaml
.\mihomo-alpha-probe.exe -d . -f .\config.yaml

The actual collection run invoked these CLI arguments against a dedicated absolute test directory, with stdout and stderr redirected to the single complete core-debug.log included below. A separate watchdog restored the working network after the test. The watchdog and client harness did not generate or rewrite this Alpha configuration during the A/B/A sequence.

  1. In terminal B, inspect the interface and route, then run a curl request in each forwarding state without restarting or reconfiguring the core:
powershell
$outboundIndex = 10
Get-NetIPInterface -InterfaceIndex $outboundIndex -AddressFamily IPv4 |
    Format-List InterfaceIndex,InterfaceAlias,Forwarding,WeakHostSend,WeakHostReceive
Get-NetRoute -DestinationPrefix '203.0.113.10/32'

# A1
Set-NetIPInterface -InterfaceIndex $outboundIndex -AddressFamily IPv4 -Forwarding Disabled -PolicyStore ActiveStore
curl.exe --noproxy '*' --connect-timeout 2 --max-time 3 -v http://203.0.113.10:18080/

# B
Set-NetIPInterface -InterfaceIndex $outboundIndex -AddressFamily IPv4 -Forwarding Enabled -PolicyStore ActiveStore
curl.exe --noproxy '*' --connect-timeout 2 --max-time 3 -v http://203.0.113.10:18080/

# A2: restore this before restoring any full-public TUN routes
Set-NetIPInterface -InterfaceIndex $outboundIndex -AddressFamily IPv4 -Forwarding Disabled -PolicyStore ActiveStore
curl.exe --noproxy '*' --connect-timeout 2 --max-time 3 -v http://203.0.113.10:18080/
  1. Observe that B produces a mihomo-alpha-probe.exe incoming TCP connection caught by ProcessName(...)->REJECT. A1 and A2 do not. End the probe after A2 and restore the original routing setup. In this capture the probe process was terminated after the final timeout, so the complete log ends without a graceful-shutdown message.

The dns block sets the isolated TUN's IPv4 range to 198.19.0.1/16, avoiding overlap with the existing 198.18.0.0/16 TUN. The requests use a literal IP. The complete log retains incidental DNS-hijack messages to the test adapter's local DNS address; those are not the TCP reproduction traffic. The first process rule is a deliberate recursion guard, and find-process-mode: always makes attribution explicit.

Additional socket control used in each phase

After each curl request, the collection run used this equivalent Python 3.14 socket control with a two-second timeout. It is an optional client-side diagnostic; the curl-only sequence above reproduces the core issue.

python
import socket
import struct

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
    sock.settimeout(2)
    # Windows sets IP_UNICAST_IF in network byte order.
    sock.setsockopt(socket.IPPROTO_IP, 31, struct.pack('!I', 10))
    # Windows gets IP_UNICAST_IF in HOST byte order.
    print(struct.unpack('=I', sock.getsockopt(socket.IPPROTO_IP, 31, 4))[0])
    try:
        sock.connect(('203.0.113.10', 18080))
        sock.sendall(b'GET / HTTP/1.1\r\nHost: 203.0.113.10\r\nConnection: close\r\n\r\n')
        print(repr(sock.recv(100)))
    except OSError as error:
        print(type(error).__name__, str(error))

Both byte-order conventions follow Microsoft's IPPROTO_IP socket option documentation. The observed returned index was 10 in every phase.

Complete client results from the collection run (timestamps in UTC)
json
[
  {
    "time": "2026-09-05T18:32:24.504753+00:00",
    "phase": "A1_forwarding_disabled",
    "client": "curl.exe",
    "exit": 28,
    "stdout": "",
    "stderr": "*   Trying 203.0.113.10:18080...\r\n* Established connection to 203.0.113.10 (203.0.113.10 port 18080) from 198.19.0.1 port 53226 \r\n  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current\r\n                                 Dload  Upload  Total   Spent   Left   Speed\r\n\r  0      0   0      0   0      0      0      0                              0* using HTTP/1.x\r\n> GET / HTTP/1.1\r\r\n> Host: 203.0.113.10:18080\r\r\n> User-Agent: curl/8.21.0\r\r\n> Accept: */*\r\r\n> \r\r\n* Request completely sent off\r\n\r  0      0   0      0   0      0      0      0           00:01              0* Operation timed out after 3012 milliseconds with 0 bytes received\r\n\r  0      0   0      0   0      0      0      0           00:03              0\r\n* closing connection #0\r\ncurl: (28) Operation timed out after 3012 milliseconds with 0 bytes received\r\n",
    "elapsed_seconds": 3.036
  },
  {
    "time": "2026-09-05T18:32:27.541104+00:00",
    "phase": "A1_forwarding_disabled",
    "client": "python-IP_UNICAST_IF",
    "IP_UNICAST_IF_get_host_order": 10,
    "result": "TimeoutError: timed out",
    "elapsed_seconds": 2.003
  },
  {
    "time": "2026-09-05T18:32:30.784018+00:00",
    "phase": "B_forwarding_enabled",
    "client": "curl.exe",
    "exit": 52,
    "stdout": "",
    "stderr": "*   Trying 203.0.113.10:18080...\r\n* Established connection to 203.0.113.10 (203.0.113.10 port 18080) from 198.19.0.1 port 58105 \r\n  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current\r\n                                 Dload  Upload  Total   Spent   Left   Speed\r\n\r  0      0   0      0   0      0      0      0                              0* using HTTP/1.x\r\n> GET / HTTP/1.1\r\r\n> Host: 203.0.113.10:18080\r\r\n> User-Agent: curl/8.21.0\r\r\n> Accept: */*\r\r\n> \r\r\n* Request completely sent off\r\n\r  0      0   0      0   0      0      0      0                              0\r  0      0   0      0   0      0      0      0                              0* Empty reply from server\r\n\r  0      0   0      0   0      0      0      0                              0\r\n* shutting down connection #0\r\ncurl: (52) Empty reply from server\r\n",
    "elapsed_seconds": 0.026
  },
  {
    "time": "2026-09-05T18:32:30.809972+00:00",
    "phase": "B_forwarding_enabled",
    "client": "python-IP_UNICAST_IF",
    "IP_UNICAST_IF_get_host_order": 10,
    "recv": "b''",
    "elapsed_seconds": 0.02
  },
  {
    "time": "2026-09-05T18:32:32.048801+00:00",
    "phase": "A2_forwarding_disabled",
    "client": "curl.exe",
    "exit": 28,
    "stdout": "",
    "stderr": "*   Trying 203.0.113.10:18080...\r\n* Established connection to 203.0.113.10 (203.0.113.10 port 18080) from 198.19.0.1 port 60157 \r\n  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current\r\n                                 Dload  Upload  Total   Spent   Left   Speed\r\n\r  0      0   0      0   0      0      0      0                              0* using HTTP/1.x\r\n> GET / HTTP/1.1\r\r\n> Host: 203.0.113.10:18080\r\r\n> User-Agent: curl/8.21.0\r\r\n> Accept: */*\r\r\n> \r\r\n* Request completely sent off\r\n\r  0      0   0      0   0      0      0      0           00:01              0\r  0      0   0      0   0      0      0      0           00:02              0* Operation timed out after 3008 milliseconds with 0 bytes received\r\n\r\n* closing connection #0\r\ncurl: (28) Operation timed out after 3008 milliseconds with 0 bytes received\r\n",
    "elapsed_seconds": 3.033
  },
  {
    "time": "2026-09-05T18:32:35.082398+00:00",
    "phase": "A2_forwarding_disabled",
    "client": "python-IP_UNICAST_IF",
    "IP_UNICAST_IF_get_host_order": 10,
    "result": "TimeoutError: timed out",
    "elapsed_seconds": 2.011
  }
]

Logs

bash
time="2026-09-06T02:32:20.291750300+08:00" level=info msg="Start initial configuration in progress"
time="2026-09-06T02:32:20.291750300+08:00" level=info msg="Geodata Loader mode: memconservative"
time="2026-09-06T02:32:20.291750300+08:00" level=info msg="Geosite Matcher implementation: succinct"
time="2026-09-06T02:32:20.291750300+08:00" level=info msg="Initial configuration complete, total time: 0ms"
time="2026-09-06T02:32:20.294298500+08:00" level=info msg="Sniffer is closed"
time="2026-09-06T02:32:20.309437200+08:00" level=warning msg="[TUN] default interface changed by monitor, => 以太网"
time="2026-09-06T02:32:22.706230500+08:00" level=info msg="[TUN] Tun adapter listening at: MihomoAlphaProbe([198.19.0.1/30],[]), mtu: 1420, auto route: true, auto redir: false, ip stack: System"
time="2026-09-06T02:32:22.706744100+08:00" level=info msg="Start initial compatible provider default"
time="2026-09-06T02:32:22.734053100+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:63999"
time="2026-09-06T02:32:22.746003000+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:56920"
time="2026-09-06T02:32:22.906925600+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:64936"
time="2026-09-06T02:32:23.104413300+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:56414"
time="2026-09-06T02:32:23.145701900+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:57882"
time="2026-09-06T02:32:24.205516700+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:58184"
time="2026-09-06T02:32:24.221276600+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:63647"
time="2026-09-06T02:32:24.233485200+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:55007"
time="2026-09-06T02:32:24.528095400+08:00" level=debug msg="[Rule] use default rules"
time="2026-09-06T02:32:25.078632400+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:55007"
time="2026-09-06T02:32:25.341374300+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:55007"
time="2026-09-06T02:32:25.360090900+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:55007"
time="2026-09-06T02:32:25.369287100+08:00" level=debug msg="[DNS] hijack udp:198.19.0.2:53 from 198.19.0.1:55007"
time="2026-09-06T02:32:25.990838200+08:00" level