mirror of https://github.com/status-im/consul.git
dns: minor cleanups
This commit is contained in:
parent
72ae8c8f33
commit
9fa237ddb6
26
agent/dns.go
26
agent/dns.go
|
@ -278,22 +278,23 @@ func (d *DNSServer) nameservers(edns bool) (ns []dns.RR, extra []dns.RR) {
|
||||||
d.logger.Println("[WARN] Unable to parse address %v, got error: %v", addr, err)
|
d.logger.Println("[WARN] Unable to parse address %v, got error: %v", addr, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
ip := net.ParseIP(host)
|
ip := net.ParseIP(host)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// name is "name.dc" and domain is "consul."
|
// Use "NODENAME.node.DC.DOMAIN" as a unique name for the server
|
||||||
// we want "name.node.dc.consul."
|
// since we use that name in other places as well.
|
||||||
|
// 'name' is "NODENAME.DC" so we need to split it
|
||||||
|
// to construct the server name.
|
||||||
lastdot := strings.LastIndexByte(name, '.')
|
lastdot := strings.LastIndexByte(name, '.')
|
||||||
nodeName := name[:lastdot]
|
nodeName, dc := name[:lastdot], name[lastdot:]
|
||||||
if InvalidDnsRe.MatchString(nodeName) {
|
if InvalidDnsRe.MatchString(nodeName) {
|
||||||
d.logger.Printf("[WARN] dns: Node name %q is not a valid dns host name, will not be added to NS record", nodeName)
|
d.logger.Printf("[WARN] dns: Node name %q is not a valid dns host name, will not be added to NS record", nodeName)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fqdn := nodeName + ".node" + name[lastdot:] + "." + d.domain
|
fqdn := nodeName + ".node" + dc + "." + d.domain
|
||||||
|
|
||||||
// create a consistent, unique and sanitized name for the server
|
|
||||||
fqdn = dns.Fqdn(strings.ToLower(fqdn))
|
fqdn = dns.Fqdn(strings.ToLower(fqdn))
|
||||||
|
|
||||||
servers[fqdn] = ip
|
servers[fqdn] = ip
|
||||||
|
@ -304,19 +305,21 @@ func (d *DNSServer) nameservers(edns bool) (ns []dns.RR, extra []dns.RR) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, ip := range servers {
|
for name, ip := range servers {
|
||||||
// the name server record
|
// NS record
|
||||||
nsrr := &dns.NS{
|
nsrr := &dns.NS{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: d.domain,
|
Name: d.domain,
|
||||||
Rrtype: dns.TypeNS,
|
Rrtype: dns.TypeNS,
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: 0,
|
Ttl: uint32(d.config.NodeTTL / time.Second),
|
||||||
},
|
},
|
||||||
Ns: name,
|
Ns: name,
|
||||||
}
|
}
|
||||||
ns = append(ns, nsrr)
|
ns = append(ns, nsrr)
|
||||||
// the glue record providing the ip address
|
|
||||||
extra = append(extra, d.formatNodeRecord(ip.String(), name, dns.TypeANY, d.config.NodeTTL, edns)...)
|
// A or AAAA glue record
|
||||||
|
glue := d.formatNodeRecord(ip.String(), name, dns.TypeANY, d.config.NodeTTL, edns)
|
||||||
|
extra = append(extra, glue...)
|
||||||
|
|
||||||
// don't provide more than 3 servers
|
// don't provide more than 3 servers
|
||||||
if len(ns) >= 3 {
|
if len(ns) >= 3 {
|
||||||
|
@ -504,8 +507,7 @@ RPC:
|
||||||
n := out.NodeServices.Node
|
n := out.NodeServices.Node
|
||||||
edns := req.IsEdns0() != nil
|
edns := req.IsEdns0() != nil
|
||||||
addr := d.agent.TranslateAddress(datacenter, n.Address, n.TaggedAddresses)
|
addr := d.agent.TranslateAddress(datacenter, n.Address, n.TaggedAddresses)
|
||||||
records := d.formatNodeRecord(addr,
|
records := d.formatNodeRecord(addr, req.Question[0].Name, qType, d.config.NodeTTL, edns)
|
||||||
req.Question[0].Name, qType, d.config.NodeTTL, edns)
|
|
||||||
if records != nil {
|
if records != nil {
|
||||||
resp.Answer = append(resp.Answer, records...)
|
resp.Answer = append(resp.Answer, records...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue