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 IPs. Fixes #5698.

Signed-off-by: Peter Cai <peter@typeblog.net>
  • Loading branch information
PeterCxy authored and bradfitz committed Oct 23, 2022
1 parent 70dde89 commit 4597ec1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions net/dnscache/dnscache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 4597ec1

Please sign in to comment.