Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Network shutdown #191

Merged
merged 1 commit into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ configureNAT() {
fi

# Create a bridge with a static IP for the VM guest

{ ip link add dev dockerbridge type bridge ; rc=$?; } || :

if (( rc != 0 )); then
Expand Down Expand Up @@ -287,6 +286,22 @@ configureNAT() {
return 0
}

closeBridge() {

local pid="/var/run/dnsmasq.pid"
[ -s "$pid" ] && pKill "$(<"$pid")"

[[ "${NETWORK,,}" == "user"* ]] && return 0

ip link set "$VM_NET_TAP" down promisc off &> null || true
ip link delete "$VM_NET_TAP" &> null || true

ip link set dockerbridge down &> null || true
ip link delete dockerbridge &> null || true

return 0
}

closeNetwork() {

# Shutdown nginx
Expand All @@ -298,26 +313,16 @@ closeNetwork() {
exec 30<&- || true
exec 40<&- || true

if [[ "$DHCP" == [Yy1]* ]]; then
if [[ "$DHCP" != [Yy1]* ]]; then

ip link set "$VM_NET_TAP" down || true
ip link delete "$VM_NET_TAP" || true

else

local pid="/var/run/dnsmasq.pid"
[ -s "$pid" ] && pKill "$(<"$pid")"

[[ "${NETWORK,,}" == "user"* ]] && return 0

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
closeBridge
return 0

fi

ip link set "$VM_NET_TAP" down || true
ip link delete "$VM_NET_TAP" || true

return 0
}

Expand Down Expand Up @@ -457,15 +462,10 @@ else
# Configure for tap interface
if ! configureNAT; then

closeBridge
NETWORK="user"
warn "falling back to usermode networking! Performance will be bad and port mapping will not work."

ip link set "$VM_NET_TAP" down promisc off &> null || true
ip link delete "$VM_NET_TAP" &> null || true

ip link set dockerbridge down &> null || true
ip link delete dockerbridge &> null || true

fi

fi
Expand Down
Loading