diff --git a/config.sample/relayclients b/config.sample/relayclients index 792c76b..a0fbc4e 100644 --- a/config.sample/relayclients +++ b/config.sample/relayclients @@ -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 diff --git a/plugins/sender_permitted_from b/plugins/sender_permitted_from index d888701..42f26d8 100644 --- a/plugins/sender_permitted_from +++ b/plugins/sender_permitted_from @@ -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; };