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
# #
@ -782,25 +791,28 @@ sub chain_base($) {
$chain =~ tr/./_/; $chain =~ tr/./_/;
if ( $chain =~ /^[0-9]/ || $chain =~ /[^\w]/ ) { if ( $chain =~ /^[0-9]/ || $chain =~ /[^\w]/ ) {
#
# Not valid variable name
#
if ( $basemap{$_[0]} ) {
#
# We've mapped this name previously
#
$basemap{$_[0]};
} else {
# #
# Must map. Remove all illegal characters # Must map. Remove all illegal characters
# #
$chain =~ s/[^\w]//g; $chain =~ s/[^\w]//g;
$chain = join( '' , 'if_', $chain ) unless $chain =~ /^[a-zA-z]/; #
$basemap{$_[0]} = join ( '_', $chain, ++$baseseq ); # 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 { } else {
$chain; #
# We'll store the identity mapping
#
$name = $chain;
} }
#
# Store the mapping
#
$basemap{$key} = $name;
} }
# #