Follow the logic of the non-async version and other MTAs: make first

the MX lookups and, only if they return nothing, make the A lookups.

git-svn-id: https://svn.perl.org/qpsmtpd/trunk@880 958fd67b-6ff1-0310-b445-bb7760255be9
This commit is contained in:
Radu Greab 2008-05-01 06:18:46 +00:00
parent 79aa27f444
commit 149c9c4790

View File

@ -73,7 +73,8 @@ sub check_dns {
$qp->input_sock->pause_read; $qp->input_sock->pause_read;
my $a_records = []; my $a_records = [];
my $num_queries = $has_ipv6 ? 3 : 2; # queries in progress my $num_queries = 1; # queries in progress
my $mx_found = 0;
ParaDNS->new( ParaDNS->new(
callback => sub { callback => sub {
@ -81,6 +82,7 @@ sub check_dns {
return if $mx =~ /^[A-Z]+$/; # error return if $mx =~ /^[A-Z]+$/; # error
my $addr = $mx->[0]; my $addr = $mx->[0];
$mx_found = 1;
$num_queries++; $num_queries++;
ParaDNS->new( ParaDNS->new(
@ -100,28 +102,42 @@ sub check_dns {
); );
} }
}, },
finished => sub { $num_queries--; $self->finish_up($qp, $a_records, $num_queries) }, finished => sub {
unless ($mx_found) {
$num_queries++;
ParaDNS->new(
callback => sub { push @$a_records, $_[0] if $_[0] !~ /^[A-Z]+$/; },
finished => sub { $num_queries--; $self->finish_up($qp, $a_records, $num_queries) },
host => $host,
type => 'A',
);
if ($has_ipv6) {
$num_queries++;
ParaDNS->new(
callback => sub { push @$a_records, $_[0] if $_[0] !~ /^[A-Z]+$/; },
finished => sub { $num_queries--; $self->finish_up($qp, $a_records, $num_queries) },
host => $host,
type => 'AAAA',
);
}
}
$num_queries--;
$self->finish_up($qp, $a_records, $num_queries);
},
host => $host, host => $host,
type => 'MX', type => 'MX',
) or return; ) or $qp->input_sock->continue_read, return;
ParaDNS->new(
callback => sub { push @$a_records, $_[0] if $_[0] !~ /^[A-Z]+$/; },
finished => sub { $num_queries--; $self->finish_up($qp, $a_records, $num_queries) },
host => $host,
type => 'A',
) or return;
ParaDNS->new(
callback => sub { push @$a_records, $_[0] if $_[0] !~ /^[A-Z]+$/; },
finished => sub { $num_queries--; $self->finish_up($qp, $a_records, $num_queries) },
host => $host,
type => 'AAAA',
) or return if $has_ipv6;
return 1; return 1;
} }
sub finish_up { sub finish_up {
my ($self, $qp, $a_records, $num_queries, $source) = @_; my ($self, $qp, $a_records, $num_queries) = @_;
return if defined $qp->transaction->notes('resolvable_fromhost'); return if defined $qp->transaction->notes('resolvable_fromhost');