GH-3798: A few more PR updates

This commit is contained in:
Matt Keeler 2018-04-11 20:32:35 -04:00
parent d065d3a6db
commit cec8d5145b
4 changed files with 15 additions and 11 deletions

View File

@ -396,15 +396,17 @@ func (p *PreparedQuery) Execute(args *structs.PreparedQueryExecuteRequest,
} else if qs.Node == "_ip" {
if args.Source.Ip != "" {
_, nodes, err := state.Nodes(nil)
if err == nil {
for _, node := range nodes {
if args.Source.Ip == node.Address {
qs.Node = node.Node
break
}
if err != nil {
return err
}
for _, node := range nodes {
if args.Source.Ip == node.Address {
qs.Node = node.Node
break
}
}
}
}
// Either a source IP was given but we couldnt find the associated node
// or no source ip was given. In both cases we should wipe the Node value

View File

@ -962,9 +962,11 @@ func (d *DNSServer) preparedQueryLookup(network, datacenter, query string, remot
args.Source.Ip = subnet.Address.String()
} else {
switch v := remoteAddr.(type) {
case *net.UDPAddr:
args.Source.Ip = v.IP.String()
case *net.TCPAddr:
args.Source.Ip = v.IP.String()
case *net.UDPAddr:
case *net.IPAddr:
args.Source.Ip = v.IP.String()
}
}

View File

@ -1926,7 +1926,7 @@ func TestDNS_PreparedQueryNearIP(t *testing.T) {
require.NoError(t, err)
}
retry.Run(t, func(r *retry.R) {
m :=new(dns.Msg)
m := new(dns.Msg)
m.SetQuestion("some.query.we.like.query.consul.", dns.TypeA)
m.SetEdns0(4096, false)
o := new(dns.OPT)
@ -1957,7 +1957,7 @@ func TestDNS_PreparedQueryNearIP(t *testing.T) {
r.Fatalf("Expecting A RR #%d = %s, Actual RR was %s", i, serviceNodes[i].address, actual)
}
} else {
r.Fatalf("DNS Answer container a non-A RR")
r.Fatalf("DNS Answer contained a non-A RR")
}
}
})

View File

@ -180,7 +180,7 @@ The table below shows this endpoint's support for
results nearest the agent servicing the request. Using `_ip` is supported and
will automatically return results nearest to the node associated with the
source IP where the query is executed from. For HTTP the source IP is the
remote peer's IP address or the value of the X-Forwarded-For head with the
remote peer's IP address or the value of the X-Forwarded-For header with the
header taking precedence. For DNS the source IP is the value of the EDNS
client IP or the remote peer's IP address. If unspecified, the response
will be shuffled by default.