]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - etc/rc.d/netif
Remove explicit inclusion of lpd from FILES
[FreeBSD/FreeBSD.git] / etc / rc.d / netif
1 #!/bin/sh
2 #
3 # Copyright (c) 2003 The FreeBSD Project. All rights reserved.
4 #
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.
13 #
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.
24 #
25 # $FreeBSD$
26 #
27
28 # PROVIDE: netif
29 # REQUIRE: atm1 FILESYSTEMS serial sppp sysctl
30 # REQUIRE: ipfilter ipfs
31 # KEYWORD: nojailvnet
32
33 . /etc/rc.subr
34 . /etc/network.subr
35
36 name="netif"
37 rcvar="${name}_enable"
38 start_cmd="netif_start"
39 stop_cmd="netif_stop"
40 cloneup_cmd="clone_up"
41 clonedown_cmd="clone_down"
42 clear_cmd="doclear"
43 vnetup_cmd="vnet_up"
44 vnetdown_cmd="vnet_down"
45 extra_commands="cloneup clonedown clear vnetup vnetdown"
46 cmdifn=
47
48 set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces
49 set_rcvar_obsolete ipv6_prefer
50
51 netif_start()
52 {
53         local _if
54
55         # Set the list of interfaces to work on.
56         #
57         cmdifn=$*
58
59         if [ -z "$cmdifn" ]; then
60                 #
61                 # We're operating as a general network start routine.
62                 #
63
64                 # disable SIGINT (Ctrl-c) when running at startup
65                 trap : 2
66         fi
67
68         # Create cloned interfaces
69         clone_up $cmdifn
70
71         # Rename interfaces.
72         ifnet_rename $cmdifn
73
74         # Configure the interface(s).
75         netif_common ifn_start $cmdifn
76
77         if [ -f /etc/rc.d/ipfilter ] ; then
78                 # Resync ipfilter
79                 /etc/rc.d/ipfilter quietresync
80         fi
81         if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then
82                 /etc/rc.d/bridge start $cmdifn
83         fi
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
87                 done
88         fi
89 }
90
91 netif_stop()
92 {
93         _clone_down=1
94         netif_stop0 $*
95 }
96
97 doclear()
98 {
99         _clone_down=
100         netif_stop0 $*
101 }
102
103 netif_stop0()
104 {
105         local _if
106
107         # Set the list of interfaces to work on.
108         #
109         cmdifn=$*
110
111         # Deconfigure the interface(s)
112         netif_common ifn_stop $cmdifn
113
114         # Destroy cloned interfaces
115         if [ -n "$_clone_down" ]; then
116                 clone_down $cmdifn
117         fi
118
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
122                 done
123         fi
124 }
125
126 vnet_up()
127 {
128         cmdifn=$*
129
130         netif_common ifn_vnetup $cmdifn
131 }
132
133 vnet_down()
134 {
135         cmdifn=$*
136
137         netif_common ifn_vnetdown $cmdifn
138 }
139
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.
144 netif_common()
145 {
146         local _cooked_list _tmp_list _fail _func _ok _str _cmdifn
147
148         _func=
149
150         if [ -z "$1" ]; then
151                 err 1 "netif_common(): No function name specified."
152         else
153                 _func="$1"
154                 shift
155         fi
156
157         # Set the scope of the command (all interfaces or just one).
158         #
159         _cooked_list=
160         _tmp_list=
161         _cmdifn=$*
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"
169         else
170                 _cooked_list="`list_net_interfaces`"
171         fi
172
173         # Expand epair[0-9] to epair[0-9][ab].
174         for ifn in $_cooked_list; do
175         case ${ifn#epair} in
176         [0-9]*[ab])     ;;      # Skip epair[0-9]*[ab].
177         [0-9]*)
178                 for _str in $_cooked_list; do
179                 case $_str in
180                 $ifn)   _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;;
181                 *)      _tmp_list="$_tmp_list ${ifn}" ;;
182                 esac
183                 done
184                 _cooked_list=${_tmp_list# }
185         ;;
186         esac
187         done
188
189         _dadwait=
190         _fail=
191         _ok=
192         for ifn in ${_cooked_list# }; do
193                 # Skip if ifn does not exist.
194                 case $_func in
195                 ifn_stop)
196                         if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then
197                                 warn "$ifn does not exist.  Skipped."
198                                 _fail="${_fail} ${ifn}"
199                                 continue
200                         fi
201                 ;;
202                 esac
203                 if ${_func} ${ifn} $2; then
204                         _ok="${_ok} ${ifn}"
205                         if ipv6if ${ifn}; then
206                                 _dadwait=1
207                         fi
208                 else
209                         _fail="${_fail} ${ifn}"
210                 fi
211         done
212
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`
217                 sleep 1
218         ;;
219         esac
220
221         _str=
222         if [ -n "${_ok}" ]; then
223                 case ${_func} in
224                 ifn_start)
225                         _str='Starting'
226                 ;;
227                 ifn_stop)
228                         _str='Stopping'
229                 ;;
230                 ifn_vnetup)
231                         _str='Moving'
232                 ;;
233                 ifn_vnetdown)
234                         _str='Reclaiming'
235                 ;;
236                 esac
237                 echo "${_str} Network:${_ok}."
238                 case ${_func} in
239                 ifn_vnetup)
240                         # Clear _ok not to do "ifconfig $ifn"
241                         # because $ifn is no longer in the current vnet.
242                         _ok=
243                 ;;
244                 esac
245                 if check_startmsgs; then
246                         for ifn in ${_ok}; do
247                                 /sbin/ifconfig ${ifn}
248                         done
249                 fi
250         fi
251
252         debug "The following interfaces were not configured: $_fail"
253 }
254
255 load_rc_config $name
256 run_rc_command $*