projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix is_ipaddr? change pc92 A/D default
[spider.git]
/
perl
/
DXCIDR.pm
diff --git
a/perl/DXCIDR.pm
b/perl/DXCIDR.pm
index b702d7b899c197f2647dd92da34d2efb3f502396..fae0f671140925cbe3aa9cfe7536cb663da510a5 100644
(file)
--- a/
perl/DXCIDR.pm
+++ b/
perl/DXCIDR.pm
@@
-68,6
+68,7
@@
sub _read
sub _load
{
sub _load
{
+ return unless $active;
my $suffix = shift;
my @in = _read($suffix);
return 0 unless @in;
my $suffix = shift;
my @in = _read($suffix);
return 0 unless @in;
@@
-122,20
+123,30
@@
sub add
{
return 0 unless $active;
my $count = 0;
{
return 0 unless $active;
my $count = 0;
+ my @out;
for my $ip (@_) {
# protect against stupid or malicious
next unless is_ipaddr($ip);
next if $ip =~ /^127\./;
next if $ip =~ /^::1$/;
for my $ip (@_) {
# protect against stupid or malicious
next unless is_ipaddr($ip);
next if $ip =~ /^127\./;
next if $ip =~ /^::1$/;
+ next if find($ip);
if ($ip =~ /\./) {
if ($ip =~ /\./) {
- $ipv4->add_any($ip);
- ++$count;
- ++$count4;
+ eval {$ipv4->add_any($ip)};
+ if ($@) {
+ push @out, $@;
+ } else {
+ ++$count;
+ ++$count4;
+ }
} elsif ($ip =~ /:/) {
} elsif ($ip =~ /:/) {
- $ipv6->add_any($ip);
- ++$count;
- ++$count6;
+ eval {$ipv6->add_any($ip)};
+ if ($@) {
+ push @out, $@;
+ } else {
+ ++$count;
+ ++$count6;
+ }
} else {
LogDbg('err', "DXCIDR::add non-ip address '$ip' read");
}
} else {
LogDbg('err', "DXCIDR::add non-ip address '$ip' read");
}
@@
-162,7
+173,8
@@
sub _sort
my @in;
my @out;
for (@_) {
my @in;
my @out;
for (@_) {
- push @in, [inet_pton(m|:|?AF_INET6:AF_INET, $_), split m|/|];
+ my @ip = split m|/|;
+ push @in, [inet_pton(m|:|?AF_INET6:AF_INET, $ip[0]), @ip];
}
@out = sort {$a->[0] <=> $b->[0]} @in;
return map { "$_->[1]/$_->[2]"} @out;
}
@out = sort {$a->[0] <=> $b->[0]} @in;
return map { "$_->[1]/$_->[2]"} @out;
@@
-196,7
+208,12
@@
sub init
return;
}
return;
}
- import Net::CIDR::Lite;
+ eval {import Net::CIDR::Lite };
+ if ($@) {
+ LogDbg('DXProt', "DXCIDR: import Net::CIDR::Lite error $@");
+ return;
+ }
+
$active = 1;
my $fn = _fn();
$active = 1;
my $fn = _fn();