fix: Delete network on shutdown

This commit is contained in:
Kroese 2023-07-05 13:04:17 +02:00 committed by GitHub
parent 9b696e38ce
commit 03d333e299

View file

@ -31,7 +31,10 @@ configureDHCP() {
error "and that the NET_ADMIN capability has been added to the container config: --cap-add NET_ADMIN" && exit 16
fi
ip link set "${VM_NET_TAP}" up
while ! ip link set "${VM_NET_TAP}" up; do
info "Waiting for address to become available..."
sleep 2
done
TAP_NR=$(</sys/class/net/"${VM_NET_TAP}"/ifindex)
TAP_PATH="/dev/tap${TAP_NR}"
@ -127,11 +130,20 @@ configureNAT () {
fi
ip address add ${VM_NET_IP%.*}.1/24 broadcast ${VM_NET_IP%.*}.255 dev dockerbridge
ip link set dockerbridge up
while ! ip link set dockerbridge up; do
info "Waiting for address to become available..."
sleep 2
done
# QEMU Works with taps, set tap to the bridge created
ip tuntap add dev "${VM_NET_TAP}" mode tap
ip link set "${VM_NET_TAP}" up promisc on
while ! ip link set "${VM_NET_TAP}" up promisc on; do
info "Waiting for tap to become available..."
sleep 2
done
ip link set dev "${VM_NET_TAP}" master dockerbridge
# Add internet connection to the VM
@ -165,6 +177,24 @@ configureNAT () {
return 0
}
closeNetwork () {
if [[ "${DHCP}" == [Yy1]* ]]; then
ip link set "${VM_NET_TAP}" down || true
ip link delete "${VM_NET_TAP}" || true
else
ip link set "${VM_NET_TAP}" down promisc off || true
ip link delete "${VM_NET_TAP}" || true
ip link set dockerbridge down || true
ip link delete dockerbridge || true
fi
}
# ######################################
# Configure Network
# ######################################