From f1b3a8a28cca16ce5e8c7876e973a693f2dadb58 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Tue, 14 Apr 2026 16:43:39 +0800 Subject: [PATCH] Fix sing-box tun --- .../Singbox/SingboxInboundService.cs | 2 +- .../Singbox/SingboxRoutingService.cs | 45 +++++-------------- 2 files changed, 11 insertions(+), 36 deletions(-) diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs index 3a27c7da..13c4e40b 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs @@ -11,7 +11,7 @@ public partial class CoreConfigSingboxService _coreConfig.inbounds = []; if (!context.IsTunEnabled - || (context.IsTunEnabled && _node.Port != listenPort)) + || (context.IsTunEnabled && _node.Address != Global.Loopback && _node.Port != listenPort)) { var inbound = new Inbound4Sbox() { diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 01c32cc2..5d19ddb7 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -34,14 +34,14 @@ public partial class CoreConfigSingboxService _coreConfig.route.rules.AddRange(tunRules); } - var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe(); _coreConfig.route.rules.Add(new() { port = [53], - action = "hijack-dns", - process_name = lstDnsExe + network = ["udp"], + action = "hijack-dns" }); + var lstDirectExe = BuildRoutingDirectExe(); _coreConfig.route.rules.Add(new() { outbound = Global.DirectTag, @@ -79,28 +79,6 @@ public partial class CoreConfigSingboxService } } - if (_config.Inbound.First().SniffingEnabled) - { - _coreConfig.route.rules.Add(new() - { - action = "sniff" - }); - _coreConfig.route.rules.Add(new() - { - protocol = ["dns"], - action = "hijack-dns" - }); - } - else - { - _coreConfig.route.rules.Add(new() - { - port = [53], - network = ["udp"], - action = "hijack-dns" - }); - } - var hostsDomains = new List(); if (rawDNSItem is not { Enabled: true }) { @@ -234,9 +212,8 @@ public partial class CoreConfigSingboxService } } - private static (List lstDnsExe, List lstDirectExe) BuildRoutingDirectExe() + private static List BuildRoutingDirectExe() { - var dnsExeSet = new HashSet(StringComparer.OrdinalIgnoreCase); var directExeSet = new HashSet(StringComparer.OrdinalIgnoreCase); var coreInfoResult = CoreInfoManager.Instance.GetCoreInfo(); @@ -248,20 +225,18 @@ public partial class CoreConfigSingboxService continue; } + if (coreConfig.CoreExes == null) + { + continue; + } + foreach (var baseExeName in coreConfig.CoreExes) { - if (coreConfig.CoreType != ECoreType.sing_box) - { - dnsExeSet.Add(Utils.GetExeName(baseExeName)); - } directExeSet.Add(Utils.GetExeName(baseExeName)); } } - var lstDnsExe = new List(dnsExeSet); - var lstDirectExe = new List(directExeSet); - - return (lstDnsExe, lstDirectExe); + return new List(directExeSet); } private void GenRoutingUserRule(RulesItem? item)