Add wireguard remote dns support (#10036)

This commit is contained in:
DHR60
2026-08-28 06:38:43 +00:00
committed by GitHub
parent 2a65e5ac80
commit 0d452328a2
14 changed files with 73 additions and 4 deletions
@@ -11,6 +11,7 @@ public class WireguardFmtTests
PrivateKey = interface-private-key PrivateKey = interface-private-key
Address = 10.0.0.2/32, fd00::2/128 ; inline comment Address = 10.0.0.2/32, fd00::2/128 ; inline comment
MTU = 1420 MTU = 1420
DNS = 2001::db8::53, 1.2.3.4, 2001:db8::54
[Peer] [Peer]
PublicKey = peer-public-key PublicKey = peer-public-key
@@ -35,6 +36,7 @@ public class WireguardFmtTests
await first.GetProtocolExtra().WgReserved.Should().BeEqualTo("1, 2, 3"); await first.GetProtocolExtra().WgReserved.Should().BeEqualTo("1, 2, 3");
await first.GetProtocolExtra().WgInterfaceAddress.Should().BeEqualTo("10.0.0.2/32, fd00::2/128"); await first.GetProtocolExtra().WgInterfaceAddress.Should().BeEqualTo("10.0.0.2/32, fd00::2/128");
await first.GetProtocolExtra().WgMtu.Should().BeEqualTo(1420); await first.GetProtocolExtra().WgMtu.Should().BeEqualTo(1420);
await first.GetProtocolExtra().WgDns.Should().BeEqualTo("2001::db8::53, 1.2.3.4, 2001:db8::54");
var second = resolved[1]; var second = resolved[1];
await second.Address.Should().BeEqualTo("example.com"); await second.Address.Should().BeEqualTo("example.com");
@@ -922,6 +922,7 @@ public static class ConfigHandler
WgInterfaceAddress = profileItem.GetProtocolExtra().WgInterfaceAddress?.TrimEx(), WgInterfaceAddress = profileItem.GetProtocolExtra().WgInterfaceAddress?.TrimEx(),
WgReserved = wgReserved, WgReserved = wgReserved,
WgMtu = profileItem.GetProtocolExtra().WgMtu is null or <= 0 ? Global.TunMtus.First() : profileItem.GetProtocolExtra().WgMtu, WgMtu = profileItem.GetProtocolExtra().WgMtu is null or <= 0 ? Global.TunMtus.First() : profileItem.GetProtocolExtra().WgMtu,
WgDns = profileItem.GetProtocolExtra().WgDns?.TrimEx(),
}); });
if (profileItem.Password.IsNullOrEmpty()) if (profileItem.Password.IsNullOrEmpty())
@@ -31,6 +31,7 @@ public class WireguardFmt : BaseFmt
WgReserved = GetQueryDecoded(query, "reserved"), WgReserved = GetQueryDecoded(query, "reserved"),
WgInterfaceAddress = GetQueryDecoded(query, "address"), WgInterfaceAddress = GetQueryDecoded(query, "address"),
WgMtu = int.TryParse(GetQueryDecoded(query, "mtu"), out var mtuVal) ? mtuVal : null, WgMtu = int.TryParse(GetQueryDecoded(query, "mtu"), out var mtuVal) ? mtuVal : null,
WgDns = GetQueryDecoded(query, "dns"),
}); });
return item; return item;
@@ -71,6 +72,10 @@ public class WireguardFmt : BaseFmt
{ {
dicQuery.Add("mtu", protoExtra.WgMtu.ToString()); dicQuery.Add("mtu", protoExtra.WgMtu.ToString());
} }
if (!protoExtra.WgDns.IsNullOrEmpty())
{
dicQuery.Add("dns", Utils.UrlEncode(protoExtra.WgDns));
}
return ToUri(EConfigType.WireGuard, item.Address, item.Port, item.Password, dicQuery, remark); return ToUri(EConfigType.WireGuard, item.Address, item.Port, item.Password, dicQuery, remark);
} }
@@ -133,6 +138,7 @@ public class WireguardFmt : BaseFmt
var wgMtu = interfaceDic.TryGetValue("MTU", out var mtuStr) && int.TryParse(mtuStr, out var mtuVal) ? mtuVal : 0; var wgMtu = interfaceDic.TryGetValue("MTU", out var mtuStr) && int.TryParse(mtuStr, out var mtuVal) ? mtuVal : 0;
var wgInterfaceAddress = interfaceDic.TryGetValue("Address", out var interfaceAddress) ? interfaceAddress : string.Empty; var wgInterfaceAddress = interfaceDic.TryGetValue("Address", out var interfaceAddress) ? interfaceAddress : string.Empty;
var wgDns = interfaceDic.TryGetValue("DNS", out var dns) ? dns : string.Empty;
var index = 0; var index = 0;
var resultList = new List<ProfileItem>(); var resultList = new List<ProfileItem>();
@@ -156,6 +162,7 @@ public class WireguardFmt : BaseFmt
WgInterfaceAddress = wgInterfaceAddress, WgInterfaceAddress = wgInterfaceAddress,
WgReserved = (peerDic.TryGetValue("Reserved", out var reserved) ? reserved : string.Empty).NullIfEmpty(), WgReserved = (peerDic.TryGetValue("Reserved", out var reserved) ? reserved : string.Empty).NullIfEmpty(),
WgMtu = wgMtu > 0 ? wgMtu : null, WgMtu = wgMtu > 0 ? wgMtu : null,
WgDns = wgDns,
}; };
var item = new ProfileItem var item = new ProfileItem
@@ -172,6 +172,8 @@ public class Outboundsettings4Ray
public int? workers { get; set; } public int? workers { get; set; }
public int? version { get; set; } public int? version { get; set; }
public List<string>? remoteDNS { get; set; }
} }
public class WireguardPeer4Ray public class WireguardPeer4Ray
@@ -27,6 +27,7 @@ public record ProtocolExtraItem
public string? WgInterfaceAddress { get; init; } public string? WgInterfaceAddress { get; init; }
public string? WgReserved { get; init; } public string? WgReserved { get; init; }
public int? WgMtu { get; init; } public int? WgMtu { get; init; }
public string? WgDns { get; init; }
// hysteria2 // hysteria2
public string? SalamanderPass { get; init; } public string? SalamanderPass { get; init; }
+9
View File
@@ -3015,6 +3015,15 @@ namespace ServiceLib.Resx {
} }
} }
/// <summary>
/// 查找类似 DNS 的本地化字符串。
/// </summary>
public static string TbDNS {
get {
return ResourceManager.GetString("TbDNS", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 DNS Hosts: (&quot;domain1 ip1 ip2&quot; per line) 的本地化字符串。 /// 查找类似 DNS Hosts: (&quot;domain1 ip1 ip2&quot; per line) 的本地化字符串。
/// </summary> /// </summary>
+3
View File
@@ -1869,4 +1869,7 @@ The "Get Certificate" action may fail if a self-signed certificate is used or if
<data name="TbBlockAAAAQueriesTips" xml:space="preserve"> <data name="TbBlockAAAAQueriesTips" xml:space="preserve">
<value>Block IPv6 queries when enabled</value> <value>Block IPv6 queries when enabled</value>
</data> </data>
<data name="TbDNS" xml:space="preserve">
<value>DNS</value>
</data>
</root> </root>
@@ -1870,4 +1870,7 @@
<data name="TbBlockAAAAQueriesTips" xml:space="preserve"> <data name="TbBlockAAAAQueriesTips" xml:space="preserve">
<value>开启后将阻止 IPv6 查询</value> <value>开启后将阻止 IPv6 查询</value>
</data> </data>
<data name="TbDNS" xml:space="preserve">
<value>DNS</value>
</data>
</root> </root>
@@ -297,7 +297,8 @@ public partial class CoreConfigV2rayService
secretKey = _node.Password, secretKey = _node.Password,
reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(s => s.Trim()).Select(int.Parse).ToList(), reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(s => s.Trim()).Select(int.Parse).ToList(),
mtu = protocolExtra.WgMtu > 0 ? protocolExtra.WgMtu : Global.TunMtus.First(), mtu = protocolExtra.WgMtu > 0 ? protocolExtra.WgMtu : Global.TunMtus.First(),
peers = [peer] remoteDNS = Utils.String2List(protocolExtra.WgDns)?.Select(s => s.Trim()).ToList(),
peers = [peer],
}; };
outbound.settings = setting; outbound.settings = setting;
outbound.settings.vnext = null; outbound.settings.vnext = null;
@@ -70,6 +70,9 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
[Reactive] [Reactive]
public partial int WgMtu { get; set; } public partial int WgMtu { get; set; }
[Reactive]
public partial string WgDns { get; set; }
[Reactive] [Reactive]
public partial bool Uot { get; set; } public partial bool Uot { get; set; }
@@ -310,6 +313,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
WgInterfaceAddress = protocolExtra.WgInterfaceAddress ?? string.Empty; WgInterfaceAddress = protocolExtra.WgInterfaceAddress ?? string.Empty;
WgReserved = protocolExtra.WgReserved ?? string.Empty; WgReserved = protocolExtra.WgReserved ?? string.Empty;
WgMtu = protocolExtra.WgMtu ?? 1280; WgMtu = protocolExtra.WgMtu ?? 1280;
WgDns = protocolExtra.WgDns ?? string.Empty;
Uot = protocolExtra.Uot ?? false; Uot = protocolExtra.Uot ?? false;
CongestionControl = protocolExtra.CongestionControl ?? string.Empty; CongestionControl = protocolExtra.CongestionControl ?? string.Empty;
InsecureConcurrency = protocolExtra.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null; InsecureConcurrency = protocolExtra.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null;
@@ -431,6 +435,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
WgInterfaceAddress = WgInterfaceAddress.NullIfEmpty(), WgInterfaceAddress = WgInterfaceAddress.NullIfEmpty(),
WgReserved = WgReserved.NullIfEmpty(), WgReserved = WgReserved.NullIfEmpty(),
WgMtu = WgMtu >= 576 ? WgMtu : null, WgMtu = WgMtu >= 576 ? WgMtu : null,
WgDns = WgDns.NullIfEmpty(),
Uot = Uot ? true : null, Uot = Uot ? true : null,
CongestionControl = CongestionControl.NullIfEmpty(), CongestionControl = CongestionControl.NullIfEmpty(),
InsecureConcurrency = InsecureConcurrency > 0 ? InsecureConcurrency : null, InsecureConcurrency = InsecureConcurrency > 0 ? InsecureConcurrency : null,
@@ -580,7 +580,7 @@
Grid.Row="2" Grid.Row="2"
ColumnDefinitions="300,Auto" ColumnDefinitions="300,Auto"
IsVisible="False" IsVisible="False"
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto"> RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<TextBlock <TextBlock
Grid.Row="1" Grid.Row="1"
@@ -649,7 +649,7 @@
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
PlaceholderText="Ipv4,Ipv6" /> PlaceholderText="Ipv4, Ipv6" />
<TextBlock <TextBlock
Grid.Row="6" Grid.Row="6"
@@ -665,6 +665,21 @@
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
HorizontalAlignment="Left" HorizontalAlignment="Left"
PlaceholderText="1280" /> PlaceholderText="1280" />
<TextBlock
Grid.Row="7"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Text="{x:Static resx:ResUI.TbDNS}" />
<TextBox
x:Name="txtDns"
Grid.Row="7"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
PlaceholderText="1.1.1.1, 2606:4700:4700::1111" />
</Grid> </Grid>
<Grid <Grid
x:Name="gridAnytls" x:Name="gridAnytls"
@@ -125,6 +125,7 @@ public partial class AddServerWindow : WindowBase<AddServerViewModel>
this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(currentTypeDisposables); this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(currentTypeDisposables);
this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(currentTypeDisposables); this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(currentTypeDisposables);
this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(currentTypeDisposables); this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(currentTypeDisposables);
this.Bind(ViewModel, vm => vm.WgDns, v => v.txtDns.Text).DisposeWith(currentTypeDisposables);
break; break;
case EConfigType.Anytls: case EConfigType.Anytls:
+19 -1
View File
@@ -748,6 +748,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="300" /> <ColumnDefinition Width="300" />
@@ -830,7 +831,7 @@
Grid.Column="1" Grid.Column="1"
Width="400" Width="400"
Margin="{StaticResource Margin4}" Margin="{StaticResource Margin4}"
materialDesign:HintAssist.Hint="Ipv4,Ipv6" materialDesign:HintAssist.Hint="Ipv4, Ipv6"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
<TextBlock <TextBlock
@@ -849,6 +850,23 @@
HorizontalAlignment="Left" HorizontalAlignment="Left"
materialDesign:HintAssist.Hint="1280" materialDesign:HintAssist.Hint="1280"
Style="{StaticResource DefTextBox}" /> Style="{StaticResource DefTextBox}" />
<TextBlock
Grid.Row="7"
Grid.Column="0"
Margin="{StaticResource Margin4}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbDNS}" />
<TextBox
x:Name="txtDns"
Grid.Row="7"
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
materialDesign:HintAssist.Hint="1.1.1.1, 2606:4700:4700::1111"
Style="{StaticResource DefTextBox}" />
</Grid> </Grid>
<Grid <Grid
x:Name="gridAnytls" x:Name="gridAnytls"
@@ -124,6 +124,7 @@ public partial class AddServerWindow
this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(currentTypeDisposables); this.Bind(ViewModel, vm => vm.WgReserved, v => v.txtPath9.Text).DisposeWith(currentTypeDisposables);
this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(currentTypeDisposables); this.Bind(ViewModel, vm => vm.WgInterfaceAddress, v => v.txtRequestHost9.Text).DisposeWith(currentTypeDisposables);
this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(currentTypeDisposables); this.Bind(ViewModel, vm => vm.WgMtu, v => v.txtShortId9.Text).DisposeWith(currentTypeDisposables);
this.Bind(ViewModel, vm => vm.WgDns, v => v.txtDns.Text).DisposeWith(currentTypeDisposables);
break; break;
case EConfigType.Anytls: case EConfigType.Anytls: