From 4597ec10372eddbad2ca6e139898bc3110c96486 Mon Sep 17 00:00:00 2001 From: Peter Cai Date: Sat, 22 Oct 2022 15:55:59 -0400 Subject: [PATCH] net/dnscache: Handle 4-in-6 addresses in DNS responses 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 IPs. Fixes #5698. Signed-off-by: Peter Cai --- net/dnscache/dnscache.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/dnscache/dnscache.go b/net/dnscache/dnscache.go index 6c98322e0..9a78380aa 100644 --- a/net/dnscache/dnscache.go +++ b/net/dnscache/dnscache.go @@ -276,6 +276,11 @@ func (r *Resolver) lookupIP(host string) (ip, ip6 netip.Addr, allIPs []netip.Add return netip.Addr{}, netip.Addr{}, nil, fmt.Errorf("no IPs for %q found", host) } + // Unmap everything; LookupNetIP can return mapped addresses (see #5698) + for i := range ips { + ips[i] = ips[i].Unmap() + } + have4 := false for _, ipa := range ips { if ipa.Is4() {