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,12 +396,14 @@ func (p *PreparedQuery) Execute(args *structs.PreparedQueryExecuteRequest,
} else if qs.Node == "_ip" { } else if qs.Node == "_ip" {
if args.Source.Ip != "" { if args.Source.Ip != "" {
_, nodes, err := state.Nodes(nil) _, nodes, err := state.Nodes(nil)
if err == nil { if err != nil {
for _, node := range nodes { return err
if args.Source.Ip == node.Address { }
qs.Node = node.Node
break for _, node := range nodes {
} if args.Source.Ip == node.Address {
qs.Node = node.Node
break
} }
} }
} }

View File

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

View File

@ -1926,7 +1926,7 @@ func TestDNS_PreparedQueryNearIP(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
} }
retry.Run(t, func(r *retry.R) { 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.SetQuestion("some.query.we.like.query.consul.", dns.TypeA)
m.SetEdns0(4096, false) m.SetEdns0(4096, false)
o := new(dns.OPT) 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) r.Fatalf("Expecting A RR #%d = %s, Actual RR was %s", i, serviceNodes[i].address, actual)
} }
} else { } 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 results nearest the agent servicing the request. Using `_ip` is supported and
will automatically return results nearest to the node associated with the 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 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 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 client IP or the remote peer's IP address. If unspecified, the response
will be shuffled by default. will be shuffled by default.