summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2009-03-30 11:51:52 -0700
committerStephen Hemminger <stephen.hemminger@vyatta.com>2009-03-30 11:51:52 -0700
commit14d2f5e78951a8f956c547b74cf99620df3d17be (patch)
tree9a6aeb269b7671d16ed9118f230e7374c5417a84
parenta46201e88236b92229ae14883ce5c18a4ebdf14e (diff)
downloadvyatta-cfg-quagga-14d2f5e78951a8f956c547b74cf99620df3d17be.tar.gz
vyatta-cfg-quagga-14d2f5e78951a8f956c547b74cf99620df3d17be.zip
Fix bgp check script
Problem introduced when converted to use closures (by me). Closures don't work if arg check attempts to exit because of how the exception model works in GetOptions. Bug 4258
-rwxr-xr-xscripts/bgp/vyatta-bgp.pl143
1 files changed, 73 insertions, 70 deletions
diff --git a/scripts/bgp/vyatta-bgp.pl b/scripts/bgp/vyatta-bgp.pl
index 931069c2..3306654c 100755
--- a/scripts/bgp/vyatta-bgp.pl
+++ b/scripts/bgp/vyatta-bgp.pl
@@ -5,107 +5,110 @@ use Vyatta::Config;
use Vyatta::Misc;
use Getopt::Long;
-my $pg = -1;
-my ($as, $neighbor);
+my ( $pg, $as, $neighbor );
+my ( $checkas, $peername, $checkifpeergroup, $checkpeergroups );
GetOptions(
- "peergroup=s" => \$pg,
- "as=s" => \$as,
- "neighbor=s" => \$neighbor,
- "check-peer-name=s" => sub { check_peer_name( $_[1] ) },
- "check-as" => sub { check_as($pg, $neighbor, $as); },
- "check-peer-groups" => sub { check_for_peer_groups($pg, $as); },
- "check-if-peer-group" => sub { check_if_peer_group($pg); },
+ "peergroup=s" => \$pg,
+ "as=s" => \$as,
+ "neighbor=s" => \$neighbor,
+ "check-peer-name=s" => \$peername,
+ "check-as" => \$checkas,
+ "check-peer-groups" => \$checkpeergroups,
+ "check-if-peer-group" => \$checkifpeergroup,
);
+check_peer_name($peername) if ($peername);
+check_for_peer_groups( $pg, $as ) if ($checkpeergroups);
+check_as( ( $pg ? $pg : -1 ), $neighbor, $as ) if ($checkas);
+check_if_peer_group($pg) if ($checkifpeergroup);
+
exit 0;
sub check_if_peer_group {
my $neighbor = shift;
-
+
exit 1 if is_ip_v4_or_v6($neighbor);
exit 0;
}
-
# Make sure the neighbor is a proper IP or name
sub check_peer_name {
- my $neighbor = shift;
-
- $_ = $neighbor;
- my $version = is_ip_v4_or_v6($neighbor);
- if ((!defined($version)) && (/[\s\W]/g)) {
- print "malformed neighbor address $neighbor\n";
- exit 1;
- }
-
- # Quagga treats the first byte as a potential IPv6 address
- # so we can't use it as a peer group name. So let's check for it.
- if ($version == 6 && /^[A-Fa-f]{1,4}$/) {
- print "malformed neighbor address $neighbor\n";
- exit 1;
- }
+ my $neighbor = shift;
+
+ $_ = $neighbor;
+ my $version = is_ip_v4_or_v6($neighbor);
+ if ( ( !defined($version) ) && (/[\s\W]/g) ) {
+ die "malformed neighbor address $neighbor\n";
+ }
+
+ # Quagga treats the first byte as a potential IPv6 address
+ # so we can't use it as a peer group name. So let's check for it.
+ if ( $version == 6 && /^[A-Fa-f]{1,4}$/ ) {
+ die "malformed neighbor address $neighbor\n";
+ }
}
-# Make sure we aren't deleteing a peer-group that has
+# Make sure we aren't deleteing a peer-group that has
# neighbors configured to us it
sub check_for_peer_groups {
- my $config = new Vyatta::Config;
- my $pg = shift;
- my $as = shift;
- my @peers;
-
- # short circuit if the neighbor is an IP rather than name
- return if is_ip_v4_or_v6($pg);
-
- # get the list of neighbors and see if they have a peer-group set
- $config->setLevel("protocols bgp $as neighbor");
- my @neighbors = $config->listNodes();
-
- foreach my $node (@neighbors) {
- my $peergroup = $config->returnValue("$node peer-group");
- if ($peergroup eq $pg) { push @peers, $node; }
- }
-
- # if we found peers in the previous statements
- # notify an return errors
- if (@peers) {
- foreach my $node (@peers) {
- print "neighbor $node uses peer-group $pg\n";
+ my $config = new Vyatta::Config;
+ my $pg = shift;
+ die "Peer group not defined\n" unless $pg;
+ my $as = shift;
+ die "AS not defined\n" unless $as;
+ my @peers;
+
+ # short circuit if the neighbor is an IP rather than name
+ return if is_ip_v4_or_v6($pg);
+
+ # get the list of neighbors and see if they have a peer-group set
+ $config->setLevel("protocols bgp $as neighbor");
+ my @neighbors = $config->listNodes();
+
+ foreach my $node (@neighbors) {
+ my $peergroup = $config->returnValue("$node peer-group");
+ if ( $peergroup eq $pg ) { push @peers, $node; }
}
-
- print "please delete these peers before removing the peer-group\n";
- exit 1;
- }
- return;
+ # if we found peers in the previous statements
+ # notify an return errors
+ if (@peers) {
+ foreach my $node (@peers) {
+ print "neighbor $node uses peer-group $pg\n";
+ }
+
+ die "please delete these peers before removing the peer-group\n";
+ }
}
# make sure nodes are either in a peer group of have
-# a remote AS assigned to them.
+# a remote AS assigned to them.
sub check_as {
- my $pg = shift;
- my $neighbor = shift;
- my $as = shift;
- my $config = new Vyatta::Config;
- my $pgtest = $neighbor;
+ my $pg = shift;
+ my $neighbor = shift;
+ die "Neighbor not defined" unless $neighbor;
+ my $as = shift;
+ die "AS not defined\n" unless $as;
+ my $config = new Vyatta::Config;
+ my $pgtest = $neighbor;
- # if this is peer-group then short circuit this
- return unless is_ip_v4_or_v6($pg);
+ # if this is peer-group then short circuit this
+ return unless is_ip_v4_or_v6($pg);
- $config->setLevel("protocols bgp $as neighbor $neighbor");
- my $remoteas = $config->returnValue("remote-as");
+ $config->setLevel("protocols bgp $as neighbor $neighbor");
+ my $remoteas = $config->returnValue("remote-as");
- return unless $remoteas;
+ return unless $remoteas;
- return if ($pg > 0);
+ return if ( $pg > 0 );
- my $peergroup = $config->returnValue("peer-group");
- my $peergroupas = $config->returnValue(" .. $peergroup remote-as");
+ my $peergroup = $config->returnValue("peer-group");
+ my $peergroupas = $config->returnValue(" .. $peergroup remote-as");
- die "protocols bgp $as neighbor $neighbor: must define a remote-as or peer-group\n"
+ die "protocols bgp $as neighbor $neighbor: must define a remote-as or peer-group\n"
unless $peergroup;
- die "protocols bgp $as neighbor $neighbor: must define a remote-as in neighbor or peer-group $peergroup\n"
+ die "protocols bgp $as neighbor $neighbor: must define a remote-as in neighbor or peer-group $peergroup\n"
unless $peergroupas;
}