From cec8d5145bcda41d76c4b68f853ab6f75bdb982a Mon Sep 17 00:00:00 2001 From: Matt Keeler Date: Wed, 11 Apr 2018 20:32:35 -0400 Subject: [PATCH] GH-3798: A few more PR updates --- agent/consul/prepared_query_endpoint.go | 16 +++++++++------- agent/dns.go | 4 +++- agent/dns_test.go | 4 ++-- website/source/api/query.html.md | 2 +- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/agent/consul/prepared_query_endpoint.go b/agent/consul/prepared_query_endpoint.go index c631c1173c..e776b4f9de 100644 --- a/agent/consul/prepared_query_endpoint.go +++ b/agent/consul/prepared_query_endpoint.go @@ -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 diff --git a/agent/dns.go b/agent/dns.go index 28b9cbdf5b..ab00690ac6 100644 --- a/agent/dns.go +++ b/agent/dns.go @@ -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() } } diff --git a/agent/dns_test.go b/agent/dns_test.go index a6fbeeb275..934a66517c 100644 --- a/agent/dns_test.go +++ b/agent/dns_test.go @@ -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") } } }) diff --git a/website/source/api/query.html.md b/website/source/api/query.html.md index 799519f5aa..4af9160e36 100644 --- a/website/source/api/query.html.md +++ b/website/source/api/query.html.md @@ -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.