]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-scripts: Simplify determination of real interface
authorMartin Schwenke <martin@meltin.net>
Wed, 17 Aug 2022 01:38:44 +0000 (11:38 +1000)
committerAmitay Isaacs <amitay@samba.org>
Fri, 16 Sep 2022 03:36:32 +0000 (03:36 +0000)
This can now be made trivial.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/config/functions

index 518bc201f7b4ba6f4eb98aa495208169aca77038..dcb04ebb5efc128bef9bee4b11c9dd2bc37cbf2a 100755 (executable)
@@ -631,21 +631,11 @@ flush_route_cache ()
 # 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##*@}"
-           ;;
-       *)
-           echo "$_t"
-    esac
+       _iface="$1"
+
+       # If $_iface is a VLAN (i.e. contains an '@') then strip every
+       # before the '@', otherwise print the whole interface
+       echo "${_iface##*@}"
 }
 
 # Check whether an interface is operational
@@ -653,7 +643,7 @@ interface_monitor ()
 {
     _iface="$1"
 
-    _iface_info=$(ip link show "$_iface" 2>&1) || {
+    _iface_info=$(ip -br link show "$_iface" 2>&1) || {
        echo "ERROR: Monitored interface ${_iface} does not exist"
        return 1
     }
@@ -661,7 +651,7 @@ interface_monitor ()
 
     # If the interface is a virtual one (e.g. VLAN) then get the
     # underlying interface.
-    _realiface=$(interface_get_real "$_iface_info")
+    _realiface=$(interface_get_real "${_iface_info%% *}")
 
     if _bi=$(get_proc "net/bonding/${_realiface}" 2>/dev/null) ; then
        # This is a bond: various monitoring strategies