From c96db9a01c8d5fae41d32addb206b0f287d2f3e1 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Mon, 15 Jun 2009 11:35:46 -0700 Subject: [PATCH] Set optional provider variables when NOROUTE is true --- Shorewall/Perl/Shorewall/Providers.pm | 60 +++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index a42466447..b8b30bb35 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -360,14 +360,15 @@ sub add_a_provider( ) { $balance = $default_balance unless $balance; - $providers{$table} = { provider => $table, - number => $number , - mark => $val ? in_hex($val) : $val , - interface => $interface , - optional => $optional , - gateway => $gateway , - shared => $shared , - default => $default }; + $providers{$table} = { provider => $table, + number => $number , + mark => $val ? in_hex($val) : $val , + interface => $interface , + optional => $optional , + gateway => $gateway , + gatewaycase => $gatewaycase , + shared => $shared , + default => $default }; if ( $track ) { fatal_error "The 'track' option requires a numeric value in the MARK column" if $mark eq '-'; @@ -702,6 +703,48 @@ sub finish_providers() { } } +sub test_optional_providers() { + my $first = 1; + for my $table ( @providers ) { + my $tableref = $providers{$table}; + + if ( $tableref->{optional} ) { + my $interface = $tableref->{interface}; + my $base = uc chain_base( $interface ); + my $variable; + + if ( $first ) { + emit 'else'; + push_indent; + $first = 0; + } else { + emit ''; + } + + if ( $tableref->{shared} ) { + $variable = $tableref->{mac}; + } elsif ( $tableref->{gatewaycase} eq 'detect' ) { + $variable = $tableref->{gateway}; + } else { + $variable = ''; + } + + if ( $variable ) { + emit qq(if interface_is_usable $interface && [ -n "$variable" ]; then); + } else { + emit qq(if interface_is_usable $interface; then); + } + + emit( " ${base}_IS_UP=Yes" , + 'else', + " ${base}_IS_UP=" , + 'fi' ); + } + } + + pop_indent unless $first; +} + sub setup_providers() { my $providers = 0; @@ -728,6 +771,7 @@ sub setup_providers() { setup_null_routing if $config{NULL_ROUTE_RFC1918}; emit "\nrun_ip route flush cache"; pop_indent; + test_optional_providers; emit "fi\n"; setup_route_marking if @routemarked_interfaces;