]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
network: add options to tweak timeouts
authorHarald Hoyer <harald@redhat.com>
Fri, 3 Jul 2015 11:30:40 +0000 (13:30 +0200)
committerHarald Hoyer <harald@redhat.com>
Wed, 11 Nov 2015 14:26:29 +0000 (15:26 +0100)
 rd.net.dhcp.retry=<cnt>
     If this option is set, dracut will try to connect via dhcp
     <cnt> times before failing. Default is 1.

 rd.net.timeout.dhcp=<arg>
     If this option is set, dhclient is called with "-timeout <arg>".

 rd.net.timeout.iflink=<seconds>
     Wait <seconds> until link shows up. Default is 60 seconds.

 rd.net.timeout.ifup=<seconds>
     Wait <seconds> until link has state "UP". Default is 20 seconds.

 rd.net.timeout.route=<seconds>
     Wait <seconds> until route shows up. Default is 20 seconds.

 rd.net.timeout.ipv6dad=<seconds>
     Wait <seconds> until IPv6 DAD is finished. Default is 50 seconds.

 rd.net.timeout.ipv6auto=<seconds>
     Wait <seconds> until IPv6 automatic addresses are assigned.
     Default is 40 seconds.

 rd.net.timeout.carrier=<seconds>
     Wait <seconds> until carrier is recognized. Default is 5 seconds.

(cherry picked from commit d8ad687e1a4c0343eb076902b11aff2b2b2c4b85)

dracut.cmdline.7.asc
modules.d/40network/ifup.sh
modules.d/40network/net-lib.sh

index 8c7e9654bb44b165ab52ce06fbb6a663381ff3d3..d790afd3f2d0f2ea5d7883d2c85f58fe22690df7 100644 (file)
@@ -606,6 +606,31 @@ NFS
 **rd.nfs.domain=**__<NFSv4 domain name>__::
     Set the NFSv4 domain name. Will overwrite the settings in _/etc/idmap.conf_.
 
+**rd.net.dhcp.retry=**__<cnt>__::
+    If this option is set, dracut will try to connect via dhcp <cnt> times before failing.
+    Default is 1.
+
+**rd.net.timeout.dhcp=**__<arg>__::
+    If this option is set, dhclient is called with "-timeout <arg>".
+
+**rd.net.timeout.iflink=**__<seconds>__::
+    Wait <seconds> until link shows up. Default is 60 seconds.
+
+**rd.net.timeout.ifup=**__<seconds>__::
+    Wait <seconds> until link has state "UP". Default is 20 seconds.
+
+**rd.net.timeout.route=**__<seconds>__::
+    Wait <seconds> until route shows up. Default is 20 seconds.
+
+**rd.net.timeout.ipv6dad=**__<seconds>__::
+    Wait <seconds> until IPv6 DAD is finished. Default is 50 seconds.
+
+**rd.net.timeout.ipv6auto=**__<seconds>__::
+    Wait <seconds> until IPv6 automatic addresses are assigned. Default is 40 seconds.
+
+**rd.net.timeout.carrier=**__<seconds>__::
+    Wait <seconds> until carrier is recognized. Default is 5 seconds.
+
 CIFS
 ~~~
 **root=**cifs://[__<username>__[:__<password>__]@]__<server-ip>__:__<root-dir>__::
