Merge branch '2dust:master' into master

This commit is contained in:
JieXu 2026-05-08 19:14:40 +08:00 committed by GitHub
commit bbdf29d69b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 12 deletions

View file

@ -1,6 +1,7 @@
using AwesomeAssertions; using AwesomeAssertions;
using ServiceLib.Common; using ServiceLib.Common;
using ServiceLib.Enums; using ServiceLib.Enums;
using ServiceLib.Manager;
using ServiceLib.Models; using ServiceLib.Models;
using ServiceLib.Services.CoreConfig; using ServiceLib.Services.CoreConfig;
using Xunit; using Xunit;
@ -28,6 +29,31 @@ public class CoreConfigSingboxServiceTests
singboxConfig.inbounds.Should().Contain(i => i.type == nameof(EInboundProtocol.mixed)); 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<SingboxConfig>(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] [Fact]
public void GenerateClientConfigContent_PolicyGroup_ShouldExpandChildrenAndBuildSelector() public void GenerateClientConfigContent_PolicyGroup_ShouldExpandChildrenAndBuildSelector()
{ {

View file

@ -1684,7 +1684,7 @@
<value>ICMP 路由策略</value> <value>ICMP 路由策略</value>
</data> </data>
<data name="TbLegacyProtect" xml:space="preserve"> <data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value> <value>舊版 TUN 保護</value>
</data> </data>
<data name="TbCamouflageDomain" xml:space="preserve"> <data name="TbCamouflageDomain" xml:space="preserve">
<value>偽裝域名</value> <value>偽裝域名</value>
@ -1702,30 +1702,30 @@
<value>僅用於抓取自簽證書,存在中間人風險。</value> <value>僅用於抓取自簽證書,存在中間人風險。</value>
</data> </data>
<data name="menuUdpTestServer" xml:space="preserve"> <data name="menuUdpTestServer" xml:space="preserve">
<value>Test Configurations UDP Delay</value> <value>測試 UDP 延遲(多選)</value>
</data> </data>
<data name="TbSettingsUdpTestUrl" xml:space="preserve"> <data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>UDP Test Url</value> <value>UDP 測試網址</value>
</data> </data>
<data name="TbSettingsSendThrough" xml:space="preserve"> <data name="TbSettingsSendThrough" xml:space="preserve">
<value>Local outbound address (SendThrough)</value> <value>本機出站位址 (SendThrough)</value>
</data> </data>
<data name="TbSettingsSendThroughTip" xml:space="preserve"> <data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value> <value>適用於多網路介面環境,請填寫本機 IPv4 位址</value>
</data> </data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve"> <data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Please fill in the correct IPv4 address for SendThrough.</value> <value>請填寫正確的 SendThrough IPv4 位址。</value>
</data> </data>
<data name="TbSettingsBindInterface" xml:space="preserve"> <data name="TbSettingsBindInterface" xml:space="preserve">
<value>Bind Interface</value> <value>綁定網路介面</value>
</data> </data>
<data name="TbSettingsBindInterfaceTip" xml:space="preserve"> <data name="TbSettingsBindInterfaceTip" xml:space="preserve">
<value>For multi-interface environments, enter the name of the interface to bind. Only effective on Windows systems and TUN mode</value> <value>適用於多網路介面環境請填寫要綁定的介面名稱Windows 系統有效,其他系統僅在 TUN 模式下生效。</value>
</data> </data>
<data name="TbPreSharedKey" xml:space="preserve"> <data name="TbPreSharedKey" xml:space="preserve">
<value>PreSharedKey</value> <value>PreSharedKey</value>
</data> </data>
<data name="menuExport2InnerUri" xml:space="preserve"> <data name="menuExport2InnerUri" xml:space="preserve">
<value>Export v2rayN Internal Share Link to Clipboard</value> <value>匯出 v2rayN 內部分享連結至剪貼簿(多選)</value>
</data> </data>
</root> </root>

View file

@ -8,10 +8,10 @@ public partial class CoreConfigSingboxService
{ {
var listen = "0.0.0.0"; var listen = "0.0.0.0";
var listenPort = AppManager.Instance.GetLocalPort(EInboundProtocol.socks); var listenPort = AppManager.Instance.GetLocalPort(EInboundProtocol.socks);
var isUsingLocalMixedPort = _node.Address == Global.Loopback && _node.Port == listenPort;
_coreConfig.inbounds = []; _coreConfig.inbounds = [];
if (!context.IsTunEnabled if (!context.IsTunEnabled || !isUsingLocalMixedPort)
|| (context.IsTunEnabled && _node.Address != Global.Loopback && _node.Port != listenPort))
{ {
var inbound = new Inbound4Sbox() var inbound = new Inbound4Sbox()
{ {