summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStig Thormodsrud <stig@uffda.(none)>2007-11-15 11:49:21 -0800
committerStig Thormodsrud <stig@uffda.(none)>2007-11-15 11:49:21 -0800
commit17a7c7d56e1ec21821a3527f1f14953bd3ed02a5 (patch)
treeb34085fd5062f705be3ca05622ceeac0f7d3b5ab /scripts
parent0529c54dd6ceef4ca301344407653c00883835ff (diff)
parentb9a25a8aec69e8f0cead72a7cff81dcbffebeb76 (diff)
downloadvyatta-cfg-quagga-17a7c7d56e1ec21821a3527f1f14953bd3ed02a5.tar.gz
vyatta-cfg-quagga-17a7c7d56e1ec21821a3527f1f14953bd3ed02a5.zip
Merge branch 'master' of http://phuket.vyatta.com/vyatta-cfg-quagga
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/bgp/vyatta-bgp.pl97
1 files changed, 95 insertions, 2 deletions
diff --git a/scripts/bgp/vyatta-bgp.pl b/scripts/bgp/vyatta-bgp.pl
index d20ad8fa..059ce1a5 100755
--- a/scripts/bgp/vyatta-bgp.pl
+++ b/scripts/bgp/vyatta-bgp.pl
@@ -1,15 +1,33 @@
#!/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;
+# Make sure the neighbor is a proper IP or name
sub check_peer_name() {
my $neighbor = shift;
@@ -18,5 +36,80 @@ 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 = $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();
+
+ foreach $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 $node (@peers) {
+ print "neighbor $node uses peer-group $pg\n";
+ }
+
+ print "please delete these peers before removing the peer-group\n";
+ exit 1;
+ }
+
+ 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;
+ my $as = shift;
+ 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; }
+
+ $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;
+ }
+ }
+
+ return;
}