summaryrefslogtreecommitdiff
path: root/scripts/vyatta-tunnel-cleanup
blob: 41b349228383c4e1fb06fa8eb2e876319edd6aa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 $config = 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";
}