wg-installer: add cleanup script
Add script to cleanup unused wireguard interfaces. Signed-off-by: Nick Hainke <vincent@systemli.org>
This commit is contained in:
parent
7f5484fc9d
commit
714b51c630
1 changed files with 37 additions and 0 deletions
|
@ -1,3 +1,5 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
next_port () {
|
next_port () {
|
||||||
local port_start=$1
|
local port_start=$1
|
||||||
local port_end=$2
|
local port_end=$2
|
||||||
|
@ -11,3 +13,38 @@ next_port () {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cleanup_wginterfaces() {
|
||||||
|
neighbors_available
|
||||||
|
}
|
||||||
|
|
||||||
|
delete_wg_interface() {
|
||||||
|
ip link del dev "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
check_wg_neighbors() {
|
||||||
|
local phy
|
||||||
|
|
||||||
|
wg_interfaces=$(ip link | grep wg | awk '{print $2}' | sed 's/://')
|
||||||
|
for phy in $wg_interfaces; do
|
||||||
|
linklocal=$(ip -6 a list dev $phy | grep "scope link" | awk '{print $2}' | sed 's/\/64//') 2>/dev/null
|
||||||
|
ips=$(ping ff02::1%$phy -w5 -W5 -c10 | awk '/from/{print($4)}' | sed 's/.$//') 2>/dev/null
|
||||||
|
delete=1
|
||||||
|
for ip in $ips; do
|
||||||
|
if [ $ip != $linklocal ] && [ $(owipcalc $ip linklocal) -eq 1 ]; then
|
||||||
|
delte=0
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ $delete -eq 1 ]; then
|
||||||
|
delete_wg_interface "$phy"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
case $1 in
|
||||||
|
cleanup_wginterfaces)
|
||||||
|
"$@"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
Loading…
Reference in a new issue