diff options
author | Robert Bays <rbays@moresby.(none)> | 2007-11-14 21:58:13 -0800 |
---|---|---|
committer | Robert Bays <rbays@moresby.(none)> | 2007-11-14 21:58:13 -0800 |
commit | 04a2f81e5559f7a0d2f1cb22e1b72196e19b3d0b (patch) | |
tree | 934243a72b5c01a6c787f46d1b16e1b7617d4fd3 /scripts/bgp/vyatta-bgp.pl | |
parent | 1a9535e68042f67087cd400523dc42103292c2fe (diff) | |
download | vyatta-cfg-quagga-04a2f81e5559f7a0d2f1cb22e1b72196e19b3d0b.tar.gz vyatta-cfg-quagga-04a2f81e5559f7a0d2f1cb22e1b72196e19b3d0b.zip |
enable peer-groups
Diffstat (limited to 'scripts/bgp/vyatta-bgp.pl')
-rwxr-xr-x | scripts/bgp/vyatta-bgp.pl | 83 |
1 files changed, 82 insertions, 1 deletions
diff --git a/scripts/bgp/vyatta-bgp.pl b/scripts/bgp/vyatta-bgp.pl index d20ad8fa..ee4c9a49 100755 --- a/scripts/bgp/vyatta-bgp.pl +++ b/scripts/bgp/vyatta-bgp.pl @@ -1,12 +1,29 @@ #!/usr/bin/perl use lib "/opt/vyatta/share/perl5/"; +use VyattaConfig; use VyattaMisc; use Getopt::Long; GetOptions("check-peer-name=s" => \$peername, + "check-as" => \$checkas, + "check-peer-groups" => \$checkpeergroups, + "peergroup=s" => \$pg, + "as=s" => \$as, + "neighbor=s" => \$neighbor, ); -if (defined $peername) { check_peer_name($peername); } +if (defined $peername) { check_peer_name($peername); } +elsif (defined $checkpeergroups && + defined $pg && + defined $as) { check_for_peer_groups($pg, $as); } +elsif (defined $neighbor && + defined $as && + defined $checkas && + defined $pg) { check_as($pg, $neighbor, $as); } +elsif (defined $neighbor && + defined $as && + defined $checkas) { check_as(-1, $neighbor, $as); } + exit 0; @@ -20,3 +37,67 @@ sub check_peer_name() { } exit 0; } + +sub check_for_peer_groups() { + my $config = new VyattaConfig; + my $pg = shift; + my $as = shift; + my $node; + my @peers, @neighbors; + + $config->setLevel("protocols bgp $as neighbor"); + my @neighbors = $config->listNodes(); + + foreach $node (@neighbors) { + my $peergroup = $config->returnValue("$node peer-group"); + if ($peergroup eq $pg) { push @peers, $node; } + } + + if (@peers) { + foreach $node (@peers) { + print "neighbor $node uses peer-group $pg\n"; + } + + print "please delete these peers before removing the peer-group\n"; + exit 1; + } + + exit 0; +} + +sub check_as() { + my $pg = shift; + my $neighbor = shift; + my $as = shift; + my $config = new VyattaConfig; + my $pgtest = $neighbor; + + $pgtest =~ s/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}//; + if ($pgtest ne "") { return; } + + $config->setLevel("protocols bgp $as neighbor $neighbor"); + $remoteas = $config->returnValue("remote-as"); + + if (! defined $remoteas) { + if ($pg > 0) { + $peergroup = 1; + $peergroupas = 1; + } + else { + $peergroup = $config->returnValue("peer-group"); + $peergroupas = $config->returnValue(" .. $peergroup remote-as"); + } + + if (! defined $peergroup) { + print "You must define a remote-as or peer-group for neighbor $neighbor before commiting\n"; + exit 1; + } + + if (! defined $peergroupas) { + print "You must define a remote-as in neighbor $neighbor or peer-group $peergroup before commiting\n"; + exit 1; + } + } + + exit 0; +} |