[Rt-commit] rtir branch, ipv6, updated. 2.6.0-29-gc45e5b6
Ruslan Zakirov
ruz at bestpractical.com
Tue Oct 25 18:03:47 EDT 2011
The branch, ipv6 has been updated
via c45e5b6247e07c3fedcc72f9c2c79891e06b01c4 (commit)
via 144c0a71302bfc96e716d22b5e4842670bdf828b (commit)
via ee0a80345374710ad651b1856e3237dd7f5a2cb2 (commit)
from 0c4dac280e413dd62b956e63decad6d4b9010f3f (commit)
Summary of changes:
lib/RT/Action/RTIR_FindIP.pm | 33 ++++++++++++++++++++++++++++-----
t/custom-fields/ipv6.t | 3 ++-
2 files changed, 30 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit ee0a80345374710ad651b1856e3237dd7f5a2cb2
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Wed Oct 26 01:56:33 2011 +0400
output debugging when a test fails
diff --git a/t/custom-fields/ipv6.t b/t/custom-fields/ipv6.t
index b8b5c54..38df66a 100644
--- a/t/custom-fields/ipv6.t
+++ b/t/custom-fields/ipv6.t
@@ -264,7 +264,8 @@ diag "check that IPs in messages don't add duplicates" if $ENV{'TEST_VERBOSE'};
my %has;
$has{ $_->Content }++ foreach @{ $values->ItemsArrayRef };
is(scalar values %has, 1, "one IP were added");
- ok(!grep( $_ != 1, values %has ), "no duplicated values");
+ ok(!grep( $_ != 1, values %has ), "no duplicated values")
+ or diag "duplicates: ". join ',', grep $has{$_}>1, keys %has;
ok($has{ $valid{ 'abcd::192.168.1.1' } }, "IP is there")
or diag "but has values ". join ", ", keys %has;
}
commit 144c0a71302bfc96e716d22b5e4842670bdf828b
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Wed Oct 26 01:57:50 2011 +0400
better check surroundings of IPs
don't allow bad values after IP, this includes separators and units,
however, allow lonely separator right after, so IP can be at the
end of a sentence.
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 5e4465a..88dffef 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -7,14 +7,36 @@ use base qw(RT::Action::RTIR);
use Regexp::Common qw(net);
use Regexp::Common::net::CIDR ();
-use Regexp::IPv6 qw($IPv6_re);
+use Regexp::IPv6 qw();
use Net::CIDR ();
my $IPv4_mask_re = qr{3[0-2]|[1-2]?[0-9]};
+my $IPv4_prefix_check_re = qr{(?<![0-9.])};
+my $IPv4_sufix_check_re = qr{(?!\.?[0-9])};
+my $IPv4_CIDR_re = qr{
+ $IPv4_prefix_check_re
+ $RE{net}{CIDR}{IPv4}{-keep}
+ $IPv4_sufix_check_re
+}x;
+my $IPv4_re = qr[
+ $IPv4_prefix_check_re
+ (?!0\.0\.0\.0)
+ ($RE{net}{IPv4})
+ (?!/$IPv4_mask_re)
+ $IPv4_sufix_check_re
+]x;
+
my $IPv6_mask_re = qr{12[0-8]|1[01][0-9]|[1-9]?[0-9]};
-my $IP4_re = qr[(?<![0-9.])(?!0\.0\.0\.0)($RE{net}{IPv4})(?!/$IPv4_mask_re)(?![0-9.])];
-my $IP6_re = qr[(?<![0-9a-fA-F:.])($IPv6_re)(?:/($IPv6_mask_re))?(?![0-9a-fA-F:.])];
-my $IP_re = qr{$IP6_re|$IP4_re|$RE{net}{CIDR}{IPv4}{-keep}};
+my $IPv6_prefix_check_re = qr{(?<![0-9a-fA-F:.])};
+my $IPv6_sufix_check_re = qr{(?!(?:\:{0,2}|\.)[0-9a-fA-F])};
+my $IPv6_re = qr[
+ $IPv6_prefix_check_re
+ ($Regexp::IPv6::IPv6_re)
+ (?:/($IPv6_mask_re))?
+ $IPv6_sufix_check_re
+]x;
+
+my $IP_re = qr{$IPv6_re|$IPv4_re|$IPv4_CIDR_re};
=head2 Prepare
commit c45e5b6247e07c3fedcc72f9c2c79891e06b01c4
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date: Wed Oct 26 02:01:43 2011 +0400
properly skip IPv6 with /128 mask
cidr to range returns range with equal IPs on both sides,
our method of skipping duplicates doesn't deal with that,
so just treat it specially.
diff --git a/lib/RT/Action/RTIR_FindIP.pm b/lib/RT/Action/RTIR_FindIP.pm
index 88dffef..37701db 100644
--- a/lib/RT/Action/RTIR_FindIP.pm
+++ b/lib/RT/Action/RTIR_FindIP.pm
@@ -79,7 +79,8 @@ sub Commit {
my $content = $attach->Content || '';
while ( $content =~ m/$IP_re/go ) {
if ( $1 && defined $2 ) { # IPv6/mask
- my $range = (Net::CIDR::cidr2range( "$1/$2" ))[0] or next;
+ my $range = $2 == 128 ? $1 : (Net::CIDR::cidr2range( "$1/$2" ))[0]
+ or next;
$spots_left -= $self->AddIP(
IP => $range, CustomField => $cf, Skip => \%existing
);
-----------------------------------------------------------------------
More information about the Rt-commit
mailing list