summaryrefslogtreecommitdiff
path: root/scripts/vyatta_quagga_utils.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/vyatta_quagga_utils.pl')
-rw-r--r--scripts/vyatta_quagga_utils.pl45
1 files changed, 16 insertions, 29 deletions
diff --git a/scripts/vyatta_quagga_utils.pl b/scripts/vyatta_quagga_utils.pl
index eaf83649..c0087ea6 100644
--- a/scripts/vyatta_quagga_utils.pl
+++ b/scripts/vyatta_quagga_utils.pl
@@ -1,62 +1,49 @@
#!/usr/bin/perl
+use strict;
use lib "/opt/vyatta/share/perl5/";
use Vyatta::Config;
use Vyatta::Misc;
use NetAddr::IP;
use Getopt::Long;
-GetOptions("check-prefix-boundry=s" => \$prefix,
- "not-exists=s" => \$notexists,
- "exists=s" => \$exists,
- "check-ospf-area=s" => \$area,
+GetOptions("check-prefix-boundry=s" => sub { check_prefix_boundry( $_[1] ); },
+ "not-exists=s" => sub { check_not_exists($_[1]); },
+ "exists=s" => sub { check_exists($_[1]); },
+ "check-ospf-area=s" => sub { check_ospf_area($_[1]); },
);
-if (defined $prefix) { check_prefix_boundry($prefix); }
-if (defined $notexists) { check_not_exists($notexists); }
-if (defined $exists) { check_exists($exists); }
-if (defined $area) { check_ospf_area($area); }
-
exit 0;
-sub check_prefix_boundry() {
+sub check_prefix_boundry {
my $prefix = shift;
my ($net, $network, $cidr);
$net = new NetAddr::IP $prefix;
$network = $net->network();
$cidr = $net->cidr();
- if ("$cidr" ne "$network") {
- print "Your prefix must fall on a natural network boundry. ",
- "Did you mean $network?\n";
- exit 1;
- }
+
+ die "Your prefix must fall on a natural network boundry. ",
+ "Did you mean $network?\n"
+ if ($cidr ne $network);
exit 0;
}
-sub check_exists() {
+sub check_exists {
my $node = shift;
my $config = new Vyatta::Config;
- if ( $config->exists("$node") ) {
- exit 0;
- }
-
- exit 1;
+ exit $config->exists($node) ? 0 : 1;
}
-sub check_not_exists() {
+sub check_not_exists {
my $node = shift;
my $config = new Vyatta::Config;
- if (! $config->exists("$node") ) {
- exit 0;
- }
-
- exit 1;
+ exit $config->exists($node) ? 1 : 0;
}
-sub check_ospf_area() {
+sub check_ospf_area {
my $area = shift;
#
@@ -68,7 +55,7 @@ sub check_ospf_area() {
}
}
if ($area =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
- foreach $octet ($1, $2, $3, $4) {
+ foreach my $octet ($1, $2, $3, $4) {
if (($octet < 0) || ($octet > 255)) { exit 1; }
}
exit 0