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