sbin/*hammer: Use typedef'd for struct zone_stat*
[dragonfly.git] / etc / rc.d / netif
blob222220ba4daca2b030cab7c6d2235a3e8d54f47f
1 #!/bin/sh
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
7 # are met:
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 $
28 # PROVIDE: netif
29 # REQUIRE: cleanvar mountcritlocal serial sppp sysctl tty
31 . /etc/rc.subr
32 . /etc/network.subr
34 name="network"
35 start_cmd="network_start"
36 stop_cmd="network_stop"
37 cloneup_cmd="clone_up"
38 clonedown_cmd="clone_down"
39 extra_commands="cloneup clonedown"
40 _cmdifn=
42 network_start()
44 # Set the list of interfaces to work on.
46 _cmdifn=$*
48 if [ -z "$_cmdifn" ]; then
50 # We're operating as a general network start routine.
53 # Create cloned interfaces
54 clone_up
56 # Create IPv6<-->IPv4 tunnels
57 gif_up
59 # Rename interfaces.
60 ifnet_rename
63 # Configure the interface(s).
64 network_common ifn_start verbose
66 # Give our interfaces a little time to come up
67 # before we start pounding them. In particular, dhclient
68 # and named can get mightily confused.
69 sleep 2
72 network_stop()
74 # Set the list of interfaces to work on.
76 _cmdifn=$*
78 echo -n "Stopping network:"
80 # Deconfigure the interface(s)
81 network_common ifn_stop
82 echo '.'
85 # network_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).
92 network_common()
94 _func=
95 _verbose=
97 if [ -z "$1" ]; then
98 err 1 "network_common(): No function name specified."
99 else
100 _func="$1"
102 [ -n "$2" ] && _verbose=yes
104 # Get a list of network interfaces.
105 _ifn_list="`list_net_interfaces`"
107 # Set the scope of the command (all interfaces or just one).
109 _cooked_list=
110 if [ -n "$_cmdifn" ]; then
111 for i in $_cmdifn ; do
112 eval _if=\"`expr "$_ifn_list" : ".*\(${i}\).*"`\"
113 if [ -z "$_if" ]; then
114 err 1 "No such network interface: $i"
116 _cooked_list="$_cooked_list $_if"
117 done
118 else
119 _cooked_list="$_ifn_list"
122 for ifn in ${_cooked_list}; do
123 if ${_func} ${ifn} ; then
124 eval showstat_$ifn=1
125 else
126 _fail="$_fail $ifn"
128 done
130 # Display interfaces configured by this script
132 for ifn in ${_cooked_list}; do
133 eval showstat=\$showstat_${ifn}
134 if [ ! -z ${showstat} ]; then
135 if [ -n "$_verbose" ]; then
136 ifconfig ${ifn} 2>/dev/null
137 else
138 echo -n " ${ifn}"
141 done
142 debug "The following interfaces were not configured: $_fail"
145 ifn_start()
147 local ifn cfg
148 ifn="$1"
149 cfg=1
151 [ -z "$ifn" ] && return 1
153 ifscript_up ${ifn} && cfg=0
154 ifconfig_up ${ifn} && cfg=0
155 ifalias_up ${ifn} && cfg=0
156 childif_create ${ifn} && cfg=0
158 return $cfg
161 ifn_stop()
163 local ifn cfg
164 ifn="$1"
165 cfg=1
167 [ -z "$ifn" ] && return 1
169 ifalias_down ${ifn} && cfg=0
170 ifconfig_down ${ifn} && cfg=0
171 ifscript_down ${ifn} && cfg=0
172 childif_destroy ${ifn} && cfg=0
174 return $cfg
177 # childif_create
178 # Create and configure child interfaces. Return 0 if child
179 # interfaces are created.
181 childif_create()
183 local cfg child child_vlans child_wlans create_args debug_flags ifn i
184 cfg=1
185 ifn=$1
187 # Create wireless interfaces
188 child_wlans=`get_if_var $ifn wlans_IF`
190 for child in ${child_wlans}; do
191 create_args="wlandev $ifn `get_if_var $child create_args_IF`"
192 debug_flags="`get_if_var $child wlandebug_IF`"
194 if expr $child : 'wlan[0-9][0-9]*$' >/dev/null 2>&1; then
195 ifconfig $child create ${create_args} && cfg=0
196 if [ -n "${debug_flags}" ]; then
197 wlandebug -i $child ${debug_flags}
199 else
200 i=`ifconfig wlan create ${create_args}`
201 if [ -n "${debug_flags}" ]; then
202 wlandebug -i $i ${debug_flags}
204 ifconfig $i name $child && cfg=0
206 ifn_start $child
207 done
209 # Create vlan interfaces
210 child_vlans=`get_if_var $ifn vlans_IF`
212 for child in ${child_vlans}; do
213 if expr $child : '[1-9][0-9]*$' >/dev/null 2>&1; then
214 child="${ifn}.${child}"
215 create_args=`get_if_var $child create_args_IF`
216 ifconfig $child create ${create_args} && cfg=0
217 else
218 create_args="vlandev $ifn `get_if_var $child create_args_IF`"
219 if expr $child : 'vlan[0-9][0-9]*$' >/dev/null 2>&1; then
220 ifconfig $child create ${create_args} && cfg=0
221 else
222 i=`ifconfig vlan create ${create_args}`
223 ifconfig $i name $child && cfg=0
226 ifn_start $child
227 done
229 return ${cfg}
232 # childif_destroy
233 # Destroy child interfaces.
235 childif_destroy()
237 local cfg child child_vlans child_wlans ifn
238 cfg=1
240 child_wlans=`get_if_var $ifn wlans_IF`
241 for child in ${child_wlans}; do
242 if ! `ifconfig -n $child > /dev/null 2>&1`; then
243 continue
245 ifn_stop $child
246 ifconfig $child destroy && cfg=0
247 done
249 return ${cfg}
252 load_rc_config $name
253 run_rc_command $*