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.
25 # $FreeBSD: src/etc/rc.d/netif,v 1.2 2003/06/29 05:34:41 mtm Exp $
29 # REQUIRE: cleanvar mountcritlocal serial sppp sysctl tty
36 start_cmd="netif_start"
38 cloneup_cmd="clone_up"
39 clonedown_cmd="clone_down"
40 extra_commands="cloneup clonedown"
45 # Set the list of interfaces to work on.
49 if [ -z "$_cmdifn" ]; then
51 # We're operating as a general network start routine.
54 # Create cloned interfaces
57 # Create IPv6<-->IPv4 tunnels
64 # Configure the interface(s).
65 netif_common ifn_start verbose
67 # Give our interfaces a little time to come up
68 # before we start pounding them, e.g., DHCP client.
74 # Set the list of interfaces to work on.
78 echo -n "Stopping network:"
80 # Deconfigure the interface(s)
85 # netif_common routine verbose
86 # Common configuration subroutine for network interfaces. This
87 # routine takes all the preparatory steps needed for configuring
88 # an interface and then calls $routine. If $verbose is specified,
89 # it will call ifconfig(8) to show, in long format, the configured
90 # interfaces. If $verbose is not given, it will simply output the
91 # configured interface(s).
99 err 1 "netif_common(): No function name specified."
103 [ -n "$2" ] && _verbose=yes
105 # Get a list of network interfaces.
106 _ifn_list="`list_net_interfaces`"
108 # Set the scope of the command (all interfaces or just one).
111 if [ -n "$_cmdifn" ]; then
112 for i in $_cmdifn ; do
113 eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\"
114 if [ -z "$_if" ]; then
115 err 1 "No such network interface: $i"
117 _cooked_list="$_cooked_list $_if"
120 _cooked_list="$_ifn_list"
123 for ifn in ${_cooked_list}; do
124 if ${_func} ${ifn} ; then
131 # Display interfaces configured by this script
133 for ifn in ${_cooked_list}; do
134 eval showstat=\$showstat_${ifn}
135 if [ ! -z ${showstat} ]; then
136 if [ -n "$_verbose" ]; then
137 ifconfig ${ifn} 2>/dev/null
143 debug "The following interfaces were not configured: $_fail"
147 # Bring up and configure an interface.
155 [ -z "$ifn" ] && err 1 "ifn_start called without an interface"
157 ifscript_up ${ifn} && cfg=0
158 ifconfig_up ${ifn} && cfg=0
159 ifalias_up ${ifn} && cfg=0
160 childif_create ${ifn} && cfg=0
166 # Shutdown and de-configure an interface.
174 [ -z "$ifn" ] && err 1 "ifn_stop called without an interface"
176 ifalias_down ${ifn} && cfg=0
177 ifconfig_down ${ifn} && cfg=0
178 ifscript_down ${ifn} && cfg=0
179 childif_destroy ${ifn} && cfg=0
185 # Create and configure child interfaces. Return 0 if child
186 # interfaces are created.
190 local cfg child child_vlans child_wlans create_args debug_flags ifn i
194 # Create wireless interfaces
195 child_wlans=`get_if_var $ifn wlans_IF`
197 for child in ${child_wlans}; do
198 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
199 debug_flags="`get_if_var $child wlandebug_IF`"
201 if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then
202 ifconfig $child create ${create_args} && cfg=0
203 if [ -n "${debug_flags}" ]; then
204 wlandebug -i $child ${debug_flags}
207 i=`ifconfig wlan create ${create_args}`
208 if [ -n "${debug_flags}" ]; then
209 wlandebug -i $i ${debug_flags}
211 ifconfig $i name $child && cfg=0
216 # Create vlan interfaces
217 child_vlans=`get_if_var $ifn vlans_IF`
219 for child in ${child_vlans}; do
220 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
221 child="${ifn}.${child}"
222 create_args=`get_if_var $child create_args_IF`
223 ifconfig $child create ${create_args} && cfg=0
225 create_args="vlandev $ifn `get_if_var $child create_args_IF`"
226 if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
227 ifconfig $child create ${create_args} && cfg=0
229 i=`ifconfig vlan create ${create_args}`
230 ifconfig $i name $child && cfg=0
240 # Destroy child interfaces.
244 local cfg child child_vlans child_wlans ifn
247 child_wlans=`get_if_var $ifn wlans_IF`
248 for child in ${child_wlans}; do
249 if ! `ifconfig -n $child > /dev/null 2>&1`; then
253 ifconfig $child destroy && cfg=0
259 # Load the old "network" config file also for compatibility
260 load_rc_config network