mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-22 23:57:26 +08:00
chore: skip duplicates nameserver when parse
This commit is contained in:
parent
33823f1728
commit
150c6ccd25
@ -1162,16 +1162,6 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns.
|
||||
var nameservers []dns.NameServer
|
||||
|
||||
for idx, server := range servers {
|
||||
if strings.HasPrefix(server, "dhcp://") {
|
||||
nameservers = append(
|
||||
nameservers,
|
||||
dns.NameServer{
|
||||
Net: "dhcp",
|
||||
Addr: server[len("dhcp://"):],
|
||||
},
|
||||
)
|
||||
continue
|
||||
}
|
||||
server = parsePureDNSServer(server)
|
||||
u, err := url.Parse(server)
|
||||
if err != nil {
|
||||
@ -1222,6 +1212,13 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns.
|
||||
dnsNetType = "quic" // DNS over QUIC
|
||||
case "system":
|
||||
dnsNetType = "system" // System DNS
|
||||
case "dhcp":
|
||||
addr = server[len("dhcp://"):] // some special notation cannot be parsed by url
|
||||
dnsNetType = "dhcp" // UDP from DHCP
|
||||
if addr == "system" { // Compatible with old writing "dhcp://system"
|
||||
dnsNetType = "system"
|
||||
addr = ""
|
||||
}
|
||||
case "rcode":
|
||||
dnsNetType = "rcode"
|
||||
addr = u.Host
|
||||
@ -1247,16 +1244,18 @@ func parseNameServer(servers []string, respectRules bool, preferH3 bool) ([]dns.
|
||||
proxyName = dns.RespectRules
|
||||
}
|
||||
|
||||
nameservers = append(
|
||||
nameservers,
|
||||
dns.NameServer{
|
||||
Net: dnsNetType,
|
||||
Addr: addr,
|
||||
ProxyName: proxyName,
|
||||
Params: params,
|
||||
PreferH3: preferH3,
|
||||
},
|
||||
)
|
||||
nameserver := dns.NameServer{
|
||||
Net: dnsNetType,
|
||||
Addr: addr,
|
||||
ProxyName: proxyName,
|
||||
Params: params,
|
||||
PreferH3: preferH3,
|
||||
}
|
||||
if slices.ContainsFunc(nameservers, nameserver.Equal) {
|
||||
continue // skip duplicates nameserver
|
||||
}
|
||||
|
||||
nameservers = append(nameservers, nameserver)
|
||||
}
|
||||
return nameservers, nil
|
||||
}
|
||||
|
@ -99,10 +99,6 @@ func transform(servers []NameServer, resolver *Resolver) []dnsClient {
|
||||
ret = append(ret, newDoHClient(s.Addr, resolver, s.PreferH3, s.Params, s.ProxyAdapter, s.ProxyName))
|
||||
continue
|
||||
case "dhcp":
|
||||
if s.Addr == "system" { // Compatible with old writing
|
||||
ret = append(ret, newSystemClient())
|
||||
continue
|
||||
}
|
||||
ret = append(ret, newDHCPClient(s.Addr))
|
||||
continue
|
||||
case "system":
|
||||
|
Loading…
Reference in New Issue
Block a user