Skip to content

Commit

Permalink
net/dnscache: Handle 4-in-6 addresses in DNS responses
Browse files Browse the repository at this point in the history
On Android, the system resolver can return IPv4 addresses as IPv6-mapped
addresses (i.e. `::ffff:a.b.c.d`). After the switch to `net/netip`
(19008a3), this case is no longer handled and a response like this will
be seen as failure to resolve any IPv4 addresses.

Handle this case by simply calling `Unmap()` on the returned IP when it
is a 4-in-6 address. Fixes tailscale#5698.

Signed-off-by: Peter Cai <peter@typeblog.net>
  • Loading branch information
PeterCxy committed Oct 22, 2022
1 parent 3697609 commit 65213d5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions net/dnscache/dnscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ func (r *Resolver) lookupIP(host string) (ip, ip6 netip.Addr, allIPs []netip.Add

have4 := false
for _, ipa := range ips {
if ipa.Is4() {
if ipa.Is4() || ipa.Is4In6() {
if !have4 {
ip6 = ip
ip = ipa
ip = ipa.Unmap()
have4 = true
}
} else {
Expand Down

0 comments on commit 65213d5

Please sign in to comment.