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 | |
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.
-rwxr-xr-x | scripts/vyatta-gateway-static_route-check.pl | 66 | ||||
-rw-r--r-- | templates/protocols/static/route/node.tag/next-hop/node.def | 4 | ||||
-rw-r--r-- | templates/system/gateway-address/node.def | 1 |
3 files changed, 49 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; diff --git a/templates/protocols/static/route/node.tag/next-hop/node.def b/templates/protocols/static/route/node.tag/next-hop/node.def index eb41b4e4..f5d5d417 100644 --- a/templates/protocols/static/route/node.tag/next-hop/node.def +++ b/templates/protocols/static/route/node.tag/next-hop/node.def @@ -31,3 +31,7 @@ end: -c "no ip route $VAR(../@) $VAR(@)" fi fi + if [[ "$VAR(../@)" = "0.0.0.0/0" ]] + then + ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl warn + fi diff --git a/templates/system/gateway-address/node.def b/templates/system/gateway-address/node.def index 11f8e0f0..70419e26 100644 --- a/templates/system/gateway-address/node.def +++ b/templates/system/gateway-address/node.def @@ -11,3 +11,4 @@ update: oldgw=`/opt/vyatta/sbin/vyatta-cli-expand-var.pl \\$VAR\(/system/gateway delete: if ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl "$VAR(@)" then vtysh -c "configure terminal" -c "no ip route 0.0.0.0/0 $VAR(@)" fi +end: ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl warn |