network: don't die if gateway is down and root server is local
authorPádraig Brady <P@draigBrady.com>
Thu, 28 Oct 2010 13:49:37 +0000 (15:49 +0200)
committerHarald Hoyer <harald@redhat.com>
Thu, 28 Oct 2010 15:11:34 +0000 (17:11 +0200)
modules.d/40network/netroot: Don't arping the gateway if we don't need to

modules.d/40network/netroot

index 81a9ad3..3e9fe35 100755 (executable)
@@ -83,21 +83,40 @@ done
 [ -e /tmp/net.$netif.override ] && . /tmp/net.$netif.override
 [ -e /tmp/dhclient.$netif.dhcpopts ] && . /tmp/dhclient.$netif.dhcpopts
 
-# Handle STP Timeout: arping default router or if not available the
-# root server. Note: This assumes that if no router is present the
+# Handle STP Timeout: arping the default router if root server is
+# unknown or not local, or if not available the root server.
+# Note: This assumes that if no router is present the
 # root server is on the same subnet.
 #
 # TODO There's some netroot variants that don't (yet) have their 
 # server-ip netroot
-[ -n "$new_routers" ] && dest=${new_routers%%,*}
-[ -n "$gw" ] && dest=$gw
-if [ -z "$dest" ] ; then
+
+# Get router IP if set
+[ -n "$new_routers" ] && gw_ip=${new_routers%%,*}
+[ -n "$gw" ] && gw_ip=$gw
+# Get root server IP if set
+if [ -n "$netroot" ]; then
     dummy=${netroot#*:}
     dummy=${dummy%%:*}
     case "$dummy" in
-        [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) dest=$dummy;;
+        [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) netroot_ip=$dummy;;
     esac
 fi
+# Default arping dest to router
+dest="$gw_ip"
+# Change to arping root server if appropriate
+if [ -n "$netroot_ip" ]; then
+    if [ -z "$dest" ]; then
+         # no gateway so check root server
+        dest="$netroot_ip"
+    else
+        r=$(ip route get "$netroot_ip")
+        if ! strstr "$r" ' via ' ; then
+            # local root server, so don't arping gateway
+            dest="$netroot_ip"
+        fi
+    fi
+fi
 if [ -n "$dest" ] && ! arping -q -f -w 60 -I $netif $dest ; then
     die "Resolving $dest via ARP on $netif failed"
 fi