From owner-freebsd-rc@FreeBSD.ORG Sat Sep 25 00:15:25 2010 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B9FC41065673 for ; Sat, 25 Sep 2010 00:15:25 +0000 (UTC) (envelope-from emaste@freebsd.org) Received: from mail1.sandvine.com (Mail1.sandvine.com [64.7.137.134]) by mx1.freebsd.org (Postfix) with ESMTP id 656898FC0A for ; Sat, 25 Sep 2010 00:15:25 +0000 (UTC) Received: from labgw2.phaedrus.sandvine.com (192.168.222.22) by WTL-EXCH-1.sandvine.com (192.168.196.31) with Microsoft SMTP Server id 14.0.694.0; Fri, 24 Sep 2010 20:04:35 -0400 Received: by labgw2.phaedrus.sandvine.com (Postfix, from userid 10332) id 9979F33C00; Fri, 24 Sep 2010 20:04:35 -0400 (EDT) Date: Fri, 24 Sep 2010 20:04:35 -0400 From: Ed Maste To: Message-ID: <20100925000435.GA62501@sandvine.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="LZvS9be/3tNcYl/X" Content-Disposition: inline User-Agent: Mutt/1.4.2.1i Subject: Wait for carrier in /etc/rc.d/defaultroute X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 25 Sep 2010 00:15:25 -0000 --LZvS9be/3tNcYl/X Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline /etc/rc.d/defaultroute currently bails immediately if all interfaces set to use DHCP have no carrier. This caused grief at work as it takes some time for link to be established, and defaultroute ran before this happened. The rest of rc.d/ ran then before DHCP could assign an address and route. The attached patch introduces a defaultroute_carrier_delay variable and a change to /etc/rc.d/defaultroute to wait that long before bailing out if there are no interfaces with carrier. With the default settings defaultroute will wait for five seconds to see if any interface gets carrier. The original 30 second wait for a default route to appear is unchanged. Any comments? I'll commit it sometime next week if there's no concern. -Ed --LZvS9be/3tNcYl/X Content-Type: text/plain; charset="us-ascii" Content-Disposition: attachment; filename="defaultroute.patch" Index: etc/defaults/rc.conf =================================================================== --- etc/defaults/rc.conf (revision 213127) +++ etc/defaults/rc.conf (working copy) @@ -108,6 +108,7 @@ synchronous_dhclient="NO" # Start dhclient directly on configured # interfaces during startup. defaultroute_delay="30" # Time to wait for a default route on a DHCP interface. +defaultroute_carrier_delay="5" # Time to wait for carrier while waiting for a default route. wpa_supplicant_program="/usr/sbin/wpa_supplicant" wpa_supplicant_flags="-s" # Extra flags to pass to wpa_supplicant wpa_supplicant_conf_file="/etc/wpa_supplicant.conf" Index: etc/rc.d/defaultroute =================================================================== --- etc/rc.d/defaultroute (revision 213127) +++ etc/rc.d/defaultroute (working copy) @@ -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 @@ 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 @@ # 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 --LZvS9be/3tNcYl/X--