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: atm1 FILESYSTEMS serial sppp sysctl
30 # REQUIRE: ipfilter ipfs
37 rcvar="${name}_enable"
38 start_cmd="netif_start"
40 cloneup_cmd="clone_up"
41 clonedown_cmd="clone_down"
44 vnetdown_cmd="vnet_down"
45 extra_commands="cloneup clonedown clear vnetup vnetdown"
48 set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
49 set_rcvar_obsolete ipv6_prefer
55 # Set the list of interfaces to work on.
59 if [ -z "$cmdifn" ]; then
61 # We're operating as a general network start routine.
64 # disable SIGINT (Ctrl-c) when running at startup
68 # Create cloned interfaces
74 # Configure the interface(s).
75 netif_common ifn_start $cmdifn
77 if [ -f /etc/rc.d/ipfilter ] ; then
79 /etc/rc.d/ipfilter quietresync
81 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
82 /etc/rc.d/bridge start $cmdifn
84 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
85 for _if in $cmdifn; do
86 /etc/rc.d/routing start any $_if
107 # Set the list of interfaces to work on.
111 # Deconfigure the interface(s)
112 netif_common ifn_stop $cmdifn
114 # Destroy cloned interfaces
115 if [ -n "$_clone_down" ]; then
119 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
120 for _if in $cmdifn; do
121 /etc/rc.d/routing stop any $_if
130 netif_common ifn_vnetup $cmdifn
137 netif_common ifn_vnetdown $cmdifn
140 # netif_common routine
141 # Common configuration subroutine for network interfaces. This
142 # routine takes all the preparatory steps needed for configuriing
143 # an interface and then calls $routine.
146 local _cooked_list _tmp_list _fail _func _ok _str _cmdifn
151 err 1 "netif_common(): No function name specified."
157 # Set the scope of the command (all interfaces or just one).
162 if [ -n "$_cmdifn" ]; then
163 # Don't check that the interface(s) exist. We need to run
164 # the down code even when the interface doesn't exist to
165 # kill off wpa_supplicant.
166 # XXXBED: is this really true or does wpa_supplicant die?
167 # if so, we should get rid of the devd entry
168 _cooked_list="$_cmdifn"
170 _cooked_list="`list_net_interfaces`"
173 # Expand epair[0-9] to epair[0-9][ab].
174 for ifn in $_cooked_list; do
176 [0-9]*[ab]) ;; # Skip epair[0-9]*[ab].
178 for _str in $_cooked_list; do
180 $ifn) _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;;
181 *) _tmp_list="$_tmp_list ${ifn}" ;;
184 _cooked_list=${_tmp_list# }
192 for ifn in ${_cooked_list# }; do
193 # Skip if ifn does not exist.
196 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
197 warn "$ifn does not exist. Skipped."
198 _fail="${_fail} ${ifn}"
203 if ${_func} ${ifn} $2; then
205 if ipv6if ${ifn}; then
209 _fail="${_fail} ${ifn}"
213 # inet6 address configuration needs sleep for DAD.
214 case ${_func}:${_dadwait} in
215 ifn_start:1|ifn_vnetup:1|ifn_vnetdown:1)
216 sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
222 if [ -n "${_ok}" ]; then
237 echo "${_str} Network:${_ok}."
240 # Clear _ok not to do "ifconfig $ifn"
241 # because $ifn is no longer in the current vnet.
245 if check_startmsgs; then
246 for ifn in ${_ok}; do
247 /sbin/ifconfig ${ifn}
252 debug "The following interfaces were not configured: $_fail"