From 64fd1167d1e54b46d582e8a6fc0c94aab5321eab Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Tue, 16 Jun 2009 15:39:04 -0700 Subject: [PATCH] replace a couple of instances of 'which' with 'mywhich'; relocate some global variable code --- Shorewall/Perl/Shorewall/Compiler.pm | 8 +++++--- Shorewall/Perl/Shorewall/Providers.pm | 23 ++++++++++------------- Shorewall/Perl/prog.header | 4 ++-- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Compiler.pm b/Shorewall/Perl/Shorewall/Compiler.pm index 190efed19..02dffb08f 100644 --- a/Shorewall/Perl/Shorewall/Compiler.pm +++ b/Shorewall/Perl/Shorewall/Compiler.pm @@ -242,6 +242,8 @@ sub generate_script_2() { set_global_variables(1); + handle_optional_interfaces; + emit ';;'; if ( $global_variables == ( ALL_COMMANDS | NOT_RESTORE ) ) { @@ -253,6 +255,8 @@ sub generate_script_2() { set_global_variables(0); + handle_optional_interfaces; + emit ';;'; } @@ -262,8 +266,6 @@ sub generate_script_2() { emit ( 'esac' ) , } - handle_optional_interfaces; - pop_indent; emit "\n}\n"; # End of initialize() @@ -339,7 +341,7 @@ sub generate_script_3($) { ' [ -x "$IPSET" ] || fatal_error "IPSET=$IPSET does not exist or is not executable"', ' ;;', ' *)', - ' IPSET="$(which $IPSET)"', + ' IPSET="$(mywhich $IPSET)"', ' [ -n "$IPSET" ] || fatal_error "The ipset utility cannot be located"' , ' ;;', 'esac', diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index 729ae3c69..a81019d9b 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -785,31 +785,32 @@ sub lookup_provider( $ ) { # # This function is called by the compiler when it is generating the initialize() function. -# It sets the ..._IS_USABLE interface variables appropriately for the optional interfaces +# The function emits code to set the ..._IS_USABLE interface variables appropriately for the +# optional interfaces # sub handle_optional_interfaces() { my $interfaces = find_interfaces_by_option 'optional'; - if ( $interfaces ) { + if ( @$interfaces ) { my $variable; for my $interface ( @$interfaces ) { my $base = uc chain_base( $interface ); - my $table = $provider_interfaces{$interface}; + my $provider = $provider_interfaces{$interface}; emit ''; - if ( $table ) { + if ( $provider ) { # # This is a provider -- get the provider table entry # - my $tableref = $providers{$table}; + my $providerref = $providers{$provider}; - if ( $tableref->{shared} ) { - $variable = $tableref->{mac}; - } elsif ( $tableref->{gatewaycase} eq 'detect' ) { - $variable = $tableref->{gateway}; + if ( $providerref->{shared} ) { + $variable = $providerref->{mac}; + } elsif ( $providerref->{gatewaycase} eq 'detect' ) { + $variable = $providerref->{gateway}; } else { $variable = ''; } @@ -834,10 +835,6 @@ sub handle_optional_interfaces() { } } -sub is_provider_interface( $ ) { - return $provider_interfaces{$_[0]} || 0; -} - # # The Tc module has collected the 'sticky' rules in the 'tcpre' and 'tcout' chains. In this function, we apply them # to the 'tracked' providers diff --git a/Shorewall/Perl/prog.header b/Shorewall/Perl/prog.header index 58b25c06f..615cea2b4 100644 --- a/Shorewall/Perl/prog.header +++ b/Shorewall/Perl/prog.header @@ -1030,7 +1030,7 @@ find_echo() { result=$(echo -e "a\tb") [ ${#result} -eq 3 ] && { echo "echo -e"; return; } - result=$(which echo) + result=$(mywhich echo) [ -n "$result" ] && { echo "$result -e"; return; } echo echo @@ -1063,7 +1063,7 @@ find_mac() # $1 = IP address, $2 = interface conditionally_flush_conntrack() { if [ -n "$PURGE" ]; then - if [ -n $(which conntrack) ]; then + if [ -n $(mywhich conntrack) ]; then conntrack -F else error_message "WARNING: The '-p' option requires the conntrack utility which does not appear to be installed on this system"