summaryrefslogtreecommitdiff
path: root/scripts/vyatta-tunnel-cleanup
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-11-24 12:08:34 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-11-24 12:12:17 -0800
commit2c3ddde8f8f6ca2eba49c35ee3729db85b02139f (patch)
tree5ecc4082a26fbd7072a8444044102ca6f2bd4fc5 /scripts/vyatta-tunnel-cleanup
parentc343feaf28007d9f0f34bc4fe854a200dae9bce2 (diff)
downloadvyatta-cfg-quagga-2c3ddde8f8f6ca2eba49c35ee3729db85b02139f.tar.gz
vyatta-cfg-quagga-2c3ddde8f8f6ca2eba49c35ee3729db85b02139f.zip
Fix tunnel cleanup script
Lots of errors in original version.
Diffstat (limited to 'scripts/vyatta-tunnel-cleanup')
-rwxr-xr-xscripts/vyatta-tunnel-cleanup39
1 files changed, 24 insertions, 15 deletions
diff --git a/scripts/vyatta-tunnel-cleanup b/scripts/vyatta-tunnel-cleanup
index 41b34922..2113d3ba 100755
--- a/scripts/vyatta-tunnel-cleanup
+++ b/scripts/vyatta-tunnel-cleanup
@@ -3,27 +3,36 @@
# This script gets run after tunnels have been deleted, it removes
# the underlying tunnel link, if all tunnels of that type are gone.
+use strict;
+use warnings;
+use lib "/opt/vyatta/share/perl5";
+use Vyatta::Config;
+
+# encapsulations and special network device
+my %encapsulation = (
+ 'gre' => 'gre0',
+ 'ipip' => 'tunl0',
+ 'sit' => 'sit0',
+);
+
# Create map of encapsulations still in use
my $config = new Vyatta::Config;
$config->setLevel("interfaces tunnel");
+
my %tunnel;
-foreach my $tun ($config->listNodes()) {
- my $mode = $config->returnValue("$tun encapsulation");
- $tunnel{$mode} = 1;
+foreach my $tun ( $config->listNodes() ) {
+ my $mode = $config->returnValue("$tun encapsulation");
+ $tunnel{$mode} = 1;
}
-my %encapsulation = (
- 'gre' => 'gre0',
- 'ipip' => 'tunl0',
- 'sit' => 'sit0',
-);
-
-foreach my $type (keys %encapsulation) {
- next if $tunnel{$type};
+foreach my $type ( keys %encapsulation ) {
+ # skip if tunnel is still in use
+ next if $tunnel{$type};
- my $dev = $tunnels{$type};
- next unless ( -d "/sys/class/net/$dev" );
+ # skip if pseudo device is already gone
+ my $dev = $encapsulation{$type};
+ next unless ( -d "/sys/class/net/$dev" );
- system("ip link del $dev") == 0
- or die "Can't delete $dev\n";
+ system("ip link del $dev") == 0
+ or warn "Can't delete $dev\n";
}