summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorStephen Hemminger <stephen.hemminger@vyatta.com>2010-11-19 12:40:55 -0800
committerStephen Hemminger <stephen.hemminger@vyatta.com>2010-11-19 14:23:40 -0800
commitfb1bf8a2eefbdb467a948688ab388628455ef480 (patch)
tree92dfba3cde94ee954943244f7d7e7bd4f1054ac4 /scripts
parent6a9f575f6530e753baaa1dd66b9befd119695ed5 (diff)
downloadvyatta-cfg-quagga-fb1bf8a2eefbdb467a948688ab388628455ef480.tar.gz
vyatta-cfg-quagga-fb1bf8a2eefbdb467a948688ab388628455ef480.zip
Cleanup tunnel slave device on last delete
Need to leave gre0 around for case of multiple tunnels
Diffstat (limited to 'scripts')
-rw-r--r--scripts/vyatta-tunnel-cleanup29
1 files changed, 29 insertions, 0 deletions
diff --git a/scripts/vyatta-tunnel-cleanup b/scripts/vyatta-tunnel-cleanup
new file mode 100644
index 00000000..fdca80a3
--- /dev/null
+++ b/scripts/vyatta-tunnel-cleanup
@@ -0,0 +1,29 @@
+#! /usr/bin/perl
+
+# This script gets run after tunnels have been deleted, it removes
+# the underlying tunnel link, if all tunnels of that type are gone.
+
+# Create map of encapsulations still in use
+my $confg = new Vyatta::Config;
+$config->setLevel("interfaces tunnel");
+my %tunnel;
+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};
+
+ my $dev = $tunnels{$type};
+ next unless ( -d "/sys/class/net/$dev" );
+
+ system("ip link del $dev") == 0
+ or die "Can't delete $dev\n";
+}