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
Allow enable legacy process name tun protect
  • Loading branch information
DHR60 committed Mar 28, 2026
commit 6b3f09bd103ebf947e3c7eb34e340575eadf4abc
34 changes: 24 additions & 10 deletions v2rayN/ServiceLib/Handler/ConfigHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public static class ConfigHandler
EnableTun = false,
Mtu = 9000,
IcmpRouting = Global.TunIcmpRoutingPolicies.First(),
EnableLegacyProtect = false,
};
config.GuiItem ??= new();
config.MsgUIItem ??= new();
Expand Down Expand Up @@ -1414,19 +1415,32 @@ public static async Task<RetResult> AddGroupRegionServer(Config config, SubItem?
/// <returns>A SOCKS profile item or null if not needed</returns>
public static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
{
if (node.ConfigType != EConfigType.Custom || !(node.PreSocksPort > 0))
ProfileItem? itemSocks = null;
if (node.ConfigType != EConfigType.Custom
&& coreType != ECoreType.sing_box
&& config.TunModeItem.EnableTun
&& config.TunModeItem.EnableLegacyProtect)
{
return null;
itemSocks = new ProfileItem()
{
CoreType = ECoreType.sing_box,
ConfigType = EConfigType.SOCKS,
Address = Global.Loopback,
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
};
}
ProfileItem? itemSocks = null;
var preCoreType = AppManager.Instance.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
itemSocks = new ProfileItem()
else if (node.ConfigType == EConfigType.Custom
&& node.PreSocksPort is > 0 and <= 65535)
{
CoreType = preCoreType,
ConfigType = EConfigType.SOCKS,
Address = Global.Loopback,
Port = node.PreSocksPort.Value,
};
var preCoreType = AppManager.Instance.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
itemSocks = new ProfileItem()
{
CoreType = preCoreType,
ConfigType = EConfigType.SOCKS,
Address = Global.Loopback,
Port = node.PreSocksPort.Value,
};
}
return itemSocks;
}

Expand Down
1 change: 1 addition & 0 deletions v2rayN/ServiceLib/Models/ConfigItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public class TunModeItem
public int Mtu { get; set; }
public bool EnableIPv6Address { get; set; }
public string IcmpRouting { get; set; }
public bool EnableLegacyProtect { get; set; }
}

[Serializable]
Expand Down
9 changes: 9 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.

3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1695,4 +1695,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1692,4 +1692,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.hu.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1695,4 +1695,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1695,4 +1695,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
</root>
5 changes: 4 additions & 1 deletion v2rayN/ServiceLib/Resx/ResUI.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1695,4 +1695,7 @@
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1692,4 +1692,7 @@
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP 路由策略</value>
</data>
<data name="TbLegacyProtect" xml:space="preserve">
<value>旧版 TUN 保护</value>
</data>
</root>
5 changes: 4 additions & 1 deletion v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1692,4 +1692,7 @@
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP 路由策略</value>
</data>
</root>
<data name="TbLegacyProtect" xml:space="preserve">
<value>Legacy TUN Protect</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public RetResult GenerateClientConfigContent()
ret.Success = true;

ret.Data = ApplyFullConfigTemplate();
if (context.TunProtectSsPort is > 0 and <= 65535)
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
&& context.TunProtectSsPort is > 0 and <= 65535)
{
var ssInbound = new
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public RetResult GenerateClientConfigContent()
var ret = new RetResult();
try
{
if (context.IsTunEnabled && context.TunProtectSsPort > 0 && context.ProxyRelaySsPort > 0)
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
&& context.IsTunEnabled
&& context.TunProtectSsPort is > 0 and <= 65535
&& context.ProxyRelaySsPort is > 0 and <= 65535)
{
return GenerateClientProxyRelayConfig();
}
Expand Down
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/ViewModels/OptionSettingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class OptionSettingViewModel : MyReactiveObject
[Reactive] public int TunMtu { get; set; }
[Reactive] public bool TunEnableIPv6Address { get; set; }
[Reactive] public string TunIcmpRouting { get; set; }
[Reactive] public bool TunEnableLegacyProtect { get; set; }

#endregion Tun mode

Expand Down Expand Up @@ -220,6 +221,7 @@ private async Task Init()
TunMtu = _config.TunModeItem.Mtu;
TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address;
TunIcmpRouting = _config.TunModeItem.IcmpRouting;
TunEnableLegacyProtect = _config.TunModeItem.EnableLegacyProtect;

#endregion Tun mode

Expand Down Expand Up @@ -379,6 +381,7 @@ private async Task SaveSettingAsync()
_config.TunModeItem.Mtu = TunMtu;
_config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address;
_config.TunModeItem.IcmpRouting = TunIcmpRouting;
_config.TunModeItem.EnableLegacyProtect = TunEnableLegacyProtect;

//coreType
await SaveCoreType();
Expand Down
14 changes: 13 additions & 1 deletion v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@
Margin="{StaticResource Margin4}"
ColumnDefinitions="Auto,Auto,Auto"
DockPanel.Dock="Top"
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">

<TextBlock
Grid.Row="2"
Expand Down Expand Up @@ -851,6 +851,18 @@
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />

<TextBlock
Grid.Row="8"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbLegacyProtect}" />
<ToggleSwitch
x:Name="togEnableLegacyProtect"
Grid.Row="8"
Grid.Column="1"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
</Grid>
</TabItem>

Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public OptionSettingWindow()
this.Bind(ViewModel, vm => vm.TunMtu, v => v.cmbMtu.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunEnableIPv6Address, v => v.togEnableIPv6Address.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunIcmpRouting, v => v.cmbIcmpRoutingPolicy.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunEnableLegacyProtect, v => v.togEnableLegacyProtect.IsChecked).DisposeWith(disposables);

this.Bind(ViewModel, vm => vm.CoreType1, v => v.cmbCoreType1.SelectedValue).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.SelectedValue).DisposeWith(disposables);
Expand Down
15 changes: 15 additions & 0 deletions v2rayN/v2rayN/Views/OptionSettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
Expand Down Expand Up @@ -1105,6 +1106,20 @@
Grid.Column="1"
Margin="{StaticResource Margin8}"
HorizontalAlignment="Left" />

<TextBlock
Grid.Row="8"
Grid.Column="0"
Margin="{StaticResource Margin8}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbLegacyProtect}" />
<ToggleButton
x:Name="togEnableLegacyProtect"
Grid.Row="8"
Grid.Column="1"
Margin="{StaticResource Margin8}"
HorizontalAlignment="Left" />
</Grid>
</TabItem>

Expand Down
1 change: 1 addition & 0 deletions v2rayN/v2rayN/Views/OptionSettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public OptionSettingWindow()
this.Bind(ViewModel, vm => vm.TunMtu, v => v.cmbMtu.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunEnableIPv6Address, v => v.togEnableIPv6Address.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunIcmpRouting, v => v.cmbIcmpRoutingPolicy.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunEnableLegacyProtect, v => v.togEnableLegacyProtect.IsChecked).DisposeWith(disposables);

this.Bind(ViewModel, vm => vm.CoreType1, v => v.cmbCoreType1.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.Text).DisposeWith(disposables);
Expand Down