Handle routes and rules for main and default

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2011-08-29 10:05:36 -07:00
parent 45bc3a7ea0
commit 3031c37edd

View File

@ -90,10 +90,10 @@ sub initialize( $ ) {
$first_default_route = 1; $first_default_route = 1;
$first_fallback_route = 1; $first_fallback_route = 1;
%providers = ( local => { number => LOCAL_TABLE , mark => 0 , optional => 0 } , %providers = ( local => { number => LOCAL_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
main => { number => MAIN_TABLE , mark => 0 , optional => 0 } , main => { number => MAIN_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
default => { number => DEFAULT_TABLE , mark => 0 , optional => 0 } , default => { number => DEFAULT_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } ,
unspec => { number => UNSPEC_TABLE , mark => 0 , optional => 0 } ); unspec => { number => UNSPEC_TABLE , mark => 0 , optional => 0 ,routes => [], rules => [] } );
@providers = (); @providers = ();
} }
@ -736,6 +736,7 @@ sub add_an_rtrule( ) {
my $number = $providerref->{number}; my $number = $providerref->{number};
fatal_error "You may not add rules for the $provider provider" if $number == LOCAL_TABLE || $number == UNSPEC_TABLE;
fatal_error "You must specify either the source or destination in a route_rules entry" if $source eq '-' && $dest eq '-'; fatal_error "You must specify either the source or destination in a route_rules entry" if $source eq '-' && $dest eq '-';
if ( $dest eq '-' ) { if ( $dest eq '-' ) {
@ -797,7 +798,6 @@ sub add_a_route( ) {
for ( keys %providers ) { for ( keys %providers ) {
if ( $providers{$_}{number} == $provider_number ) { if ( $providers{$_}{number} == $provider_number ) {
$provider = $_; $provider = $_;
fatal_error "You may not add routes to the $provider table" if $provider_number == LOCAL_TABLE || $provider_number == UNSPEC_TABLE;
$found = 1; $found = 1;
last; last;
} }
@ -816,6 +816,8 @@ sub add_a_route( ) {
my $physical = $device eq '-' ? $providers{$provider}{physical} : physical_name( $device ); my $physical = $device eq '-' ? $providers{$provider}{physical} : physical_name( $device );
my $routes = $providerref->{routes}; my $routes = $providerref->{routes};
fatal_error "You may not add routes to the $provider table" if $number == LOCAL_TABLE || $number == UNSPEC_TABLE;
if ( $gateway ne '-' ) { if ( $gateway ne '-' ) {
if ( $device ne '-' ) { if ( $device ne '-' ) {
push @$routes, qq(run_ip route add $dest via $gateway dev $physical table $number); push @$routes, qq(run_ip route add $dest via $gateway dev $physical table $number);
@ -874,6 +876,25 @@ sub start_providers() {
emit 'DEFAULT_ROUTE='; emit 'DEFAULT_ROUTE=';
emit 'FALLBACK_ROUTE='; emit 'FALLBACK_ROUTE=';
emit ''; emit '';
emit '';
emit qq(> \${VARDIR}/undo_main_routing);
emit qq(echo ". \${VARDIR}/undo_main_routing" >> \${VARDIR}/undo_routing\n);
emit '';
emit $_ for @{$providers{main}{routes}};
emit '';
emit $_ for @{$providers{main}{rules}};
if ( @{$providers{default}{rules}} || @{$providers{default}{rules}} ) {
emit '';
emit qq(> \${VARDIR}/undo_default_routing);
emit qq(echo ". \${VARDIR}/undo_default_routing" >> \${VARDIR}/undo_routing\n);
emit '';
emit $_ for @{$providers{default}{routes}};
emit '';
emit $_ for @{$providers{default}{rules}};
}
} }
sub finish_providers() { sub finish_providers() {
@ -1080,6 +1101,8 @@ sub setup_providers() {
start_providers; start_providers;
emit '';
emit "start_provider_$_" for @providers; emit "start_provider_$_" for @providers;
emit ''; emit '';
@ -1088,9 +1111,7 @@ sub setup_providers() {
setup_null_routing if $config{NULL_ROUTE_RFC1918}; setup_null_routing if $config{NULL_ROUTE_RFC1918};
emit "\nrun_ip route flush cache"; emit "\nrun_ip route flush cache";
#
# This completes the if-block begun in the first_entry closure above
#
pop_indent; pop_indent;
emit "fi\n"; emit "fi\n";