From 3a31a0cef3ad77bf9b055195367fd5217f8595d9 Mon Sep 17 00:00:00 2001 From: brooks Date: Thu, 15 May 2008 01:06:10 +0000 Subject: Change the default value of synchronous_dhclient to NO. To preserve the existing behavior of etc/rc.d/netif, add code to wait up to if_up_delay seconds (30 seconds by default) for a default route to be configured if there are any dhcp interfaces. This should be extended to test that the interface is actually up. X-MFC after: --- etc/defaults/rc.conf | 3 ++- etc/network.subr | 23 +++++++++++++++++++++++ etc/rc.d/netif | 23 +++++++++++++++++++++++ share/man/man5/rc.conf.5 | 8 ++++++-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index bd8ebb5..3d03b04 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -103,7 +103,7 @@ dhclient_flags="" # Extra flags to pass to dhcp client. #dhclient_flags_fxp0="" # Extra dhclient flags for fxp0 only background_dhclient="NO" # Start dhcp client in the background. #background_dhclient_fxp0="YES" # Start dhcp client on fxp0 in the background. -synchronous_dhclient="YES" # Start dhclient directly on configured +synchronous_dhclient="NO" # Start dhclient directly on configured # interfaces during startup. wpa_supplicant_program="/usr/sbin/wpa_supplicant" wpa_supplicant_flags="-s" # Extra flags to pass to wpa_supplicant @@ -178,6 +178,7 @@ tcp_drop_synfin="NO" # Set to YES to drop TCP packets with SYN+FIN icmp_drop_redirect="NO" # Set to YES to ignore ICMP REDIRECT packets icmp_log_redirect="NO" # Set to YES to log ICMP REDIRECT packets network_interfaces="auto" # List of network interfaces (or "auto"). +if_up_delay="30" # Time to wait for interfaces to come up. cloned_interfaces="" # List of cloned network interfaces to create. #cloned_interfaces="gif0 gif1 gif2 gif3" # Pre-cloning GENERIC config. ifconfig_lo0="inet 127.0.0.1" # default loopback device configuration. diff --git a/etc/network.subr b/etc/network.subr index 686f792..0a326b1 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -768,6 +768,29 @@ list_net_interfaces() return 0 } +# get_default_if -address_family +# Get the interface of the default route for the given address family. +# The -address_family argument must be suitable passing to route(8). +# +get_default_if() +{ + routeget="`route -n get $1 default 2>/dev/null`" + oldifs="$IFS" + IFS=" +" + defif= + for line in $routeget ; do + case $line in + *interface:*) + defif=${line##*: } + ;; + esac + done + IFS=${oldifs} + + echo $defif +} + hexdigit() { if [ $1 -lt 10 ]; then diff --git a/etc/rc.d/netif b/etc/rc.d/netif index 8298da4..37e0f13 100644 --- a/etc/rc.d/netif +++ b/etc/rc.d/netif @@ -70,6 +70,29 @@ network_start() # Configure the interface(s). network_common ifn_start + if [ -z "$cmdifn" ]; then + dhcp_interfaces=`list_net_interfaces dhcp` + if [ -n "${dhcp_interfaces}" ]; then + delay=${if_up_delay} + while [ ${delay} -gt 0 ]; do + defif=`get_default_if -inet` + if [ -n "${defif}" ]; then + if [ ${delay} -ne ${if_up_delay} ]; then + echo "($defif)" + fi + break + fi + if [ ${delay} -eq ${if_up_delay} ]; then + echo -n "Waiting for an interface to come up: " + else + echo -n . + fi + sleep 1 + delay=`expr $delay - 1` + done + fi + fi + if [ -f /etc/rc.d/ipfilter ] ; then # Resync ipfilter /etc/rc.d/ipfilter quietresync diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index cf291a5..49f030e 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -393,10 +393,10 @@ only. .It Va synchronous_dhclient .Pq Bt bool Set to -.Dq Li NO +.Dq Li YES to start .Xr dhclient 8 -only in response to interface events and not synchronously at startup. +synchronously at startup. This behavior can be overridden on a per-interface basis by replacing the .Dq Li DHCP @@ -406,6 +406,10 @@ variable with .Dq Li SYNCDHCP or .Dq Li NOSYNCDHCP . +.It Va if_up_delay +.Pq Vt int +When set to a positive value, wait up to this long after configuring +DHCP interfaces at startup to give the interfaces time to receive a lease. .It Va firewall_enable .Pq Vt bool Set to -- cgit v1.1