diff --git a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs index 3f563685..abce5de6 100644 --- a/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs +++ b/v2rayN/ServiceLib/Handler/Builder/CoreConfigContextBuilder.cs @@ -49,6 +49,7 @@ public class CoreConfigContextBuilder RoutingItem = await ConfigHandler.GetDefaultRouting(config), IsWindows = Utils.IsWindows(), IsMacOS = Utils.IsMacOS(), + IsLinux = Utils.IsLinux(), HasGlobalIPv6Address = Utils.HasGlobalIPv6Address(), ProtectCoreTypeList = config.TunModeItem.EnableTun ? [ECoreType.Xray, ECoreType.sing_box] : [] }; diff --git a/v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs b/v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs index 6d8b340c..6df45717 100644 --- a/v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/CoreConfigContext.cs @@ -24,6 +24,7 @@ public record CoreConfigContext public bool IsWindows { get; init; } public bool IsMacOS { get; init; } + public bool IsLinux { get; init; } // Defaults to true so that a context built without this flag keeps routing IPv6 into the // tunnel; only a positive detection of the host having no global IPv6 address turns it off. diff --git a/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs index cf3b146b..5978e79f 100644 --- a/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs +++ b/v2rayN/ServiceLib/Models/CoreConfigs/V2rayConfig.cs @@ -92,6 +92,10 @@ public class Inboundsettings4Ray public string? autoOutboundsInterface { get; set; } public List? dns { get; set; } + + public bool? autoSystemDnsToGateway { get; set; } + + public List? autoSystemWfpBlockLeak { get; set; } } public class Sniffing4Ray diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayInboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayInboundService.cs index 296bf379..cfed9aaa 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayInboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayInboundService.cs @@ -90,6 +90,15 @@ public partial class CoreConfigV2rayService // tunInbound.sniffing.routeOnly = inbound.sniffing.routeOnly; tunInbound.sniffing.routeOnly = true; + if (context.IsWindows && _config.TunModeItem.StrictRoute == true) + { + tunInbound.settings.autoSystemWfpBlockLeak = ["dns", "misconfigtun"]; + } + if (context.IsLinux) + { + tunInbound.settings.autoSystemDnsToGateway = true; + } + if (_config.TunModeItem.RouteExcludeAddress is { Count: > 0 }) { var wholeInternet = IPNetwork2.Parse("0.0.0.0/0");