discovery: Instead of looping over conf.Search, use NameList()
@@ -179,13 +179,12 @@ func lookupAll(name string, qtype uint16) (*dns.Msg, error) {
for _, server := range conf.Servers {
servAddr := net.JoinHostPort(server, conf.Port)
- for _, suffix := range conf.Search {
- response, err = lookup(name, qtype, client, servAddr, suffix, false)
+ for _, lname := range conf.NameList(name) {
+ response, err = lookup(lname, qtype, client, servAddr, false)
if err != nil {
log.
With("server", server).
With("name", name).
- With("suffix", suffix).
With("reason", err).
Warn("DNS resolution failed.")
continue
@@ -194,22 +193,12 @@ func lookupAll(name string, qtype uint16) (*dns.Msg, error) {
return response, nil
}
}
- response, err = lookup(name, qtype, client, servAddr, "", false)
- if err == nil {
- return response, nil
- }
- log.
- With("server", server).
- With("name", name).
- With("reason", err).
- Warn("DNS resolution failed.")
}
return response, fmt.Errorf("could not resolve %s: no server responded", name)
}
-func lookup(name string, queryType uint16, client *dns.Client, servAddr string, suffix string, edns bool) (*dns.Msg, error) {
+func lookup(lname string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) {
msg := &dns.Msg{}
- lname := strings.Join([]string{name, suffix}, ".")
msg.SetQuestion(dns.Fqdn(lname), queryType)
if edns {
@@ -224,7 +213,7 @@ func lookup(name string, queryType uint16, client *dns.Client, servAddr string,
if edns { // Truncated even though EDNS is used
client.Net = "tcp"
}
- return lookup(name, queryType, client, servAddr, suffix, !edns)
+ return lookup(lname, queryType, client, servAddr, !edns)
}
if err != nil {
return nil, err
