feat(core): support AUTO option and filter non-IP NDIS interfaces for BindInterface (#10519)

* feat(core): support AUTO detection and manual selection for BindInterface (#10519)

- Implements the 3-state design agreed in #10519:
  1. Empty: do not bind interface, preserve existing behavior.
  2. AUTO: automatically detect default active physical network interface and bind to it.
  3. Specific interface: prioritize user-selected network interface.
- Centralizes interface resolution in NetworkUtils.GetRealBindInterfaceName().
- Supports AUTO in CoreConfigContextBuilder, Singbox, and V2ray template services.
- Adds comprehensive unit tests covering AUTO detection, context validation, and config generation.

* refactor: optimize AUTO bindInterface resolution and add mock-based tests

- Resolve AUTO interface once in CoreConfigContextBuilder and store in CoreConfigContext.ResolvedBindInterface as single-source-of-truth
- Downstream sing-box and Xray outbound/TUN services consume ResolvedBindInterface directly
- Unify TrimEx and case-insensitive check via NetworkUtils.IsAuto to tolerate user input whitespace
- Log and issue validator warning when AUTO fails to resolve any physical adapter
- Extract pure SelectDefaultInterface function with NetworkInterfaceCandidate for deterministic, mock-based unit testing
- Add comprehensive unit tests covering Ethernet vs Wi-Fi preference, no-gateway fallback, and virtual adapter filtering

* refactor(network): filter non-IP NDIS interfaces and simplify AUTO bindInterface resolution

* fix(ui,network): align BindInterface ComboBox width and refine physical NIC matching

* Update CoreConfigContextBuilder.cs

---------

Co-authored-by: 2dust <31833384+2dust@users.noreply.github.com>
This commit is contained in:
Lyu Bingrong
2026-11-08 00:53:06 -08:00
committed by GitHub
parent 1e167449ea
commit 968beb4432
9 changed files with 129 additions and 21 deletions
@@ -121,17 +121,28 @@ public class CoreConfigContextBuilder
&& !Utils.IsLocalIP(context.AppConfig.CoreBasicItem.SendThrough))
{
validatorResult.Warnings.Add(string.Format(ResUI.MsgInvalidProperty, ResUI.TbSettingsSendThrough));
var appConfig = JsonUtils.DeepCopy(config);
var appConfig = JsonUtils.DeepCopy(context.AppConfig);
appConfig.CoreBasicItem.SendThrough = string.Empty;
context = context with { AppConfig = appConfig };
}
if (!context.AppConfig.CoreBasicItem.BindInterface.IsNullOrEmpty()
&& (!Utils.ContainsInterfaceName(context.AppConfig.CoreBasicItem.BindInterface)
|| !(context.IsTunEnabled || context.IsWindows)))
var bindInterface = context.AppConfig.CoreBasicItem.BindInterface?.TrimEx();
if (bindInterface.IsNotEmpty())
{
validatorResult.Warnings.Add(string.Format(ResUI.MsgInvalidProperty, ResUI.TbSettingsBindInterface));
var appConfig = JsonUtils.DeepCopy(config);
appConfig.CoreBasicItem.BindInterface = string.Empty;
if (NetworkUtils.IsAutoBindInterface(bindInterface))
{
bindInterface = NetworkUtils.GetDefaultPhysicalInterfaceName()?.TrimEx();
}
if (bindInterface.IsNullOrEmpty()
|| !Utils.ContainsInterfaceName(bindInterface)
|| !(context.IsTunEnabled || context.IsWindows))
{
validatorResult.Warnings.Add(string.Format(ResUI.MsgInvalidProperty, ResUI.TbSettingsBindInterface));
bindInterface = string.Empty;
}
var appConfig = JsonUtils.DeepCopy(context.AppConfig);
appConfig.CoreBasicItem.BindInterface = bindInterface;
context = context with { AppConfig = appConfig };
}