From 71882f2f2c47a9df17ffdec69c6b9e8be3e4a237 Mon Sep 17 00:00:00 2001 From: Mohit Mehta Date: Thu, 5 Jun 2008 14:46:06 +0000 Subject: Fix Bug 3269 system gateway-address conflicts with static default - route is only deleted from route table if both gateway-address and the static route equivalent to setting a gateway-address are not set --- Makefile.am | 1 + scripts/vyatta-gateway-static_route-check.pl | 71 ++++++++++++++++++++++ .../static/route/node.tag/next-hop/node.def | 4 +- templates/system/gateway-address/node.def | 3 +- 4 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 scripts/vyatta-gateway-static_route-check.pl diff --git a/Makefile.am b/Makefile.am index 82880874..d7bc399c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -6,6 +6,7 @@ sbin_SCRIPTS += scripts/vyatta_quagga_utils.pl sbin_SCRIPTS += scripts/policy/vyatta-check-as-prepend.pl sbin_SCRIPTS += scripts/vyatta-vtysh.pl sbin_SCRIPTS += scripts/vyatta-policy-action-verify.pl +sbin_SCRIPTS += scripts/vyatta-gateway-static_route-check.pl cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ cpio -0pd diff --git a/scripts/vyatta-gateway-static_route-check.pl b/scripts/vyatta-gateway-static_route-check.pl new file mode 100644 index 00000000..b90fca92 --- /dev/null +++ b/scripts/vyatta-gateway-static_route-check.pl @@ -0,0 +1,71 @@ +#!/usr/bin/perl +# Module: vyatta-gateway-static_route-check.pl +# +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# A copy of the GNU General Public License is available as +# `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution +# or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. +# You can also obtain it by writing to the Free Software Foundation, +# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, +# MA 02110-1301, USA. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2008 Vyatta, Inc. +# All Rights Reserved. +# +# 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 +# **** End License **** + +use strict; +use warnings; +use lib "/opt/vyatta/share/perl5/"; + +use NetAddr::IP; +use VyattaConfig; + + +if (($#ARGV == 1) && ($ARGV[0] eq '0.0.0.0/0')) { + # check when deleting static-route + my $vcCHECK_GATEWAY = new VyattaConfig(); + $vcCHECK_GATEWAY->setLevel('system'); + if ( $vcCHECK_GATEWAY->exists('.') ) { + my $gateway_ip = $vcCHECK_GATEWAY->returnValue('gateway-address'); + if ( defined($gateway_ip) && $gateway_ip eq $ARGV[1] ) { + exit 1; + } + } + +} elsif ($#ARGV == 0) { + # check when deleting gateway-address + my $vcCHECK_STATIC_ROUTE = new VyattaConfig(); + $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; + } + } + } + } + } + } +} + +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 cfd4b923..1bb4b579 100644 --- a/templates/protocols/static/route/node.tag/next-hop/node.def +++ b/templates/protocols/static/route/node.tag/next-hop/node.def @@ -3,7 +3,9 @@ type: ipv4 help: Set the next-hop router delete:expression: "touch /tmp/static.$PPID" end:expression: "if [ -f \"/tmp/static.$PPID\" ]; then \ - ${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" -c \"no ip route $VAR(../@) $VAR(@)\" ; \ + if ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl \"$VAR(../@)\" \"$VAR(@)\"; then \ + ${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" -c \"no ip route $VAR(../@) $VAR(@)\" ; \ + fi; rm /tmp/static.$PPID; \ else \ if [ -n \"$VAR(./distance/@)\" ]; then \ diff --git a/templates/system/gateway-address/node.def b/templates/system/gateway-address/node.def index 6a77c0a5..87416e8c 100644 --- a/templates/system/gateway-address/node.def +++ b/templates/system/gateway-address/node.def @@ -4,5 +4,6 @@ create:expression: "${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" update:expression: "oldgw=`/opt/vyatta/sbin/vyatta-cli-expand-var.pl '$(/system/gateway-address/@)' ` && \ ${vyatta_sbindir}/vyatta-vtysh.pl -noerr -c \"configure terminal\" -c \"no ip route 0.0.0.0/0 $oldgw \" && \ ${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" -c \"ip route 0.0.0.0/0 $VAR(@)\" " -delete:expression: "${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" -c \"no ip route 0.0.0.0/0 $VAR(@)\" " +delete:expression: "if ${vyatta_sbindir}/vyatta-gateway-static_route-check.pl \"$VAR(@)\"; then \ + ${vyatta_sbindir}/vyatta-vtysh.pl -c \"configure terminal\" -c \"no ip route 0.0.0.0/0 $VAR(@)\"; fi" -- cgit v1.2.3