From 4ed4443abbbb2ed17597fb768e30ab27a76cdc8b Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Thu, 3 Feb 2011 09:44:46 -0800 Subject: [PATCH] Do a fancier job of comparing networks --- Shorewall/Perl/Shorewall/Accounting.pm | 2 +- Shorewall/Perl/Shorewall/IPAddrs.pm | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Shorewall/Perl/Shorewall/Accounting.pm b/Shorewall/Perl/Shorewall/Accounting.pm index 87462c989..ae8e1764d 100644 --- a/Shorewall/Perl/Shorewall/Accounting.pm +++ b/Shorewall/Perl/Shorewall/Accounting.pm @@ -122,7 +122,7 @@ sub process_accounting_rule( ) { my $prevnet = $tables{$table}; if ( $prevnet ) { - fatal_error "Previous net associated with $table ($prevnet) does not match this one ($net)" unless $net eq $prevnet; + fatal_error "Previous net associated with $table ($prevnet) does not match this one ($net)" unless compare_nets( $net , $prevnet ); } else { $tables{$table} = $net; } diff --git a/Shorewall/Perl/Shorewall/IPAddrs.pm b/Shorewall/Perl/Shorewall/IPAddrs.pm index 1aafa521d..f8a1697c8 100644 --- a/Shorewall/Perl/Shorewall/IPAddrs.pm +++ b/Shorewall/Perl/Shorewall/IPAddrs.pm @@ -59,6 +59,7 @@ our @EXPORT = qw( ALLIPv4 validate_address validate_net decompose_net + compare_nets validate_host validate_range ip_range_explicit @@ -284,6 +285,15 @@ sub decompose_net( $ ) { } +sub compare_nets( $$ ) { + my ( @net1, @net2 ); + + @net1 = decompose_net( $_[0] ); + @net2 = decompose_net( $_[1] ); + + $net1[0] eq $net2[0] && $net1[1] == $net2[1]; +} + sub allipv4() { @allipv4; }