diff --git a/setup/so-functions b/setup/so-functions index bf95ea9d8..4544ded62 100755 --- a/setup/so-functions +++ b/setup/so-functions @@ -745,6 +745,66 @@ configure_network_sensor() { return $err } +remove_hyper_bridge() { + # Check if br0 exists + if ! nmcli -f name -t con show | grep -q '^br0$'; then + info "No br0 bridge found, skipping bridge removal" + return + fi + + info "Removing hypervisor bridge br0" + + # Get the bridge slave interface name + local slave_iface + slave_iface=$(nmcli -f connection.slave-type,connection.interface-name -t con show --active | grep bridge | grep -v br0 | head -1 | cut -d: -f2) + + if [[ -z "$slave_iface" ]]; then + # Try finding it from inactive bridge-slave connections + slave_iface=$(nmcli -f connection.type,connection.interface-name -t con show | grep bridge-slave | head -1 | cut -d: -f2) + fi + + # Get IP settings from br0 before removing it + local ipmethod addresses gateway dns dnssearch + ipmethod=$(nmcli -f ipv4.method -t con show br0 | cut -d: -f2) + addresses=$(nmcli -f ipv4.addresses -t con show br0 | cut -d: -f2) + gateway=$(nmcli -f ipv4.gateway -t con show br0 | cut -d: -f2) + dns=$(nmcli -f ipv4.dns -t con show br0 | cut -d: -f2) + dnssearch=$(nmcli -f ipv4.dns-search -t con show br0 | cut -d: -f2) + + # Remove bridge-slave connections + for con in $(nmcli -f name -t con show | grep '^bridge-slave-'); do + logCmd "nmcli con delete $con" + done + + # Remove br0 + logCmd "nmcli con delete br0" + + if [[ -n "$slave_iface" ]]; then + # Ensure the original connection profile exists for the slave interface + if ! nmcli -f name -t con show | grep -q "^${slave_iface}$"; then + info "Recreating connection profile for $slave_iface" + logCmd "nmcli con add type ethernet ifname $slave_iface con-name $slave_iface" + fi + + # Transfer IP settings back to the original interface + if [[ "$ipmethod" == "manual" && -n "$addresses" ]]; then + info "Restoring static IP configuration to $slave_iface" + logCmd "nmcli con mod $slave_iface ipv4.addresses $addresses" + logCmd "nmcli con mod $slave_iface ipv4.gateway $gateway" + [[ -n "$dns" ]] && logCmd "nmcli con mod $slave_iface ipv4.dns $dns" + [[ -n "$dnssearch" ]] && logCmd "nmcli con mod $slave_iface ipv4.dns-search $dnssearch" + logCmd "nmcli con mod $slave_iface ipv4.method manual" + else + logCmd "nmcli con mod $slave_iface ipv4.method auto" + fi + + logCmd "nmcli con up $slave_iface" + info "Bridge br0 removed, network restored on $slave_iface" + else + info "Warning: Could not determine original interface from bridge slave. Bridge removed but network may need manual configuration." + fi +} + configure_hyper_bridge() { info "Setting up hypervisor bridge" info "Checking $MNIC ipv4.method is auto or manual" @@ -1541,6 +1601,9 @@ clear_previous_setup_results() { reinstall_init() { info "Putting system in state to run setup again" + # Remove hypervisor bridge if present so network works without it + remove_hyper_bridge + if [[ $install_type =~ ^(MANAGER|EVAL|MANAGERSEARCH|MANAGERHYPE|STANDALONE|FLEET|IMPORT)$ ]]; then local salt_services=( "salt-master" "salt-minion" ) else