Lines 1-272
Link Here
|
1 |
#!/bin/sh |
1 |
#!/bin/sh |
2 |
# |
2 |
# |
3 |
# Copyright (c) 2003 The FreeBSD Project. All rights reserved. |
3 |
# Copyright (c) 2003 The FreeBSD Project. All rights reserved. |
4 |
# |
4 |
# |
5 |
# Redistribution and use in source and binary forms, with or without |
5 |
# Redistribution and use in source and binary forms, with or without |
6 |
# modification, are permitted provided that the following conditions |
6 |
# modification, are permitted provided that the following conditions |
7 |
# are met: |
7 |
# are met: |
8 |
# 1. Redistributions of source code must retain the above copyright |
8 |
# 1. Redistributions of source code must retain the above copyright |
9 |
# notice, this list of conditions and the following disclaimer. |
9 |
# notice, this list of conditions and the following disclaimer. |
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
10 |
# 2. Redistributions in binary form must reproduce the above copyright |
11 |
# notice, this list of conditions and the following disclaimer in the |
11 |
# notice, this list of conditions and the following disclaimer in the |
12 |
# documentation and/or other materials provided with the distribution. |
12 |
# documentation and/or other materials provided with the distribution. |
13 |
# |
13 |
# |
14 |
# THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR |
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 |
15 |
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
16 |
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
16 |
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
17 |
# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, |
17 |
# IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, |
18 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
18 |
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
19 |
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
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 |
20 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
21 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
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 |
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. |
23 |
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 |
# |
24 |
# |
25 |
# $FreeBSD$ |
25 |
# $FreeBSD$ |
26 |
# |
26 |
# |
27 |
|
27 |
|
28 |
# PROVIDE: netif |
28 |
# PROVIDE: netif |
29 |
# REQUIRE: FILESYSTEMS iovctl serial sppp sysctl |
29 |
# REQUIRE: FILESYSTEMS iovctl serial sppp sysctl |
30 |
# REQUIRE: hostid ipfs |
30 |
# REQUIRE: hostid ipfs |
31 |
# KEYWORD: nojailvnet shutdown |
31 |
# KEYWORD: nojailvnet |
32 |
|
32 |
|
33 |
. /etc/rc.subr |
33 |
. /etc/rc.subr |
34 |
. /etc/network.subr |
34 |
. /etc/network.subr |
35 |
|
35 |
|
36 |
name="netif" |
36 |
name="netif" |
37 |
desc="Network interface setup" |
37 |
desc="Network interface setup" |
38 |
rcvar="${name}_enable" |
38 |
rcvar="${name}_enable" |
39 |
start_cmd="netif_start" |
39 |
start_cmd="netif_start" |
40 |
stop_cmd="netif_stop" |
40 |
stop_cmd="netif_stop" |
41 |
wlanup_cmd="wlan_up" |
41 |
wlanup_cmd="wlan_up" |
42 |
wlandown_cmd="wlan_down" |
42 |
wlandown_cmd="wlan_down" |
43 |
cloneup_cmd="clone_up" |
43 |
cloneup_cmd="clone_up" |
44 |
clonedown_cmd="clone_down" |
44 |
clonedown_cmd="clone_down" |
45 |
clear_cmd="doclear" |
45 |
clear_cmd="doclear" |
46 |
vnetup_cmd="vnet_up" |
46 |
vnetup_cmd="vnet_up" |
47 |
vnetdown_cmd="vnet_down" |
47 |
vnetdown_cmd="vnet_down" |
48 |
extra_commands="cloneup clonedown clear vnetup vnetdown" |
48 |
extra_commands="cloneup clonedown clear vnetup vnetdown" |
49 |
cmdifn= |
49 |
cmdifn= |
50 |
|
50 |
|
51 |
set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces |
51 |
set_rcvar_obsolete ipv6_enable ipv6_activate_all_interfaces |
52 |
set_rcvar_obsolete ipv6_prefer |
52 |
set_rcvar_obsolete ipv6_prefer |
53 |
|
53 |
|
54 |
netif_start() |
54 |
netif_start() |
55 |
{ |
55 |
{ |
56 |
local _if |
56 |
local _if |
57 |
|
57 |
|
58 |
# Set the list of interfaces to work on. |
58 |
# Set the list of interfaces to work on. |
59 |
# |
59 |
# |
60 |
cmdifn=$* |
60 |
cmdifn=$* |
61 |
|
61 |
|
62 |
if [ -z "$cmdifn" ]; then |
62 |
if [ -z "$cmdifn" ]; then |
63 |
# |
63 |
# |
64 |
# We're operating as a general network start routine. |
64 |
# We're operating as a general network start routine. |
65 |
# |
65 |
# |
66 |
|
66 |
|
67 |
# disable SIGINT (Ctrl-c) when running at startup |
67 |
# disable SIGINT (Ctrl-c) when running at startup |
68 |
trap : 2 |
68 |
trap : 2 |
69 |
fi |
69 |
fi |
70 |
|
70 |
|
71 |
# Create IEEE802.11 interface |
71 |
# Create IEEE802.11 interface |
72 |
wlan_up $cmdifn |
72 |
wlan_up $cmdifn |
73 |
|
73 |
|
74 |
# Create cloned interfaces |
74 |
# Create cloned interfaces |
75 |
clone_up $cmdifn |
75 |
clone_up $cmdifn |
76 |
|
76 |
|
77 |
# Rename interfaces. |
77 |
# Rename interfaces. |
78 |
ifnet_rename $cmdifn |
78 |
ifnet_rename $cmdifn |
79 |
|
79 |
|
80 |
# Configure the interface(s). |
80 |
# Configure the interface(s). |
81 |
netif_common ifn_start $cmdifn |
81 |
netif_common ifn_start $cmdifn |
82 |
|
82 |
|
83 |
if [ -f /etc/rc.d/ipfilter ] ; then |
83 |
if [ -f /etc/rc.d/ipfilter ] ; then |
84 |
# Resync ipfilter |
84 |
# Resync ipfilter |
85 |
/etc/rc.d/ipfilter quietresync |
85 |
/etc/rc.d/ipfilter quietresync |
86 |
fi |
86 |
fi |
87 |
if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then |
87 |
if [ -f /etc/rc.d/bridge -a -n "$cmdifn" ] ; then |
88 |
/etc/rc.d/bridge start $cmdifn |
88 |
/etc/rc.d/bridge start $cmdifn |
89 |
fi |
89 |
fi |
90 |
if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then |
90 |
if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then |
91 |
for _if in $cmdifn; do |
91 |
for _if in $cmdifn; do |
92 |
/etc/rc.d/routing static any $_if |
92 |
/etc/rc.d/routing static any $_if |
93 |
done |
93 |
done |
94 |
fi |
94 |
fi |
95 |
} |
95 |
} |
96 |
|
96 |
|
97 |
netif_stop() |
97 |
netif_stop() |
98 |
{ |
98 |
{ |
99 |
_clone_down=1 |
99 |
_clone_down=1 |
100 |
_wlan_down=1 |
100 |
_wlan_down=1 |
101 |
netif_stop0 $* |
101 |
netif_stop0 $* |
102 |
} |
102 |
} |
103 |
|
103 |
|
104 |
doclear() |
104 |
doclear() |
105 |
{ |
105 |
{ |
106 |
_clone_down= |
106 |
_clone_down= |
107 |
_wlan_down= |
107 |
_wlan_down= |
108 |
netif_stop0 $* |
108 |
netif_stop0 $* |
109 |
} |
109 |
} |
110 |
|
110 |
|
111 |
netif_stop0() |
111 |
netif_stop0() |
112 |
{ |
112 |
{ |
113 |
local _if |
113 |
local _if |
114 |
|
114 |
|
115 |
# Set the list of interfaces to work on. |
115 |
# Set the list of interfaces to work on. |
116 |
# |
116 |
# |
117 |
cmdifn=$* |
117 |
cmdifn=$* |
118 |
|
118 |
|
119 |
# Deconfigure the interface(s) |
119 |
# Deconfigure the interface(s) |
120 |
netif_common ifn_stop $cmdifn |
120 |
netif_common ifn_stop $cmdifn |
121 |
|
121 |
|
122 |
# Destroy wlan interfaces |
122 |
# Destroy wlan interfaces |
123 |
if [ -n "$_wlan_down" ]; then |
123 |
if [ -n "$_wlan_down" ]; then |
124 |
wlan_down $cmdifn |
124 |
wlan_down $cmdifn |
125 |
fi |
125 |
fi |
126 |
|
126 |
|
127 |
# Destroy cloned interfaces |
127 |
# Destroy cloned interfaces |
128 |
if [ -n "$_clone_down" ]; then |
128 |
if [ -n "$_clone_down" ]; then |
129 |
clone_down $cmdifn |
129 |
clone_down $cmdifn |
130 |
fi |
130 |
fi |
131 |
|
131 |
|
132 |
if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then |
132 |
if [ -f /etc/rc.d/routing -a -n "$cmdifn" ] ; then |
133 |
for _if in $cmdifn; do |
133 |
for _if in $cmdifn; do |
134 |
/etc/rc.d/routing stop any $_if |
134 |
/etc/rc.d/routing stop any $_if |
135 |
done |
135 |
done |
136 |
fi |
136 |
fi |
137 |
} |
137 |
} |
138 |
|
138 |
|
139 |
vnet_up() |
139 |
vnet_up() |
140 |
{ |
140 |
{ |
141 |
cmdifn=$* |
141 |
cmdifn=$* |
142 |
|
142 |
|
143 |
netif_common ifn_vnetup $cmdifn |
143 |
netif_common ifn_vnetup $cmdifn |
144 |
} |
144 |
} |
145 |
|
145 |
|
146 |
vnet_down() |
146 |
vnet_down() |
147 |
{ |
147 |
{ |
148 |
cmdifn=$* |
148 |
cmdifn=$* |
149 |
|
149 |
|
150 |
netif_common ifn_vnetdown $cmdifn |
150 |
netif_common ifn_vnetdown $cmdifn |
151 |
} |
151 |
} |
152 |
|
152 |
|
153 |
# netif_common routine |
153 |
# netif_common routine |
154 |
# Common configuration subroutine for network interfaces. This |
154 |
# Common configuration subroutine for network interfaces. This |
155 |
# routine takes all the preparatory steps needed for configuriing |
155 |
# routine takes all the preparatory steps needed for configuriing |
156 |
# an interface and then calls $routine. |
156 |
# an interface and then calls $routine. |
157 |
netif_common() |
157 |
netif_common() |
158 |
{ |
158 |
{ |
159 |
local _cooked_list _tmp_list _fail _func _ok _str _cmdifn |
159 |
local _cooked_list _tmp_list _fail _func _ok _str _cmdifn |
160 |
|
160 |
|
161 |
_func= |
161 |
_func= |
162 |
|
162 |
|
163 |
if [ -z "$1" ]; then |
163 |
if [ -z "$1" ]; then |
164 |
err 1 "netif_common(): No function name specified." |
164 |
err 1 "netif_common(): No function name specified." |
165 |
else |
165 |
else |
166 |
_func="$1" |
166 |
_func="$1" |
167 |
shift |
167 |
shift |
168 |
fi |
168 |
fi |
169 |
|
169 |
|
170 |
# Set the scope of the command (all interfaces or just one). |
170 |
# Set the scope of the command (all interfaces or just one). |
171 |
# |
171 |
# |
172 |
_cooked_list= |
172 |
_cooked_list= |
173 |
_tmp_list= |
173 |
_tmp_list= |
174 |
_cmdifn=$* |
174 |
_cmdifn=$* |
175 |
if [ -n "$_cmdifn" ]; then |
175 |
if [ -n "$_cmdifn" ]; then |
176 |
# Don't check that the interface(s) exist. We need to run |
176 |
# Don't check that the interface(s) exist. We need to run |
177 |
# the down code even when the interface doesn't exist to |
177 |
# the down code even when the interface doesn't exist to |
178 |
# kill off wpa_supplicant. |
178 |
# kill off wpa_supplicant. |
179 |
# XXXBED: is this really true or does wpa_supplicant die? |
179 |
# XXXBED: is this really true or does wpa_supplicant die? |
180 |
# if so, we should get rid of the devd entry |
180 |
# if so, we should get rid of the devd entry |
181 |
_cooked_list="$_cmdifn" |
181 |
_cooked_list="$_cmdifn" |
182 |
else |
182 |
else |
183 |
_cooked_list="`list_net_interfaces`" |
183 |
_cooked_list="`list_net_interfaces`" |
184 |
fi |
184 |
fi |
185 |
|
185 |
|
186 |
# Expand epair[0-9] to epair[0-9][ab]. |
186 |
# Expand epair[0-9] to epair[0-9][ab]. |
187 |
for ifn in $_cooked_list; do |
187 |
for ifn in $_cooked_list; do |
188 |
case ${ifn#epair} in |
188 |
case ${ifn#epair} in |
189 |
[0-9]*[ab]) ;; # Skip epair[0-9]*[ab]. |
189 |
[0-9]*[ab]) ;; # Skip epair[0-9]*[ab]. |
190 |
[0-9]*) |
190 |
[0-9]*) |
191 |
for _str in $_cooked_list; do |
191 |
for _str in $_cooked_list; do |
192 |
case $_str in |
192 |
case $_str in |
193 |
$ifn) _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;; |
193 |
$ifn) _tmp_list="$_tmp_list ${ifn}a ${ifn}b" ;; |
194 |
*) _tmp_list="$_tmp_list ${ifn}" ;; |
194 |
*) _tmp_list="$_tmp_list ${ifn}" ;; |
195 |
esac |
195 |
esac |
196 |
done |
196 |
done |
197 |
_cooked_list=${_tmp_list# } |
197 |
_cooked_list=${_tmp_list# } |
198 |
;; |
198 |
;; |
199 |
esac |
199 |
esac |
200 |
done |
200 |
done |
201 |
|
201 |
|
202 |
_dadwait= |
202 |
_dadwait= |
203 |
_fail= |
203 |
_fail= |
204 |
_ok= |
204 |
_ok= |
205 |
for ifn in ${_cooked_list# }; do |
205 |
for ifn in ${_cooked_list# }; do |
206 |
# Skip if ifn does not exist. |
206 |
# Skip if ifn does not exist. |
207 |
case $_func in |
207 |
case $_func in |
208 |
ifn_stop) |
208 |
ifn_stop) |
209 |
if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then |
209 |
if ! ${IFCONFIG_CMD} $ifn > /dev/null 2>&1; then |
210 |
warn "$ifn does not exist. Skipped." |
210 |
warn "$ifn does not exist. Skipped." |
211 |
_fail="${_fail} ${ifn}" |
211 |
_fail="${_fail} ${ifn}" |
212 |
continue |
212 |
continue |
213 |
fi |
213 |
fi |
214 |
;; |
214 |
;; |
215 |
esac |
215 |
esac |
216 |
if ${_func} ${ifn} $2; then |
216 |
if ${_func} ${ifn} $2; then |
217 |
_ok="${_ok} ${ifn}" |
217 |
_ok="${_ok} ${ifn}" |
218 |
if ipv6if ${ifn}; then |
218 |
if ipv6if ${ifn}; then |
219 |
_dadwait=1 |
219 |
_dadwait=1 |
220 |
fi |
220 |
fi |
221 |
else |
221 |
else |
222 |
_fail="${_fail} ${ifn}" |
222 |
_fail="${_fail} ${ifn}" |
223 |
fi |
223 |
fi |
224 |
done |
224 |
done |
225 |
|
225 |
|
226 |
# inet6 address configuration needs sleep for DAD. |
226 |
# inet6 address configuration needs sleep for DAD. |
227 |
case ${_func}:${_dadwait} in |
227 |
case ${_func}:${_dadwait} in |
228 |
ifn_start:1|ifn_vnetup:1|ifn_vnetdown:1) |
228 |
ifn_start:1|ifn_vnetup:1|ifn_vnetdown:1) |
229 |
sleep `${SYSCTL_N} net.inet6.ip6.dad_count` |
229 |
sleep `${SYSCTL_N} net.inet6.ip6.dad_count` |
230 |
sleep 1 |
230 |
sleep 1 |
231 |
;; |
231 |
;; |
232 |
esac |
232 |
esac |
233 |
|
233 |
|
234 |
_str= |
234 |
_str= |
235 |
if [ -n "${_ok}" ]; then |
235 |
if [ -n "${_ok}" ]; then |
236 |
case ${_func} in |
236 |
case ${_func} in |
237 |
ifn_start) |
237 |
ifn_start) |
238 |
_str='Starting' |
238 |
_str='Starting' |
239 |
;; |
239 |
;; |
240 |
ifn_stop) |
240 |
ifn_stop) |
241 |
_str='Stopping' |
241 |
_str='Stopping' |
242 |
;; |
242 |
;; |
243 |
ifn_vnetup) |
243 |
ifn_vnetup) |
244 |
_str='Moving' |
244 |
_str='Moving' |
245 |
;; |
245 |
;; |
246 |
ifn_vnetdown) |
246 |
ifn_vnetdown) |
247 |
_str='Reclaiming' |
247 |
_str='Reclaiming' |
248 |
;; |
248 |
;; |
249 |
esac |
249 |
esac |
250 |
echo "${_str} Network:${_ok}." |
250 |
echo "${_str} Network:${_ok}." |
251 |
case ${_func} in |
251 |
case ${_func} in |
252 |
ifn_vnetup) |
252 |
ifn_vnetup) |
253 |
# Clear _ok not to do "ifconfig $ifn" |
253 |
# Clear _ok not to do "ifconfig $ifn" |
254 |
# because $ifn is no longer in the current vnet. |
254 |
# because $ifn is no longer in the current vnet. |
255 |
_ok= |
255 |
_ok= |
256 |
;; |
256 |
;; |
257 |
esac |
257 |
esac |
258 |
if check_startmsgs; then |
258 |
if check_startmsgs; then |
259 |
for ifn in ${_ok}; do |
259 |
for ifn in ${_ok}; do |
260 |
/sbin/ifconfig ${ifn} |
260 |
/sbin/ifconfig ${ifn} |
261 |
done |
261 |
done |
262 |
fi |
262 |
fi |
263 |
fi |
263 |
fi |
264 |
|
264 |
|
265 |
debug "The following interfaces were not configured: $_fail" |
265 |
debug "The following interfaces were not configured: $_fail" |
266 |
} |
266 |
} |
267 |
|
267 |
|
268 |
# Load the old "network" config file also for compatibility. |
268 |
# Load the old "network" config file also for compatibility. |
269 |
# This is needed for mfsBSD at least. |
269 |
# This is needed for mfsBSD at least. |
270 |
load_rc_config network |
270 |
load_rc_config network |
271 |
load_rc_config $name |
271 |
load_rc_config $name |
272 |
run_rc_command $* |
272 |
run_rc_command $* |