diff --git a/retrieval/target_provider.go b/retrieval/target_provider.go index 9a92e4403..46cc2652e 100644 --- a/retrieval/target_provider.go +++ b/retrieval/target_provider.go @@ -15,8 +15,8 @@ package retrieval import ( "fmt" + "net" "net/url" - "strconv" "strings" "time" @@ -106,17 +106,13 @@ func lookupSRV(name string) (*dns.Msg, error) { return nil, fmt.Errorf("Couldn't load resolv.conf: %s", err) } - port, err := strconv.Atoi(conf.Port) - if err != nil { - return nil, fmt.Errorf("Invalid dns port in %s", resolvConf) - } - client := &dns.Client{} response := &dns.Msg{} for _, server := range conf.Servers { + servAddr := net.JoinHostPort(server, conf.Port) for _, suffix := range conf.Search { - response, err = lookup(name, dns.TypeSRV, client, server, port, suffix, false) + response, err = lookup(name, dns.TypeSRV, client, servAddr, suffix, false) if err == nil { if len(response.Answer) > 0 { return response, nil @@ -125,7 +121,7 @@ func lookupSRV(name string) (*dns.Msg, error) { glog.Warningf("Resolving %s.%s failed: %s", name, suffix, err) } } - response, err = lookup(name, dns.TypeSRV, client, server, port, "", false) + response, err = lookup(name, dns.TypeSRV, client, servAddr, "", false) if err == nil { return response, nil } @@ -133,7 +129,7 @@ func lookupSRV(name string) (*dns.Msg, error) { return response, fmt.Errorf("Couldn't resolve %s: No server responded", name) } -func lookup(name string, queryType uint16, client *dns.Client, server string, port int, suffix string, edns bool) (*dns.Msg, error) { +func lookup(name string, queryType uint16, client *dns.Client, servAddr string, suffix string, edns bool) (*dns.Msg, error) { msg := &dns.Msg{} lname := strings.Join([]string{name, suffix}, ".") msg.SetQuestion(dns.Fqdn(lname), queryType) @@ -149,7 +145,7 @@ func lookup(name string, queryType uint16, client *dns.Client, server string, po msg.Extra = append(msg.Extra, opt) } - response, _, err := client.Exchange(msg, fmt.Sprintf("%s:%d", server, port)) + response, _, err := client.Exchange(msg, servAddr) if err != nil { return nil, err } @@ -167,7 +163,7 @@ func lookup(name string, queryType uint16, client *dns.Client, server string, po client.Net = "tcp" } - return lookup(name, queryType, client, server, port, suffix, !edns) + return lookup(name, queryType, client, servAddr, suffix, !edns) } return response, nil