Blame SOURCES/0266-network-add-options-to-tweak-timeouts.patch

18971c
From d8ad687e1a4c0343eb076902b11aff2b2b2c4b85 Mon Sep 17 00:00:00 2001
18971c
From: Harald Hoyer <harald@redhat.com>
18971c
Date: Fri, 3 Jul 2015 13:30:40 +0200
18971c
Subject: [PATCH] network: add options to tweak timeouts
18971c
18971c
 rd.net.dhcp.retry=<cnt>
18971c
     If this option is set, dracut will try to connect via dhcp
18971c
     <cnt> times before failing. Default is 1.
18971c
18971c
 rd.net.timeout.dhcp=<arg>
18971c
     If this option is set, dhclient is called with "-timeout <arg>".
18971c
18971c
 rd.net.timeout.iflink=<seconds>
18971c
     Wait <seconds> until link shows up. Default is 60 seconds.
18971c
18971c
 rd.net.timeout.ifup=<seconds>
18971c
     Wait <seconds> until link has state "UP". Default is 20 seconds.
18971c
18971c
 rd.net.timeout.route=<seconds>
18971c
     Wait <seconds> until route shows up. Default is 20 seconds.
18971c
18971c
 rd.net.timeout.ipv6dad=<seconds>
18971c
     Wait <seconds> until IPv6 DAD is finished. Default is 50 seconds.
18971c
18971c
 rd.net.timeout.ipv6auto=<seconds>
18971c
     Wait <seconds> until IPv6 automatic addresses are assigned.
18971c
     Default is 40 seconds.
18971c
18971c
 rd.net.timeout.carrier=<seconds>
18971c
     Wait <seconds> until carrier is recognized. Default is 5 seconds.
18971c
---
18971c
 dracut.cmdline.7.asc           | 25 +++++++++++++++++++++++
18971c
 modules.d/40network/ifup.sh    | 26 ++++++++++++++++++++----
18971c
 modules.d/40network/net-lib.sh | 36 ++++++++++++++++++++++++++++------
18971c
 3 files changed, 77 insertions(+), 10 deletions(-)
18971c
18971c
diff --git a/dracut.cmdline.7.asc b/dracut.cmdline.7.asc
18971c
index c7e3bd40..5f3dead1 100644
18971c
--- a/dracut.cmdline.7.asc
18971c
+++ b/dracut.cmdline.7.asc
18971c
@@ -572,6 +572,31 @@ NFS
18971c
 **rd.nfs.domain=**__<NFSv4 domain name>__::
18971c
     Set the NFSv4 domain name. Will overwrite the settings in _/etc/idmap.conf_.
18971c
 
18971c
+**rd.net.dhcp.retry=**__<cnt>__::
18971c
+    If this option is set, dracut will try to connect via dhcp <cnt> times before failing.
18971c
+    Default is 1.
18971c
+
18971c
+**rd.net.timeout.dhcp=**__<arg>__::
18971c
+    If this option is set, dhclient is called with "-timeout <arg>".
18971c
+
18971c
+**rd.net.timeout.iflink=**__<seconds>__::
18971c
+    Wait <seconds> until link shows up. Default is 60 seconds.
18971c
+
18971c
+**rd.net.timeout.ifup=**__<seconds>__::
18971c
+    Wait <seconds> until link has state "UP". Default is 20 seconds.
18971c
+
18971c
+**rd.net.timeout.route=**__<seconds>__::
18971c
+    Wait <seconds> until route shows up. Default is 20 seconds.
18971c
+
18971c
+**rd.net.timeout.ipv6dad=**__<seconds>__::
18971c
+    Wait <seconds> until IPv6 DAD is finished. Default is 50 seconds.
18971c
+
18971c
+**rd.net.timeout.ipv6auto=**__<seconds>__::
18971c
+    Wait <seconds> until IPv6 automatic addresses are assigned. Default is 40 seconds.
18971c
+
18971c
+**rd.net.timeout.carrier=**__<seconds>__::
18971c
+    Wait <seconds> until carrier is recognized. Default is 5 seconds.
18971c
+
18971c
 CIFS
18971c
 ~~~
18971c
 **root=**cifs://[__<username>__[:__<password>__]@]__<server-ip>__:__<root-dir>__::
