summaryrefslogtreecommitdiff
path: root/scripts/vyatta-vti-config.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/vyatta-vti-config.pl')
-rwxr-xr-xscripts/vyatta-vti-config.pl37
1 files changed, 36 insertions, 1 deletions
diff --git a/scripts/vyatta-vti-config.pl b/scripts/vyatta-vti-config.pl
index aa1efee..57fded4 100755
--- a/scripts/vyatta-vti-config.pl
+++ b/scripts/vyatta-vti-config.pl
@@ -43,11 +43,13 @@ my $result = 0;
my $updown="";
my $intfName="";
my $action="";
+my $checkref="";
GetOptions(
"updown" => \$updown,
"intf=s" => \$intfName,
"action=s" => \$action,
+ "checkref" => \$checkref,
);
@@ -68,6 +70,19 @@ if ($updown ne '') {
}
#
+# --checkref --intf=<intfName>
+# Return 1 if the interface reference exits.
+#
+if ($checkref ne '' ) {
+ if (!(defined $intfName) || $intfName eq '' ) {
+ # invalid
+ exit -1;
+ }
+ my $rval = vti_check_reference($intfName);
+ exit $rval;
+}
+
+#
# Prepare Vyatta::Config object
#
use Vyatta::Config;
@@ -174,8 +189,28 @@ sub vti_handle_updown {
use Vyatta::Config;
my $vcIntf = new Vyatta::Config();
$vcIntf->setLevel('interfaces');
- my $disabled = $vcIntf->exists("vti $intfName disabled");
+ my $disabled = $vcIntf->existsOrig("vti $intfName disabled");
if (!defined($disabled) || ! $disabled) {
system("sudo /sbin/ip link set $intfName $action\n");
}
}
+
+sub vti_check_reference {
+ my ($intfName) = @_;
+ use Vyatta::Config;
+ my $vcVPN = new Vyatta::Config();
+ $vcVPN->setLevel('vpn ipsec site-to-site');
+ my @peers = $vcVPN->listNodes('peer');
+ if (@peers == 0) {
+ return 0;
+ }
+ foreach my $peer (@peers) {
+ if (! $vcVPN->exists("peer $peer vti")) {
+ next;
+ }
+ if ( $vcVPN->exists("peer $peer vti bind $intfName")) {
+ return 1;
+ }
+ }
+ return 0;
+}