mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-26 04:24:44 +03:00
fix(sub): enable remote DNS resolution in Clash WireGuard proxies (#7154)
Mihomo ignores a WireGuard proxy's dns list unless remote-dns-resolve is set, so destination domains were resolved by the client's local DNS outside the tunnel and timed out on poisoned networks. The flag is emitted only when every configured server is a bare IP: mihomo aborts the whole config on a value its name-server parser rejects. That is the rule the AmneziaWG builder already applies. Closes #7151
This commit is contained in:
@@ -701,6 +701,11 @@ func (s *SubClashService) buildWireguardProxy(subReq *SubService, inbound *model
|
||||
}
|
||||
if len(servers) > 0 {
|
||||
proxy["dns"] = servers
|
||||
// mihomo ignores dns without this flag, but aborts the whole config on
|
||||
// a value its dns.ParseNameServer rejects, so only bare IPs opt in.
|
||||
if allBareIPs(servers) {
|
||||
proxy["remote-dns-resolve"] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1159,6 +1159,52 @@ func TestBuildWireguardProxyForClash(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildWireguardProxyForClashRemoteDNSResolve(t *testing.T) {
|
||||
clientPriv, _, err := wgutil.GenerateWireguardKeypair()
|
||||
if err != nil {
|
||||
t.Fatalf("client keypair: %v", err)
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
dns string
|
||||
wantDNS []string
|
||||
wantRemote bool
|
||||
}{
|
||||
{name: "bare ips opt in", dns: "1.1.1.1, 8.8.8.8", wantDNS: []string{"1.1.1.1", "8.8.8.8"}, wantRemote: true},
|
||||
{name: "doh url keeps dns without the flag", dns: "https://1.1.1.1/dns-query", wantDNS: []string{"https://1.1.1.1/dns-query"}},
|
||||
{name: "mixed list is not all bare", dns: "1.1.1.1, dns.example.com", wantDNS: []string{"1.1.1.1", "dns.example.com"}},
|
||||
{name: "no dns", dns: ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
svc := &SubClashService{SubService: &SubService{}}
|
||||
inbound := &model.Inbound{
|
||||
Listen: "203.0.113.9",
|
||||
Port: 51820,
|
||||
Protocol: model.WireGuard,
|
||||
Settings: `{"dns":"` + tt.dns + `"}`,
|
||||
}
|
||||
client := model.Client{Email: "user", PrivateKey: clientPriv, AllowedIPs: []string{"10.0.0.2/32"}}
|
||||
|
||||
proxy := svc.buildProxy(svc.SubService, inbound, client, nil, nil)
|
||||
if proxy == nil {
|
||||
t.Fatal("buildProxy returned nil")
|
||||
}
|
||||
dns, _ := proxy["dns"].([]string)
|
||||
if !reflect.DeepEqual(dns, tt.wantDNS) {
|
||||
t.Fatalf("dns = %v, want %v", proxy["dns"], tt.wantDNS)
|
||||
}
|
||||
remote, present := proxy["remote-dns-resolve"]
|
||||
if tt.wantRemote && remote != true {
|
||||
t.Fatalf("remote-dns-resolve = %v, want true", remote)
|
||||
}
|
||||
if !tt.wantRemote && present {
|
||||
t.Fatalf("remote-dns-resolve = %v, want absent", remote)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildWireguardProxyForClashNoKey(t *testing.T) {
|
||||
svc := &SubClashService{SubService: &SubService{}}
|
||||
inbound := &model.Inbound{Listen: "203.0.113.9", Port: 51820, Protocol: model.WireGuard, Settings: `{}`}
|
||||
|
||||
Reference in New Issue
Block a user