wit-network-config/files/wit-gc

33 lines
1.0 KiB
Bash
Executable File

#!/bin/bash
set -Eeuo pipefail
EMPTYBR=$(for br in /sys/devices/virtual/net/br*; do if [ ! -d $br ]; then continue; fi; ls $br/brif/ | grep -qv "vxlan\|vlan" || echo ${br##*/}; done)
for BRIDGE in $EMPTYBR
do
echo "removing unused customer bridge/vxlan: $BRIDGE"
for uplinkif in /sys/devices/virtual/net/$BRIDGE/brif/*; do
ip link del dev ${uplinkif##*/}
done
ip link set down $BRIDGE
brctl delbr $BRIDGE
done
for route in $(vtysh -c "show ip route kernel" | grep 'unknown inactive' | sed 's|.* \([0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,3\}\) \[.\/\([0-9]\{1,3\}\)\].*|\1-met-\2|')
do
echo "removing zombie route: ${route/-met-/ metric }"
ip route add ${route/-met-/ via 127.1.1.1 metric }
ip route del ${route/-met-/ metric }
done
#all this spiel is not needed for ipv6
#for route in $(vtysh -c "show ipv6 route kernel" | grep 'unknown inactive' | awk '{ print $3 }')
# do
# echo "removing zombie route: $route"
# ip route add blackhole $route
# ip route del $route
#done