From e9a94b0cfbf5cd92b1ed8e3f8a1da20bbbdbaf4e Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Thu, 15 Apr 2010 14:12:48 -0700 Subject: [PATCH] Unify reference count adjustment Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Chains.pm | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Chains.pm b/Shorewall/Perl/Shorewall/Chains.pm index 525690772..dec598444 100644 --- a/Shorewall/Perl/Shorewall/Chains.pm +++ b/Shorewall/Perl/Shorewall/Chains.pm @@ -722,6 +722,18 @@ sub add_tunnel_rule( $$ ) { insert_rule1( $chainref, $chainref->{new}++, $rule ); } +# +# Adjust reference counts after moving a rule from $name1 to $name2 +# +sub adjust_reference_counts( $$$ ) { + my ($toref, $name1, $name2) = @_; + + if ( $toref ) { + delete $toref->{references}{$name1} unless --$toref->{references}{$name1} > 0; + $toref->{references}{$name2}++; + } +} + # # Move the rules from one chain to another # @@ -744,13 +756,7 @@ sub move_rules( $$ ) { $name1 =~ s/\+/\\+/; for ( @{$chain1->{rules}} ) { - if ( / -[jg] ([^\s]+)\b/ ) { - my $toref = $tableref->{$1}; - if ( $toref ) { - delete $toref->{references}{$name1} unless --$toref->{references}{$name1} > 0; - $toref->{references}{$name2}++; - } - } + adjust_reference_counts( $tableref->{$1}, $name1, $name2 ) if / -[jg] ([^\s]+)\b/; } if ( $debug ) { @@ -801,14 +807,8 @@ sub copy_rules( $$ ) { } for ( @rules ) { - if ( / -[jg] ([^\s]+)\b/ ) { - my $toref = $tableref->{$1}; - if ( $toref ) { - delete $toref->{references}{$name1} unless --$toref->{references}{$name1} > 0; - $toref->{references}{$name2}++; - } - } - } + adjust_reference_counts( $tableref->{$1}, $name1, $name2 ) if / -[jg] ([^\s]+)\b/; + } push @$rules, @rules; #