Skip to content

Instantly share code, notes, and snippets.

@dosaboy
Last active April 3, 2020 11:31
Show Gist options
  • Save dosaboy/37121dcfd6581066cec8f6377817a4ef to your computer and use it in GitHub Desktop.
Save dosaboy/37121dcfd6581066cec8f6377817a4ef to your computer and use it in GitHub Desktop.
#!/bin/bash -eux
# Origin: https://gist.github.com/dosaboy/37121dcfd6581066cec8f6377817a4ef
#
# Authors:
# - edward.hope-morley@canonical.com
#
# Description:
# Send a gratuitous arp for every floating ip in use on a node. Uses same
# method to send garp as neutron.
# Create set of FIPs in use on this node
declare -a fips=()
for ns in `find /var/run/netns/ -name qrouter-\*`; do
ns=`basename $ns`
readarray -t _fips<<<"`sudo ip netns exec $ns iptables -t nat -S| egrep "SNAT\s--to-source"| awk '{print $NF}'`"
((${#_fips[@]}==0)) || [ -z "${_fips[0]}" ] && continue
fips+=( ${_fips[@]} )
done
# Find corresponding fip ns for each FIP
declare -A fip_ns_index=()
for ns in `find /var/run/netns/ -name fip-\*`; do
ns=`basename $ns`
for fip in ${fips[@]}; do
# of the fip is actually connected to this fip ns it will have a route to a qrouter ns via an fpr interface
if `sudo ip netns exec $ns ip r get $fip| grep -q fpr-`; then
fip_ns_index[$fip]=$ns
fi
done
done
# Send garp for each FIP
for fip in ${!fip_ns_index[@]}; do
# there should only ever be one fg- interface per fip ns
ns=${fip_ns_index[$fip]}
fg_iface=`sudo ip netns exec $ns ip -br a| awk '{print $1}'| grep fg-`
sudo ip netns exec $ns arping -A -I $fg_iface -c 1 -w 1.5 $fip
sudo ip netns exec $ns arping -U -I $fg_iface -c 1 -w 1.5 $fip
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment