From 794d1afe441cc2ad0b5326a7cd6acac01534c192 Mon Sep 17 00:00:00 2001 From: Preetha Appan Date: Thu, 3 Aug 2017 10:16:54 -0500 Subject: [PATCH] Removed a copy pasted irrelevant comment, and other code review feedback --- agent/consul/servers/router.go | 1 - agent/dns.go | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/agent/consul/servers/router.go b/agent/consul/servers/router.go index 35d4580c1c..a3dfa9af02 100644 --- a/agent/consul/servers/router.go +++ b/agent/consul/servers/router.go @@ -502,7 +502,6 @@ func (r *Router) FindServerAddrs(datacenter string) ([]string, error) { } var ret []string - // Try each manager until we get a server. for _, manager := range managers { if manager.IsOffline() { continue diff --git a/agent/dns.go b/agent/dns.go index 1434650ff1..6195cb85c2 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -372,7 +372,7 @@ PARSE: INVALID: d.logger.Printf("[WARN] dns: QName invalid: %s", qName) d.addSOA(d.domain, resp) - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) resp.SetRcode(req, dns.RcodeNameError) } @@ -415,7 +415,7 @@ RPC: // If we have no address, return not found! if out.NodeServices == nil { d.addSOA(d.domain, resp) - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) resp.SetRcode(req, dns.RcodeNameError) return } @@ -431,7 +431,7 @@ RPC: } // Add NS record and A record - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) } // formatNodeRecord takes a Node and returns an A, AAAA, or CNAME record @@ -646,7 +646,7 @@ RPC: // If we have no nodes, return not found! if len(out.Nodes) == 0 { d.addSOA(d.domain, resp) - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) resp.SetRcode(req, dns.RcodeNameError) return } @@ -663,7 +663,7 @@ RPC: } // Add NS and A records - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) // If the network is not TCP, restrict the number of responses if network != "tcp" { @@ -682,8 +682,8 @@ RPC: } } -// addNSAndARecordsForDomain uses the agent's advertise address to -func (d *DNSServer) addNSAndARecordsForDomain(msg *dns.Msg) { +// addAuthority adds NS records and corresponding A records with the IP addresses of servers +func (d *DNSServer) addAuthority(msg *dns.Msg) { serverAddrs := d.agent.delegate.ServerAddrs() for _, addr := range serverAddrs { ipAddrStr := strings.Split(addr, ":")[0] @@ -701,7 +701,7 @@ func (d *DNSServer) addNSAndARecordsForDomain(msg *dns.Msg) { } msg.Ns = append(msg.Ns, ns) - //add an A record for the NS record + // add an A record for the NS record a := &dns.A{ Hdr: dns.RR_Header{ Name: nsName, @@ -753,7 +753,7 @@ RPC: // here since the RPC layer loses the type information. if err.Error() == consul.ErrQueryNotFound.Error() { d.addSOA(d.domain, resp) - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) resp.SetRcode(req, dns.RcodeNameError) return } @@ -796,7 +796,7 @@ RPC: // If we have no nodes, return not found! if len(out.Nodes) == 0 { d.addSOA(d.domain, resp) - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) resp.SetRcode(req, dns.RcodeNameError) return } @@ -821,7 +821,7 @@ RPC: // If the answer is empty and the response isn't truncated, return not found if len(resp.Answer) == 0 && !resp.Truncated { - d.addNSAndARecordsForDomain(resp) + d.addAuthority(resp) d.addSOA(d.domain, resp) return }