Fix sing-box bind interface config

This commit is contained in:
Vinny 2026-05-08 07:28:39 +03:00
parent 7b14f2376c
commit 3cd9225bd2
2 changed files with 24 additions and 1 deletions

View file

@ -28,6 +28,29 @@ 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_BindInterface_ShouldUseDialBindInterface()
{
var config = CoreConfigTestFactory.CreateConfig(ECoreType.sing_box);
config.CoreBasicItem.BindInterface = "eth0";
CoreConfigTestFactory.BindAppManagerConfig(config);
var node = CoreConfigTestFactory.CreateVmessNode(ECoreType.sing_box);
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())!;
var proxy = cfg.outbounds.First(o => o.tag == Global.ProxyTag);
proxy.bind_interface.Should().Be("eth0");
proxy.detour.Should().BeNullOrEmpty();
}
[Fact] [Fact]
public void GenerateClientConfigContent_PolicyGroup_ShouldExpandChildrenAndBuildSelector() public void GenerateClientConfigContent_PolicyGroup_ShouldExpandChildrenAndBuildSelector()
{ {

View file

@ -72,7 +72,7 @@ public partial class CoreConfigSingboxService
} }
foreach (var outbound in _coreConfig.outbounds ?? []) foreach (var outbound in _coreConfig.outbounds ?? [])
{ {
outbound.detour = ShouldBindNet(outbound) ? bindInterface : null; outbound.bind_interface = ShouldBindNet(outbound) ? bindInterface : null;
} }
} }