mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 11:42:43 +08:00
chore: better parse udp dns
This commit is contained in:
parent
6decaef050
commit
5bcea37d59
|
@ -860,10 +860,7 @@ func parseNameServer(servers []string, preferH3 bool) ([]dns.NameServer, error)
|
|||
var nameservers []dns.NameServer
|
||||
|
||||
for idx, server := range servers {
|
||||
// parse without scheme .e.g 8.8.8.8:53
|
||||
if !strings.Contains(server, "://") {
|
||||
server = "udp://" + server
|
||||
}
|
||||
server, _ = parsePureDNSServer(server)
|
||||
u, err := url.Parse(server)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("DNS NameServer[%d] format error: %s", idx, err.Error())
|
||||
|
@ -939,6 +936,25 @@ func parseNameServer(servers []string, preferH3 bool) ([]dns.NameServer, error)
|
|||
return nameservers, nil
|
||||
}
|
||||
|
||||
func parsePureDNSServer(server string) (string, bool) {
|
||||
addPre := func(server string) string {
|
||||
return "udp://" + server
|
||||
}
|
||||
if ip := net.ParseIP(server); ip == nil {
|
||||
// parse without scheme .e.g 8.8.8.8:53
|
||||
|
||||
if strings.Contains(server,"://") {
|
||||
return server, true
|
||||
}
|
||||
if addr, err := net.ResolveUDPAddr("", server); err == nil {
|
||||
return addPre(addr.String()), true
|
||||
} else {
|
||||
return addPre(server), false
|
||||
}
|
||||
} else {
|
||||
return addPre(net.JoinHostPort(ip.String(), "53")), true
|
||||
}
|
||||
}
|
||||
func parseNameServerPolicy(nsPolicy map[string]string, preferH3 bool) (map[string]dns.NameServer, error) {
|
||||
policy := map[string]dns.NameServer{}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user