mirror of https://github.com/status-im/consul.git
parent
35a2c84d3d
commit
3a2c865ff6
13
agent/dns.go
13
agent/dns.go
|
@ -274,9 +274,16 @@ func recursorAddr(recursor string) (string, error) {
|
|||
// Add the port if none
|
||||
START:
|
||||
_, _, err := net.SplitHostPort(recursor)
|
||||
if ae, ok := err.(*net.AddrError); ok && ae.Err == "missing port in address" {
|
||||
recursor = ipaddr.FormatAddressPort(recursor, 53)
|
||||
goto START
|
||||
if ae, ok := err.(*net.AddrError); ok {
|
||||
if ae.Err == "missing port in address" {
|
||||
recursor = ipaddr.FormatAddressPort(recursor, 53)
|
||||
goto START
|
||||
} else if ae.Err == "too many colons in address" {
|
||||
if ip := net.ParseIP(recursor); ip != nil && ip.To4() == nil {
|
||||
recursor = ipaddr.FormatAddressPort(recursor, 53)
|
||||
goto START
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -109,6 +109,21 @@ func TestRecursorAddr(t *testing.T) {
|
|||
if addr != "8.8.8.8:53" {
|
||||
t.Fatalf("bad: %v", addr)
|
||||
}
|
||||
addr, err = recursorAddr("2001:4860:4860::8888")
|
||||
if err != nil {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
if addr != "[2001:4860:4860::8888]:53" {
|
||||
t.Fatalf("bad: %v", addr)
|
||||
}
|
||||
addr, err = recursorAddr("1.2.3.4::53")
|
||||
if err == nil || !strings.Contains(err.Error(), "too many colons in address") {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
addr, err = recursorAddr("2001:4860:4860::8888:::53")
|
||||
if err == nil || !strings.Contains(err.Error(), "too many colons in address") {
|
||||
t.Fatalf("err: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncodeKVasRFC1464(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue