#! /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. use strict; use warnings; use lib "/opt/vyatta/share/perl5"; use Vyatta::Config; # encapsulations and module names my %encapsulation = ( 'gre' => 'ip_gre', 'ipip' => 'ipip', 'sit' => 'sit', ); # 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 $type ( keys %encapsulation ) { # skip if tunnel is still in use next if $tunnel{$type}; my $module = $encapsulation{$type}; next unless ( -d "/sys/module/$module" ); system("sudo /sbin/rmmod $module") == 0 or warn "rmmod $module failed\n"; }