Add support to CIDR notation in network-alias file. Thanks to Thibaud Aubert for the feature request.

This commit is contained in:
Darold Gilles 2013-05-28 00:44:29 +02:00
parent f06f9fc6aa
commit cbfaefa52e
2 changed files with 26 additions and 8 deletions

View File

@ -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(/(?<!\{\d)[\s,;\t](?!\d+\})/, $data[1]);
foreach my $r (@rg) {
$r =~ s/^\^//;
&check_regex($r, "$file at line $i");
# If this is not a cidr notation
if ($r !~ /^\d+\.\d+\.\d+\.\d+\/\d+$/) {
&check_regex($r, "$file at line $i");
}
$alias{"$r"} = $data[0];
}
} else {

View File

@ -1,10 +1,15 @@
#-------------------------------------------------------------------------------
# Squid Analyzer Network Alias configuration file
# FORMAT : NETWORK_NAME NETWORK_REGEX1,NETWORK_REGEX2,...
# Field separator must be one or more tabulation. See examples below.
# FORMAT: NETWORK_NAME NETWORK_REGEX1,NETWORK_REGEX2,...
# Field separator must be one or more tabulation.
# You can also use the CIDR notation:
# FORMAT: NETWORK_NAME xxx.xxx.xxx.xxx/n
#
# See examples below.
#
#-------------------------------------------------------------------------------
#Home Network 192\.168\.1\.
#Associated Networks ^10\.169\.[2-4]\.,^10\.169\.[7-9]\.
#ClassB Network ^10\.172\.
#ClassB Network 10.172.0.0/16
#ClassC Network 192.168.1.0/24