spf: improved support for IPv6 clients

This commit is contained in:
Matt Simerson 2012-11-14 16:58:16 -05:00
parent 51f5c887db
commit b8baa4b91b
2 changed files with 23 additions and 1 deletions

View File

@ -4,3 +4,9 @@
127.0.0.1
# leading/trailing whitespace is ignored
192.0.
#
# IPv6 formats ends in a nibble (not a netmask, prefixlen, or colon)
# RFC 3849 example
2001:DB8
2001:DB8::1
2001:0DB8:0000:0000:0000:0000:0000:0001

View File

@ -59,6 +59,8 @@ use warnings;
#use Mail::SPF 2.000; # eval'ed in ->register
use Qpsmtpd::Constants;
use Net::IP;
sub register {
my ($self, $qp, %args) = @_;
eval 'use Mail::SPF';
@ -237,13 +239,27 @@ sub is_in_relayclients {
my $more_relay_clients = $self->qp->config('morerelayclients', 'map');
my %relay_clients = map { $_ => 1 } @relay_clients;
my $ipv6 = $client_ip =~ /:/ ? 1 : 0;
if ( $ipv6 && $client_ip =~ /::/ ) { # IPv6 compressed notation
$client_ip = Net::IP::ip_expand_address($client_ip,6);
};
while ($client_ip) {
if ( exists $relay_clients{$client_ip} ||
exists $more_relay_clients->{$client_ip} ) {
$self->log( LOGDEBUG, "skip, IP in relayclients" );
return 1;
};
$client_ip =~ s/\d+\.?$// or last; # strip off another 8 bits
# added IPv6 support (Michael Holzt - 2012-11-14)
if ( $ipv6 ) {
$client_ip =~ s/[0-9a-f]:*$//; # strip off another nibble
chop $client_ip if ':' eq substr($client_ip, -1, 1);
}
else {
$client_ip =~ s/\d+\.?$// or last; # strip off another 8 bits
}
}
return;
};