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

View File

@@ -11,6 +11,7 @@ public class WireguardFmtTests
PrivateKey = interface-private-key
Address = 10.0.0.2/32, fd00::2/128 ; inline comment
MTU = 1420
DNS = 2001::db8::53, 1.2.3.4, 2001:db8::54
[Peer]
PublicKey = peer-public-key
@@ -35,6 +36,7 @@ public class WireguardFmtTests
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().WgMtu.Should().BeEqualTo(1420);
await first.GetProtocolExtra().WgDns.Should().BeEqualTo("2001::db8::53, 1.2.3.4, 2001:db8::54");
var second = resolved[1];
await second.Address.Should().BeEqualTo("example.com");

View File

@@ -922,6 +922,7 @@ public static class ConfigHandler
WgInterfaceAddress = profileItem.GetProtocolExtra().WgInterfaceAddress?.TrimEx(),
WgReserved = wgReserved,
WgMtu = profileItem.GetProtocolExtra().WgMtu is null or <= 0 ? Global.TunMtus.First() : profileItem.GetProtocolExtra().WgMtu,
WgDns = profileItem.GetProtocolExtra().WgDns?.TrimEx(),
});
if (profileItem.Password.IsNullOrEmpty())

View File

@@ -31,6 +31,7 @@ public class WireguardFmt : BaseFmt
WgReserved = GetQueryDecoded(query, "reserved"),
WgInterfaceAddress = GetQueryDecoded(query, "address"),
WgMtu = int.TryParse(GetQueryDecoded(query, "mtu"), out var mtuVal) ? mtuVal : null,
WgDns = GetQueryDecoded(query, "dns"),
});
return item;
@@ -71,6 +72,10 @@ public class WireguardFmt : BaseFmt
{
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);
}
@@ -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 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 resultList = new List<ProfileItem>();
@@ -156,6 +162,7 @@ public class WireguardFmt : BaseFmt
WgInterfaceAddress = wgInterfaceAddress,
WgReserved = (peerDic.TryGetValue("Reserved", out var reserved) ? reserved : string.Empty).NullIfEmpty(),
WgMtu = wgMtu > 0 ? wgMtu : null,
WgDns = wgDns,
};
var item = new ProfileItem

View File

@@ -172,6 +172,8 @@ public class Outboundsettings4Ray
public int? workers { get; set; }
public int? version { get; set; }
public List<string>? remoteDNS { get; set; }
}
public class WireguardPeer4Ray

View File

@@ -27,6 +27,7 @@ public record ProtocolExtraItem
public string? WgInterfaceAddress { get; init; }
public string? WgReserved { get; init; }
public int? WgMtu { get; init; }
public string? WgDns { get; init; }
// hysteria2
public string? SalamanderPass { get; init; }

View File

@@ -3015,6 +3015,15 @@ namespace ServiceLib.Resx {
}
}
/// <summary>
/// 查找类似 DNS 的本地化字符串。
/// </summary>
public static string TbDNS {
get {
return ResourceManager.GetString("TbDNS", resourceCulture);
}
}
/// <summary>
/// 查找类似 DNS Hosts: (&quot;domain1 ip1 ip2&quot; per line) 的本地化字符串。
/// </summary>

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">
<value>Block IPv6 queries when enabled</value>
</data>
<data name="TbDNS" xml:space="preserve">
<value>DNS</value>
</data>
</root>

View File

@@ -1870,4 +1870,7 @@
<data name="TbBlockAAAAQueriesTips" xml:space="preserve">
<value>开启后将阻止 IPv6 查询</value>
</data>
<data name="TbDNS" xml:space="preserve">
<value>DNS</value>
</data>
</root>

View File

@@ -297,7 +297,8 @@ public partial class CoreConfigV2rayService
secretKey = _node.Password,
reserved = Utils.String2List(protocolExtra.WgReserved)?.Select(s => s.Trim()).Select(int.Parse).ToList(),
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.vnext = null;

View File

@@ -70,6 +70,9 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
[Reactive]
public partial int WgMtu { get; set; }
[Reactive]
public partial string WgDns { get; set; }
[Reactive]
public partial bool Uot { get; set; }
@@ -310,6 +313,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
WgInterfaceAddress = protocolExtra.WgInterfaceAddress ?? string.Empty;
WgReserved = protocolExtra.WgReserved ?? string.Empty;
WgMtu = protocolExtra.WgMtu ?? 1280;
WgDns = protocolExtra.WgDns ?? string.Empty;
Uot = protocolExtra.Uot ?? false;
CongestionControl = protocolExtra.CongestionControl ?? string.Empty;
InsecureConcurrency = protocolExtra.InsecureConcurrency > 0 ? protocolExtra.InsecureConcurrency : null;
@@ -431,6 +435,7 @@ public partial class AddServerViewModel : MyReactiveObject, ICloseable
WgInterfaceAddress = WgInterfaceAddress.NullIfEmpty(),
WgReserved = WgReserved.NullIfEmpty(),
WgMtu = WgMtu >= 576 ? WgMtu : null,
WgDns = WgDns.NullIfEmpty(),
Uot = Uot ? true : null,
CongestionControl = CongestionControl.NullIfEmpty(),
InsecureConcurrency = InsecureConcurrency > 0 ? InsecureConcurrency : null,

View File

@@ -580,7 +580,7 @@
Grid.Row="2"
ColumnDefinitions="300,Auto"
IsVisible="False"
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto">
RowDefinitions="Auto,Auto,Auto,Auto,Auto,Auto,Auto,Auto">
<TextBlock
Grid.Row="1"
@@ -649,7 +649,7 @@
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
PlaceholderText="Ipv4,Ipv6" />
PlaceholderText="Ipv4, Ipv6" />
<TextBlock
Grid.Row="6"
@@ -665,6 +665,21 @@
Margin="{StaticResource Margin4}"
HorizontalAlignment="Left"
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
x:Name="gridAnytls"

View File

@@ -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.WgInterfaceAddress, v => v.txtRequestHost9.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;
case EConfigType.Anytls:

View File

@@ -748,6 +748,7 @@
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300" />
@@ -830,7 +831,7 @@
Grid.Column="1"
Width="400"
Margin="{StaticResource Margin4}"
materialDesign:HintAssist.Hint="Ipv4,Ipv6"
materialDesign:HintAssist.Hint="Ipv4, Ipv6"
Style="{StaticResource DefTextBox}" />
<TextBlock
@@ -849,6 +850,23 @@
HorizontalAlignment="Left"
materialDesign:HintAssist.Hint="1280"
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
x:Name="gridAnytls"

View File

@@ -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.WgInterfaceAddress, v => v.txtRequestHost9.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;
case EConfigType.Anytls: