From 1531ad3bcd69b1836a7e59500f1d3cc68fbe9043 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sat, 28 Aug 2010 15:15:41 -0700 Subject: [PATCH] Re-implement interface->shell-variable mapping --- Shorewall/Perl/Shorewall/Zones.pm | 44 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Zones.pm b/Shorewall/Perl/Shorewall/Zones.pm index cc67bdad9..3ae26be06 100644 --- a/Shorewall/Perl/Shorewall/Zones.pm +++ b/Shorewall/Perl/Shorewall/Zones.pm @@ -775,6 +775,15 @@ sub is_a_bridge( $ ) { # sub chain_base($) { my $chain = $_[0]; + my $name = $basemap{$chain}; + # + # Return existing mapping, if any + # + return $name if $name; + # + # Remember initial value + # + my $key = $chain; # # Handle VLANs and wildcards # @@ -783,24 +792,27 @@ sub chain_base($) { if ( $chain =~ /^[0-9]/ || $chain =~ /[^\w]/ ) { # - # Not valid variable name + # Must map. Remove all illegal characters # - if ( $basemap{$_[0]} ) { - # - # We've mapped this name previously - # - $basemap{$_[0]}; - } else { - # - # Must map. Remove all illegal characters - # - $chain =~ s/[^\w]//g; - $chain = join( '' , 'if_', $chain ) unless $chain =~ /^[a-zA-z]/; - $basemap{$_[0]} = join ( '_', $chain, ++$baseseq ); - } - } else { - $chain; + $chain =~ s/[^\w]//g; + # + # Prefix with if_ if it begins with a digit + # + $chain = join( '' , 'if_', $chain ) if $chain =~ /^[0-9]/; + # + # Save and return mapped name + # + $name = join ( '_', $chain, ++$baseseq ); + } else { + # + # We'll store the identity mapping + # + $name = $chain; } + # + # Store the mapping + # + $basemap{$key} = $name; } #