Skip to content

Commit

Permalink
improved support for IPv6 addresses: new --ipv4cidr and --ipv6cidr op…
Browse files Browse the repository at this point in the history
…tions for proper subnetting of IPv6 (Håvard Moen, BenediktS)
  • Loading branch information
schweikert committed Jul 23, 2015
1 parent 36c2c9b commit 629f636
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* unreleased
- improved support for IPv6 addresses: new --ipv4cidr and --ipv6cidr options
for proper subnetting of IPv6 (Håvard Moen, BenediktS)

* 2014-06-11: version 1.35
- use just 'postgrey' as process name, instead of '/usr/sbin/postgrey', because
Linux tools are limited to 15 characters (#5)
Expand Down
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Requirements
- BerkeleyDB (Perl Module)
- Berkeley DB >= 4.1 (Library)
- Digest::SHA (Perl Module, only for --privacy option)
- NetAddr::IP


Documentation
Expand Down
28 changes: 16 additions & 12 deletions postgrey
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ package postgrey;
use strict;
use Pod::Usage;
use Getopt::Long 2.25 qw(:config posix_default no_ignore_case);
use Net::IP;
use NetAddr::IP;
use Net::Server; # used only to find out which version we use
use Net::Server::Multiplex;
Expand Down Expand Up @@ -183,20 +182,25 @@ sub do_client_substitutions($$$)
return ($ip, undef);
}

my $ipaddr = new Net::IP($ip) or return ($ip, undef);
if($ipaddr->version == 4) {
my $ipaddr;
if($ip =~ /\./) {
# IPv4
my @ip=split(/\./, $ip);
return ($ip, undef) unless defined $ip[3];
# skip if it contains the last two IP numbers in the hostname
# (we assume it is a pool of dialup addresses of a provider)
return ($ip, undef) if $revdns =~ /$ip[2]/ and $revdns =~ /$ip[3]/;

my @ip=split(/\./, $ip);
return ($ip, undef) unless defined $ip[3];
# skip if it contains the last two IP numbers in the hostname
# (we assume it is a pool of dialup addresses of a provider)
return ($ip, undef) if $revdns =~ /$ip[2]/ and $revdns =~ /$ip[3]/;

$ipaddr = new NetAddr::IP($ip . '/' . $self->{postgrey}{ipv4cidr});
$ipaddr = NetAddr::IP->new($ip, $self->{postgrey}{ipv4cidr});
}
elsif($ip =~ /:/) {
# IPv6
$ipaddr = NetAddr::IP->new($ip, $self->{postgrey}{ipv6cidr});
}
else {
$ipaddr = new6 NetAddr::IP($ip . '/' . $self->{postgrey}{ipv6cidr});
};
warn "doesn't look like an IP address: $ipaddr\n";
return ($ip, undef);
}
return ($ipaddr->network, undef);
}

Expand Down

0 comments on commit 629f636

Please sign in to comment.