diff --git a/Shorewall/Perl/Shorewall/Providers.pm b/Shorewall/Perl/Shorewall/Providers.pm index 34b948e25..9b16ab0b9 100644 --- a/Shorewall/Perl/Shorewall/Providers.pm +++ b/Shorewall/Perl/Shorewall/Providers.pm @@ -698,13 +698,14 @@ 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); @@ -1156,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' unless $metrics; + 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