#!/usr/bin/perl
# 
# Script to unload DCCP modules (e.g. after compiling new ones)

@ARGV = qw#/proc/modules#;

# create a topological order among the modules
# the `dccp' module comes last, after dccp_ipv4, dccp_ipv6, ...
sub by_dependency {
	return ($a !~ m#(ccid|ipv6|ipv4|dccp)#);
}

while(<>) { push(@module_list, $1) if (m#^(dccp\S*)\s+#) }

for (sort by_dependency @module_list) {
	system "rmmod -v $_ " .  ((m#ipv#)? "-f" : "");
	$? == 0 || die "some problems unloading $_\n";
}
