Re-implement interface->shell-variable mapping

This commit is contained in:
Tom Eastep 2010-08-28 15:15:41 -07:00
parent 3a36a9de4b
commit 1531ad3bcd

View File

@ -775,6 +775,15 @@ sub is_a_bridge( $ ) {
# #
sub chain_base($) { sub chain_base($) {
my $chain = $_[0]; 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 # Handle VLANs and wildcards
# #
@ -783,24 +792,27 @@ sub chain_base($) {
if ( $chain =~ /^[0-9]/ || $chain =~ /[^\w]/ ) { if ( $chain =~ /^[0-9]/ || $chain =~ /[^\w]/ ) {
# #
# Not valid variable name # Must map. Remove all illegal characters
# #
if ( $basemap{$_[0]} ) { $chain =~ s/[^\w]//g;
# #
# We've mapped this name previously # Prefix with if_ if it begins with a digit
# #
$basemap{$_[0]}; $chain = join( '' , 'if_', $chain ) if $chain =~ /^[0-9]/;
} else { #
# # Save and return mapped name
# Must map. Remove all illegal characters #
# $name = join ( '_', $chain, ++$baseseq );
$chain =~ s/[^\w]//g; } else {
$chain = join( '' , 'if_', $chain ) unless $chain =~ /^[a-zA-z]/; #
$basemap{$_[0]} = join ( '_', $chain, ++$baseseq ); # We'll store the identity mapping
} #
} else { $name = $chain;
$chain;
} }
#
# Store the mapping
#
$basemap{$key} = $name;
} }
# #