Skip to content

fix(network): select the Windows NAT default route - #1

Merged
agalwood merged 2 commits into
mainfrom
fix/1999_windows_default_route_20260828
Aug 28, 2026
Merged

agalwood merged 2 commits into
mainfrom
fix/1999_windows_default_route_20260828

Conversation

@agalwood

Copy link
Copy Markdown
Member

Summary

Fix Windows NAT discovery and mapping when virtual adapters such as Tailscale compete with the physical default route.

The fix has already been published as @motrix/nat@0.1.1.

Related to agalwood/Motrix#1999.

Key changes

  • Resolve the Windows IPv4 default route through the trusted %SystemRoot%\System32\route.exe, preferring a physical adapter before comparing route metrics.
  • Cache and single-flight asynchronous route verification, with safe fallback behavior when route inspection is unavailable.
  • Bind UPnP discovery to the verified local interface and atomically synchronize the NAT-PMP/PCP gateway and PCP client address.
  • Invalidate stale gateways, mappings, and renewal state after route changes, while coalescing discovery/remap work across rapid network and lifecycle transitions.
  • Add coverage for the Tailscale routing case, route parsing and refresh behavior, client rebinding, remapping, and stop/start races.
  • Document the network-route API and prepare the 0.1.1 release.

Validation

  • pnpm run prepublishOnly
    • Biome and custom NAT-module lint passed
    • TypeScript type-check passed
    • Vitest: 404 tests passed, 4 skipped
    • tsup build passed
  • npm publish dry run passed
  • @motrix/nat@0.1.1 published successfully

@agalwood
agalwood merged commit ac80d37 into main Aug 28, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant