feat: Add custom Tun IPv4 and IPv6 address settings

- Updated UI resources to include options for custom Tun IPv4 and IPv6 addresses.
- Modified the SingboxInboundService to handle custom Tun addresses based on user input.
- Enhanced OptionSettingViewModel to store and manage custom Tun address values.
- Updated OptionSettingWindow views and bindings to reflect new settings for Tun addresses.
This commit is contained in:
ioococ 2025-12-01 20:49:34 +08:00
parent 83c63b914a
commit 4addce2c2f
11 changed files with 618 additions and 519 deletions

View file

@ -91,6 +91,8 @@ public static class ConfigHandler
{ {
EnableTun = false, EnableTun = false,
Mtu = 9000, Mtu = 9000,
TunIPv4Address = "172.18.0.1/30",
TunIPv6Address = "fdfe:dcba:9876::1/126",
}; };
config.GuiItem ??= new(); config.GuiItem ??= new();
config.MsgUIItem ??= new(); config.MsgUIItem ??= new();

View file

@ -147,6 +147,8 @@ public class TunModeItem
public int Mtu { get; set; } public int Mtu { get; set; }
public bool EnableExInbound { get; set; } public bool EnableExInbound { get; set; }
public bool EnableIPv6Address { get; set; } public bool EnableIPv6Address { get; set; }
public string TunIPv4Address { get; set; }
public string TunIPv6Address { get; set; }
} }
[Serializable] [Serializable]

File diff suppressed because it is too large Load diff

View file

@ -1077,6 +1077,12 @@
<data name="TbSettingsEnableIPv6Address" xml:space="preserve"> <data name="TbSettingsEnableIPv6Address" xml:space="preserve">
<value>Enable IPv6 Address</value> <value>Enable IPv6 Address</value>
</data> </data>
<data name="TbSettingsTunIPv4Address" xml:space="preserve">
<value>Custom Tun IPv4 Address</value>
</data>
<data name="TbSettingsTunIPv6Address" xml:space="preserve">
<value>Custom Tun IPv6 Address</value>
</data>
<data name="menuAddWireguardServer" xml:space="preserve"> <data name="menuAddWireguardServer" xml:space="preserve">
<value>Add [WireGuard] </value> <value>Add [WireGuard] </value>
</data> </data>
@ -1641,4 +1647,4 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="menuServerList2" xml:space="preserve"> <data name="menuServerList2" xml:space="preserve">
<value>Configuration Item 2, Select and add from self-built</value> <value>Configuration Item 2, Select and add from self-built</value>
</data> </data>
</root> </root>

View file

@ -1074,6 +1074,12 @@
<data name="TbSettingsEnableIPv6Address" xml:space="preserve"> <data name="TbSettingsEnableIPv6Address" xml:space="preserve">
<value>启用 IPv6</value> <value>启用 IPv6</value>
</data> </data>
<data name="TbSettingsTunIPv4Address" xml:space="preserve">
<value>自定义 Tun IPv4 地址</value>
</data>
<data name="TbSettingsTunIPv6Address" xml:space="preserve">
<value>自定义 Tun IPv6 地址</value>
</data>
<data name="menuAddWireguardServer" xml:space="preserve"> <data name="menuAddWireguardServer" xml:space="preserve">
<value>添加 [WireGuard] </value> <value>添加 [WireGuard] </value>
</data> </data>
@ -1638,4 +1644,4 @@
<data name="menuServerList2" xml:space="preserve"> <data name="menuServerList2" xml:space="preserve">
<value>子配置项二,从自建中选择添加</value> <value>子配置项二,从自建中选择添加</value>
</data> </data>
</root> </root>

View file

@ -68,7 +68,11 @@ public partial class CoreConfigSingboxService
tunInbound.stack = _config.TunModeItem.Stack; tunInbound.stack = _config.TunModeItem.Stack;
if (_config.TunModeItem.EnableIPv6Address == false) if (_config.TunModeItem.EnableIPv6Address == false)
{ {
tunInbound.address = ["172.18.0.1/30"]; tunInbound.address = [_config.TunModeItem.TunIPv4Address];
}
else
{
tunInbound.address = [_config.TunModeItem.TunIPv4Address, _config.TunModeItem.TunIPv6Address];
} }
singboxConfig.inbounds.Add(tunInbound); singboxConfig.inbounds.Add(tunInbound);

View file

@ -97,6 +97,8 @@ public class OptionSettingViewModel : MyReactiveObject
[Reactive] public int TunMtu { get; set; } [Reactive] public int TunMtu { get; set; }
[Reactive] public bool TunEnableExInbound { get; set; } [Reactive] public bool TunEnableExInbound { get; set; }
[Reactive] public bool TunEnableIPv6Address { get; set; } [Reactive] public bool TunEnableIPv6Address { get; set; }
[Reactive] public string TunIPv4Address { get; set; }
[Reactive] public string TunIPv6Address { get; set; }
#endregion Tun mode #endregion Tun mode
@ -221,6 +223,8 @@ public class OptionSettingViewModel : MyReactiveObject
TunMtu = _config.TunModeItem.Mtu; TunMtu = _config.TunModeItem.Mtu;
TunEnableExInbound = _config.TunModeItem.EnableExInbound; TunEnableExInbound = _config.TunModeItem.EnableExInbound;
TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address; TunEnableIPv6Address = _config.TunModeItem.EnableIPv6Address;
TunIPv4Address = _config.TunModeItem.TunIPv4Address;
TunIPv6Address = _config.TunModeItem.TunIPv6Address;
#endregion Tun mode #endregion Tun mode
@ -377,6 +381,8 @@ public class OptionSettingViewModel : MyReactiveObject
_config.TunModeItem.Mtu = TunMtu; _config.TunModeItem.Mtu = TunMtu;
_config.TunModeItem.EnableExInbound = TunEnableExInbound; _config.TunModeItem.EnableExInbound = TunEnableExInbound;
_config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address; _config.TunModeItem.EnableIPv6Address = TunEnableIPv6Address;
_config.TunModeItem.TunIPv4Address = TunIPv4Address;
_config.TunModeItem.TunIPv6Address = TunIPv6Address;
//coreType //coreType
await SaveCoreType(); await SaveCoreType();

View file

@ -463,7 +463,7 @@
VerticalAlignment="Center" VerticalAlignment="Center"
IsVisible="{Binding BlIsLinux}" IsVisible="{Binding BlIsLinux}"
Text="{x:Static resx:ResUI.TbSettingsHide2TrayWhenCloseTip}" /> Text="{x:Static resx:ResUI.TbSettingsHide2TrayWhenCloseTip}" />
<TextBlock <TextBlock
Grid.Row="10" Grid.Row="10"
Grid.Column="0" Grid.Column="0"
@ -786,7 +786,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"
@ -868,6 +868,30 @@
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.TbSettingsTunIPv4Address}" />
<TextBox
x:Name="txtTunIPv4Address"
Grid.Row="8"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="9"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsTunIPv6Address}" />
<TextBox
x:Name="txtTunIPv6Address"
Grid.Row="9"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}" />
</Grid> </Grid>
</TabItem> </TabItem>

View file

@ -115,6 +115,8 @@ 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.TunEnableExInbound, v => v.togEnableExInbound.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunEnableExInbound, v => v.togEnableExInbound.IsChecked).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.TunIPv4Address, v => v.txtTunIPv4Address.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunIPv6Address, v => v.txtTunIPv6Address.Text).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);

View file

@ -1030,6 +1030,8 @@
<RowDefinition Height="Auto" /> <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" />
@ -1124,6 +1126,31 @@
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 Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsTunIPv4Address}" />
<TextBox
x:Name="txtTunIPv4Address"
Grid.Row="8"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}" />
<TextBlock
Grid.Row="9"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbSettingsTunIPv6Address}" />
<TextBox
x:Name="txtTunIPv6Address"
Grid.Row="9"
Grid.Column="1"
Width="200"
Margin="{StaticResource Margin4}" />
</Grid> </Grid>
</TabItem> </TabItem>

View file

@ -120,6 +120,8 @@ 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.TunEnableExInbound, v => v.togEnableExInbound.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.TunEnableExInbound, v => v.togEnableExInbound.IsChecked).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.TunIPv4Address, v => v.txtTunIPv4Address.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.TunIPv6Address, v => v.txtTunIPv6Address.Text).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);