diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | scripts/vyatta-tunnel-cleanup | 29 | ||||
-rw-r--r-- | templates/interfaces/tunnel/node.def | 8 |
3 files changed, 33 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am index 20312755..3d4175c6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,7 @@ sbin_SCRIPTS += scripts/dns-forwarding/vyatta-dns-forwarding.pl sbin_SCRIPTS += scripts/dynamic-dns/vyatta-dynamic-dns.pl sbin_SCRIPTS += scripts/vyatta-system-nameservers sbin_SCRIPTS += scripts/vyatta-interfaces.pl +sbin_SCRIPTS += scripts/vyatta-tunnel-cleanup sbin_SCRIPTS += scripts/check-ipv4-ipv6.pl sbin_SCRIPTS += scripts/vyatta-bonding.pl sbin_SCRIPTS += scripts/vyatta-raid-event 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"; +} diff --git a/templates/interfaces/tunnel/node.def b/templates/interfaces/tunnel/node.def index 912e4c13..f4d53c1a 100644 --- a/templates/interfaces/tunnel/node.def +++ b/templates/interfaces/tunnel/node.def @@ -38,11 +38,9 @@ delete: ip link set $VAR(@) down ip link delete $VAR(@) else ip tunnel del $VAR(@) mode $VAR(./encapsulation/@) - case "$VAR(./encapsulation/@)" in - ipip) ip link del tunl0 ;; - gre) ip link del gre0 ;; - sit) ip link del sit0 ;; - esac fi +end: if [ ${COMMIT_ACTION} = "DELETE" ]; then + /opt/vyatta/sbin/vyatta-tunnel-cleanup + fi |