tapsetup: make deleting interfaces a function

This commit is contained in:
Martine Lenders 2020-09-25 12:29:01 +02:00
parent ff8b7a92d4
commit 73b8342528
No known key found for this signature in database
GPG Key ID: CCD317364F63286F

View File

@ -213,26 +213,36 @@ del_ipv6_routes() {
done done
} }
delete_bridge() { delete_iface() {
echo "deleting ${BRNAME}" IFACE="$1"
echo "deleting ${IFACE}"
case "${PLATFORM}" in
FreeBSD|OSX)
ifconfig "${IFACE}" destroy ;;
Linux)
ip link delete "${IFACE}" ;;
*) ;;
esac
}
delete_bridge() {
case "${PLATFORM}" in case "${PLATFORM}" in
FreeBSD) FreeBSD)
sysctl net.link.tap.user_open=0 sysctl net.link.tap.user_open=0
for IF in $(ifconfig ${BRIDGE} | grep -oiE "member: .+ " | cut -d' ' -f2); do for IF in $(ifconfig ${BRIDGE} | grep -oiE "member: .+ " | cut -d' ' -f2); do
ifconfig $IF destroy || exit 1 delete_iface ${IF}
done done
ifconfig ${BRNAME} destroy || exit 1 delete_iface ${BRNAME} || exit 1
kldunload if_tap # unloading might fail due to dependencies kldunload if_tap # unloading might fail due to dependencies
kldunload if_bridge ;; kldunload if_bridge ;;
Linux) Linux)
for IF in $(ls /sys/class/net/${BRNAME}/brif); do for IF in $(ls /sys/class/net/${BRNAME}/brif); do
if [ "${IF}" != "${UPLINK}" ]; then if [ "${IF}" != "${UPLINK}" ]; then
ip link delete "${IF}" delete_iface ${IF}
fi fi
done done
ip link delete ${BRNAME} || exit 1 delete_iface ${BRNAME} || exit 1
# restore the old uplink # restore the old uplink
if [ -n "${UPLINK}" ]; then if [ -n "${UPLINK}" ]; then
@ -240,7 +250,7 @@ delete_bridge() {
fi ;; fi ;;
OSX) OSX)
for IF in $(ifconfig ${BRIDGE} | grep -oiE "member: .+ " | cut -d' ' -f2); do for IF in $(ifconfig ${BRIDGE} | grep -oiE "member: .+ " | cut -d' ' -f2); do
ifconfig $IF destroy || exit 1 delete_iface ${IF}
done done
ifconfig ${BRNAME} destroy || exit 1 ;; ifconfig ${BRNAME} destroy || exit 1 ;;
*) *)