Skip to content

feat(tun): user-configurable MTU and outbound interface#27

Merged
PhoenixNil merged 2 commits into
mainfrom
feat/tun-configurable-mtu-outbound
May 23, 2026
Merged

feat(tun): user-configurable MTU and outbound interface#27
PhoenixNil merged 2 commits into
mainfrom
feat/tun-configurable-mtu-outbound

Conversation

@PhoenixNil
Copy link
Copy Markdown
Owner

@PhoenixNil PhoenixNil commented May 23, 2026

Summary

  • Replace TUN's runtime outbound-interface detection with an explicit user-facing dialog: defaults to "auto" (xray picks), with optional override for MTU (68-9000) and a specific interface.
  • Add ResetTunDnsServers so stale DNS entries on the xray-tun adapter get cleared between runs.
  • Upgrade xray-core 26.4.25 → 26.5.9.

Why

The previous probe (UDP-to-8.8.8.8 + NIC matching) could fail in multi-NIC / VPN setups and blocked TUN startup. xray-core's autoOutboundsInterface="auto" already handles the common case — this PR exposes it to the user instead of doing our own detection. As a side benefit, users on unusual network topologies can now override the interface manually.

Test plan

  • TUN toggle → confirmation dialog appears with collapsed "更多选项"; cancel → toggle reverts, no relaunch.
  • Confirm with defaults → relaunches elevated, TUN comes up cleanly.
  • Set custom MTU (e.g. 1280) → reflected in generated xray_config.json and persisted across restart.
  • Pick a specific outbound interface → bound via sockopt.interface for the proxy/direct/chain outbounds.
  • Persisted-but-missing interface scenario → still shown in the dropdown so the user can change it deliberately.
  • Disconnect TUN → no leftover DNS on the xray-tun adapter (verify with netsh interface ipv4 show dnsservers).

PhoenixNil and others added 2 commits May 23, 2026 08:23
Replace the runtime "detect default outbound interface" probe with explicit
user configuration via a new confirmation dialog when enabling TUN mode.
Auto mode (the default) lets xray pick the interface itself -- same behavior
as before, just without the manual probe.

- AppSettings: persist TunMtu (default 1500) and TunOutboundInterface
  (default "auto").
- XrayConfigConstants: shared TunInterfaceName, MTU bounds, and
  NormalizeTunMtu so TunService and XrayConfigBuilder agree on the
  adapter name and value validation.
- XrayConfigBuilder: drop tunOutboundInterfaceName parameter; read MTU
  and interface from settings. "auto" skips sockopt.interface entirely.
- TunService: remove DetectDefaultOutboundInterfaceName + helpers. Add
  ResetTunDnsServers (netsh, single elevated batch) to clear stale DNS
  on the xray-tun adapter; route-cleanup path bundles the reset into
  its existing elevated batch so the user still sees one UAC.
- TunConfirmationDialog: collapsed "更多选项" panel exposes MTU
  (NumberBox 68-9000) and an Interface ComboBox seeded with active
  adapters; a persisted-but-missing interface is surfaced so the user
  can see what's saved.
- ControlPanelViewModel: TUN toggle shows the new dialog and persists
  the chosen values before relaunching elevated.

Also pin Microsoft.WindowsAppSDK.AI / Microsoft.Windows.AI.MachineLearning
to 2.0.* (was "*") to avoid an unintended jump to a future major.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9cecf8a807

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +81 to +83
.Where(ni => ni.OperationalStatus == OperationalStatus.Up
&& ni.NetworkInterfaceType != NetworkInterfaceType.Loopback)
.Select(ni => ni.Name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Exclude TUN/virtual NICs from outbound interface list

The advanced interface picker currently includes every OperationalStatus.Up adapter except loopback, which can surface tunnel/virtual NICs (including Xray/Wintun adapters) as selectable outbound targets. If a user picks one of these, TunOutboundInterface is written into sockopt.interface and Xray can bind its own outbound traffic to a non-physical interface, leading to routing loops or broken connectivity in TUN mode. The previous implementation explicitly filtered these adapter types/names, so this is a regression in the new manual-selection flow.

Useful? React with 👍 / 👎.

@PhoenixNil PhoenixNil merged commit b618107 into main May 23, 2026
4 checks passed
@PhoenixNil PhoenixNil deleted the feat/tun-configurable-mtu-outbound branch May 23, 2026 01:30
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