wgengine/tsdns: respond with any available addrs for ALL queries

This appears to have been the intent of the previous code,
but in practice, it only returned A records.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder 2021-01-08 14:14:10 -08:00 committed by Josh Bleecher Snyder
parent fa3e8e1a28
commit e0c4ffa71f
2 changed files with 9 additions and 3 deletions

View File

@ -211,17 +211,22 @@ func (r *Resolver) Resolve(domain string, tp dns.Type) (netaddr.IP, dns.RCode, e
// Refactoring note: this must happen after we check suffixes, // Refactoring note: this must happen after we check suffixes,
// otherwise we will respond with NOTIMP to requests that should be forwarded. // otherwise we will respond with NOTIMP to requests that should be forwarded.
switch { switch tp {
case tp == dns.TypeA || tp == dns.TypeALL: case dns.TypeA:
if !addr.Is4() { if !addr.Is4() {
return netaddr.IP{}, dns.RCodeSuccess, nil return netaddr.IP{}, dns.RCodeSuccess, nil
} }
return addr, dns.RCodeSuccess, nil return addr, dns.RCodeSuccess, nil
case tp == dns.TypeAAAA || tp == dns.TypeALL: case dns.TypeAAAA:
if !addr.Is6() { if !addr.Is6() {
return netaddr.IP{}, dns.RCodeSuccess, nil return netaddr.IP{}, dns.RCodeSuccess, nil
} }
return addr, dns.RCodeSuccess, nil return addr, dns.RCodeSuccess, nil
case dns.TypeALL:
// Answer with whatever we've got.
// It could be IPv4, IPv6, or a zero addr.
// TODO: Return all available resolutions (A and AAAA, if we have them).
return addr, dns.RCodeSuccess, nil
default: default:
return netaddr.IP{}, dns.RCodeNotImplemented, errNotImplemented return netaddr.IP{}, dns.RCodeNotImplemented, errNotImplemented
} }

View File

@ -214,6 +214,7 @@ func TestResolve(t *testing.T) {
{"no-ipv6", "test1.ipn.dev.", dns.TypeAAAA, netaddr.IP{}, dns.RCodeSuccess}, {"no-ipv6", "test1.ipn.dev.", dns.TypeAAAA, netaddr.IP{}, dns.RCodeSuccess},
{"nxdomain", "test3.ipn.dev.", dns.TypeA, netaddr.IP{}, dns.RCodeNameError}, {"nxdomain", "test3.ipn.dev.", dns.TypeA, netaddr.IP{}, dns.RCodeNameError},
{"foreign domain", "google.com.", dns.TypeA, netaddr.IP{}, dns.RCodeRefused}, {"foreign domain", "google.com.", dns.TypeA, netaddr.IP{}, dns.RCodeRefused},
{"all", "test1.ipn.dev.", dns.TypeA, testipv4, dns.RCodeSuccess},
} }
for _, tt := range tests { for _, tt := range tests {