check_ethernet: add fallback to any recently seen neighbor

Jetstream mesh devices do not have a default gateway before
the mesh is established. This was causing the check_ethernet
hook to fail if there was no active SSH connection to the DUT.

This adds a fallback to ping any recently seen neighbor.

BUG=b:74075854
TEST=Checked fallback on devices with no default gateway and no
  active ssh connection.

Change-Id: I36f416e10d9d5e0f2db71c9b67210ea210b184c6
Reviewed-on: https://chromium-review.googlesource.com/1033999
Commit-Ready: Laurence Goodby <lgoodby@chromium.org>
Tested-by: Laurence Goodby <lgoodby@chromium.org>
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: Grant Grundler <grundler@chromium.org>
diff --git a/recover_duts/hooks/check_ethernet.hook b/recover_duts/hooks/check_ethernet.hook
index e0cfa05..2580a27 100755
--- a/recover_duts/hooks/check_ethernet.hook
+++ b/recover_duts/hooks/check_ethernet.hook
@@ -129,6 +129,19 @@
                        if (a[1] != "127.0.0.1") print a[1]}'
 }
 
+# Return the IP address of a neighbor reachable via ethernet
+find_ethernet_neighbor() {
+  local eth
+  local neighbor_ip
+
+  for eth in $(find_ethernet_interfaces); do
+    neighbor_ip=$(ip -4 neigh show dev ${eth} |
+                  awk '/REACHABLE|DELAY|STALE/ {print $1; exit}')
+    [ -n "${neighbor_ip}" ] && echo ${neighbor_ip} && return 0
+  done
+  return 1
+}
+
 # Try to find a connected SSH client (our autotest server) and ping it
 ping_controlling_server() {
   local default_gateway="$(get_default_gateway)" || default_gateway=
@@ -140,6 +153,12 @@
   if [ -n "${ssh_client}" ]; then
     do_ping ${ssh_client} && return 0
   fi
+
+  # Last attempt: any recently seen neighbor
+  local neighbor="$(find_ethernet_neighbor)" || neighbor=
+  if [ -n "${neighbor}" ]; then
+    do_ping ${neighbor} && return 0
+  fi
   return 1
 }