diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 84e33b9d3f23..32dd8ff26035 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -95,6 +95,8 @@ nisdomainname="NO" # Set to NIS domain if using NIS (or NO). dhclient_program="/sbin/dhclient" # Path to dhcp client program. dhclient_flags="" # Additional flags to pass to dhcp client. background_dhclient="NO" # Start dhcp client in the background. +syncronous_dhclient="YES" # Start dhclient directly on configured + # interfaces during startup. firewall_enable="NO" # Set to YES to enable firewall functionality firewall_script="/etc/rc.firewall" # Which script to run to set up the firewall firewall_type="UNKNOWN" # Firewall type (see /etc/rc.firewall) diff --git a/etc/network.subr b/etc/network.subr index 5eccd53234ef..77c26095934c 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -44,7 +44,7 @@ ifconfig_up() ifconfig_args=`ifconfig_getargs $1` if [ -n "${ifconfig_args}" ]; then ifconfig $1 up - eval "ifconfig $1 ${ifconfig_args}" + ifconfig $1 ${ifconfig_args} _cfg=0 fi @@ -60,7 +60,9 @@ ifconfig_up() if [ $_cfg -ne 0 ] ; then ifconfig $1 up fi - /etc/rc.d/dhclient start $1 + if syncdhcpif $1; then + /etc/rc.d/dhclient start $1 + fi _cfg=0 fi @@ -72,6 +74,8 @@ ifconfig_up() # 0 if inet entries were found and removed. It returns 1 if # no entries were found or they could not be removed. # +# XXX: should not be only inet +# ifconfig_down() { [ -z "$1" ] && return 1 @@ -105,9 +109,36 @@ ifconfig_down() _cfg=0 fi + ifconfig $1 down + return $_cfg } +# get_if_var if var [default] +# Return the value of the pseudo-hash corresponding to $if where +# $var is a string containg the sub-string "IF" which will be +# replaced with $if after the characters defined in _punct are +# replaced with '_'. If the variable is unset, replace it with +# $default if given. +get_if_var() +{ + if [ $# -ne 2 -a $# -ne 3 ]; then + err 3 'USAGE: get_if_var name var [default]' + fi + + _if=$1 + _punct=". - / +" + for _punct_c in $punct; do + _if=`ltr ${_if} ${_punct_c} '_'` + done + _var=$2 + _default=$3 + + prefix=${_var%%IF*} + suffix=${_var##*IF} + eval echo \${${prefix}${_if}${suffix}-${_default}} +} + # _ifconfig_getargs if # Echos the arguments for the supplied interface to stdout. # returns 1 if empty. In general, ifconfig_getargs should be used @@ -119,9 +150,7 @@ _ifconfig_getargs() return 1 fi - eval _args=\${ifconfig_$1-$ifconfig_DEFAULT} - - echo "$_args" + get_if_var $_ifn ifconfig_IF "$ifconfig_DEFAULT" } # ifconfig_getargs if @@ -137,12 +166,11 @@ ifconfig_getargs() for _arg in $_tmpargs; do case $_arg in - [Dd][Hh][Cc][Pp]) - ;; - [Nn][Oo][Aa][Uu][Tt][Oo]) - ;; - [Ww][Pp][Aa]) - ;; + [Dd][Hh][Cc][Pp]) ;; + [Nn][Oo][Aa][Uu][Tt][Oo]) ;; + [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;; + [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) ;; + [Ww][Pp][Aa]) ;; *) _args="$_args $_arg" ;; @@ -178,11 +206,40 @@ dhcpif() [Dd][Hh][Cc][Pp]) return 0 ;; + [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) + return 0 + ;; + [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) + return 0 + ;; esac done return 1 } +# syncdhcpif +# Returns 0 if the interface should be configured synchronously and +# 1 otherwise. +syncdhcpif() +{ + _tmpargs=`_ifconfig_getargs $1` + for _arg in $_tmpargs; do + case $_arg in + [Nn][Oo][Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) + return 1 + ;; + [Ss][Yy][Nn][Cc][Dd][Hh][Cc][Pp]) + return 0 + ;; + esac + done + if checkyesno syncronous_dhclient; then + return 0 + else + return 1 + fi +} + # wpaif if # Returns 0 if the interface is a WPA interface and 1 otherwise. wpaif() @@ -226,7 +283,7 @@ ipv4_addrs_common() _action=$2 # get ipv4-addresses - eval cidr_addr=\${ipv4_addrs_${_if}} + cidr_addr=`get_if_var $_if ipv4_addrs_IF` for _cidr in ${cidr_addr}; do _ipaddr=${_cidr%%/*} @@ -266,7 +323,7 @@ ifalias_up() _ret=1 alias=0 while : ; do - eval ifconfig_args=\$ifconfig_$1_alias${alias} + ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` if [ -n "${ifconfig_args}" ]; then ifconfig $1 ${ifconfig_args} alias alias=$((${alias} + 1)) @@ -288,7 +345,7 @@ ifalias_down() _ret=1 alias=0 while : ; do - eval ifconfig_args=\$ifconfig_$1_alias${alias} + ifconfig_args=`get_if_var $1 ifconfig_IF_alias${alias}` if [ -n "${ifconfig_args}" ]; then ifconfig $1 ${ifconfig_args} -alias alias=$((${alias} + 1)) @@ -367,7 +424,7 @@ gif_up() { ;; *) for i in ${gif_interfaces}; do - eval peers=\$gifconfig_$i + peers=`get_if_var $i gifconfig_IF` case ${peers} in '') continue @@ -391,7 +448,7 @@ gif_up() { ipx_up() { ifn="$1" - eval ifconfig_args=\$ifconfig_${ifn}_ipx + ifconfig_args=`get_if_var $ifn ifconfig_IF_ipx` if [ -n "${ifconfig_args}" ]; then ifconfig ${ifn} ${ifconfig_args} return 0 @@ -438,7 +495,7 @@ ifnet_rename() _ifn_list="`ifconfig -l`" [ -z "$_ifn_list" ] && return 0 for _if in ${_ifn_list} ; do - eval _ifname=\$ifconfig_${_if}_name + _ifname=`get_if_var $_if ifconfig_IF_name` if [ ! -z "$_ifname" ]; then ifconfig $_if name $_ifname fi @@ -499,7 +556,7 @@ list_net_interfaces() if dhcpif $_if; then _dhcplist="${_dhcplist}${_aprefix}${_if}" [ -z "$_aprefix" ] && _aprefix=' ' - elif [ -n "`_ifconfig_getargs $if`" ]; then + elif [ -n "`_ifconfig_getargs $_if`" ]; then _nodhcplist="${_nodhcplist}${_bprefix}${_if}" [ -z "$_bprefix" ] && _bprefix=' ' fi @@ -564,7 +621,7 @@ network6_interface_setup() esac for i in $interfaces; do rtsol_interface=yes - eval prefix=\$ipv6_prefix_$i + prefix=`get_if_var $i ipv6_prefix_IF` if [ -n "${prefix}" ]; then rtsol_available=no rtsol_interface=no @@ -584,7 +641,7 @@ network6_interface_setup() esac done fi - eval ipv6_ifconfig=\$ipv6_ifconfig_$i + ipv6_ifconfig=`get_if_var $i ipv6_ifconfig_IF` if [ -n "${ipv6_ifconfig}" ]; then rtsol_available=no rtsol_interface=no @@ -619,7 +676,7 @@ network6_interface_setup() for i in $interfaces; do alias=0 while : ; do - eval ipv6_ifconfig=\$ipv6_ifconfig_${i}_alias${alias} + ipv6_ifconfig=`get_if_var $i ipv6_ifconfig_IF_alias${alias}` if [ -z "${ipv6_ifconfig}" ]; then break; fi @@ -695,7 +752,7 @@ network6_static_routes_setup() ;; *) for i in ${ipv6_static_routes}; do - eval ipv6_route_args=\$ipv6_route_${i} + ipv6_route_args=`get_if_var $i ipv6_route_IF` route add -inet6 ${ipv6_route_args} done ;; diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index fa05c721d072..587247588606 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -364,6 +364,22 @@ to start the DHCP client in background. This can cause trouble with applications depending on a working network, but it will provide a faster startup in many cases. +.It Va syncronous_dhclient +.Pq Bt bool +Set to +.Dq Li NO +to start +.Xr dhclient 8 +only in response to interface events and not syncronously at startup. +This behavior can be overridden on a per-interface basis by replacing +the +.Dq Li DHCP +keyword in the +.Va ifconfig_ Ns Aq Ar interface +variable with +.Dq Li SYNCDHCP +or +.Dq Li NOSYNCDHCP . .It Va firewall_enable .Pq Vt bool Set to @@ -942,19 +958,25 @@ for more information. Set to the list of network interfaces to configure on this host or .Dq Li AUTO (the default) for all current interfaces. -For example, if the only active network devices in the system -are the loopback device -.Pq Li lo0 -and a NIC using the -.Xr ed 4 -driver, -this could be set to -.Dq Li "lo0 ed0" . +Setting the +.Va network_interfaces +variable to anything other than the default is deprecated. +Interfaces that the administrator wishes to store configration for, +but not start at boot should be configured with the +.Dq Li NOAUTO +keyword in their +.Va ifconfig_ Ns Aq Ar interface +variables as described below. .Pp An .Va ifconfig_ Ns Aq Ar interface variable is also assumed to exist for each value of .Ar interface . +When an interface name contains any of the characters +.Dq Li .-/+ +they are translated to +.Dq Li _ +before lookup. The variable can contain arguments to .Xr ifconfig 8 , as well as special case-insensitive keywords described below.