Unify reference count adjustment

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2010-04-15 14:12:48 -07:00
parent cf59d9ec68
commit e9a94b0cfb

View File

@ -722,6 +722,18 @@ sub add_tunnel_rule( $$ ) {
insert_rule1( $chainref, $chainref->{new}++, $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 # Move the rules from one chain to another
# #
@ -744,13 +756,7 @@ sub move_rules( $$ ) {
$name1 =~ s/\+/\\+/; $name1 =~ s/\+/\\+/;
for ( @{$chain1->{rules}} ) { for ( @{$chain1->{rules}} ) {
if ( / -[jg] ([^\s]+)\b/ ) { adjust_reference_counts( $tableref->{$1}, $name1, $name2 ) if / -[jg] ([^\s]+)\b/;
my $toref = $tableref->{$1};
if ( $toref ) {
delete $toref->{references}{$name1} unless --$toref->{references}{$name1} > 0;
$toref->{references}{$name2}++;
}
}
} }
if ( $debug ) { if ( $debug ) {
@ -801,13 +807,7 @@ sub copy_rules( $$ ) {
} }
for ( @rules ) { for ( @rules ) {
if ( / -[jg] ([^\s]+)\b/ ) { adjust_reference_counts( $tableref->{$1}, $name1, $name2 ) if / -[jg] ([^\s]+)\b/;
my $toref = $tableref->{$1};
if ( $toref ) {
delete $toref->{references}{$name1} unless --$toref->{references}{$name1} > 0;
$toref->{references}{$name2}++;
}
}
} }
push @$rules, @rules; push @$rules, @rules;