diff --git a/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs b/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs index 91f2884b..2f12d22f 100644 --- a/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs +++ b/v2rayN/ServiceLib.Tests/CoreConfig/Singbox/CoreConfigSingboxServiceTests.cs @@ -1,6 +1,7 @@ using AwesomeAssertions; using ServiceLib.Common; using ServiceLib.Enums; +using ServiceLib.Manager; using ServiceLib.Models; using ServiceLib.Services.CoreConfig; using Xunit; @@ -28,6 +29,31 @@ public class CoreConfigSingboxServiceTests singboxConfig.inbounds.Should().Contain(i => i.type == nameof(EInboundProtocol.mixed)); } + [Fact] + public void GenerateClientConfigContent_TunWithLoopbackPreSocks_ShouldKeepMixedInbound() + { + var config = CoreConfigTestFactory.CreateConfig(ECoreType.sing_box); + CoreConfigTestFactory.BindAppManagerConfig(config); + var node = CoreConfigTestFactory.CreateSocksNode(ECoreType.sing_box); + node.Address = Global.Loopback; + node.Port = 1080; + var context = CoreConfigTestFactory.CreateContext(config, node, ECoreType.sing_box) with + { + IsTunEnabled = true, + }; + + var result = new CoreConfigSingboxService(context).GenerateClientConfigContent(); + + result.Success.Should().BeTrue($"ret msg: {result.Msg}"); + var cfg = JsonUtils.Deserialize(result.Data!.ToString())!; + + cfg.inbounds.Should().Contain(i => + i.type == nameof(EInboundProtocol.mixed) + && i.listen == Global.Loopback + && i.listen_port == AppManager.Instance.GetLocalPort(EInboundProtocol.socks)); + cfg.inbounds.Should().Contain(i => i.type == "tun"); + } + [Fact] public void GenerateClientConfigContent_PolicyGroup_ShouldExpandChildrenAndBuildSelector() { diff --git a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx index 547f5749..61f231b1 100644 --- a/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx +++ b/v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx @@ -1684,7 +1684,7 @@ ICMP 路由策略 - Legacy TUN Protect + 舊版 TUN 保護 偽裝域名 @@ -1702,30 +1702,30 @@ 僅用於抓取自簽證書,存在中間人風險。 - Test Configurations UDP Delay + 測試 UDP 延遲(多選) - UDP Test Url + UDP 測試網址 - Local outbound address (SendThrough) + 本機出站位址 (SendThrough) - For multi-interface environments, enter the local machine's IPv4 address + 適用於多網路介面環境,請填寫本機 IPv4 位址 - Please fill in the correct IPv4 address for SendThrough. + 請填寫正確的 SendThrough IPv4 位址。 - Bind Interface + 綁定網路介面 - For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode + 適用於多網路介面環境,請填寫要綁定的介面名稱;Windows 系統有效,其他系統僅在 TUN 模式下生效。 PreSharedKey - Export v2rayN Internal Share Link to Clipboard + 匯出 v2rayN 內部分享連結至剪貼簿(多選) - \ No newline at end of file + diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs index b1e24a74..2e13c624 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxInboundService.cs @@ -8,10 +8,10 @@ public partial class CoreConfigSingboxService { var listen = "0.0.0.0"; var listenPort = AppManager.Instance.GetLocalPort(EInboundProtocol.socks); + var isUsingLocalMixedPort = _node.Address == Global.Loopback && _node.Port == listenPort; _coreConfig.inbounds = []; - if (!context.IsTunEnabled - || (context.IsTunEnabled && _node.Address != Global.Loopback && _node.Port != listenPort)) + if (!context.IsTunEnabled || !isUsingLocalMixedPort) { var inbound = new Inbound4Sbox() {