mirror of
https://github.com/2dust/v2rayN.git
synced 2026-03-30 12:07:40 +00:00
Allow enable legacy process name tun protect (#9005)
This commit is contained in:
parent
80178aeb2f
commit
c61b023ab3
17 changed files with 97 additions and 16 deletions
|
|
@ -92,6 +92,7 @@ public static class ConfigHandler
|
||||||
EnableTun = false,
|
EnableTun = false,
|
||||||
Mtu = 9000,
|
Mtu = 9000,
|
||||||
IcmpRouting = Global.TunIcmpRoutingPolicies.First(),
|
IcmpRouting = Global.TunIcmpRoutingPolicies.First(),
|
||||||
|
EnableLegacyProtect = false,
|
||||||
};
|
};
|
||||||
config.GuiItem ??= new();
|
config.GuiItem ??= new();
|
||||||
config.MsgUIItem ??= new();
|
config.MsgUIItem ??= new();
|
||||||
|
|
@ -1414,19 +1415,32 @@ public static class ConfigHandler
|
||||||
/// <returns>A SOCKS profile item or null if not needed</returns>
|
/// <returns>A SOCKS profile item or null if not needed</returns>
|
||||||
public static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
|
public static ProfileItem? GetPreSocksItem(Config config, ProfileItem node, ECoreType coreType)
|
||||||
{
|
{
|
||||||
if (node.ConfigType != EConfigType.Custom || !(node.PreSocksPort > 0))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ProfileItem? itemSocks = null;
|
ProfileItem? itemSocks = null;
|
||||||
var preCoreType = AppManager.Instance.RunningCoreType = config.TunModeItem.EnableTun ? ECoreType.sing_box : ECoreType.Xray;
|
if (node.ConfigType != EConfigType.Custom
|
||||||
itemSocks = new ProfileItem()
|
&& coreType != ECoreType.sing_box
|
||||||
|
&& config.TunModeItem.EnableTun
|
||||||
|
&& config.TunModeItem.EnableLegacyProtect)
|
||||||
{
|
{
|
||||||
CoreType = preCoreType,
|
itemSocks = new ProfileItem()
|
||||||
ConfigType = EConfigType.SOCKS,
|
{
|
||||||
Address = Global.Loopback,
|
CoreType = ECoreType.sing_box,
|
||||||
Port = node.PreSocksPort.Value,
|
ConfigType = EConfigType.SOCKS,
|
||||||
};
|
Address = Global.Loopback,
|
||||||
|
Port = AppManager.Instance.GetLocalPort(EInboundProtocol.socks)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else if (node.ConfigType == EConfigType.Custom
|
||||||
|
&& node.PreSocksPort is > 0 and <= 65535)
|
||||||
|
{
|
||||||
|
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;
|
return itemSocks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,7 @@ public class TunModeItem
|
||||||
public int Mtu { get; set; }
|
public int Mtu { get; set; }
|
||||||
public bool EnableIPv6Address { get; set; }
|
public bool EnableIPv6Address { get; set; }
|
||||||
public string IcmpRouting { get; set; }
|
public string IcmpRouting { get; set; }
|
||||||
|
public bool EnableLegacyProtect { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
[Serializable]
|
||||||
|
|
|
||||||
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
9
v2rayN/ServiceLib/Resx/ResUI.Designer.cs
generated
|
|
@ -3150,6 +3150,15 @@ namespace ServiceLib.Resx {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 查找类似 Legacy TUN Protect 的本地化字符串。
|
||||||
|
/// </summary>
|
||||||
|
public static string TbLegacyProtect {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("TbLegacyProtect", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 查找类似 Address (IPv4, IPv6) 的本地化字符串。
|
/// 查找类似 Address (IPv4, IPv6) 的本地化字符串。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -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">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP routing policy</value>
|
<value>ICMP routing policy</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>Legacy TUN Protect</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -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">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP routing policy</value>
|
<value>ICMP routing policy</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>Legacy TUN Protect</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -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">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP routing policy</value>
|
<value>ICMP routing policy</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>Legacy TUN Protect</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -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">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP routing policy</value>
|
<value>ICMP routing policy</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>Legacy TUN Protect</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1695,4 +1695,7 @@
|
||||||
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP routing policy</value>
|
<value>ICMP routing policy</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>Legacy TUN Protect</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
|
|
@ -1692,4 +1692,7 @@
|
||||||
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP 路由策略</value>
|
<value>ICMP 路由策略</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>旧版 TUN 保护</value>
|
||||||
|
</data>
|
||||||
</root>
|
</root>
|
||||||
|
|
@ -1692,4 +1692,7 @@
|
||||||
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
|
||||||
<value>ICMP 路由策略</value>
|
<value>ICMP 路由策略</value>
|
||||||
</data>
|
</data>
|
||||||
</root>
|
<data name="TbLegacyProtect" xml:space="preserve">
|
||||||
|
<value>Legacy TUN Protect</value>
|
||||||
|
</data>
|
||||||
|
</root>
|
||||||
|
|
@ -61,7 +61,8 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||||
ret.Success = true;
|
ret.Success = true;
|
||||||
|
|
||||||
ret.Data = ApplyFullConfigTemplate();
|
ret.Data = ApplyFullConfigTemplate();
|
||||||
if (context.TunProtectSsPort is > 0 and <= 65535)
|
if (!context.AppConfig.TunModeItem.EnableLegacyProtect
|
||||||
|
&& context.TunProtectSsPort is > 0 and <= 65535)
|
||||||
{
|
{
|
||||||
var ssInbound = new
|
var ssInbound = new
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,10 @@ public partial class CoreConfigV2rayService(CoreConfigContext context)
|
||||||
var ret = new RetResult();
|
var ret = new RetResult();
|
||||||
try
|
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();
|
return GenerateClientProxyRelayConfig();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ public class OptionSettingViewModel : MyReactiveObject
|
||||||
[Reactive] public int TunMtu { get; set; }
|
[Reactive] public int TunMtu { get; set; }
|
||||||
[Reactive] public bool TunEnableIPv6Address { get; set; }
|
[Reactive] public bool TunEnableIPv6Address { get; set; }
|
||||||
[Reactive] public string TunIcmpRouting { get; set; }
|
[Reactive] public string TunIcmpRouting { get; set; }
|
||||||
|
[Reactive] public bool TunEnableLegacyProtect { get; set; }
|
||||||
|
|
||||||
#endregion Tun mode
|
#endregion Tun mode
|
||||||
|
|
||||||
|
|
@ -220,6 +221,7 @@ public class OptionSettingViewModel : MyReactiveObject
|
||||||
TunMtu = _config.TunModeItem.Mtu;
|
TunMtu = _config.TunModeItem.Mtu;
|
||||||
TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address;
|
TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address;
|
||||||
TunIcmpRouting = _config.TunModeItem.IcmpRouting;
|
TunIcmpRouting = _config.TunModeItem.IcmpRouting;
|
||||||
|
TunEnableLegacyProtect = _config.TunModeItem.EnableLegacyProtect;
|
||||||
|
|
||||||
#endregion Tun mode
|
#endregion Tun mode
|
||||||
|
|
||||||
|
|
@ -379,6 +381,7 @@ public class OptionSettingViewModel : MyReactiveObject
|
||||||
_config.TunModeItem.Mtu = TunMtu;
|
_config.TunModeItem.Mtu = TunMtu;
|
||||||
_config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address;
|
_config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address;
|
||||||
_config.TunModeItem.IcmpRouting = TunIcmpRouting;
|
_config.TunModeItem.IcmpRouting = TunIcmpRouting;
|
||||||
|
_config.TunModeItem.EnableLegacyProtect = TunEnableLegacyProtect;
|
||||||
|
|
||||||
//coreType
|
//coreType
|
||||||
await SaveCoreType();
|
await SaveCoreType();
|
||||||
|
|
|
||||||
|
|
@ -768,7 +768,7 @@
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
ColumnDefinitions="Auto,Auto,Auto"
|
ColumnDefinitions="Auto,Auto,Auto"
|
||||||
DockPanel.Dock="Top"
|
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
|
<TextBlock
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
|
|
@ -851,6 +851,18 @@
|
||||||
Margin="{StaticResource Margin4}"
|
Margin="{StaticResource Margin4}"
|
||||||
HorizontalAlignment="Left" />
|
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>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,6 +116,7 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
|
||||||
this.Bind(ViewModel, vm => vm.TunMtu, v => v.cmbMtu.SelectedValue).DisposeWith(disposables);
|
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.TunEnableIPv6Address, v => v.togEnableIPv6Address.IsChecked).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.TunIcmpRouting, v => v.cmbIcmpRoutingPolicy.SelectedValue).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.CoreType1, v => v.cmbCoreType1.SelectedValue).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.SelectedValue).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.SelectedValue).DisposeWith(disposables);
|
||||||
|
|
|
||||||
|
|
@ -1009,6 +1009,7 @@
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
|
<RowDefinition Height="Auto" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
|
|
@ -1105,6 +1106,20 @@
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
Margin="{StaticResource Margin8}"
|
Margin="{StaticResource Margin8}"
|
||||||
HorizontalAlignment="Left" />
|
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>
|
</Grid>
|
||||||
</TabItem>
|
</TabItem>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ public partial class OptionSettingWindow
|
||||||
this.Bind(ViewModel, vm => vm.TunMtu, v => v.cmbMtu.Text).DisposeWith(disposables);
|
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.TunEnableIPv6Address, v => v.togEnableIPv6Address.IsChecked).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.TunIcmpRouting, v => v.cmbIcmpRoutingPolicy.Text).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.CoreType1, v => v.cmbCoreType1.Text).DisposeWith(disposables);
|
||||||
this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.Text).DisposeWith(disposables);
|
this.Bind(ViewModel, vm => vm.CoreType2, v => v.cmbCoreType2.Text).DisposeWith(disposables);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue