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 start_cmd="network_start"
38 stop_cmd="network_stop"
39 cloneup_cmd="clone_up"
40 clonedown_cmd="clone_down"
43 vnetdown_cmd="vnet_down"
44 extra_commands="cloneup clonedown clear vnetup vnetdown"
47 set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
48 set_rcvar_obsolete ipv6_prefer
54 # Set the list of interfaces to work on.
58 if [ -z "$cmdifn" ]; then
60 # We're operating as a general network start routine.
63 # disable SIGINT (Ctrl-c) when running at startup
66 # Create Fast EtherChannel interfaces
70 # Create cloned interfaces
76 # Configure the interface(s).
77 network_common ifn_start $cmdifn
79 if [ -f /etc/rc.d/ipfilter ] ; then
81 /etc/rc.d/ipfilter quietresync
83 if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
84 /etc/rc.d/bridge start $cmdifn
86 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
87 for _if in $cmdifn; do
88 /etc/rc.d/routing start any $_if
109 # Set the list of interfaces to work on.
113 # Deconfigure the interface(s)
114 network_common ifn_stop $cmdifn
116 # Destroy cloned interfaces
117 if [ -n "$_clone_down" ]; then
121 if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then
122 for _if in $cmdifn; do
123 /etc/rc.d/routing stop any $_if
132 network_common ifn_vnetup $cmdifn
139 network_common ifn_vnetdown $cmdifn
142 # network_common routine
143 # Common configuration subroutine for network interfaces. This
144 # routine takes all the preparatory steps needed for configuriing
145 # an interface and then calls $routine.
148 local _cooked_list _tmp_list _fail _func _ok _str _cmdifn
153 err 1 "network_common(): No function name specified."
159 # Set the scope of the command (all interfaces or just one).
164 if [ -n "$_cmdifn" ]; then
165 # Don't check that the interface(s) exist. We need to run
166 # the down code even when the interface doesn't exist to
167 # kill off wpa_supplicant.
168 # XXXBED: is this really true or does wpa_supplicant die?
169 # if so, we should get rid of the devd entry
170 _cooked_list="$_cmdifn"
172 _cooked_list="`list_net_interfaces`"
175 # Expand epair[0-9] to epair[0-9][ab].
176 for ifn in $_cooked_list; do
178 [0-9]*[ab]) ;; # Skip epair[0-9]*[ab].
180 for _str in $_cooked_list; do
182 $ifn) _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;;
183 *) _tmp_list="$_tmp_list ${ifn}" ;;
186 _cooked_list=${_tmp_list# }
194 for ifn in ${_cooked_list# }; do
195 # Skip if ifn does not exist.
198 if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
199 warn "$ifn does not exist. Skipped."
200 _fail="${_fail} ${ifn}"
205 if ${_func} ${ifn} $2; then
207 if ipv6if ${ifn}; then
211 _fail="${_fail} ${ifn}"
215 # inet6 address configuration needs sleep for DAD.
216 case ${_func}:${_dadwait} in
217 ifn_start:1|ifn_vnetup:1|ifn_vnetdown:1)
218 sleep `${SYSCTL_N} net.inet6.ip6.dad_count`
224 if [ -n "${_ok}" ]; then
239 echo "${_str} Network:${_ok}."
242 # Clear _ok not to do "ifconfig $ifn"
243 # because $ifn is no longer in the current vnet.
247 if check_startmsgs; then
248 for ifn in ${_ok}; do
249 /sbin/ifconfig ${ifn}
254 debug "The following interfaces were not configured: $_fail"