Eventscripts - add facility to 10.interface to delete unmanaged IPs
authorMartin Schwenke <martin@meltin.net>
Thu, 17 Nov 2011 05:47:00 +0000 (16:47 +1100)
committerMartin Schwenke <martin@meltin.net>
Thu, 17 Nov 2011 05:47:00 +0000 (16:47 +1100)
For a number of reasons (delip failure, admin stupidity, ...) an
interface that hosts public addresses can also contain spurious,
unmanaged addresses.

Add functionality to 10.interfaces, controlled by new configuration
variable CTDB_DELETE_UNEXPECTED_IPS, to delete these addresses when
encountered as part of a monitor event.

Signed-off-by: Martin Schwenke <martin@meltin.net>
config/events.d/10.interface

index dd54f1e395250d006513cceb97e4a2da3718d558..a425e27c606b3fa46c3ab7bf295c44570a86f934 100755 (executable)
@@ -49,10 +49,39 @@ get_all_interfaces ()
     all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
 }
 
+delete_unexpected_ips ()
+{
+    [ "$CTDB_DELETE_UNEXPECTED_IPS" = "yes" ] || return
+
+    for _i in $all_interfaces ; do
+       # Get the IPs actually on this interface
+       _ips=$(ip addr show dev "$_i" | \
+           sed -n -e 's@.*inet[[:space:]]*\([^[:space:]]*\).*scope global.*@\1@p')
+       for _ip in $_ips ; do
+
+           # The NATGW address is OK
+           if [ "$CTDB_NATGW_PUBLIC_IP" = "$_ip" -a \
+               "$CTDB_NATGW_PUBLIC_IFACE" = "$_i" ] ; then
+               continue
+           fi
+
+           # If CTDB knows about the address then it is OK
+           if ctdb ipinfo "${_ip%/*}" >/dev/null 2>&1 ; then
+               continue
+           fi
+
+           echo "WARNING: Removing unmanaged IP address $_ip from interface $_i"
+           delete_ip_from_iface "$_i" "${_ip%/*}" "${_ip#*/}"
+       done
+    done
+}
+
 monitor_interfaces()
 {
        get_all_interfaces
 
+       delete_unexpected_ips
+
        fail=false
        up_interfaces_found=false