fix problem with spf where we would generate errors about too many void lookups

the problem was that we only looked up either the ipv4 or ipv6 address when
evaluating spf directives, depending on the incoming smtp connection. for
example, for spf directive "a", we would lookup the requested domain. if that
domain has an ipv4 address but no ipv6 address, and the incoming connection is
ipv6, we would count a void lookup. but we shouldn't: there is a record for
that name, it just doesn't match the address (family).
This commit is contained in:
Mechiel Lukkien 2023-03-03 11:45:19 +01:00
parent 1073ca2795
commit 30c79faff2
No known key found for this signature in database

View file

@ -338,11 +338,7 @@ func evaluate(ctx context.Context, record *Record, resolver dns.Resolver, args A
// Used for "a" and "mx". // Used for "a" and "mx".
checkHostIP := func(domain dns.Domain, d Directive, args *Args) (bool, Status, error) { checkHostIP := func(domain dns.Domain, d Directive, args *Args) (bool, Status, error) {
network := "ip4" ips, err := resolver.LookupIP(ctx, "ip", domain.ASCII+".")
if remote6 != nil {
network = "ip6"
}
ips, err := resolver.LookupIP(ctx, network, domain.ASCII+".")
trackVoidLookup(err, args) trackVoidLookup(err, args)
// If "not found", we must ignore the error and treat as zero records in answer. ../rfc/7208:1116 // If "not found", we must ignore the error and treat as zero records in answer. ../rfc/7208:1116
if err != nil && !dns.IsNotFound(err) { if err != nil && !dns.IsNotFound(err) {
@ -478,11 +474,7 @@ func evaluate(ctx context.Context, record *Record, resolver dns.Resolver, args A
break break
} }
lookups++ lookups++
network := "ip4" ips, err := resolver.LookupIP(ctx, "ip", rd.ASCII+".")
if remote6 != nil {
network = "ip6"
}
ips, err := resolver.LookupIP(ctx, network, rd.ASCII+".")
trackVoidLookup(err, &args) trackVoidLookup(err, &args)
for _, ip := range ips { for _, ip := range ips {
if checkIP(ip, d) { if checkIP(ip, d) {
@ -669,11 +661,7 @@ func expandDomainSpec(ctx context.Context, resolver dns.Resolver, domainSpec str
if !matchfn(name) { if !matchfn(name) {
continue continue
} }
network := "ip4" ips, err := resolver.LookupIP(ctx, "ip", name)
if args.RemoteIP.To4() == nil {
network = "ip6"
}
ips, err := resolver.LookupIP(ctx, network, name)
trackVoidLookup(err, &args) trackVoidLookup(err, &args)
// ../rfc/7208:1714, we don't have to check other errors. // ../rfc/7208:1714, we don't have to check other errors.
for _, ip := range ips { for _, ip := range ips {