fix(netxlite): LookupHTTPS: short circuit IP addr (#725)

This diff fixes the short-circuit-IP-addr resolver to
correctly handle IP addrs during LookupHTTPS.

The original diff was: 2b51d144bf

See https://github.com/ooni/probe/issues/2096

While there, add unit tests for IPv6.
This commit is contained in:
Simone Basso 2022-05-13 18:26:15 +02:00 committed by GitHub
commit e126e73de7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 101 additions and 0 deletions

View file

@ -209,6 +209,19 @@ func (r *resolverShortCircuitIPAddr) LookupHost(ctx context.Context, hostname st
return r.Resolver.LookupHost(ctx, hostname)
}
func (r *resolverShortCircuitIPAddr) LookupHTTPS(ctx context.Context, hostname string) (*model.HTTPSSvc, error) {
if net.ParseIP(hostname) != nil {
https := &model.HTTPSSvc{}
if isIPv6(hostname) {
https.IPv6 = append(https.IPv6, hostname)
} else {
https.IPv4 = append(https.IPv4, hostname)
}
return https, nil
}
return r.Resolver.LookupHTTPS(ctx, hostname)
}
// IsIPv6 returns true if the given candidate is a valid IP address
// representation and such representation is IPv6.
func IsIPv6(candidate string) (bool, error) {