bonding mode 4 monitoring:
[ctdb.git] / config / events.d / 10.interface
index 1e7f94b24680ce1d7221cb132100d45047263499..e0689c4397b0aa84e411dd668a6c5e57db56a416 100755 (executable)
@@ -38,13 +38,12 @@ monitor_interfaces()
        INTERFACES=`for IFACE in $INTERFACES ; do echo $IFACE ; done | sort | uniq`
 
        local fail=0
-       local force_fail=0
        local ok=0
        for IFACE in $INTERFACES ; do
 
-           local OLDLINK=`echo -n "$IFACES" | grep "^:$IFACE:" | cut -d ':' -f3 | xargs`
-           test -z "$OLDLINK" && {
-               force_fail=1
+           ip addr show $IFACE 2>/dev/null >/dev/null || {
+               echo Interface $IFACE does not exist but it is used by public addresses.
+               exit 1
            }
 
            # These interfaces are sometimes bond devices
@@ -55,33 +54,42 @@ monitor_interfaces()
                grep -q 'Currently Active Slave: None' /proc/net/bonding/$REALIFACE && {
                        echo "ERROR: No active slaves for bond device $REALIFACE"
                        fail=1
-                       test -n "$OLDLINK" && {
-                               ctdb setifacelink $IFACE down
-                       }
+                       ctdb setifacelink $IFACE down
                        continue;
                }
                grep -q '^MII Status: up' /proc/net/bonding/$REALIFACE || {
                        echo "ERROR: public network interface $REALIFACE is down"
                        fail=1
-                       test -n "$OLDLINK" && {
-                               ctdb setifacelink $IFACE down
-                       }
+                       ctdb setifacelink $IFACE down
                        continue;
                }
-               test -n "$OLDLINK" && {
-                       ok=1 # we only set ok for interfaces known to ctdbd
-                       ctdb setifacelink $IFACE up
+               grep -q '^Bonding Mode: IEEE 802.3ad Dynamic link aggregation' /proc/net/bonding/$REALIFACE && {
+                       grep 'MII Status:' /proc/net/bonding/$REALIFACE | tail -n +2 | grep -q '^MII Status: up' || {
+                               echo No active slaves for 802.ad bond device $REALIFACE
+                               ctdb setifacelink $IFACE down
+                               fail=1
+                               continue
+                       }
                }
-               return 0;
+               ok=1 # we only set ok for interfaces known to ctdbd
+               ctdb setifacelink $IFACE up
+               continue;
            }
 
            case $IFACE in
+           lo*)
+               # loopback is always working
+               ok=1 # we only set ok for interfaces known to ctdbd
+               ctdb setifacelink $IFACE up
+               ;;
            ib*)
                # we dont know how to test ib links
+               ok=1 # we only set ok for interfaces known to ctdbd
+               ctdb setifacelink $IFACE up
                ;;
            *)
                [ -z "$IFACE" ] || {
-                   [ "$(basename $(readlink /sys/class/net/$IFACE/device/driver))" = virtio_net ] ||
+                   [ "$(basename $(readlink /sys/class/net/$IFACE/device/driver) 2>/dev/null)" = virtio_net ] ||
                    ethtool $IFACE | grep -q 'Link detected: yes' || {
                        # On some systems, this is not successful when a
                        # cable is plugged but the interface has not been
@@ -91,16 +99,12 @@ monitor_interfaces()
                        ethtool $IFACE | grep -q 'Link detected: yes' || {
                            echo "ERROR: No link on the public network interface $IFACE"
                            fail=1
-                           test -n "$OLDLINK" && {
-                               ctdb setifacelink $IFACE down
-                           }
+                           ctdb setifacelink $IFACE down
                            continue
                        }
                    }
-                   test -n "$OLDLINK" && {
-                       ok=1 # we only set ok for interfaces known to ctdbd
-                       ctdb setifacelink $IFACE up
-                   }
+                   ok=1 # we only set ok for interfaces known to ctdbd
+                   ctdb setifacelink $IFACE up
                }
                ;;
            esac
@@ -111,10 +115,6 @@ monitor_interfaces()
                return 0;
        }
 
-       test x"$force_fail" != x"0" && {
-               return 1;
-       }
-
        test x"$ok" = x"1" && {
                return 2;
        }
@@ -131,21 +131,19 @@ case "$1" in
        [ -f /proc/sys/net/ipv4/conf/all/arp_filter ] && {
            echo 1 > /proc/sys/net/ipv4/conf/all/arp_filter
        }
-       cat "$CTDB_PUBLIC_ADDRESSES" | cut -d/ -f1 | while read _IP; do
-               _IP_HELD=`/sbin/ip addr show | grep "inet $_IP/"`
-               [ -z "$_IP_HELD" ] || {
-                       _IFACE=`echo $_IP_HELD | sed -e "s/.*\s//"`
-                       _NM=`echo $_IP_HELD | sed -e "s/.*$_IP\///" -e "s/\s.*//"`
-                       echo "Removing public address $_IP/$_NM from device $_IFACE"
-                       delete_ip_from_iface $_IFACE $_IP $_NM
-               }
-       done
        ;;
 
      #############################
      # called after ctdbd has done its initial recovery
      # and we start the services to become healthy
      startup)
+       # Assume all links are good initially
+       INTERFACES=`for IFACE in $INTERFACES ; do echo $IFACE ; done | sort | uniq`
+
+       for IFACE in $INTERFACES ; do
+               ctdb setifacelink $IFACE down
+       done
+       
        monitor_interfaces
 
        ;;
@@ -242,14 +240,10 @@ case "$1" in
        iptables -D INPUT -i $oiface -d $ip -j DROP 2> /dev/null
        iptables -I INPUT -i $oiface -d $ip -j DROP
 
-       # we make sure the interface is up first
-       add_ip_to_iface $niface $ip $maskbits || {
-               iptables -D INPUT -i $oiface -d $ip -j DROP 2> /dev/null
-               exit 1;
-       }
+       delete_ip_from_iface $oiface $ip $maskbits 2>/dev/null
+       delete_ip_from_iface $niface $ip $maskbits 2>/dev/null
 
-       delete_ip_from_iface $oiface $ip $maskbits || {
-               delete_ip_from_iface $niface $ip $maskbits
+       add_ip_to_iface $niface $ip $maskbits || {
                iptables -D INPUT -i $oiface -d $ip -j DROP 2> /dev/null
                exit 1;
        }