Blame SOURCES/0362-network-fix-carrier-detection.patch

712866
From 17985b2575c10b488e7af2aeef160b41a97b2358 Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Mon, 14 Dec 2015 13:10:05 +0100
712866
Subject: [PATCH] network: fix carrier detection
712866
712866
rename iface_has_link() to iface_has_carrier() to clarify usage
712866
712866
Only assign static "wildcard interface" settings, if the interface has a
712866
carrier.
712866
712866
If the interface name was specified with a name, do not do carrier
712866
checking for static configurations.
712866
712866
(cherry picked from commit df95b1003c8e7564da73de92403013763eb028fe)
712866
---
712866
 modules.d/40network/ifup.sh    | 42 ++++++++++++++++++++-----------------
712866
 modules.d/40network/net-lib.sh | 47 ++++++++++++++++++++++++++----------------
712866
 2 files changed, 52 insertions(+), 37 deletions(-)
712866
712866
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
5c6c2a
index 7c06cd86..30551987 100755
712866
--- a/modules.d/40network/ifup.sh
712866
+++ b/modules.d/40network/ifup.sh
712866
@@ -105,7 +105,7 @@ do_dhcp() {
712866
 
712866
     [ -e /tmp/dhclient.$netif.pid ] && return 0
712866
 
712866
-    if ! iface_has_link $netif; then
712866
+    if ! iface_has_carrier $netif; then
712866
         warn "No carrier detected on interface $netif"
712866
         return 1
712866
     fi
712866
@@ -155,7 +155,10 @@ do_ipv6auto() {
712866
 do_static() {
712866
     strstr $ip '*:*:*' && load_ipv6
712866
 
712866
-    if ! linkup $netif; then
712866
+    if [ -z "$dev" ] && ! iface_has_carrier "$netif"; then
712866
+        warn "No carrier detected on interface $netif"
712866
+        return 1
712866
+    elif ! linkup "$netif"; then
712866
         warn "Could not bring interface $netif up!"
712866
         return 1
712866
     fi
712866
@@ -398,27 +401,28 @@ for p in $(getargs ip=); do
712866
     done
712866
     ret=$?
712866
 
712866
-    > /tmp/net.${netif}.up
712866
+    if [ $ret -eq 0 ]; then
712866
+        > /tmp/net.${netif}.up
712866
 
712866
-    if [ -e /sys/class/net/${netif}/address ]; then
712866
-        > /tmp/net.$(cat /sys/class/net/${netif}/address).up
712866
-    fi
712866
+        if [ -e /sys/class/net/${netif}/address ]; then
712866
+            > /tmp/net.$(cat /sys/class/net/${netif}/address).up
712866
+        fi
712866
 
712866
-    case $autoconf in
712866
-        dhcp|on|any|dhcp6)
712866
+        case $autoconf in
712866
+            dhcp|on|any|dhcp6)
712866
             ;;
712866
-        *)
712866
-            if [ $ret -eq 0 ]; then
712866
-                setup_net $netif
712866
-                source_hook initqueue/online $netif
712866
-                if [ -z "$manualup" ]; then
712866
-                    /sbin/netroot $netif
712866
+            *)
712866
+                if [ $ret -eq 0 ]; then
712866
+                    setup_net $netif
712866
+                    source_hook initqueue/online $netif
712866
+                    if [ -z "$manualup" ]; then
712866
+                        /sbin/netroot $netif
712866
+                    fi
712866
                 fi
712866
-            fi
712866
-            ;;
712866
-    esac
712866
-
712866
-    exit 0
712866
+                ;;
712866
+        esac
712866
+        exit $ret
712866
+    fi
712866
 done
712866
 
712866
 # netif isn't the top stack? Then we should exit here.
712866
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
5c6c2a
index 995d32f6..07ea5709 100755
712866
--- a/modules.d/40network/net-lib.sh
712866
+++ b/modules.d/40network/net-lib.sh
712866
@@ -531,22 +531,20 @@ wait_for_if_up() {
712866
 
712866
     while [ $cnt -lt $timeout ]; do
712866
         li=$(ip -o link show up dev $1)
712866
-        if ! strstr "$li" "NO-CARRIER"; then
712866
-            if [ -n "$li" ]; then
712866
-                case "$li" in
712866
-                    *\
712866
-                        return 0;;
712866
-                    *\<*,UP\>*)
712866
-                        return 0;;
712866
-                    *\<*,UP,*\>*)
712866
-                        return 0;;
712866
-                esac
712866
-            fi
712866
-            if strstr "$li" "LOWER_UP" \
712866
-                    && strstr "$li" "state UNKNOWN" \
712866
-                    && ! strstr "$li" "DORMANT"; then
712866
-                return 0
712866
-            fi
712866
+        if [ -n "$li" ]; then
712866
+            case "$li" in
712866
+                *\
712866
+                    return 0;;
712866
+                *\<*,UP\>*)
712866
+                    return 0;;
712866
+                *\<*,UP,*\>*)
712866
+                    return 0;;
712866
+            esac
712866
+        fi
712866
+        if strstr "$li" "LOWER_UP" \
712866
+                && strstr "$li" "state UNKNOWN" \
712866
+                && ! strstr "$li" "DORMANT"; then
712866
+            return 0
712866
         fi
712866
         sleep 0.1
712866
         cnt=$(($cnt+1))
712866
@@ -614,7 +612,7 @@ hostname() {
712866
 	cat /proc/sys/kernel/hostname
712866
 }
712866
 
712866
-iface_has_link() {
712866
+iface_has_carrier() {
712866
     local cnt=0
712866
     local interface="$1" flags=""
712866
     [ -n "$interface" ] || return 2
712866
@@ -625,14 +623,27 @@ iface_has_link() {
712866
     timeout=$(($timeout*10))
712866
 
712866
     linkup "$1"
712866
+
712866
+    li=$(ip -o link show up dev $1)
712866
+    strstr "$li" "NO-CARRIER" && _no_carrier_flag=1
712866
+
712866
     while [ $cnt -lt $timeout ]; do
712866
-        [ "$(cat $interface/carrier)" = 1 ] && return 0
712866
+        if [ -n "$_no_carrier_flag" ]; then
712866
+            # NO-CARRIER flag was cleared
712866
+            strstr "$li" "NO-CARRIER" || return 0
712866
+        fi
712866
+        # double check the syscfs carrier flag
712866
+        [ -e "$interface/carrier" ] && [ "$(cat $interface/carrier)" = 1 ] && return 0
712866
         sleep 0.1
712866
         cnt=$(($cnt+1))
712866
     done
712866
     return 1
712866
 }
712866
 
712866
+iface_has_link() {
712866
+    iface_has_carrier "$@"
712866
+}
712866
+
712866
 find_iface_with_link() {
712866
     local iface_path="" iface=""
712866
     for iface_path in /sys/class/net/*; do