mirror of
https://github.com/status-im/consul.git
synced 2025-01-11 14:24:39 +00:00
Consider WAN addresses during Node and SRV record lookup
This commit is contained in:
parent
496cf5ae73
commit
a3240d28ba
@ -402,8 +402,14 @@ RPC:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine whether we should use the WAN address or not
|
||||||
|
addr := out.NodeServices.Node.Address
|
||||||
|
if d.agent.config.TranslateWanAddrs && datacenter != d.agent.config.Datacenter {
|
||||||
|
addr = out.NodeServices.Node.WanAddress
|
||||||
|
}
|
||||||
|
|
||||||
// Add the node record
|
// Add the node record
|
||||||
records := d.formatNodeRecord(out.NodeServices.Node, out.NodeServices.Node.Address,
|
records := d.formatNodeRecord(out.NodeServices.Node, addr,
|
||||||
req.Question[0].Name, qType, d.config.NodeTTL)
|
req.Question[0].Name, qType, d.config.NodeTTL)
|
||||||
if records != nil {
|
if records != nil {
|
||||||
resp.Answer = append(resp.Answer, records...)
|
resp.Answer = append(resp.Answer, records...)
|
||||||
@ -535,7 +541,7 @@ RPC:
|
|||||||
d.serviceNodeRecords(out.Nodes, req, resp, ttl, useWan)
|
d.serviceNodeRecords(out.Nodes, req, resp, ttl, useWan)
|
||||||
|
|
||||||
if qType == dns.TypeSRV {
|
if qType == dns.TypeSRV {
|
||||||
d.serviceSRVRecords(datacenter, out.Nodes, req, resp, ttl)
|
d.serviceSRVRecords(datacenter, out.Nodes, req, resp, ttl, useWan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the network is not TCP, restrict the number of responses
|
// If the network is not TCP, restrict the number of responses
|
||||||
@ -636,7 +642,7 @@ RPC:
|
|||||||
qType := req.Question[0].Qtype
|
qType := req.Question[0].Qtype
|
||||||
d.serviceNodeRecords(out.Nodes, req, resp, ttl, useWan)
|
d.serviceNodeRecords(out.Nodes, req, resp, ttl, useWan)
|
||||||
if qType == dns.TypeSRV {
|
if qType == dns.TypeSRV {
|
||||||
d.serviceSRVRecords(datacenter, out.Nodes, req, resp, ttl)
|
d.serviceSRVRecords(datacenter, out.Nodes, req, resp, ttl, useWan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the network is not TCP, restrict the number of responses.
|
// If the network is not TCP, restrict the number of responses.
|
||||||
@ -688,7 +694,7 @@ func (d *DNSServer) serviceNodeRecords(nodes structs.CheckServiceNodes, req, res
|
|||||||
}
|
}
|
||||||
|
|
||||||
// serviceARecords is used to add the SRV records for a service lookup
|
// serviceARecords is used to add the SRV records for a service lookup
|
||||||
func (d *DNSServer) serviceSRVRecords(dc string, nodes structs.CheckServiceNodes, req, resp *dns.Msg, ttl time.Duration) {
|
func (d *DNSServer) serviceSRVRecords(dc string, nodes structs.CheckServiceNodes, req, resp *dns.Msg, ttl time.Duration, useWan bool) {
|
||||||
handled := make(map[string]struct{})
|
handled := make(map[string]struct{})
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
// Avoid duplicate entries, possible if a node has
|
// Avoid duplicate entries, possible if a node has
|
||||||
@ -718,6 +724,8 @@ func (d *DNSServer) serviceSRVRecords(dc string, nodes structs.CheckServiceNodes
|
|||||||
addr := node.Node.Address
|
addr := node.Node.Address
|
||||||
if node.Service.Address != "" {
|
if node.Service.Address != "" {
|
||||||
addr = node.Service.Address
|
addr = node.Service.Address
|
||||||
|
} else if useWan == true && node.Node.WanAddress != "" {
|
||||||
|
addr = node.Node.WanAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the extra record
|
// Add the extra record
|
||||||
|
Loading…
x
Reference in New Issue
Block a user