From be3c082539d85908ce03b6d280f83343e7c930eb Mon Sep 17 00:00:00 2001 From: Erik Hollensbe Date: Wed, 6 Feb 2019 21:40:51 +0000 Subject: [PATCH] discovery/dns/dns.go: fix handling of truncated dns records https://github.com/miekg/dns/pull/815 goes into the detail, but more or less the existing solution was no longer supported and needed to be rewritten to support the new versions of the library. miekg additionally claims this is more correct in the ticket. Signed-off-by: Erik Hollensbe --- 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 b21ec3503..672d4eb5c 100644 --- a/discovery/dns/dns.go +++ b/discovery/dns/dns.go @@ -317,7 +317,11 @@ func askServerForName(name string, queryType uint16, client *dns.Client, servAdd } response, _, err := client.Exchange(msg, servAddr) - if err == dns.ErrTruncated { + if err != nil { + return nil, err + } + + if response.Truncated { if client.Net == "tcp" { return nil, fmt.Errorf("got truncated message on TCP (64kiB limit exceeded?)") } @@ -325,11 +329,6 @@ func askServerForName(name string, queryType uint16, client *dns.Client, servAdd client.Net = "tcp" return askServerForName(name, queryType, client, servAddr, false) } - if err != nil { - return nil, err - } - if msg.Id != response.Id { - return nil, fmt.Errorf("DNS ID mismatch, request: %d, response: %d", msg.Id, response.Id) - } + return response, nil }