3 # Copyright (c) 2003 The FreeBSD Project. All rights reserved.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions
8 # 1. Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # 2. Redistributions in binary form must reproduce the above copyright
11 # notice, this list of conditions and the following disclaimer in the
12 # documentation and/or other materials provided with the distribution.
14 # THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR
15 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 # IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT,
18 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 # REQUIRE: FILESYSTEMS iovctl serial sppp sysctl
30 # REQUIRE: hostid ipfilter ipfs
37 desc="Network interface setup"
38 rcvar="${name}_enable"
39 start_cmd="netif_start"
42 wlandown_cmd="wlan_down"
43 cloneup_cmd="clone_up"
44 clonedown_cmd="clone_down"
47 vnetdown_cmd="vnet_down"
48 extra_commands="cloneup clonedown clear vnetup vnetdown"
51 set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
52 set_rcvar_obsolete ipv6_prefer
58 # Set the list of interfaces to work on.
62 if [ -z "$cmdifn" ]; then
64 # We're operating as a general network start routine.
67 # disable SIGINT (Ctrl-c) when running at startup
71 # Create IEEE802.11 interface
74 # Create cloned interfaces
80 # Configure the interface(s).
81 netif_common ifn_start $cmdifn
83 if [ -f /etc/rc.d/ipfilter ] ; then
85 /etc/rc.d/ipfilter quietresync
87 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
88 /etc/rc.d/bridge start $cmdifn
90 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
91 for _if in $cmdifn; do
92 /etc/rc.d/routing static any $_if
115 # Set the list of interfaces to work on.
119 # Deconfigure the interface(s)
120 netif_common ifn_stop $cmdifn
122 # Destroy wlan interfaces
123 if [ -n "$_wlan_down" ]; then
127 # Destroy cloned interfaces
128 if [ -n "$_clone_down" ]; then
132 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
133 for _if in $cmdifn; do
134 /etc/rc.d/routing stop any $_if
143 netif_common ifn_vnetup $cmdifn
150 netif_common ifn_vnetdown $cmdifn
153 # netif_common routine
154 # Common configuration subroutine for network interfaces. This
155 # routine takes all the preparatory steps needed for configuriing
156 # an interface and then calls $routine.
159 local _cooked_list _tmp_list _fail _func _ok _str _cmdifn
164 err 1 "netif_common(): No function name specified."
170 # Set the scope of the command (all interfaces or just one).
175 if [ -n "$_cmdifn" ]; then
176 # Don't check that the interface(s) exist. We need to run
177 # the down code even when the interface doesn't exist to
178 # kill off wpa_supplicant.
179 # XXXBED: is this really true or does wpa_supplicant die?
180 # if so, we should get rid of the devd entry
181 _cooked_list="$_cmdifn"
183 _cooked_list="`list_net_interfaces`"
186 # Expand epair[0-9] to epair[0-9][ab].
187 for ifn in $_cooked_list; do
189 [0-9]*[ab]) ;; # Skip epair[0-9]*[ab].
191 for _str in $_cooked_list; do
193 $ifn) _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;;
194 *) _tmp_list="$_tmp_list ${ifn}" ;;
197 _cooked_list=${_tmp_list# }
205 for ifn in ${_cooked_list# }; do
206 # Skip if ifn does not exist.
209 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
210 warn "$ifn does not exist. Skipped."
211 _fail="${_fail} ${ifn}"
216 if ${_func} ${ifn} $2; then
218 if ipv6if ${ifn}; then
222 _fail="${_fail} ${ifn}"
226 # inet6 address configuration needs sleep for DAD.
227 case ${_func}:${_dadwait} in
228 ifn_start:1|ifn_vnetup:1|ifn_vnetdown:1)
229 sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
235 if [ -n "${_ok}" ]; then
250 echo "${_str} Network:${_ok}."
253 # Clear _ok not to do "ifconfig $ifn"
254 # because $ifn is no longer in the current vnet.
258 if check_startmsgs; then
259 for ifn in ${_ok}; do
260 /sbin/ifconfig ${ifn}
265 debug "The following interfaces were not configured: $_fail"
268 # Load the old "network" config file also for compatibility.
269 # This is needed for mfsBSD at least.
270 load_rc_config network