Fix sing-box tun

This commit is contained in:
DHR60 2026-04-14 16:43:39 +08:00
parent 43dcb90632
commit f1b3a8a28c
2 changed files with 11 additions and 36 deletions

View file

@ -11,7 +11,7 @@ public partial class CoreConfigSingboxService
_coreConfig.inbounds = []; _coreConfig.inbounds = [];
if (!context.IsTunEnabled if (!context.IsTunEnabled
|| (context.IsTunEnabled && _node.Port != listenPort)) || (context.IsTunEnabled && _node.Address != Global.Loopback && _node.Port != listenPort))
{ {
var inbound = new Inbound4Sbox() var inbound = new Inbound4Sbox()
{ {

View file

@ -34,14 +34,14 @@ public partial class CoreConfigSingboxService
_coreConfig.route.rules.AddRange(tunRules); _coreConfig.route.rules.AddRange(tunRules);
} }
var (lstDnsExe, lstDirectExe) = BuildRoutingDirectExe();
_coreConfig.route.rules.Add(new() _coreConfig.route.rules.Add(new()
{ {
port = [53], port = [53],
action = "hijack-dns", network = ["udp"],
process_name = lstDnsExe action = "hijack-dns"
}); });
var lstDirectExe = BuildRoutingDirectExe();
_coreConfig.route.rules.Add(new() _coreConfig.route.rules.Add(new()
{ {
outbound = Global.DirectTag, 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<string>(); var hostsDomains = new List<string>();
if (rawDNSItem is not { Enabled: true }) if (rawDNSItem is not { Enabled: true })
{ {
@ -234,9 +212,8 @@ public partial class CoreConfigSingboxService
} }
} }
private static (List<string> lstDnsExe, List<string> lstDirectExe) BuildRoutingDirectExe() private static List<string> BuildRoutingDirectExe()
{ {
var dnsExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var directExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); var directExeSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
var coreInfoResult = CoreInfoManager.Instance.GetCoreInfo(); var coreInfoResult = CoreInfoManager.Instance.GetCoreInfo();
@ -248,20 +225,18 @@ public partial class CoreConfigSingboxService
continue; continue;
} }
if (coreConfig.CoreExes == null)
{
continue;
}
foreach (var baseExeName in coreConfig.CoreExes) foreach (var baseExeName in coreConfig.CoreExes)
{ {
if (coreConfig.CoreType != ECoreType.sing_box)
{
dnsExeSet.Add(Utils.GetExeName(baseExeName));
}
directExeSet.Add(Utils.GetExeName(baseExeName)); directExeSet.Add(Utils.GetExeName(baseExeName));
} }
} }
var lstDnsExe = new List<string>(dnsExeSet); return new List<string>(directExeSet);
var lstDirectExe = new List<string>(directExeSet);
return (lstDnsExe, lstDirectExe);
} }
private void GenRoutingUserRule(RulesItem? item) private void GenRoutingUserRule(RulesItem? item)