1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.9 2005-10-10 18:43:03 niro Exp $ |
# $Id$ |
3 |
|
|
4 |
#%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k |
#%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k |
5 |
#%start: 20 |
#%start: 20 |
10 |
#%before: |
#%before: |
11 |
#%after: |
#%after: |
12 |
|
|
13 |
source /etc/sysconfig/rc |
source /etc/conf.d/rc |
14 |
source ${rc_functions} |
source ${rc_functions} |
15 |
|
source /etc/conf.d/network |
16 |
|
|
17 |
|
iface_wait_online() |
18 |
|
{ |
19 |
|
local timeout="$1" |
20 |
|
local iface="$2" |
21 |
|
|
22 |
|
(( timeout *= 10 )) |
23 |
|
|
24 |
|
while [ ! -e /sys/class/net/${iface} ] |
25 |
|
do |
26 |
|
(( timeout-- > 0 )) || return 1 |
27 |
|
sleep 0.1 |
28 |
|
done |
29 |
|
|
30 |
|
return 0 |
31 |
|
} |
32 |
|
|
33 |
|
iface_has_link() |
34 |
|
{ |
35 |
|
local interface="$1" |
36 |
|
local flags |
37 |
|
|
38 |
|
[[ -n ${interface} ]] || return 2 |
39 |
|
interface="/sys/class/net/${interface}" |
40 |
|
[[ -d ${interface} ]] || return 2 |
41 |
|
flags=$(cat ${interface}/flags) |
42 |
|
echo $((${flags}|0x41)) > ${interface}/flags # 0x41: IFF_UP|IFF_RUNNING |
43 |
|
[ "$(cat ${interface}/carrier)" = 1 ] || return 1 |
44 |
|
} |
45 |
|
|
46 |
# read values from files |
# read values from files |
47 |
read_value() |
read_value() |
54 |
# global |
# global |
55 |
local ONBOOT |
local ONBOOT |
56 |
local NETWORKING |
local NETWORKING |
57 |
|
|
58 |
# static |
# static |
59 |
local IP |
local IP |
60 |
local NETMASK |
local NETMASK |
90 |
local WIRELESS_NICK |
local WIRELESS_NICK |
91 |
local WIRELESS_NWID |
local WIRELESS_NWID |
92 |
local WIRELESS_POWER |
local WIRELESS_POWER |
93 |
|
local WIRELESS_WPA_DRIVER |
94 |
|
|
95 |
|
local BRIDGE_INTERFACES |
96 |
|
local BRIDGE_STP |
97 |
|
local BRIDGE_AGEING_TIME |
98 |
|
local BRIDGE_PRIORITY |
99 |
|
local BRIDGE_FORWARD_DELAY |
100 |
|
local BRIDGE_HELLO_TIME |
101 |
|
local BRIDGE_MAX_MESSAGE_AGE |
102 |
|
local BRIDGE_PATH_COST |
103 |
|
local BRIDGE_PORT_PRIORITY |
104 |
|
|
105 |
|
# point-to-point support |
106 |
|
local POINTOPOINT |
107 |
|
|
108 |
source ${file} |
source ${file} |
109 |
eval value=\$$(echo ${var}) |
eval value=\$$(echo ${var}) |
112 |
|
|
113 |
checkconfig() |
checkconfig() |
114 |
{ |
{ |
115 |
if [ -z "${NETWORKING}" ] |
if [[ -z ${NETWORKING} ]] |
116 |
then |
then |
117 |
echo "NETWORKING missing in net.${interface}, aborted" |
rc_echo "NETWORKING missing in net.${iface}, aborted" |
118 |
exit 1 |
exit 1 |
119 |
fi |
fi |
120 |
|
|
121 |
case "${NETWORKING}" in |
case "${NETWORKING}" in |
122 |
static) |
static) |
123 |
if [ -z "${IP}" ] |
if [[ -z ${IP} ]] |
124 |
then |
then |
125 |
echo "IP missing in net.${interface}, aborted" |
rc_echo "IP missing in net.${iface}, aborted" |
126 |
exit 1 |
exit 1 |
127 |
fi |
fi |
128 |
|
|
129 |
if [ -z "${NETMASK}" ] |
if [[ -z ${NETMASK} ]] |
130 |
then |
then |
131 |
echo -n "NETMASK missing in net.${interface}, " |
rc_echo -n "NETMASK missing in net.${iface}, " |
132 |
echo "using 255.255.255.0" |
rc_echo "using ${DEFAULT_NETMASK}" |
133 |
NETMASK=255.255.255.0 |
NETMASK="${DEFAULT_NETMASK}" |
134 |
fi |
fi |
135 |
|
|
136 |
if [ -z "${BROADCAST}" ] |
if [[ -z ${BROADCAST} ]] |
137 |
then |
then |
138 |
echo -n "BROADCAST missing in net.${interface}, " |
rc_echo -n "BROADCAST missing in net.${iface}, " |
139 |
echo "using default address" |
rc_echo "using default address" |
140 |
fi |
fi |
141 |
;; |
;; |
142 |
|
|
143 |
dhcp) |
dhcp) |
144 |
if [ -z "${DHCP_PROG}" ] |
if [[ -z ${DHCP_PROG} ]] |
145 |
then |
then |
146 |
echo "DHCP_PROG missing in net.${interface}, aborted" |
rc_echo -n "DHCP_PROG missing in net.${iface}," |
147 |
exit 1 |
rc_echo "using default programm ${DEFAULT_DHCP_PROG}" |
148 |
|
DHCP_PROG="${DEFAULT_DHCP_PROG}" |
149 |
fi |
fi |
150 |
|
[[ -z ${DHCP_START} ]] && DHCP_START="${DEFAULT_DHCP_START}" |
151 |
|
[[ -z ${DHCP_STOP} ]] && DHCP_STOP="${DEFAULT_DHCP_STOP}" |
152 |
;; |
;; |
153 |
|
|
154 |
esac |
esac |
164 |
# get list of all devices |
# get list of all devices |
165 |
for file in $@ |
for file in $@ |
166 |
do |
do |
167 |
|
iface="$(basename ${file} | sed s/net.//)" |
168 |
|
|
169 |
|
# exclude backup files and exclude net.routes and net.sample too |
170 |
|
case "${iface}" in |
171 |
|
*~) continue ;; |
172 |
|
routes) continue ;; |
173 |
|
sample) continue ;; |
174 |
|
esac |
175 |
|
|
176 |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
177 |
then |
then |
178 |
iface="$(basename ${file} | sed s/net.//)" |
devices="${devices} ${iface}" |
|
# exclude backup files |
|
|
case "${iface}" in |
|
|
*~) ;; |
|
|
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
|
|
esac |
|
179 |
fi |
fi |
180 |
done |
done |
181 |
|
|
188 |
|
|
189 |
if [[ -z ${iface} ]] |
if [[ -z ${iface} ]] |
190 |
then |
then |
191 |
echo "WEP: no \$iface given. Aborting setup." |
rc_echo "WEP: no \$iface given. Aborting setup." |
192 |
return 1 |
return 1 |
193 |
fi |
fi |
194 |
|
|
195 |
|
${CURS_UP} |
196 |
|
${SET_WWCOL} |
197 |
|
rc_echo "[AUTH: WEP]" |
198 |
|
|
199 |
iwconfig "${iface}" enc on |
iwconfig "${iface}" enc on |
200 |
[[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
[[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
201 |
[[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
[[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
208 |
|
|
209 |
if [[ -z ${iface} ]] |
if [[ -z ${iface} ]] |
210 |
then |
then |
211 |
echo "WPA: no \$iface given. Aborting setup." |
rc_echo "WPA: no \$iface given. Aborting setup." |
212 |
return 1 |
return 1 |
213 |
fi |
fi |
214 |
|
|
215 |
if [ ! -x /sbin/wpa_supplicant ] |
if [ ! -x $(type -P wpa_supplicant) ] |
216 |
then |
then |
217 |
echo "WPA: wpa_supplicant not installed. Aborting setup." |
rc_echo "WPA: wpa_supplicant not installed. Aborting setup." |
218 |
return 1 |
return 1 |
219 |
fi |
fi |
220 |
|
|
221 |
|
${CURS_UP} |
222 |
|
${SET_WWCOL} |
223 |
|
rc_echo "[AUTH: WPA]" |
224 |
|
|
225 |
# get default settings |
# get default settings |
226 |
[[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant |
[[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant |
227 |
|
|
228 |
# check the configuration |
# check the configuration |
229 |
[[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto |
[[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant/wpa_supplicant.auto |
230 |
[[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel |
[[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel |
231 |
if [[ -z ${WIRELESS_WPA_DRIVER} ]] |
|
232 |
then |
# use wext as default driver, do not abort here anymore |
233 |
echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup." |
[[ -z ${WIRELESS_WPA_DRIVER} ]] && WIRELESS_WPA_DRIVER=wext |
|
return 1 |
|
|
fi |
|
234 |
|
|
235 |
# write a config with the settings from net.${iface} |
# write a config with the settings from net.${iface} |
236 |
# only wpa-psk ! all other needs manual setup |
# only wpa-psk ! all other needs manual setup |
239 |
# write default cfg from skeleton |
# write default cfg from skeleton |
240 |
cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} |
cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} |
241 |
|
|
242 |
|
local wpa_proto |
243 |
|
case ${WIRELESS_AUTH_MODE} in |
244 |
|
wpa) wpa_proto="WPA" ;; |
245 |
|
wpa2) wpa_proto="WPA2" ;; |
246 |
|
esac |
247 |
|
|
248 |
# setup the network entry |
# setup the network entry |
249 |
sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ |
sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ |
250 |
-e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \ |
-e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \ |
251 |
|
-e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \ |
252 |
${WIRELESS_WPA_CONFIG} |
${WIRELESS_WPA_CONFIG} |
253 |
fi |
fi |
254 |
|
|
255 |
|
# remove old state dir |
256 |
|
[ -d /run/wpa_supplicant ] && rm -rf /run/wpa_supplicant |
257 |
|
|
258 |
# now run the wpa_supplicant dameon |
# now run the wpa_supplicant dameon |
259 |
wpa_supplicant -B \ |
wpa_supplicant -B \ |
260 |
-D"${WIRELESS_WPA_DRIVER}" \ |
-D"${WIRELESS_WPA_DRIVER}" \ |
261 |
-c"${WIRELESS_WPA_CONFIG}" \ |
-c"${WIRELESS_WPA_CONFIG}" \ |
262 |
-i"${iface}" \ |
-i"${iface}" \ |
263 |
${WIRELESS_WPA_OPTS} |
${WIRELESS_WPA_OPTS} |
264 |
|
|
265 |
|
# echo wait 5 seconds |
266 |
|
rc_echo " Waiting 5 seconds to retrieve authentification reply ... " |
267 |
|
sleep 5 |
268 |
} |
} |
269 |
|
|
270 |
setup_wireless_extensions() |
setup_wireless_extensions() |
273 |
|
|
274 |
if [[ -z ${iface} ]] |
if [[ -z ${iface} ]] |
275 |
then |
then |
276 |
echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." |
rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." |
277 |
return 1 |
return 1 |
278 |
fi |
fi |
279 |
|
|
280 |
|
if [[ -n ${WIRELESS_BITRATE} ]] || |
281 |
|
[[ -n ${WIRELESS_CHANNEL} ]] || |
282 |
|
[[ -n ${WIRELESS_ESSID} ]] || |
283 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] || |
284 |
|
[[ -n ${WIRELESS_MODE} ]] || |
285 |
|
[[ -n ${WIRELESS_NICK} ]] || |
286 |
|
[[ -n ${WIRELESS_AUTH_MODE} ]] |
287 |
|
then |
288 |
|
rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
289 |
|
fi |
290 |
|
|
291 |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
292 |
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
293 |
[[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" |
[[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" |
296 |
[[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" |
[[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" |
297 |
|
|
298 |
case "${WIRELESS_AUTH_MODE}" in |
case "${WIRELESS_AUTH_MODE}" in |
299 |
wpa) config_wireless_wpa "${iface}" ;; |
wpa|wpa2) config_wireless_wpa "${iface}" ;; |
300 |
wep|on) config_wireless_wep "${iface}" ;; |
wep|on) config_wireless_wep "${iface}" ;; |
301 |
off) iwconfig "${iface}" enc off ;; |
off) iwconfig "${iface}" enc off ;; |
302 |
|
esac |
303 |
|
} |
304 |
|
|
305 |
|
config_bridge_options() |
306 |
|
{ |
307 |
|
local iface="$1" |
308 |
|
local i |
309 |
|
local port |
310 |
|
local cost |
311 |
|
local prio |
312 |
|
|
313 |
|
# enable spanning-tree protocol |
314 |
|
case ${BRIDGE_STP} in |
315 |
|
on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;; |
316 |
|
*) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; |
317 |
esac |
esac |
318 |
|
|
319 |
|
# configure ageing time |
320 |
|
if [[ ! -z ${BRIDGE_AGEING_TIME} ]] |
321 |
|
then |
322 |
|
brctl setageing "${iface}" "${BRIDGE_AGEING_TIME}" |
323 |
|
fi |
324 |
|
|
325 |
|
# configure bridge priority |
326 |
|
if [[ ! -z ${BRIDGE_PRIORITY} ]] |
327 |
|
then |
328 |
|
brctl setbridgeprio "${iface}" "${BRIDGE_PRIORITY}" |
329 |
|
fi |
330 |
|
|
331 |
|
# configure forward delay |
332 |
|
if [[ ! -z ${BRIDGE_FORWARD_DELAY} ]] |
333 |
|
then |
334 |
|
brctl setfd "${iface}" "${BRIDGE_FORWARD_DELAY}" |
335 |
|
fi |
336 |
|
|
337 |
|
# configure hello time |
338 |
|
if [[ ! -z ${BRIDGE_HELLO_TIME} ]] |
339 |
|
then |
340 |
|
brctl sethello "${iface}" "${BRIDGE_HELLO_TIME}" |
341 |
|
fi |
342 |
|
|
343 |
|
# configure maximal message age |
344 |
|
if [[ ! -z ${BRIDGE_MAX_MESSAGE_AGE} ]] |
345 |
|
then |
346 |
|
brctl setmaxage "${iface}" "${BRIDGE_MAX_MESSAGE_AGE}" |
347 |
|
fi |
348 |
|
|
349 |
|
# configure path cost for every port |
350 |
|
if [[ ! -z ${BRIDGE_PATH_COST} ]] |
351 |
|
then |
352 |
|
for i in ${BRIDGE_PATH_COST} |
353 |
|
do |
354 |
|
port="${i%=*}" |
355 |
|
cost="${i#*=}" |
356 |
|
[[ ! -z ${port} ]] && brctl pathcost "${iface}" "${port}" "${cost}" |
357 |
|
done |
358 |
|
fi |
359 |
|
|
360 |
|
# configure port priority for every port |
361 |
|
if [[ ! -z ${BRIDGE_PORT_PRIORITY} ]] |
362 |
|
then |
363 |
|
for i in ${BRIDGE_PORT_PRIORITY} |
364 |
|
do |
365 |
|
port="${i%=*}" |
366 |
|
prio="${i#*=}" |
367 |
|
[[ ! -z ${port} ]] && brctl setportprio "${iface}" "${port}" "${prio}" |
368 |
|
done |
369 |
|
fi |
370 |
|
} |
371 |
|
|
372 |
|
config_bridge_devices() |
373 |
|
{ |
374 |
|
local iface="$1" |
375 |
|
local method="$2" |
376 |
|
local bport |
377 |
|
|
378 |
|
if [[ -z ${iface} ]] |
379 |
|
then |
380 |
|
rc_echo "BRIDGE: no \$iface given. Aborting setup." |
381 |
|
return 1 |
382 |
|
fi |
383 |
|
|
384 |
|
if [[ -z ${method} ]] |
385 |
|
then |
386 |
|
rc_echo "BRIDGE: no \$method given. Aborting setup." |
387 |
|
return 1 |
388 |
|
fi |
389 |
|
|
390 |
|
# first check for brctl |
391 |
|
if [[ -z $(type -P brctl) ]] |
392 |
|
then |
393 |
|
rc_echo "brctl not found! Please install 'net-misc/bridge-utils'." |
394 |
|
return 1 |
395 |
|
fi |
396 |
|
|
397 |
|
# check the config |
398 |
|
if [[ -z ${BRIDGE_INTERFACES} ]] |
399 |
|
then |
400 |
|
rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." |
401 |
|
return 1 |
402 |
|
fi |
403 |
|
|
404 |
|
case ${method} in |
405 |
|
add) |
406 |
|
# setup the bridge device |
407 |
|
brctl addbr "${iface}" |
408 |
|
for bport in ${BRIDGE_INTERFACES} |
409 |
|
do |
410 |
|
# enter promiscous mode |
411 |
|
ifconfig "${bport}" 0.0.0.0 promisc |
412 |
|
# now setup the bridge |
413 |
|
brctl addif "${iface}" "${bport}" |
414 |
|
done |
415 |
|
# configure all other options |
416 |
|
config_bridge_options "${iface}" |
417 |
|
;; |
418 |
|
|
419 |
|
remove) |
420 |
|
for bport in ${BRIDGE_INTERFACE} |
421 |
|
do |
422 |
|
# bring the interface down |
423 |
|
ifconfig "${bport}" down |
424 |
|
# remove the interface from the bridge |
425 |
|
brctl delif "${iface}" "${bport}" |
426 |
|
done |
427 |
|
# bring the bridge down |
428 |
|
brctl delbr "${iface}" |
429 |
|
;; |
430 |
|
esac |
431 |
|
|
432 |
|
# unset the bridge variable to be safe |
433 |
|
unset BRIDGE_INTERFACES |
434 |
|
# continue to setup generic networking |
435 |
|
} |
436 |
|
|
437 |
|
config_routes() |
438 |
|
{ |
439 |
|
local method="$1" |
440 |
|
local message |
441 |
|
|
442 |
|
# only add and del are allowed |
443 |
|
case ${method} in |
444 |
|
add) message="Adding" ;; |
445 |
|
del) message="Removing" ;; |
446 |
|
*) |
447 |
|
rc_echo "config_routes: unsupported \$method '${method}'." |
448 |
|
exit 1 |
449 |
|
;; |
450 |
|
esac |
451 |
|
|
452 |
|
# adds/delete user routes |
453 |
|
if [[ -f /etc/conf.d/net.routes ]] |
454 |
|
then |
455 |
|
( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end |
456 |
|
while read route |
457 |
|
do |
458 |
|
case "${route}" in |
459 |
|
\#*|"") continue ;; |
460 |
|
esac |
461 |
|
rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..." |
462 |
|
# do not esacpe ${route} or it breaks! |
463 |
|
route "${method}" ${route} |
464 |
|
evaluate_retval |
465 |
|
done |
466 |
|
fi |
467 |
} |
} |
468 |
|
|
469 |
networking_start() |
networking_start() |
470 |
{ |
{ |
471 |
local iface dns |
local iface dns routes ALL_INTERFACES |
472 |
|
|
473 |
|
if [[ -z $1 ]] |
474 |
|
then |
475 |
|
ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) |
476 |
|
else |
477 |
|
if [[ -e ${rc_network_settings}/net.$1 ]] |
478 |
|
then |
479 |
|
ALL_INTERFACES="$1" |
480 |
|
else |
481 |
|
${FAILURE} |
482 |
|
rc_echo "Interface $1 does not exist. Aborting" |
483 |
|
${NORMAL} |
484 |
|
exit 1 |
485 |
|
fi |
486 |
|
fi |
487 |
|
|
488 |
# get list of all devices |
# get list of all devices |
489 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
490 |
do |
do |
491 |
# checkconfig |
# checkconfig |
492 |
source ${network_settings}/net.${iface} || exit 1 |
source ${rc_network_settings}/net.${iface} || exit 1 |
493 |
checkconfig |
checkconfig |
494 |
|
|
495 |
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
# wait until the device is created |
496 |
|
iface_wait_online 5 "${iface}" || { rc_echo "device '${iface}' does not exist"; continue; } |
497 |
|
|
498 |
# setup mac |
# setup mac |
499 |
[ -n "${FORCE_MAC_TO}" ] && ifconfig ${iface} hw ether "${FORCE_MAC_TO}" |
if [[ -n ${FORCE_MAC_TO} ]] |
500 |
|
then |
501 |
|
rc_print "Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " |
502 |
|
ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" |
503 |
|
evaluate_retval |
504 |
|
fi |
505 |
|
|
506 |
|
# setup bridges |
507 |
|
if [[ ${iface} = br[0-9]* ]] |
508 |
|
then |
509 |
|
config_bridge_devices "${iface}" add |
510 |
|
fi |
511 |
|
|
512 |
|
# now configure wireless_extensions |
513 |
|
[ -x $(type -P iwconfig) ] && setup_wireless_extensions "${iface}" |
514 |
|
|
515 |
|
rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
516 |
|
|
517 |
|
# activate the interface |
518 |
|
ifconfig "${iface}" up |
519 |
|
|
520 |
# setup static or dhcp |
# setup static or dhcp |
521 |
case ${NETWORKING} in |
case ${NETWORKING} in |
522 |
dhcp|DHCP) |
dhcp|DHCP) |
523 |
${CURS_UP} |
${CURS_UP} |
524 |
${SET_WWCOL} |
${SET_WWCOL} |
525 |
echo "[DHCP]" |
rc_echo "[DHCP]" |
526 |
loadproc ${DHCP_PROG} ${DHCP_START} |
if iface_has_link "${iface}" |
527 |
|
then |
528 |
|
loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" |
529 |
|
else |
530 |
|
rc_echo "Interface '${iface}' has no link. Not running '${DHCP_PROG}'." |
531 |
|
fi |
532 |
;; |
;; |
533 |
static|STATIC) |
static|STATIC) |
534 |
${CURS_UP} |
${CURS_UP} |
535 |
${SET_WWCOL} |
${SET_WWCOL} |
536 |
echo "[STATIC]" |
rc_echo "[STATIC]" |
537 |
ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" |
ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" |
538 |
evaluate_retval |
evaluate_retval |
539 |
|
if [[ -n ${POINTOPOINT} ]] |
540 |
|
then |
541 |
|
rc_echo "Adding point-to-point route to '${POINTOPOINT}' on interface '${iface}'" |
542 |
|
ifconfig "${iface}" "${IP}" pointopoint "${POINTOPOINT}" |
543 |
|
evaluate_retval |
544 |
|
fi |
545 |
;; |
;; |
546 |
esac |
esac |
547 |
|
|
548 |
# setup def gw |
# setup def gw |
549 |
if [[ -n ${GATEWAY} ]] |
if [[ -n ${GATEWAY} ]] |
550 |
then |
then |
551 |
echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
552 |
route add default gateway ${GATEWAY} metric 1 dev ${iface} |
route add default gateway "${GATEWAY}" metric 1 dev "${iface}" |
553 |
evaluate_retval |
evaluate_retval |
554 |
|
|
555 |
|
unset GATEWAY |
556 |
fi |
fi |
557 |
|
|
558 |
# setup /etc/resolv.conf |
# setup /etc/resolv.conf |
559 |
|
# add given nameserver |
560 |
if [[ -n ${NAMESERVER} ]] |
if [[ -n ${NAMESERVER} ]] |
561 |
then |
then |
562 |
echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." |
rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." |
563 |
|
|
564 |
# whipe out the old one |
# wipe out the old one |
565 |
echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf |
echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf |
566 |
|
# include head |
567 |
|
if [ -f /etc/resolv.conf.head ] |
568 |
|
then |
569 |
|
cat /etc/resolv.conf.head >> /etc/resolv.conf |
570 |
|
else |
571 |
|
echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf |
572 |
|
fi |
573 |
|
|
574 |
for dns in ${NAMESERVER} |
for dns in ${NAMESERVER} |
575 |
do |
do |
576 |
echo "nameserver ${dns}" >> /etc/resolv.conf |
echo "nameserver ${dns}" >> /etc/resolv.conf |
577 |
done |
done |
|
fi |
|
578 |
|
|
579 |
# setup wlan extensions |
# include tail |
580 |
if [ -x /usr/sbin/iwconfig ] |
if [ -f /etc/resolv.conf.tail ] |
581 |
then |
then |
582 |
setup_wireless_extensions "${iface}" |
cat /etc/resolv.conf.tail >> /etc/resolv.conf |
583 |
|
else |
584 |
|
echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf |
585 |
|
fi |
586 |
|
|
587 |
|
unset NAMESERVER |
588 |
fi |
fi |
589 |
done |
done |
590 |
|
|
591 |
|
# setup user routes |
592 |
|
config_routes add |
593 |
} |
} |
594 |
|
|
595 |
networking_stop() |
networking_stop() |
596 |
{ |
{ |
597 |
|
if [[ -z $1 ]] |
598 |
|
then |
599 |
|
ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) |
600 |
|
else |
601 |
|
if [[ -e ${rc_network_settings}/net.$1 ]] |
602 |
|
then |
603 |
|
ALL_INTERFACES="$1" |
604 |
|
else |
605 |
|
${FAILURE} |
606 |
|
rc_echo "Interface $1 does not exist. Aborting" |
607 |
|
${NORMAL} |
608 |
|
exit 1 |
609 |
|
fi |
610 |
|
fi |
611 |
|
|
612 |
# get list of all devices |
# get list of all devices |
613 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
614 |
do |
do |
615 |
source ${network_settings}/net.${iface} || exit 1 |
source ${rc_network_settings}/net.${iface} || exit 1 |
616 |
checkconfig |
checkconfig |
617 |
|
|
618 |
if [[ -n ${GATEWAY} ]] |
if [[ -n ${GATEWAY} ]] |
619 |
then |
then |
620 |
echo -e ${COLOREDSTAR}"Removing default gateway ..." |
rc_print "Removing default gateway ..." |
621 |
route del -net default |
route del -net default |
622 |
evaluate_retval |
evaluate_retval |
623 |
fi |
fi |
624 |
|
|
625 |
echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
626 |
ifconfig ${iface} down |
ifconfig "${iface}" down |
627 |
evaluate_retval |
evaluate_retval |
628 |
|
|
629 |
|
# remove bridges |
630 |
|
if [[ ${iface} = br[0-9]* ]] |
631 |
|
then |
632 |
|
config_bridge_devices "${iface}" remove |
633 |
|
fi |
634 |
|
|
635 |
# shutdown dhcp-daemon |
# shutdown dhcp-daemon |
636 |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]] |
637 |
then |
then |
638 |
echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." |
rc_print "Stopping the dhcp-daemon ..." |
639 |
${CURS_UP} |
${CURS_UP} |
640 |
${SET_WWCOL} |
${SET_WWCOL} |
641 |
echo "[$(basename ${DHCP_PROG})]" |
rc_echo "[$(basename ${DHCP_PROG})]" |
642 |
${DHCP_PROG} ${DHCP_STOP} |
if [[ -z ${DHCP_STOP} ]] |
643 |
evaluate_retval |
then |
644 |
|
killproc ${DHCP_PROG} |
645 |
|
evaluate_retval |
646 |
|
else |
647 |
|
${DHCP_PROG} ${DHCP_STOP} "${iface}" |
648 |
|
evaluate_retval |
649 |
|
fi |
650 |
fi |
fi |
651 |
|
|
652 |
# shutdown wpa_supplicant daemon |
# shutdown wpa_supplicant daemon |
655 |
killall wpa_supplicant |
killall wpa_supplicant |
656 |
fi |
fi |
657 |
done |
done |
658 |
|
|
659 |
|
# remove state dir |
660 |
|
if [ -d /run/wpa_supplicant ] |
661 |
|
then |
662 |
|
rm -rf /run/wpa_supplicant |
663 |
|
fi |
664 |
|
|
665 |
|
# delete user routes |
666 |
|
config_routes del |
667 |
} |
} |
668 |
|
|
669 |
case $1 in |
case $1 in |
670 |
start) |
start) |
671 |
networking_start |
networking_start $2 |
672 |
update_svcstatus $1 |
update_svcstatus $1 |
673 |
splash svc_started "$(basename $0)" 0 |
splash svc_started "$(basename $0)" 0 |
674 |
;; |
;; |
675 |
|
|
676 |
stop) |
stop) |
677 |
networking_stop |
networking_stop $2 |
678 |
update_svcstatus $1 |
update_svcstatus $1 |
679 |
splash svc_stopped "$(basename $0)" 0 |
splash svc_stopped "$(basename $0)" 0 |
680 |
;; |
;; |
686 |
;; |
;; |
687 |
|
|
688 |
*) |
*) |
689 |
echo "Usage: $0 {start|stop|restart}" |
rc_echo "Usage: $0 {start|stop|restart} [interface]" |
690 |
exit 1 |
exit 1 |
691 |
;; |
;; |
692 |
esac |
esac |