Commit f0e5a61e authored by Kroese's avatar Kroese Committed by GitHub
Browse files

Delete network on shutdown

Delete network on shutdown
parents 64257d1a b07577b6
Loading
Loading
Loading
Loading
+33 −3
Original line number Diff line number Diff line
@@ -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
# ######################################
+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@ _graceful_shutdown() {
  echo && echo "❯ Quitting..."
  echo 'quit' | nc -q 1 -w 1 localhost "${QEMU_MONPORT}" >/dev/null 2>&1 || true

  closeNetwork

  return
}

+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ set -m
)
set +m

if (( KERNEL > 5 )) || ( (( KERNEL == 5 )) && (( MINOR > 2 )) ); then
if (( KERNEL > 5 )) || ( (( KERNEL == 5 )) && (( MINOR > 10 )) ); then
  pidwait -F "${_QEMU_PID}" & wait $!
else
  tail --pid "$(cat "${_QEMU_PID}")" --follow /dev/null & wait $!
+1 −1

File changed.

Contains only whitespace changes.