mirror of https://github.com/status-im/consul.git
Do reverse service lookup only if address doesn't match node
This commit is contained in:
parent
1e0a2e25d0
commit
d10e6d0292
41
agent/dns.go
41
agent/dns.go
|
@ -208,27 +208,30 @@ func (d *DNSServer) handlePtr(resp dns.ResponseWriter, req *dns.Msg) {
|
|||
}
|
||||
}
|
||||
|
||||
// lookup the service address
|
||||
serviceAddress := dnsutil.ExtractAddressFromReverse(qName)
|
||||
sargs := structs.ServiceSpecificRequest{
|
||||
Datacenter: datacenter,
|
||||
QueryOptions: structs.QueryOptions{
|
||||
Token: d.agent.tokens.UserToken(),
|
||||
AllowStale: d.config.AllowStale,
|
||||
},
|
||||
ServiceAddress: serviceAddress,
|
||||
}
|
||||
// only look into the services if we didn't find a node
|
||||
if len(m.Answer) == 0 {
|
||||
// lookup the service address
|
||||
serviceAddress := dnsutil.ExtractAddressFromReverse(qName)
|
||||
sargs := structs.ServiceSpecificRequest{
|
||||
Datacenter: datacenter,
|
||||
QueryOptions: structs.QueryOptions{
|
||||
Token: d.agent.tokens.UserToken(),
|
||||
AllowStale: d.config.AllowStale,
|
||||
},
|
||||
ServiceAddress: serviceAddress,
|
||||
}
|
||||
|
||||
var sout structs.IndexedServiceNodes
|
||||
if err := d.agent.RPC("Catalog.ServiceNodes", &sargs, &sout); err == nil {
|
||||
for _, n := range sout.ServiceNodes {
|
||||
if n.ServiceAddress == serviceAddress {
|
||||
ptr := &dns.PTR{
|
||||
Hdr: dns.RR_Header{Name: q.Name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: 0},
|
||||
Ptr: fmt.Sprintf("%s.service.%s", n.ServiceName, d.domain),
|
||||
var sout structs.IndexedServiceNodes
|
||||
if err := d.agent.RPC("Catalog.ServiceNodes", &sargs, &sout); err == nil {
|
||||
for _, n := range sout.ServiceNodes {
|
||||
if n.ServiceAddress == serviceAddress {
|
||||
ptr := &dns.PTR{
|
||||
Hdr: dns.RR_Header{Name: q.Name, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: 0},
|
||||
Ptr: fmt.Sprintf("%s.service.%s", n.ServiceName, d.domain),
|
||||
}
|
||||
m.Answer = append(m.Answer, ptr)
|
||||
break
|
||||
}
|
||||
m.Answer = append(m.Answer, ptr)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue