35 lines
1.2 KiB
Bash
Executable File
35 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
IFACE=$1
|
|
|
|
|
|
### IPv4 is IFACE public and has a route? if so, nuke it
|
|
for route in $(vtysh -c "show ip route kernel" | grep "${IFACE}" | grep -Po 'K[ >]\* \K\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/\d{1,3}')
|
|
do
|
|
echo "removing route for $IFACE: $route"
|
|
ip route del $route
|
|
done
|
|
#### IPv6 is IFACE public and has a route? if so, nuke it
|
|
#for route in $(vtysh -c "show ipv6 route kernel" | grep "$IFACE" | awk '{ print $2 }')
|
|
# do
|
|
# echo "removing route for $IFACE: $route"
|
|
# ip route del $route
|
|
#done
|
|
|
|
|
|
### is IFACE private and has a local bridge?
|
|
BRIDGE=$(readlink -f /sys/devices/virtual/net/$IFACE/brport/bridge || true)
|
|
|
|
if [ ! -z $BRIDGE ]; then
|
|
BRIDGE=${BRIDGE##*/}
|
|
echo "removing $IFACE from $BRIDGE"
|
|
brctl delif $BRIDGE $IFACE
|
|
if ! ls /sys/devices/virtual/net/$BRIDGE/brif/ | grep -qv "vxlan\|vlan" 2>/dev/null; then #if so is the *local* bridge now empty? if so, nuke the whole bridge including tunnel endpoint
|
|
echo "removing unused bridge: $BRIDGE"
|
|
for uplinkif in $(ls /sys/devices/virtual/net/$BRIDGE/brif/ 2>/dev/null); do
|
|
ip link del dev $uplinkif
|
|
done
|
|
ip link set down $BRIDGE
|
|
brctl delbr $BRIDGE
|
|
fi
|
|
fi
|