Add ICMP routing (#8894)

This commit is contained in:
DHR60
2026-03-21 11:55:34 +00:00
committed by GitHub
parent db9fe9c5ea
commit 194c240243
17 changed files with 108 additions and 0 deletions

View File

@@ -675,5 +675,14 @@ public class Global
""
];
public static readonly List<string> TunIcmpRoutingPolicies =
[
"rule",
"direct",
"unreachable",
"drop",
"reply",
];
#endregion const
}

View File

@@ -91,6 +91,7 @@ public static class ConfigHandler
{
EnableTun = false,
Mtu = 9000,
IcmpRouting = Global.TunIcmpRoutingPolicies.First(),
};
config.GuiItem ??= new();
config.MsgUIItem ??= new();

View File

@@ -144,6 +144,7 @@ public class TunModeItem
public string Stack { get; set; }
public int Mtu { get; set; }
public bool EnableIPv6Address { get; set; }
public string IcmpRouting { get; set; }
}
[Serializable]

View File

@@ -3078,6 +3078,15 @@ namespace ServiceLib.Resx {
}
}
/// <summary>
/// 查找类似 ICMP routing policy 的本地化字符串。
/// </summary>
public static string TbIcmpRoutingPolicy {
get {
return ResourceManager.GetString("TbIcmpRoutingPolicy", resourceCulture);
}
}
/// <summary>
/// 查找类似 UUID(id) 的本地化字符串。
/// </summary>

View File

@@ -1692,4 +1692,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbUsername" xml:space="preserve">
<value>Username</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>

View File

@@ -1689,4 +1689,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbUsername" xml:space="preserve">
<value>Username</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>

View File

@@ -1692,4 +1692,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbUsername" xml:space="preserve">
<value>Username</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>

View File

@@ -1692,4 +1692,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbUsername" xml:space="preserve">
<value>Username</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>

View File

@@ -1692,4 +1692,7 @@
<data name="TbUsername" xml:space="preserve">
<value>Username</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>

View File

@@ -1689,4 +1689,7 @@
<data name="TbUsername" xml:space="preserve">
<value>用户名</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP 路由策略</value>
</data>
</root>

View File

@@ -1689,4 +1689,7 @@
<data name="TbUsername" xml:space="preserve">
<value>Username</value>
</data>
<data name="TbIcmpRoutingPolicy" xml:space="preserve">
<value>ICMP routing policy</value>
</data>
</root>

View File

@@ -47,6 +47,36 @@ public partial class CoreConfigSingboxService
outbound = Global.DirectTag,
process_name = lstDirectExe
});
// ICMP Routing
var icmpRouting = _config.TunModeItem.IcmpRouting ?? "";
if (!Global.TunIcmpRoutingPolicies.Contains(icmpRouting))
{
icmpRouting = Global.TunIcmpRoutingPolicies.First();
}
if (icmpRouting == "direct")
{
_coreConfig.route.rules.Add(new()
{
network = ["icmp"],
outbound = Global.DirectTag,
});
}
else if (icmpRouting != "rule")
{
var rejectMethod = icmpRouting switch
{
"unreachable" => "default",
"drop" => "drop",
_ => "reply",
};
_coreConfig.route.rules.Add(new()
{
network = ["icmp"],
action = "reject",
method = rejectMethod,
});
}
}
if (_config.Inbound.First().SniffingEnabled)

View File

@@ -95,6 +95,7 @@ public class OptionSettingViewModel : MyReactiveObject
[Reactive] public string TunStack { get; set; }
[Reactive] public int TunMtu { get; set; }
[Reactive] public bool TunEnableIPv6Address { get; set; }
[Reactive] public string TunIcmpRouting { get; set; }
#endregion Tun mode
@@ -218,6 +219,7 @@ public class OptionSettingViewModel : MyReactiveObject
TunStack = _config.TunModeItem.Stack;
TunMtu = _config.TunModeItem.Mtu;
TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address;
TunIcmpRouting = _config.TunModeItem.IcmpRouting;
#endregion Tun mode
@@ -376,6 +378,7 @@ public class OptionSettingViewModel : MyReactiveObject
_config.TunModeItem.Stack = TunStack;
_config.TunModeItem.Mtu = TunMtu;
_config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address;
_config.TunModeItem.IcmpRouting = TunIcmpRouting;
//coreType
await SaveCoreType();

View File

@@ -824,6 +824,20 @@
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
<TextBlock
Grid.Row="6"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbIcmpRoutingPolicy}" />
<ComboBox
x:Name="cmbIcmpRoutingPolicy"
Grid.Row="6"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" />
<TextBlock
Grid.Row="7"
Grid.Column="0"

View File

@@ -34,6 +34,7 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
cmbmux4SboxProtocol.ItemsSource = Global.SingboxMuxs;
cmbMtu.ItemsSource = Global.TunMtus;
cmbStack.ItemsSource = Global.TunStacks;
cmbIcmpRoutingPolicy.ItemsSource = Global.TunIcmpRoutingPolicies;
cmbCoreType1.ItemsSource = Global.CoreTypes;
cmbCoreType2.ItemsSource = Global.CoreTypes;
@@ -114,6 +115,7 @@ public partial class OptionSettingWindow : WindowBase<OptionSettingViewModel>
this.Bind(ViewModel, vm => vm.TunStack, v => v.cmbStack.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.TunIcmpRouting, v => v.cmbIcmpRoutingPolicy.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);

View File

@@ -1076,6 +1076,22 @@
HorizontalAlignment="Left"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="6"
Grid.Column="0"
Margin="{StaticResource Margin8}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbIcmpRoutingPolicy}" />
<ComboBox
x:Name="cmbIcmpRoutingPolicy"
Grid.Row="6"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin8}"
HorizontalAlignment="Left"
Style="{StaticResource DefComboBox}" />
<TextBlock
Grid.Row="7"
Grid.Column="0"

View File

@@ -31,6 +31,7 @@ public partial class OptionSettingWindow
cmbmux4SboxProtocol.ItemsSource = Global.SingboxMuxs;
cmbMtu.ItemsSource = Global.TunMtus;
cmbStack.ItemsSource = Global.TunStacks;
cmbIcmpRoutingPolicy.ItemsSource = Global.TunIcmpRoutingPolicies;
cmbCoreType1.ItemsSource = Global.CoreTypes;
cmbCoreType2.ItemsSource = Global.CoreTypes;
@@ -119,6 +120,7 @@ public partial class OptionSettingWindow
this.Bind(ViewModel, vm => vm.TunStack, v => v.cmbStack.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.TunIcmpRouting, v => v.cmbIcmpRoutingPolicy.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);