-
Notifications
You must be signed in to change notification settings - Fork 1
/
rmmod-recursive
executable file
·47 lines (43 loc) · 978 Bytes
/
rmmod-recursive
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
set -euo pipefail
unloadRecursive() {
# Unload dependants
deptext="$(lsmod | grep "^${1}" | awk '{print $4}' || :)"
IFS=, read -r -a deps <<< "${deptext}"
for dep in "${deps[@]}"; do
unloadRecursive "${dep}"
done
# Special handling for iptables garbage
if [ "${1}" = iptable_filter ]; then
"${ipt}" -F
"${ipt}" -X
fi
if [ "${1}" = ip6table_filter ]; then
"${ip6t}" -F
"${ip6t}" -X
fi
if [ "${1}" = iptable_nat ]; then
"${ipt}" -t nat -F
"${ipt}" -t nat -X
fi
if [ "${1}" = ip6table_nat ]; then
"${ip6t}" -t nat -F
"${ip6t}" -t nat -X
fi
if [ "${1}" = iptable_mangle ]; then
"${ipt}" -t mangle -F
"${ipt}" -t mangle -X
fi
if [ "${1}" = ip6table_mangle ]; then
"${ip6t}" -t mangle -F
"${ip6t}" -t mangle -X
fi
# Unload the module
rmmod "${1}" || :
}
ipt="${IPTABLES:-iptables-legacy}"
ip6t="${IP6TABLES:-ip6tables-legacy}"
for module in "${@}"; do
echo "Unloading ${module}"
unloadRecursive "${module}"
done