diff options
author | emaste <emaste@FreeBSD.org> | 2010-09-29 13:08:23 +0000 |
---|---|---|
committer | emaste <emaste@FreeBSD.org> | 2010-09-29 13:08:23 +0000 |
commit | 0c4cfaf196bd2a404ceace72c44657c50e016f80 (patch) | |
tree | b86d5b0c78ee6aad3d7bbc3257a813c29ccbcfa7 /etc/rc.d/defaultroute | |
parent | d9c87b0853c67c042a8a1d6b29c69542823e701f (diff) | |
download | FreeBSD-src-0c4cfaf196bd2a404ceace72c44657c50e016f80.zip FreeBSD-src-0c4cfaf196bd2a404ceace72c44657c50e016f80.tar.gz |
/etc/rc.d/defaultroute currently bails immediately if all interfaces
set to use DHCP have no carrier. This can cause grief as it may take
some time for link to be established, and defaultroute may terminate
before this happens.
Introduce a defaultroute_carrier_delay variable and then wait that long
in defaultroute before bailing if no interfaces have carrier. With the
default settings defaultroute will wait for five seconds for this, and
the original 30 second wait for a default route to appear is unchanged.
Note that there is in discussion an alternative approach to the broader
problem of waiting for DHCP-configured routes. However, this change
addresses a real problem in the current defaultroute script.
Discussed on: freebsd-rc@
Diffstat (limited to 'etc/rc.d/defaultroute')
-rwxr-xr-x | etc/rc.d/defaultroute | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/etc/rc.d/defaultroute b/etc/rc.d/defaultroute index 647dc41..ea54c83 100755 --- a/etc/rc.d/defaultroute +++ b/etc/rc.d/defaultroute @@ -1,6 +1,6 @@ #!/bin/sh # -# Wait for the default route to be up +# Wait for the default route to be up if DHCP is in use # # $FreeBSD$ # @@ -16,9 +16,23 @@ name="defaultroute" start_cmd="defaultroute_start" stop_cmd=":" +# Does any interface have a carrier? +defaultroute_carrier() +{ + local carrier nocarrier + + carrier=1 + for _if in ${dhcp_interfaces}; do + output=`/sbin/ifconfig ${_if}` + nocarrier=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'` + [ -z "${nocarrier}" ] && carrier=0 + done + return ${carrier} +} + defaultroute_start() { - local output carrier nocarrier nl + local nl waited afexists inet || return 0 @@ -26,35 +40,30 @@ defaultroute_start() # if none of the dhcp interfaces is plugged in. dhcp_interfaces=`list_net_interfaces dhcp` [ -z "${dhcp_interfaces}" ] && return - carrier=false - for _if in ${dhcp_interfaces}; do - output=`/sbin/ifconfig ${_if}` - nocarrier=`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'` - [ -z "${nocarrier}" ] && carrier=true - done - if ! ${carrier}; then - return - fi # Wait for a default route - delay=${defaultroute_delay} - while [ ${delay} -gt 0 ]; do + waited=0 + while [ ${waited} -lt ${defaultroute_delay} ]; do defif=`get_default_if -inet` if [ -n "${defif}" ]; then - if [ ${delay} -ne ${defaultroute_delay} ]; then + if [ ${waited} -ne 0 ]; then echo -n "($defif)" nl=1 fi break fi - if [ ${delay} -eq ${defaultroute_delay} ]; then - echo -n "Waiting ${delay}s for the default route interface: " + if [ ${waited} -eq 0 ]; then + echo -n "Waiting ${defaultroute_delay}s for the default route interface: " else echo -n . fi + if [ ${waited} -eq ${defaultroute_carrier_delay} ] && ! defaultroute_carrier; then + echo -n "(no carrier)" + break + fi nl=1 sleep 1 - delay=$(($delay - 1)) + waited=$(($waited + 1)) done [ -n "$nl" ] && echo |