diff options
author | James Davidson <james@greycastle.net> | 2012-05-09 15:03:43 -0700 |
---|---|---|
committer | James Davidson <james.davidson@vyatta.com> | 2012-05-16 10:05:11 -0700 |
commit | 94138d5b3c7bc6761ab30ddd6fe24a622d1f986b (patch) | |
tree | bea0635eb1ccf379ddb15d48b0ff7bef920bfe83 /scripts | |
parent | 4ad53d24877117793962766c96d059ef4300151b (diff) | |
download | vyatta-cfg-quagga-94138d5b3c7bc6761ab30ddd6fe24a622d1f986b.tar.gz vyatta-cfg-quagga-94138d5b3c7bc6761ab30ddd6fe24a622d1f986b.zip |
Warn user if both gateway-address and static default route are set
Fixes bug 7428.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-gateway-static_route-check.pl | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/scripts/vyatta-gateway-static_route-check.pl b/scripts/vyatta-gateway-static_route-check.pl index f550180d..ae64e8f7 100755 --- a/scripts/vyatta-gateway-static_route-check.pl +++ b/scripts/vyatta-gateway-static_route-check.pl @@ -24,19 +24,34 @@ # # Author: Mohit Mehta # Date: June 2008 -# Description: Script to check if any one of the 'static route' is equivalent to the 'system gateway-address' -# if yes, then don't remove route from routing table unless both are unset +# Description: Script to check if any one of the 'static route' is +# equivalent to the 'system gateway-address' if yes, then +# don't remove route from routing table unless both are +# unset # **** End License **** use strict; use warnings; use lib "/opt/vyatta/share/perl5/"; -use NetAddr::IP; use Vyatta::Config; -if ( ( $#ARGV == 1 ) && ( $ARGV[0] eq '0.0.0.0/0' ) ) { +sub findStaticDefaultRoute { + my ( $cfg ) = @_; + if ($cfg->exists('protocols static')) { + my @routes = $cfg->listNodes("protocols static route"); + if (@routes > 0) { + foreach my $route (@routes) { + if ($route eq '0.0.0.0/0') { + return 1; + } + } + } + } + return 0; +} +if ( ( $#ARGV == 1 ) && ( $ARGV[0] eq '0.0.0.0/0' ) ) { # check when deleting static-route my $vcCHECK_GATEWAY = new Vyatta::Config(); $vcCHECK_GATEWAY->setLevel('system'); @@ -46,23 +61,31 @@ if ( ( $#ARGV == 1 ) && ( $ARGV[0] eq '0.0.0.0/0' ) ) { exit 1; } } - -} -elsif ( $#ARGV == 0 ) { - - # check when deleting gateway-address - my $vcCHECK_STATIC_ROUTE = new Vyatta::Config(); - $vcCHECK_STATIC_ROUTE->setLevel('protocols static'); - if ( $vcCHECK_STATIC_ROUTE->exists('.') ) { - my @routes = $vcCHECK_STATIC_ROUTE->listNodes("route"); - if ( @routes > 0 ) { - foreach my $route (@routes) { - if ( $route eq '0.0.0.0/0' ) { - my @next_hops = - $vcCHECK_STATIC_ROUTE->listNodes("route $route next-hop"); - foreach my $next_hop (@next_hops) { - if ( $next_hop eq $ARGV[0] ) { - exit 1; +} elsif ( $#ARGV == 0 ) { + if ($ARGV[0] eq 'warn') { + my $config = new Vyatta::Config(); + my $haveGatewayAddress = $config->exists("system gateway-address"); + my $haveStaticDefaultRoute = findStaticDefaultRoute($config); + if ($haveGatewayAddress && $haveStaticDefaultRoute) { + print "Warning:\n"; + print "Both a 'system gateway-address' and a protocols static default route\n"; + print "(0.0.0.0/0) are configured. This configuration is not recommended.\n"; + } + } else { + # check when deleting gateway-address + my $vcCHECK_STATIC_ROUTE = new Vyatta::Config(); + $vcCHECK_STATIC_ROUTE->setLevel('protocols static'); + if ( $vcCHECK_STATIC_ROUTE->exists('.') ) { + my @routes = $vcCHECK_STATIC_ROUTE->listNodes("route"); + if ( @routes > 0 ) { + foreach my $route (@routes) { + if ( $route eq '0.0.0.0/0' ) { + my @next_hops = + $vcCHECK_STATIC_ROUTE->listNodes("route $route next-hop"); + foreach my $next_hop (@next_hops) { + if ( $next_hop eq $ARGV[0] ) { + exit 1; + } } } } @@ -70,5 +93,4 @@ elsif ( $#ARGV == 0 ) { } } } - exit 0; |