check_ethernet.hook: Do not ignore network devices with link

The check_ethernet.hook script ignores devices with the
"cdc_ether" driver, presumably to avoid testing cellular
interfaces.  This driver isn't exclusive to cellular devices,
however (nor is it inclusive of all cellular devices).  As
such, it is prudent to test such devices if, for example,
they report themselves as currently connected.

There are two downsides to this change: on cellular-equipped
devices, this incurs a time penalty in situations where the
celluar device happens to be connected, since a ping attempt
will be performed there.   It also incurs a possible false-
positive in situations where the default gateway or ssh host
is reachable through this alternate interface, however the
chances of this being true are very slim indeed and already
exists since the script doesn't eliminate WiFi devices or
celluar devices that use a driver other than "cdc_ether".

One alternate  approach would be to remove the "cdc_ether" test
altogether, which seems risky without properly understanding
the original reasoning, and at best would delay testing by
trying devices that were doomed to fail.

Another alternate approach would be to use the connection
manager, which knows how to successfully discern between
Ethernet and wireless WAN devices.  This adds a direct
dependency on the connection manager D-Bus APIs which
probably should not happen here without deeper contemplation.

TEST=Manual: run on a host with a USB-Ethernet interface
that uses the "cdc_ether" driver.  Note that the system now
does not restart the connection manager at regular intervals.

Change-Id: I61a9ffba2f91d2b49f61b54504f6ce8d8522d363
Reviewed-by: Chris Sosa <>
Tested-by: Paul Stewart <>
Commit-Queue: Paul Stewart <>
(cherry picked from commit 661c1e7c808158e0b7112f25a6d5409ecd68bb1a)
Reviewed-by: Paul Stewart <>
diff --git a/recover_duts/hooks/check_ethernet.hook b/recover_duts/hooks/check_ethernet.hook
index f00ae7b..1feb28c 100755
--- a/recover_duts/hooks/check_ethernet.hook
+++ b/recover_duts/hooks/check_ethernet.hook
@@ -43,18 +43,26 @@
   return 1
+# Returns 0 if $1 indicates its link is connected, or 1 otherwise.
+is_connected() {
+  local device="$1"
+  ip link show "${device}" | grep -q LOWER_UP
 # Shows the list of Ethernet interfaces found on the system.
 find_ethernet_interfaces() {
   local device_path
   local driver_path
+  local device
   local driver
   for device_path in /sys/class/net/eth*; do
     if [ -e "${driver_path}" ]; then
+      device=$(basename "${device_path}")
       driver=$(basename $(readlink -f "${driver_path}"))
-      if ! is_non_ethernet_driver "${driver}"; then
-        basename "${device_path}"
+      if ! is_non_ethernet_driver "${driver}" || is_connected "${device}" ; then
+        echo "${device}"