all_interfaces=$(echo $all_interfaces $ctdb_ifaces | tr ' ' '\n' | sort -u)
}
-# If the interface is a virtual one (e.g. VLAN) then get the
-# underlying interface
-interface_get_real ()
-{
- # Output of "ip link show <iface>"
- _iface_info="$1"
-
- # Extract the full interface description to see if it is a VLAN
- _t=$(echo "$_iface_info" |
- awk 'NR == 1 { iface = $2; sub(":$", "", iface) ; \
- print iface }')
- case "$_t" in
- *@*)
- # VLAN: use the underlying interface, after the '@'
- echo "${_t##*@}"
- ;;
- *)
- # Not a regular VLAN. For backward compatibility, assume
- # there is some other sort of VLAN that doesn't have the
- # '@' in the output and only use what is before a '.'. If
- # there is no '.' then this will be the whole interface
- # name.
- echo "${_t%%.*}"
- esac
-}
-
-# Check whether an interface is operational
-interface_monitor ()
-{
- _iface="$1"
-
- _iface_info=$(ip link show "$_iface" 2>&1) || {
- echo "ERROR: Monitored interface ${_iface} does not exist"
- return 1
- }
-
-
- # If the interface is a virtual one (e.g. VLAN) then get the
- # underlying interface.
- _realiface=$(interface_get_real "$_iface_info")
-
- if _bi=$(get_proc "net/bonding/${_realiface}" 2>/dev/null) ; then
- # This is a bond: various monitoring strategies
- echo "$_bi" | grep -q 'Currently Active Slave: None' && {
- echo "ERROR: No active slaves for bond device ${_realiface}"
- return 1
- }
- echo "$_bi" | grep -q '^MII Status: up' || {
- echo "ERROR: public network interface ${_realiface} is down"
- return 1
- }
- echo "$_bi" | grep -q '^Bonding Mode: IEEE 802.3ad Dynamic link aggregation' && {
- # This works around a bug in the driver where the
- # overall bond status can be up but none of the actual
- # physical interfaces have a link.
- echo "$_bi" | grep 'MII Status:' | tail -n +2 | grep -q '^MII Status: up' || {
- echo "ERROR: No active slaves for 802.ad bond device ${_realiface}"
- return 1
- }
- }
-
- return 0
- else
- # Not a bond
- case "$_iface" in
- lo*)
- # loopback is always working
- return 0
- ;;
- ib*)
- # we don't know how to test ib links
- return 0
- ;;
- *)
- 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
- # brought up previously. Bring the interface up
- # and try again...
- ip link set "$_iface" up
- ethtool "$_iface" | grep -q 'Link detected: yes' || {
- echo "ERROR: No link on the public network interface ${_iface}"
- return 1
- }
- }
- return 0
- ;;
- esac
- fi
-}
-
monitor_interfaces()
{
get_all_interfaces
set_proc_maybe sys/net/ipv6/route/flush 1
}
+########################################################
+# Interface monitoring
+
+# If the interface is a virtual one (e.g. VLAN) then get the
+# underlying interface
+interface_get_real ()
+{
+ # Output of "ip link show <iface>"
+ _iface_info="$1"
+
+ # Extract the full interface description to see if it is a VLAN
+ _t=$(echo "$_iface_info" |
+ awk 'NR == 1 { iface = $2; sub(":$", "", iface) ; \
+ print iface }')
+ case "$_t" in
+ *@*)
+ # VLAN: use the underlying interface, after the '@'
+ echo "${_t##*@}"
+ ;;
+ *)
+ # Not a regular VLAN. For backward compatibility, assume
+ # there is some other sort of VLAN that doesn't have the
+ # '@' in the output and only use what is before a '.'. If
+ # there is no '.' then this will be the whole interface
+ # name.
+ echo "${_t%%.*}"
+ esac
+}
+
+# Check whether an interface is operational
+interface_monitor ()
+{
+ _iface="$1"
+
+ _iface_info=$(ip link show "$_iface" 2>&1) || {
+ echo "ERROR: Monitored interface ${_iface} does not exist"
+ return 1
+ }
+
+
+ # If the interface is a virtual one (e.g. VLAN) then get the
+ # underlying interface.
+ _realiface=$(interface_get_real "$_iface_info")
+
+ if _bi=$(get_proc "net/bonding/${_realiface}" 2>/dev/null) ; then
+ # This is a bond: various monitoring strategies
+ echo "$_bi" | grep -q 'Currently Active Slave: None' && {
+ echo "ERROR: No active slaves for bond device ${_realiface}"
+ return 1
+ }
+ echo "$_bi" | grep -q '^MII Status: up' || {
+ echo "ERROR: public network interface ${_realiface} is down"
+ return 1
+ }
+ echo "$_bi" | grep -q '^Bonding Mode: IEEE 802.3ad Dynamic link aggregation' && {
+ # This works around a bug in the driver where the
+ # overall bond status can be up but none of the actual
+ # physical interfaces have a link.
+ echo "$_bi" | grep 'MII Status:' | tail -n +2 | grep -q '^MII Status: up' || {
+ echo "ERROR: No active slaves for 802.ad bond device ${_realiface}"
+ return 1
+ }
+ }
+
+ return 0
+ else
+ # Not a bond
+ case "$_iface" in
+ lo*)
+ # loopback is always working
+ return 0
+ ;;
+ ib*)
+ # we don't know how to test ib links
+ return 0
+ ;;
+ *)
+ 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
+ # brought up previously. Bring the interface up
+ # and try again...
+ ip link set "$_iface" up
+ ethtool "$_iface" | grep -q 'Link detected: yes' || {
+ echo "ERROR: No link on the public network interface ${_iface}"
+ return 1
+ }
+ }
+ return 0
+ ;;
+ esac
+ fi
+}
+
########################################################
# Simple counters
_ctdb_counter_common () {