From d3193cf8b73a6069a6a9c5cc5383b711815c1c2c Mon Sep 17 00:00:00 2001 From: Larvan2 <78135608+Larvan2@users.noreply.github.com> Date: Fri, 27 Jan 2023 15:08:05 +0800 Subject: [PATCH] Chore: Better parsing pure IPv6 UDP DNS --- config/config.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 66c3a989..8935f6c8 100644 --- a/config/config.go +++ b/config/config.go @@ -940,10 +940,15 @@ func parsePureDNSServer(server string) (string, bool) { addPre := func(server string) string { return "udp://" + server } + + //IPv6 server without "[" and "]" e.g., "2400:3200:baba::1" + if strings.Count(server, ":") >= 2 && strings.Count(server, "[") == 0 && strings.Count(server, "]") == 0 { + server = "[" + server + "]:53" + } + if ip := net.ParseIP(server); ip == nil { // parse without scheme .e.g 8.8.8.8:53 - - if strings.Contains(server,"://") { + if strings.Contains(server, "://") { return server, true } if addr, err := net.ResolveUDPAddr("", server); err == nil { @@ -952,7 +957,7 @@ func parsePureDNSServer(server string) (string, bool) { return addPre(server), false } } else { - return addPre(net.JoinHostPort(ip.String(), "53")), true + return addPre(server), true } } func parseNameServerPolicy(nsPolicy map[string]string, preferH3 bool) (map[string]dns.NameServer, error) {