2018-07-26 03:57:41 -05:00
#!/bin/bash
2019-03-10 21:16:33 -05:00
set -x
2018-07-26 03:57:41 -05:00
IFACE=$1
### IPv4 is IFACE public and has a route? if so, nuke it
2019-03-10 21:16:33 -05:00
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}')
2018-07-26 03:57:41 -05:00
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
2019-03-10 21:16:33 -05:00
if ! ls /sys/devices/virtual/net/$BRIDGE/brif/ | grep -qv "vxlan\|vlan"; then #if so is the *local* bridge now empty? if so, nuke the whole bridge including tunnel endpoint
2018-07-26 03:57:41 -05:00
echo "removing unused bridge: $BRIDGE"
2019-03-10 21:16:33 -05:00
for uplinkif in ls /sys/devices/virtual/net/$BRIDGE/brif/; do
ip link del dev $uplinkif
done
2018-07-26 03:57:41 -05:00
ip link set down $BRIDGE
brctl delbr $BRIDGE
fi
fi