Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add bind interface
  • Loading branch information
DHR60 committed May 1, 2026
commit 4dc431bc3d0df6db5193777b778cd002098e0037
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static async Task<CoreConfigContextBuilderResult> Build(Config config, Pr
ProtectDomainList = [],
RawDnsItem = await AppManager.Instance.GetDNSItem(coreType),
RoutingItem = await ConfigHandler.GetDefaultRouting(config),
IsWindows = Utils.IsWindows(),
};
var validatorResult = NodeValidatorResult.Empty();
var (actNode, nodeValidatorResult) = await ResolveNodeAsync(context, node);
Expand Down
1 change: 0 additions & 1 deletion v2rayN/ServiceLib/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static class ConfigHandler
Loglevel = "warning",
MuxEnabled = false,
};
config.CoreBasicItem.SendThrough = config.CoreBasicItem.SendThrough?.TrimEx();

if (config.Inbound == null)
{
Expand Down
2 changes: 2 additions & 0 deletions v2rayN/ServiceLib/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class CoreBasicItem

public string? SendThrough { get; set; }

public string? BindInterface { get; set; }

public bool EnableFragment { get; set; }

public bool EnableCacheFile4Sbox { get; set; } = true;
Expand Down
2 changes: 2 additions & 0 deletions v2rayN/ServiceLib/Models/CoreConfigContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public record CoreConfigContext
// TUN Compatibility
public bool IsTunEnabled { get; init; } = false;
public HashSet<string> ProtectDomainList { get; init; } = [];

public bool IsWindows { get; init; }
}
18 changes: 18 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1689,9 +1689,6 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="TbCamouflageDomain" xml:space="preserve">
<value>Camouflage domain</value>
</data>
Expand All @@ -1713,4 +1710,19 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>UDP Test Url</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Local outbound address (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Please fill in the correct IPv4 address for SendThrough.</value>
</data>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>Bind Interface</value>
</data>
<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>
</data>
</root>
24 changes: 15 additions & 9 deletions v2rayN/ServiceLib/Resx/ResUI.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1311,15 +1311,6 @@
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>Le mot de passe sera vérifié en ligne de commande. En cas d’échec ou de dysfonctionnement, redémarrez l’application. Il n’est pas stocké et doit être saisi à chaque redémarrage.</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Adresse sortante locale (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>Pour environnements multi-interfaces, entrez l'adresse IPv4 de la machine locale.</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Veuillez saisir l’adresse IPv4 correcte de SendThrough.</value>
</data>
<data name="TransportHeaderType5" xml:space="preserve">
<value>Mode XHTTP</value>
</data>
Expand Down Expand Up @@ -1710,4 +1701,19 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbAllowInsecureCertFetchTips" xml:space="preserve">
<value>Only for fetching self-signed certificates. This may expose you to MITM risks.</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Adresse sortante locale (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>Pour environnements multi-interfaces, entrez l'adresse IPv4 de la machine locale</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Veuillez saisir l’adresse IPv4 correcte de SendThrough.</value>
</data>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>Lier l'interface</value>
</data>
<data name="TbSettingsBindInterfaceTip" xml:space="preserve">
<value>Pour les environnements multi-interfaces, entrez le nom de l'interface à lier. Ne fonctionne que sur les systèmes Windows et en mode TUN</value>
</data>
</root>
18 changes: 15 additions & 3 deletions v2rayN/ServiceLib/Resx/ResUI.hu.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1689,9 +1689,6 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="TbCamouflageDomain" xml:space="preserve">
<value>Álcázási tartomány</value>
</data>
Expand All @@ -1713,4 +1710,19 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>UDP Test Url</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Local outbound address (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Please fill in the correct IPv4 address for SendThrough.</value>
</data>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>Bind Interface</value>
</data>
<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>
</data>
</root>
26 changes: 16 additions & 10 deletions v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1314,15 +1314,6 @@
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>The password will be validated via the command line. If a validation error causes the application to malfunction, please restart the application. The password will not be stored and must be entered again after each restart.</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Local outbound address (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Please fill in the correct IPv4 address for SendThrough.</value>
</data>
<data name="TransportHeaderType5" xml:space="preserve">
<value>xhttp mode</value>
</data>
Expand Down Expand Up @@ -1719,4 +1710,19 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>UDP Test Url</value>
</data>
</root>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Local outbound address (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Please fill in the correct IPv4 address for SendThrough.</value>
</data>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>Bind Interface</value>
</data>
<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>
</data>
</root>
18 changes: 12 additions & 6 deletions v2rayN/ServiceLib/Resx/ResUI.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1689,9 +1689,6 @@
<data name="TbLegacyProtect" xml:space="preserve">
<value>Устаревшая защита TUN (Legacy Protect)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>Для среды с несколькими сетевыми интерфейсами укажите IPv4-адрес локального компьютера</value>
</data>
<data name="TbCamouflageDomain" xml:space="preserve">
<value>Камуфляжный домен</value>
</data>
Expand All @@ -1713,10 +1710,19 @@
<data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>URL для UDP-теста</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Локальный исходящий адрес (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>Для среды с несколькими сетевыми интерфейсами укажите IPv4-адрес локального компьютера</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Укажите корректный IPv4-адрес для SendThrough.</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Локальный исходящий адрес (SendThrough)</value>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>Привязать интерфейс</value>
</data>
<data name="TbSettingsBindInterfaceTip" xml:space="preserve">
<value>Для среды с несколькими сетевыми интерфейсами укажите имя интерфейса для привязки. Работает только в Windows и режиме TUN</value>
</data>
</root>
</root>
26 changes: 16 additions & 10 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1311,15 +1311,6 @@
<data name="TbSettingsLinuxSudoPasswordTip" xml:space="preserve">
<value>密码将调用命令行校验,如果因为校验错误导致无法正常运行时,请重启本应用。 密码不会存储,每次重启后都需要再次输入。</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>本地出站地址 (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>用于多网口环境,请填写本机 IPv4 地址</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>请填写正确的 SendThrough IPv4 地址。</value>
</data>
<data name="TransportHeaderType5" xml:space="preserve">
<value>XHTTP 模式</value>
</data>
Expand Down Expand Up @@ -1716,4 +1707,19 @@
<data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>UDP 测试地址</value>
</data>
</root>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>本地出站地址 (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>用于多网口环境,请填写本机 IPv4 地址</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>请填写正确的 SendThrough IPv4 地址。</value>
</data>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>绑定网口</value>
</data>
<data name="TbSettingsBindInterfaceTip" xml:space="preserve">
<value>用于多网口环境,填写要绑定的网口名称,仅生效于 Windows 系统和 TUN 模式</value>
</data>
</root>
18 changes: 15 additions & 3 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1686,9 +1686,6 @@
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="TbCamouflageDomain" xml:space="preserve">
<value>偽裝域名</value>
</data>
Expand All @@ -1710,4 +1707,19 @@
<data name="TbSettingsUdpTestUrl" xml:space="preserve">
<value>UDP Test Url</value>
</data>
<data name="TbSettingsSendThrough" xml:space="preserve">
<value>Local outbound address (SendThrough)</value>
</data>
<data name="TbSettingsSendThroughTip" xml:space="preserve">
<value>For multi-interface environments, enter the local machine's IPv4 address</value>
</data>
<data name="FillCorrectSendThroughIPv4" xml:space="preserve">
<value>Please fill in the correct IPv4 address for SendThrough.</value>
</data>
<data name="TbSettingsBindInterface" xml:space="preserve">
<value>Bind Interface</value>
</data>
<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>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public RetResult GenerateClientConfigContent()

ConvertGeo2Ruleset();

ApplyOutboundBindInterface();
ApplyOutboundSendThrough();

ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
Expand Down Expand Up @@ -170,6 +171,7 @@ public RetResult GenerateClientSpeedtestConfig(List<ServerTestItem> selecteds)
_coreConfig.route.rules.Add(rule);
}

ApplyOutboundBindInterface();
ApplyOutboundSendThrough();
ret.Success = true;
ret.Data = JsonUtils.Serialize(_coreConfig);
Expand Down Expand Up @@ -229,6 +231,7 @@ public RetResult GenerateClientSpeedtestConfig(int port)
listen_port = port,
type = EInboundProtocol.mixed.ToString(),
});
ApplyOutboundBindInterface();
ApplyOutboundSendThrough();

ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,38 @@ private string ApplyFullConfigTemplate()
return JsonUtils.Serialize(fullConfigTemplateNode);
}

private void ApplyOutboundSendThrough()
private void ApplyOutboundBindInterface()
{
var sendThrough = _config.CoreBasicItem.SendThrough?.TrimEx();
var bindInterface = _config.CoreBasicItem.BindInterface?.TrimEx();
if (bindInterface.IsNullOrEmpty())
{
return;
}
if (!(context.IsTunEnabled || context.IsWindows))
{
return;
}
foreach (var outbound in _coreConfig.outbounds ?? [])
{
outbound.inet4_bind_address = ShouldApplySendThrough(outbound, sendThrough) ? sendThrough : null;
outbound.detour = ShouldBindNet(outbound) ? bindInterface : null;
}
}

private static bool ShouldApplySendThrough(Outbound4Sbox outbound, string? sendThrough)
private void ApplyOutboundSendThrough()
{
var sendThrough = _config.CoreBasicItem.SendThrough?.TrimEx();
if (sendThrough.IsNullOrEmpty())
{
return false;
return;
}
foreach (var outbound in _coreConfig.outbounds ?? [])
{
outbound.inet4_bind_address = ShouldBindNet(outbound) ? sendThrough : null;
}
}

private static bool ShouldBindNet(Outbound4Sbox outbound)
{
if (outbound.type is "direct" or "block" or "dns" or "selector" or "urltest")
{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public RetResult GenerateClientConfigContent()
{
ApplyOutboundFragment();
}
ApplyOutboundBindInterface();
ApplyOutboundSendThrough();

var finalRule = BuildFinalRule();
Expand Down Expand Up @@ -203,6 +204,7 @@ public RetResult GenerateClientSpeedtestConfig(List<ServerTestItem> selecteds)
{
ApplyOutboundFragment();
}
ApplyOutboundBindInterface();
ApplyOutboundSendThrough();
//ret.Msg =string.Format(ResUI.SuccessfulConfiguration"), node.getSummary());
ret.Success = true;
Expand Down Expand Up @@ -274,6 +276,7 @@ public RetResult GenerateClientSpeedtestConfig(int port)
{
ApplyOutboundFragment();
}
ApplyOutboundBindInterface();
ApplyOutboundSendThrough();

ret.Msg = string.Format(ResUI.SuccessfulConfiguration, "");
Expand Down
Loading