From 398dbbd2e51da99a193b59dbe948fecee5246711 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 3 May 2024 10:29:32 +0800 Subject: [PATCH] Bug fix https://github.com/2dust/v2rayN/issues/5035 --- v2rayN/v2rayN/Handler/CoreConfigSingbox.cs | 22 ++++++++++++++++++---- v2rayN/v2rayN/Models/SingboxConfig.cs | 10 +++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index 793f9ef2..fbe1dcd9 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -539,24 +539,38 @@ namespace v2rayN.Handler { try { + var dnsOutbound = "dns_out"; + if (!_config.inbound[0].sniffingEnabled) + { + singboxConfig.route.rules.Add(new() + { + port = [53], + network = "udp", + outbound = dnsOutbound + }); + } + if (_config.tunModeItem.enableTun) { singboxConfig.route.auto_detect_interface = true; var tunRules = JsonUtils.Deserialize>(Utils.GetEmbedText(Global.TunSingboxRulesFileName)); - singboxConfig.route.rules.AddRange(tunRules); + if (tunRules != null) + { + singboxConfig.route.rules.AddRange(tunRules); + } GenRoutingDirectExe(out List lstDnsExe, out List lstDirectExe); singboxConfig.route.rules.Add(new() { port = new() { 53 }, - outbound = "dns_out", + outbound = dnsOutbound, process_name = lstDnsExe }); singboxConfig.route.rules.Add(new() { - outbound = "direct", + outbound = Global.DirectTag, process_name = lstDirectExe }); } @@ -805,7 +819,7 @@ namespace v2rayN.Handler { tag = "local_local", address = "223.5.5.5", - detour = "direct" + detour = Global.DirectTag, }); dns4Sbox.rules.Add(new() { diff --git a/v2rayN/v2rayN/Models/SingboxConfig.cs b/v2rayN/v2rayN/Models/SingboxConfig.cs index 5798d6c9..6c5e444b 100644 --- a/v2rayN/v2rayN/Models/SingboxConfig.cs +++ b/v2rayN/v2rayN/Models/SingboxConfig.cs @@ -41,14 +41,14 @@ [Serializable] public class Rule4Sbox { - public string outbound { get; set; } - public string server { get; set; } + public string? outbound { get; set; } + public string? server { get; set; } public bool? disable_cache { get; set; } public List? inbound { get; set; } public List? protocol { get; set; } - public string type { get; set; } - public string mode { get; set; } - public string network { get; set; } + public string? type { get; set; } + public string? mode { get; set; } + public string? network { get; set; } public bool? ip_is_private { get; set; } public List? port { get; set; } public List? port_range { get; set; }