18971c
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
18971c
index 3cff725c..2f51e6d5 100755
18971c
--- a/modules.d/40network/ifup.sh
18971c
+++ b/modules.d/40network/ifup.sh
18971c
@@ -98,15 +98,33 @@ do_dhcp() {
18971c
     # event for nfsroot
18971c
     # XXX add -V vendor class and option parsing per kernel
18971c
 
18971c
+    local _COUNT=0
18971c
+    local _timeout=$(getargs rd.net.timeout.dhcp=)
18971c
+    local _DHCPRETRY=$(getargs rd.net.dhcp.retry=)
18971c
+    _DHCPRETRY=${_DHCPRETRY:-1}
18971c
+
18971c
     [ -e /tmp/dhclient.$netif.pid ] && return 0
18971c
 
18971c
     if ! iface_has_link $netif; then
18971c
-        echo "No carrier detected"
18971c
+        warn "No carrier detected on interface $netif"
18971c
         return 1
18971c
     fi
18971c
-    echo "Starting dhcp for interface $netif"
18971c
-    dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
18971c
-        || echo "dhcp failed"
18971c
+
18971c
+    while [ $_COUNT -lt $_DHCPRETRY ]; do
18971c
+        info "Starting dhcp for interface $netif"
18971c
+        dhclient "$@" \
18971c
+                 ${_timeout:+-timeout $_timeout} \
18971c
+                 -1 -q \
18971c
+                 -cf /etc/dhclient.conf \
18971c
+                 -pf /tmp/dhclient.$netif.pid \
18971c
+                 -lf /tmp/dhclient.$netif.lease \
18971c
+                 $netif \
18971c
+            && return 0
18971c
+        _COUNT=$(($_COUNT+1))
18971c
+        [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
18971c
+    done
18971c
+    warn "dhcp for interface $netif failed"
18971c
+    return 1
18971c
 }
18971c
 
18971c
 load_ipv6() {
18971c
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
18971c
index 1f77a154..de5273ca 100755
18971c
--- a/modules.d/40network/net-lib.sh
18971c
+++ b/modules.d/40network/net-lib.sh
18971c
@@ -486,7 +486,11 @@ parse_ifname_opts() {
18971c
 wait_for_if_link() {
18971c
     local cnt=0
18971c
     local li
18971c
-    while [ $cnt -lt 600 ]; do
18971c
+    local timeout="$(getargs rd.net.timeout.iflink=)"
18971c
+    timeout=${timeout:-60}
18971c
+    timeout=$(($timeout*10))
18971c
+
18971c
+    while [ $cnt -lt $timeout ]; do
18971c
         li=$(ip -o link show dev $1 2>/dev/null)
18971c
         [ -n "$li" ] && return 0
18971c
         sleep 0.1
18971c
@@ -498,7 +502,11 @@ wait_for_if_link() {
18971c
 wait_for_if_up() {
18971c
     local cnt=0
18971c
     local li
18971c
-    while [ $cnt -lt 200 ]; do
18971c
+    local timeout="$(getargs rd.net.timeout.ifup=)"
18971c
+    timeout=${timeout:-20}
18971c
+    timeout=$(($timeout*10))
18971c
+
18971c
+    while [ $cnt -lt $timeout ]; do
18971c
         li=$(ip -o link show up dev $1)
18971c
         [ -n "$li" ] && [ -z "${li##*state UP*}" ] && return 0
18971c
         sleep 0.1
18971c
@@ -509,7 +517,11 @@ wait_for_if_up() {
18971c
 
18971c
 wait_for_route_ok() {
18971c
     local cnt=0
18971c
-    while [ $cnt -lt 200 ]; do
18971c
+    local timeout="$(getargs rd.net.timeout.route=)"
18971c
+    timeout=${timeout:-20}
18971c
+    timeout=$(($timeout*10))
18971c
+
18971c
+    while [ $cnt -lt $timeout ]; do
18971c
         li=$(ip route show)
18971c
         [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
18971c
         sleep 0.1
18971c
@@ -521,7 +533,11 @@ wait_for_route_ok() {
18971c
 wait_for_ipv6_dad() {
18971c
     local cnt=0
18971c
     local li
18971c
-    while [ $cnt -lt 500 ]; do
18971c
+    local timeout="$(getargs rd.net.timeout.ipv6dad=)"
18971c
+    timeout=${timeout:-50}
18971c
+    timeout=$(($timeout*10))
18971c
+
18971c
+    while [ $cnt -lt $timeout ]; do
18971c
         li=$(ip -6 addr show dev $1 scope link)
18971c
         strstr "$li" "tentative" || return 0
18971c
         sleep 0.1
18971c
@@ -533,7 +549,11 @@ wait_for_ipv6_dad() {
18971c
 wait_for_ipv6_auto() {
18971c
     local cnt=0
18971c
     local li
18971c
-    while [ $cnt -lt 400 ]; do
18971c
+    local timeout="$(getargs rd.net.timeout.ipv6auto=)"
18971c
+    timeout=${timeout:-40}
18971c
+    timeout=$(($timeout*10))
18971c
+
18971c
+    while [ $cnt -lt $timeout ]; do
18971c
         li=$(ip -6 addr show dev $1)
18971c
         if ! strstr "$li" "tentative"; then
18971c
             strstr "$li" "dynamic" && return 0
18971c
@@ -561,8 +581,12 @@ iface_has_link() {
18971c
     [ -n "$interface" ] || return 2
18971c
     interface="/sys/class/net/$interface"
18971c
     [ -d "$interface" ] || return 2
18971c
+    local timeout="$(getargs rd.net.timeout.carrier=)"
18971c
+    timeout=${timeout:-5}
18971c
+    timeout=$(($timeout*10))
18971c
+
18971c
     linkup "$1"
18971c
-    while [ $cnt -lt 50 ]; do
18971c
+    while [ $cnt -lt $timeout ]; do
18971c
         [ "$(cat $interface/carrier)" = 1 ] && return 0
18971c
         sleep 0.1
18971c
         cnt=$(($cnt+1))