From 3bf999e46b1c52543218c86418ae393e86c81f7f Mon Sep 17 00:00:00 2001 From: John Murret Date: Tue, 6 Feb 2024 08:16:02 -0700 Subject: [PATCH] NET-7631 - Fix Node records that point to external/ non-IP addresses (#20491) * NET-7630 - Fix TXT record creation on node queries * NET-7631 - Fix Node records that point to external/ non-IP addresses * NET-7630 - Fix TXT record creation on node queries --- agent/dns/router.go | 12 ++++++++---- agent/dns_node_lookup_test.go | 4 ++-- agent/dns_service_lookup_test.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/agent/dns/router.go b/agent/dns/router.go index 4ca3a1b054..965d286f10 100644 --- a/agent/dns/router.go +++ b/agent/dns/router.go @@ -885,8 +885,6 @@ func (r *Router) getAnswerExtrasForAddressAndTarget(nodeAddress *dnsAddress, ser reqType := parseRequestType(req) switch { - // Virtual IPs and Address requests - // both return IPs with empty targets case (reqType == requestTypeAddress || result.Type == discovery.ResultTypeVirtual) && serviceAddress.IsEmptyString() && nodeAddress.IsIP(): a, e := getAnswerExtrasForIP(qName, nodeAddress, req.Question[0], reqType, @@ -894,13 +892,19 @@ func (r *Router) getAnswerExtrasForAddressAndTarget(nodeAddress *dnsAddress, ser answer = append(answer, a...) extra = append(extra, e...) - case result.Type == discovery.ResultTypeNode: + case result.Type == discovery.ResultTypeNode && nodeAddress.IsIP(): canonicalNodeName := canonicalNameForResult(result.Type, result.Node.Name, domain, result.Tenancy, result.PortName) a, e := getAnswerExtrasForIP(canonicalNodeName, nodeAddress, req.Question[0], reqType, result, ttl, domain) answer = append(answer, a...) extra = append(extra, e...) + case result.Type == discovery.ResultTypeNode && !nodeAddress.IsIP(): + a, e := r.makeRecordFromFQDN(serviceAddress.FQDN(), result, req, reqCtx, cfg, + ttl, remoteAddress, maxRecursionLevel) + answer = append(answer, a...) + extra = append(extra, e...) + case serviceAddress.IsEmptyString() && nodeAddress.IsEmptyString(): return nil, nil @@ -1111,7 +1115,7 @@ func (r *Router) makeRecordFromFQDN(fqdn string, result *discovery.Result, MORE_REC: for _, rr := range more { switch rr.Header().Rrtype { - case dns.TypeCNAME, dns.TypeA, dns.TypeAAAA: + case dns.TypeCNAME, dns.TypeA, dns.TypeAAAA, dns.TypeTXT: // set the TTL manually rr.Header().Ttl = ttl additional = append(additional, rr) diff --git a/agent/dns_node_lookup_test.go b/agent/dns_node_lookup_test.go index 00da275454..10cafcc160 100644 --- a/agent/dns_node_lookup_test.go +++ b/agent/dns_node_lookup_test.go @@ -275,7 +275,7 @@ func TestDNS_NodeLookup_CNAME(t *testing.T) { }) defer recursor.Shutdown() - for name, experimentsHCL := range getVersionHCL(false) { + for name, experimentsHCL := range getVersionHCL(true) { t.Run(name, func(t *testing.T) { a := NewTestAgent(t, ` recursors = ["`+recursor.Addr+`"] @@ -594,7 +594,7 @@ func TestDNS_NodeLookup_TTL(t *testing.T) { }) defer recursor.Shutdown() - for name, experimentsHCL := range getVersionHCL(false) { + for name, experimentsHCL := range getVersionHCL(true) { t.Run(name, func(t *testing.T) { a := NewTestAgent(t, ` recursors = ["`+recursor.Addr+`"] diff --git a/agent/dns_service_lookup_test.go b/agent/dns_service_lookup_test.go index f09b1280ee..4ddd2c2c68 100644 --- a/agent/dns_service_lookup_test.go +++ b/agent/dns_service_lookup_test.go @@ -1328,7 +1328,7 @@ func TestDNS_AltDomain_ServiceLookup_ServiceAddress_A(t *testing.T) { } } -// TODO (v2-dns): NET-7631 - Implement external CNAME references +// TODO (v2-dns): NET-7632 - Fix node and prepared query lookups when question name has a period in it func TestDNS_ServiceLookup_ServiceAddress_SRV(t *testing.T) { if testing.Short() { t.Skip("too slow for testing.Short")