From b9a25a8aec69e8f0cead72a7cff81dcbffebeb76 Mon Sep 17 00:00:00 2001 From: Robert Bays Date: Wed, 14 Nov 2007 22:25:39 -0800 Subject: optimize checks to speed up config load --- scripts/bgp/vyatta-bgp.pl | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'scripts/bgp/vyatta-bgp.pl') diff --git a/scripts/bgp/vyatta-bgp.pl b/scripts/bgp/vyatta-bgp.pl index ee4c9a49..059ce1a5 100755 --- a/scripts/bgp/vyatta-bgp.pl +++ b/scripts/bgp/vyatta-bgp.pl @@ -27,6 +27,7 @@ elsif (defined $neighbor && exit 0; +# Make sure the neighbor is a proper IP or name sub check_peer_name() { my $neighbor = shift; @@ -35,16 +36,22 @@ sub check_peer_name() { print "malformed neighbor address $neighbor\n"; exit 1; } - exit 0; } +# Make sure we aren't deleteing a peer-group that has +# neighbors configured to us it sub check_for_peer_groups() { my $config = new VyattaConfig; my $pg = shift; my $as = shift; - my $node; + my $node = $pg; my @peers, @neighbors; + # short circuit if the neighbor is an IP rather than name + $node =~ s/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}//; + if ($node eq "") { return; } + + # get the list of neighbors and see if they have a peer-group set $config->setLevel("protocols bgp $as neighbor"); my @neighbors = $config->listNodes(); @@ -53,6 +60,8 @@ sub check_for_peer_groups() { if ($peergroup eq $pg) { push @peers, $node; } } + # if we found peers in the previous statements + # notify an return errors if (@peers) { foreach $node (@peers) { print "neighbor $node uses peer-group $pg\n"; @@ -62,9 +71,11 @@ sub check_for_peer_groups() { exit 1; } - exit 0; + return; } +# make sure nodes are either in a peer group of have +# a remote AS assigned to them. sub check_as() { my $pg = shift; my $neighbor = shift; @@ -72,6 +83,7 @@ sub check_as() { my $config = new VyattaConfig; my $pgtest = $neighbor; + # if this is peer-group then short circuit this $pgtest =~ s/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}//; if ($pgtest ne "") { return; } @@ -99,5 +111,5 @@ sub check_as() { } } - exit 0; + return; } -- cgit v1.2.3