Browse Source

[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.
pull/3937/head
Matt Palmer 7 years ago committed by Brian Brazil
parent
commit
042090a6d3
  1. 11
      discovery/dns/dns.go

11
discovery/dns/dns.go

@ -295,7 +295,7 @@ func lookupFromAnyServer(name string, qtype uint16, conf *dns.ClientConfig, logg
for _, server := range conf.Servers { for _, server := range conf.Servers {
servAddr := net.JoinHostPort(server, conf.Port) 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 { if err != nil {
level.Warn(logger).Log("msg", "DNS resolution failed", "server", server, "name", name, "err", err) level.Warn(logger).Log("msg", "DNS resolution failed", "server", server, "name", name, "err", err)
continue 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 // askServerForName makes a request to a specific DNS server for a specific
// name (and qtype). Retries in the event of response truncation, but // name (and qtype). Retries with TCP in the event of response truncation,
// otherwise just sends back whatever the server gave, whether that be a // but otherwise just sends back whatever the server gave, whether that be a
// valid-looking response, or an error. // valid-looking response, or an error.
func askServerForName(name string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) { func askServerForName(name string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) {
msg := &dns.Msg{} msg := &dns.Msg{}
@ -327,10 +327,9 @@ func askServerForName(name string, queryType uint16, client *dns.Client, servAdd
if client.Net == "tcp" { if client.Net == "tcp" {
return nil, fmt.Errorf("got truncated message on TCP (64kiB limit exceeded?)") return nil, fmt.Errorf("got truncated message on TCP (64kiB limit exceeded?)")
} }
if edns { // Truncated even though EDNS is used
client.Net = "tcp" client.Net = "tcp"
} return askServerForName(name, queryType, client, servAddr, false)
return askServerForName(name, queryType, client, servAddr, !edns)
} }
if err != nil { if err != nil {
return nil, err return nil, err

Loading…
Cancel
Save