From 4791a8ca66f7ac7f5ac04ceb0bf0308788f92639 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Mon, 11 Jun 2012 16:57:49 -0700 Subject: [PATCH] Don't delete default routes when 'fallback' is specified. Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Providers.pm | 19 ++++++++++++------- Shorewall/Perl/lib.core | 10 ++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index 0ba97b8fa..fbb88fc3f 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -61,6 +61,7 @@ my @load_interfaces; my $balancing; my $fallback; +my $metrics; my $first_default_route; my $first_fallback_route; my $maxload; @@ -96,6 +97,7 @@ sub initialize( $ ) { @load_interfaces = (); $balancing = 0; $fallback = 0; + $metrics = 0; $first_default_route = 1; $first_fallback_route = 1; $maxload = 0; @@ -696,19 +698,20 @@ CEOF emit ''; if ( $gateway ) { if ( $family == F_IPV4 ) { - emit qq(run_ip route replace $gateway dev $physical table ) . DEFAULT_TABLE; + emit qq(run_ip route replace $gateway/32 dev $physical table ) . DEFAULT_TABLE; emit qq(run_ip route replace default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number); } else { emit qq(qt \$IP -6 route del default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number); emit qq(run_ip route add default via $gateway src $address dev $physical table ) . DEFAULT_TABLE . qq( metric $number); } emit qq(echo "qt \$IP -$family route del default via $gateway table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing); + emit qq(echo "qt \$IP -4 route del $gateway/32 dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing) if $family == F_IPV4; } else { emit qq(run_ip route add default table ) . DEFAULT_TABLE . qq( dev $physical metric $number); emit qq(echo "qt \$IP -$family route del default dev $physical table ) . DEFAULT_TABLE . qq(" >> \${VARDIR}/undo_${table}_routing); } - $fallback = 1; + $metrics = 1; } emit( qq(\n) , @@ -1154,14 +1157,16 @@ sub finish_providers() { emit( " progress_message \"Fallback route '\$(echo \$FALLBACK_ROUTE | sed 's/\$\\s*//')' Added\"", 'else', - '#', - '# We don\'t have any \'fallback\' providers so we delete any default routes in the default table', - '#', - " while qt \$IP -$family route del default table " . DEFAULT_TABLE . '; do true; done', + ' #', + ' # We don\'t have any \'fallback\' providers so we delete any default routes in the default table', + ' #', + ' delete_default_routes ' . DEFAULT_TABLE, 'fi', '' ); } elsif ( $config{USE_DEFAULT_RT} ) { - emit "while qt \$IP -$family route del default table " . DEFAULT_TABLE . '; do true; done'; + emit( 'delete_default_routes ' . DEFAULT_TABLE, + '' + ); } unless ( $config{KEEP_RT_TABLES} ) { diff --git a/Shorewall/Perl/lib.core b/Shorewall/Perl/lib.core index d953d87f8..3a3167db8 100644 --- a/Shorewall/Perl/lib.core +++ b/Shorewall/Perl/lib.core @@ -339,6 +339,16 @@ replace_default_route() # $1 = USE_DEFAULT_RT fi } +# +# Delete default routes with metric 0 from the passed routing table +# +delete_default_routes() # $1 = table number +{ + $IP -$g_family route ls table $1 | fgrep default | fgrep -v metric | while read route; do + qt $IP -$g_family route del $route + done +} + restore_default_route() # $1 = USE_DEFAULT_RT { local result