From 042090a6d3c54a1d11f90f6ea1e6546bf11e57b5 Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Fri, 9 Mar 2018 21:21:58 +1100 Subject: [PATCH] [dns_sd] Send an EDNS0 query by default (#3586) Based on https://groups.google.com/d/topic/prometheus-users/02kezHbuea4/discussion Does not attempt to handle a situation where the server does not understand EDNS0, however that is an unlikely case, and the behaviour of such ancient systems is hard to predict in advance, so if it does come up, it will need to be handled on a case-by-case basis. --- discovery/dns/dns.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/discovery/dns/dns.go b/discovery/dns/dns.go index 709d44cba..a09be0185 100644 --- a/discovery/dns/dns.go +++ b/discovery/dns/dns.go @@ -295,7 +295,7 @@ func lookupFromAnyServer(name string, qtype uint16, conf *dns.ClientConfig, logg for _, server := range conf.Servers { servAddr := net.JoinHostPort(server, conf.Port) - msg, err := askServerForName(name, qtype, client, servAddr, false) + msg, err := askServerForName(name, qtype, client, servAddr, true) if err != nil { level.Warn(logger).Log("msg", "DNS resolution failed", "server", server, "name", name, "err", err) continue @@ -311,8 +311,8 @@ func lookupFromAnyServer(name string, qtype uint16, conf *dns.ClientConfig, logg } // askServerForName makes a request to a specific DNS server for a specific -// name (and qtype). Retries in the event of response truncation, but -// otherwise just sends back whatever the server gave, whether that be a +// name (and qtype). Retries with TCP in the event of response truncation, +// but otherwise just sends back whatever the server gave, whether that be a // valid-looking response, or an error. func askServerForName(name string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) { msg := &dns.Msg{} @@ -327,10 +327,9 @@ func askServerForName(name string, queryType uint16, client *dns.Client, servAdd if client.Net == "tcp" { return nil, fmt.Errorf("got truncated message on TCP (64kiB limit exceeded?)") } - if edns { // Truncated even though EDNS is used - client.Net = "tcp" - } - return askServerForName(name, queryType, client, servAddr, !edns) + + client.Net = "tcp" + return askServerForName(name, queryType, client, servAddr, false) } if err != nil { return nil, err