Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 25 Sep 2010 13:31:05 -0500
From:      Brooks Davis <brooks@freebsd.org>
To:        Ed Maste <emaste@freebsd.org>
Cc:        freebsd-rc@freebsd.org
Subject:   Re: Wait for carrier in /etc/rc.d/defaultroute
Message-ID:  <20100925183105.GI72897@lor.one-eyed-alien.net>
In-Reply-To: <20100925000435.GA62501@sandvine.com>
References:  <20100925000435.GA62501@sandvine.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--o71xDhNo7p97+qVi
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Fri, Sep 24, 2010 at 08:04:35PM -0400, Ed Maste wrote:
> /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=20
> happened.  The rest of rc.d/ ran then before DHCP could assign an
> address and route.
>=20
> 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=20
> carrier.  The original 30 second wait for a default route to appear is
> unchanged.
>=20
> Any comments?  I'll commit it sometime next week if there's no concern.

This seems like a reasionable solution.  Just checking for carrier
didn't work as well as I'd hoped.  Have you tested this on a bridge or
similar interface?

It seems like in some senses there's probably something more the nic
could be telling us about it's state so we could do a better job here.
What we really want to know is if we have any dhcp interfaces that have
a chance of getting a lease any time soon so if the interface could say "I =
think I've got a
cable attached" that would be useful.

-- Brooks

> -Ed

> Index: etc/defaults/rc.conf
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- etc/defaults/rc.conf	(revision 213127)
> +++ etc/defaults/rc.conf	(working copy)
> @@ -108,6 +108,7 @@
>  synchronous_dhclient=3D"NO"	# Start dhclient directly on configured
>  				# interfaces during startup.
>  defaultroute_delay=3D"30"		# Time to wait for a default route on a DHCP =
interface.
> +defaultroute_carrier_delay=3D"5"	# Time to wait for carrier while waitin=
g for a default route.
>  wpa_supplicant_program=3D"/usr/sbin/wpa_supplicant"
>  wpa_supplicant_flags=3D"-s"	# Extra flags to pass to wpa_supplicant
>  wpa_supplicant_conf_file=3D"/etc/wpa_supplicant.conf"
> Index: etc/rc.d/defaultroute
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> --- 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=3D"defaultroute_start"
>  stop_cmd=3D":"
> =20
> +# Does any interface have a carrier?
> +defaultroute_carrier()
> +{
> +	local carrier nocarrier
> +
> +	carrier=3D1
> +	for _if in ${dhcp_interfaces}; do
> +		output=3D`/sbin/ifconfig ${_if}`
> +		nocarrier=3D`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'`
> +		[ -z "${nocarrier}" ] && carrier=3D0
> +	done
> +	return ${carrier}
> +}
> +
>  defaultroute_start()
>  {
> -	local output carrier nocarrier nl
> +	local nl waited
> =20
>  	afexists inet || return 0
> =20
> @@ -26,35 +40,30 @@
>  	# if none of the dhcp interfaces is plugged in.
>  	dhcp_interfaces=3D`list_net_interfaces dhcp`
>  	[ -z "${dhcp_interfaces}" ] && return
> -	carrier=3Dfalse
> -	for _if in ${dhcp_interfaces}; do
> -		output=3D`/sbin/ifconfig ${_if}`
> -		nocarrier=3D`expr "${output}" : '.*[[:blank:]]status: \(no carrier\)'`
> -		[ -z "${nocarrier}" ] && carrier=3Dtrue
> -	done
> -	if ! ${carrier}; then
> -		return
> -	fi
> =20
>  	# Wait for a default route
> -	delay=3D${defaultroute_delay}
> -	while [ ${delay} -gt 0 ]; do
> +	waited=3D0
> +	while [ ${waited} -lt ${defaultroute_delay} ]; do
>  		defif=3D`get_default_if -inet`
>  		if [ -n "${defif}" ]; then
> -			if [ ${delay} -ne ${defaultroute_delay} ]; then
> +			if [ ${waited} -ne 0 ]; then
>  				echo -n "($defif)"
>  				nl=3D1
>  			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 interfa=
ce: "
>  		else
>  			echo -n .
>  		fi
> +		if [ ${waited} -eq ${defaultroute_carrier_delay} ] && ! defaultroute_c=
arrier; then
> +			echo -n "(no carrier)"
> +			break
> +		fi
>  		nl=3D1
>  		sleep 1
> -		delay=3D$(($delay - 1))
> +		waited=3D$(($waited + 1))
>  	done
> =20
>  	[ -n "$nl" ] && echo

> _______________________________________________
> freebsd-rc@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-rc
> To unsubscribe, send any mail to "freebsd-rc-unsubscribe@freebsd.org"


--o71xDhNo7p97+qVi
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

iD8DBQFMnj/oXY6L6fI4GtQRAgcHAKCo8GkQoMu8H5NvSjC/55OVrVz6fQCg1y1y
yhCyGtx6uiIdYyass//u5wo=
=7e3P
-----END PGP SIGNATURE-----

--o71xDhNo7p97+qVi--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100925183105.GI72897>