From cbfaefa52e98d7d0031affba998056321750e1f2 Mon Sep 17 00:00:00 2001 From: Darold Gilles Date: Tue, 28 May 2013 00:44:29 +0200 Subject: [PATCH] Add support to CIDR notation in network-alias file. Thanks to Thibaud Aubert for the feature request. --- SquidAnalyzer.pm | 23 ++++++++++++++++++----- etc/network-aliases | 11 ++++++++--- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/SquidAnalyzer.pm b/SquidAnalyzer.pm index b3beb20..85f55cb 100644 --- a/SquidAnalyzer.pm +++ b/SquidAnalyzer.pm @@ -597,7 +597,12 @@ sub _parseData # Replace network by his aliases if any my $network = ''; foreach my $r (keys %{$self->{NetworkAlias}}) { - if ($client =~ /^$r/) { + if ($r =~ /^\d+\.\d+\.\d+\.\d+\/\d+$/) { + if (&check_ip($client, $r)) { + $network = $self->{NetworkAlias}->{$r}; + last; + } + } elsif ($client =~ /^$r/) { $network = $self->{NetworkAlias}->{$r}; last; } @@ -1833,9 +1838,14 @@ sub _print_network_stat my $show = $net; if ($net =~ /^(\d+\.\d+\.\d+)/) { $show = "$1.0"; - foreach my $n (keys %{$self->{NetworkAlias}}) { - if ($show =~ /$self->{NetworkAlias}->{$n}/) { - $show = $n; + foreach my $r (keys %{$self->{NetworkAlias}}) { + if ($r =~ /^\d+\.\d+\.\d+\.\d+\/\d+$/) { + if (&check_ip($net, $r)) { + $show = $self->{NetworkAlias}->{$r}; + last; + } + } elsif ($show =~ /$r/) { + $show = $self->{NetworkAlias}->{$r}; last; } } @@ -2966,7 +2976,10 @@ sub parse_network_aliases my @rg = split(/(?