2021-02-02 12:05:47 +01:00
|
|
|
package resolver
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-09-28 12:42:01 +02:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-02-02 12:05:47 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// BogonResolver is a bogon aware resolver. When a bogon is encountered in
|
|
|
|
// a reply, this resolver will return an error.
|
2021-06-25 11:51:10 +02:00
|
|
|
//
|
|
|
|
// Deprecation warning
|
|
|
|
//
|
|
|
|
// This resolver is deprecated. The right thing to do would be to check
|
|
|
|
// for bogons right after a domain name resolution in the nettest.
|
2021-02-02 12:05:47 +01:00
|
|
|
type BogonResolver struct {
|
|
|
|
Resolver
|
|
|
|
}
|
|
|
|
|
|
|
|
// LookupHost implements Resolver.LookupHost
|
|
|
|
func (r BogonResolver) LookupHost(ctx context.Context, hostname string) ([]string, error) {
|
|
|
|
addrs, err := r.Resolver.LookupHost(ctx, hostname)
|
|
|
|
for _, addr := range addrs {
|
2021-11-02 12:20:04 +01:00
|
|
|
if netxlite.IsBogon(addr) {
|
2021-09-28 12:42:01 +02:00
|
|
|
return nil, netxlite.ErrDNSBogon
|
2021-02-02 12:05:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return addrs, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Resolver = BogonResolver{}
|