diff options
author | Doug Freed <dwfreed@mtu.edu> | 2016-01-14 23:35:05 -0700 |
---|---|---|
committer | Doug Freed <dwfreed@mtu.edu> | 2016-01-14 23:35:05 -0700 |
commit | 9ca88a753c7c1831ebfa17ab9b7e356a131874d1 (patch) | |
tree | 700efeb3fc6c7b56b194053d53de52bc9a799d70 | |
parent | b437ade6d08fb41bd2ed865fc2955fb918646dff (diff) | |
download | antispammeta-9ca88a753c7c1831ebfa17ab9b7e356a131874d1.tar.bz2 antispammeta-9ca88a753c7c1831ebfa17ab9b7e356a131874d1.tar.xz antispammeta-9ca88a753c7c1831ebfa17ab9b7e356a131874d1.tar.zst |
Fix async DNS resolution to handle things better
- Handles CNAMEs now
- Handles multiple IPs for a given host
-rw-r--r-- | lib/ASM/Event.pm | 12 | ||||
-rw-r--r-- | lib/ASM/Util.pm | 12 |
2 files changed, 17 insertions, 7 deletions
diff --git a/lib/ASM/Event.pm b/lib/ASM/Event.pm index b22552c..8cf6be5 100644 --- a/lib/ASM/Event.pm +++ b/lib/ASM/Event.pm @@ -720,8 +720,10 @@ sub on_banlist $::event->{DNS}->add( sub { my ($packet) = @_; - $ip = ASM::Util->stripResp($packet); - $::sc{$chan}{ipbans}{$ip} = { bannedBy => $banner, bannedOn => $bantime } if defined($ip); + my @ips = ASM::Util->stripResp($packet); + foreach $ip (@ips) { + $::sc{$chan}{ipbans}{$ip} = { bannedBy => $banner, bannedOn => $bantime }; + } }, $host, 'A'); } } @@ -752,8 +754,10 @@ sub on_quietlist $::event->{DNS}->add( sub { my ($packet) = @_; - $ip = ASM::Util->stripResp($packet); - $::sc{$chan}{ipquiets}{$ip} = { bannedBy => $banner, bannedOn => $bantime } if defined($ip); + my @ips = ASM::Util->stripResp($packet); + foreach $ip (@ips) { + $::sc{$chan}{ipquiets}{$ip} = { bannedBy => $banner, bannedOn => $bantime }; + } }, $host, 'A'); } } diff --git a/lib/ASM/Util.pm b/lib/ASM/Util.pm index dc10d64..55c49ab 100644 --- a/lib/ASM/Util.pm +++ b/lib/ASM/Util.pm @@ -7,6 +7,7 @@ use strict; use Term::ANSIColor qw (:constants); use Socket qw( inet_aton inet_ntoa ); use Data::Dumper; +use Net::DNS 0.55 qw(rrsort); no if $] >= 5.017011, warnings => 'experimental::smartmatch'; @@ -245,12 +246,17 @@ sub stripResp my @answer = $response->answer; if ($response->{header}->{rcode} ne "NOERROR") { dprint($module, Dumper($response), 'dns'); - return; + return undef; } - if ((!(@answer)) || ($answer[0]->{type} ne 'A')) { + if (!(@answer)) { return undef; } - return dottedQuadToInt($module, $answer[0]->{address}); + my @addresses = rrsort('A', @answer); + my @results = (); + foreach my $address (@addresses) { + push @results, dottedQuadToInt($module, $address->{address}); + } + return @results; } sub getHostIPFast |