#!/bin/bash

echo "=== ES40 Network remove ==="

# Remove feth from bridge
echo "Removing feth5000 from bridge200..."
sudo /sbin/ifconfig bridge200 deletem feth5000 2>/dev/null || true

# Destroy bridge
echo "Destroying bridge200..."
sudo /sbin/ifconfig bridge200 destroy 2>/dev/null || true

# Destroy feth pair
echo "Destroying feth5000/feth5001..."
sudo /sbin/ifconfig feth5000 destroy 2>/dev/null || true
sudo /sbin/ifconfig feth5001 destroy 2>/dev/null || true

# Optional: Disable IP forwarding (only if you don't need it for other things)
read -p "Disable IP forwarding? (y/N): " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
    echo "Disabling IP forwarding..."
    sudo sysctl -w net.inet.ip.forwarding=0 > /dev/null
fi

echo ""
echo "=== ES40 network removed ==="
echo ""
echo "Remaining interfaces:"
/sbin/ifconfig -a | grep -E 'bridge200|feth500' || echo "No remaining feth/bridge200 interfaces found."