index 0138e010edc74bbb52dfdc67e1affd234cb4432b..bb20afe2c2b7057136bbdaef5e485918afd66d3f 100755 (executable)
@@ -93,15 +93,33 @@ do_dhcp() {
     # event for nfsroot
     # XXX add -V vendor class and option parsing per kernel
 
+    local _COUNT=0
+    local _timeout=$(getargs rd.net.timeout.dhcp=)
+    local _DHCPRETRY=$(getargs rd.net.dhcp.retry=)
+    _DHCPRETRY=${_DHCPRETRY:-1}
+
     [ -e /tmp/dhclient.$netif.pid ] && return 0
 
     if ! iface_has_link $netif; then
-        echo "No carrier detected"
+        warn "No carrier detected on interface $netif"
         return 1
     fi
-    echo "Starting dhcp for interface $netif"
-    dhclient "$@" -1 -q -cf /etc/dhclient.conf -pf /tmp/dhclient.$netif.pid -lf /tmp/dhclient.$netif.lease $netif \
-        || echo "dhcp failed"
+
+    while [ $_COUNT -lt $_DHCPRETRY ]; do
+        info "Starting dhcp for interface $netif"
+        dhclient "$@" \
+                 ${_timeout:+-timeout $_timeout} \
+                 -1 -q \
+                 -cf /etc/dhclient.conf \
+                 -pf /tmp/dhclient.$netif.pid \
+                 -lf /tmp/dhclient.$netif.lease \
+                 $netif \
+            && return 0
+        _COUNT=$(($_COUNT+1))
+        [ $_COUNT -lt $_DHCPRETRY ] && sleep 1
+    done
+    warn "dhcp for interface $netif failed"
+    return 1
 }
 
 load_ipv6() {
index 2e796191f53c862ea3ae407f74e2efc69ff1a055..2f25de7422215d08e32c2f549934ac871ba47a14 100755 (executable)
@@ -504,7 +504,11 @@ parse_ifname_opts() {
 wait_for_if_link() {
     local cnt=0
     local li
-    while [ $cnt -lt 600 ]; do
+    local timeout="$(getargs rd.net.timeout.iflink=)"
+    timeout=${timeout:-60}
+    timeout=$(($timeout*10))
+
+    while [ $cnt -lt $timeout ]; do
         li=$(ip -o link show dev $1 2>/dev/null)
         [ -n "$li" ] && return 0
         sleep 0.1
@@ -516,7 +520,11 @@ wait_for_if_link() {
 wait_for_if_up() {
     local cnt=0
     local li
-    while [ $cnt -lt 200 ]; do
+    local timeout="$(getargs rd.net.timeout.ifup=)"
+    timeout=${timeout:-20}
+    timeout=$(($timeout*10))
+
+    while [ $cnt -lt $timeout ]; do
         li=$(ip -o link show up dev $1)
         [ -n "$li" ] && [ -z "${li##*state UP*}" ] && return 0
         sleep 0.1
@@ -527,7 +535,11 @@ wait_for_if_up() {
 
 wait_for_route_ok() {
     local cnt=0
-    while [ $cnt -lt 200 ]; do
+    local timeout="$(getargs rd.net.timeout.route=)"
+    timeout=${timeout:-20}
+    timeout=$(($timeout*10))
+
+    while [ $cnt -lt $timeout ]; do
         li=$(ip route show)
         [ -n "$li" ] && [ -z "${li##*$1*}" ] && return 0
         sleep 0.1
@@ -539,7 +551,11 @@ wait_for_route_ok() {
 wait_for_ipv6_dad() {
     local cnt=0
     local li
-    while [ $cnt -lt 500 ]; do
+    local timeout="$(getargs rd.net.timeout.ipv6dad=)"
+    timeout=${timeout:-50}
+    timeout=$(($timeout*10))
+
+    while [ $cnt -lt $timeout ]; do
         li=$(ip -6 addr show dev $1 scope link)
         strstr "$li" "tentative" || return 0
         sleep 0.1
@@ -551,7 +567,11 @@ wait_for_ipv6_dad() {
 wait_for_ipv6_auto() {
     local cnt=0
     local li
-    while [ $cnt -lt 400 ]; do
+    local timeout="$(getargs rd.net.timeout.ipv6auto=)"
+    timeout=${timeout:-40}
+    timeout=$(($timeout*10))
+
+    while [ $cnt -lt $timeout ]; do
         li=$(ip -6 addr show dev $1)
         if ! strstr "$li" "tentative"; then
             strstr "$li" "dynamic" && return 0
@@ -579,8 +599,12 @@ iface_has_link() {
     [ -n "$interface" ] || return 2
     interface="/sys/class/net/$interface"
     [ -d "$interface" ] || return 2
+    local timeout="$(getargs rd.net.timeout.carrier=)"
+    timeout=${timeout:-5}
+    timeout=$(($timeout*10))
+
     linkup "$1"
-    while [ $cnt -lt 50 ]; do
+    while [ $cnt -lt $timeout ]; do
         [ "$(cat $interface/carrier)" = 1 ] && return 0
         sleep 0.1
         cnt=$(($cnt+1))