1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.12 2007-07-21 19:31:11 niro Exp $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.19 2008-12-22 22:01:15 niro Exp $ |
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 |
|
|
16 |
# read values from files |
# read values from files |
24 |
# global |
# global |
25 |
local ONBOOT |
local ONBOOT |
26 |
local NETWORKING |
local NETWORKING |
27 |
|
|
28 |
# static |
# static |
29 |
local IP |
local IP |
30 |
local NETMASK |
local NETMASK |
60 |
local WIRELESS_NICK |
local WIRELESS_NICK |
61 |
local WIRELESS_NWID |
local WIRELESS_NWID |
62 |
local WIRELESS_POWER |
local WIRELESS_POWER |
63 |
|
local WIRELESS_WPA_DRIVER |
64 |
|
|
65 |
|
local BRIDGE_INTERFACES |
66 |
|
local BRIDGE_STP |
67 |
|
|
68 |
source ${file} |
source ${file} |
69 |
eval value=\$$(echo ${var}) |
eval value=\$$(echo ${var}) |
72 |
|
|
73 |
checkconfig() |
checkconfig() |
74 |
{ |
{ |
75 |
if [ -z "${NETWORKING}" ] |
if [[ -z ${NETWORKING} ]] |
76 |
then |
then |
77 |
echo "NETWORKING missing in net.${interface}, aborted" |
echo "NETWORKING missing in net.${interface}, aborted" |
78 |
exit 1 |
exit 1 |
80 |
|
|
81 |
case "${NETWORKING}" in |
case "${NETWORKING}" in |
82 |
static) |
static) |
83 |
if [ -z "${IP}" ] |
if [[ -z ${IP} ]] |
84 |
then |
then |
85 |
echo "IP missing in net.${interface}, aborted" |
echo "IP missing in net.${interface}, aborted" |
86 |
exit 1 |
exit 1 |
87 |
fi |
fi |
88 |
|
|
89 |
if [ -z "${NETMASK}" ] |
if [[ -z ${NETMASK} ]] |
90 |
then |
then |
91 |
echo -n "NETMASK missing in net.${interface}, " |
echo -n "NETMASK missing in net.${interface}, " |
92 |
echo "using 255.255.255.0" |
echo "using 255.255.255.0" |
93 |
NETMASK=255.255.255.0 |
NETMASK=255.255.255.0 |
94 |
fi |
fi |
95 |
|
|
96 |
if [ -z "${BROADCAST}" ] |
if [[ -z ${BROADCAST} ]] |
97 |
then |
then |
98 |
echo -n "BROADCAST missing in net.${interface}, " |
echo -n "BROADCAST missing in net.${interface}, " |
99 |
echo "using default address" |
echo "using default address" |
101 |
;; |
;; |
102 |
|
|
103 |
dhcp) |
dhcp) |
104 |
if [ -z "${DHCP_PROG}" ] |
if [[ -z ${DHCP_PROG} ]] |
105 |
then |
then |
106 |
echo "DHCP_PROG missing in net.${interface}, aborted" |
echo "DHCP_PROG missing in net.${interface}, aborted" |
107 |
exit 1 |
exit 1 |
255 |
{ |
{ |
256 |
local iface="$1" |
local iface="$1" |
257 |
local method="$2" |
local method="$2" |
258 |
|
local bport |
259 |
|
|
260 |
if [[ -z ${iface} ]] |
if [[ -z ${iface} ]] |
261 |
then |
then |
277 |
fi |
fi |
278 |
|
|
279 |
# check the config |
# check the config |
280 |
if [[ -z ${BRIDGE_INTERFACE} ]] |
if [[ -z ${BRIDGE_INTERFACES} ]] |
281 |
then |
then |
282 |
echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup." |
echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." |
283 |
return 1 |
return 1 |
284 |
fi |
fi |
285 |
|
|
287 |
add) |
add) |
288 |
# setup the bridge device |
# setup the bridge device |
289 |
brctl addbr ${iface} |
brctl addbr ${iface} |
290 |
# enter promiscous mode |
for bport in ${BRIDGE_INTERFACES} |
291 |
ifconfig ${BRIDGE_INTERFACE} 0.0.0.0 promisc |
do |
292 |
# now setup the bridge |
# enter promiscous mode |
293 |
brctl addif ${iface} ${BRIDGE_INTERFACE} |
ifconfig ${bport} 0.0.0.0 promisc |
294 |
|
# now setup the bridge |
295 |
|
brctl addif ${iface} ${bport} |
296 |
|
done |
297 |
|
# enable spanning-tree protocol |
298 |
|
case ${BRIDGE_STP} in |
299 |
|
on|off) brctl stp ${iface} ${BRIDGE_STP} ;; |
300 |
|
*) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; |
301 |
|
esac |
302 |
;; |
;; |
303 |
|
|
304 |
remove) |
remove) |
305 |
# bring the interface down |
for bport in ${BRIDGE_INTERFACE} |
306 |
ifconfig ${BRIDGE_INTERFACE} down |
do |
307 |
# remove the interface from the bridge |
# bring the interface down |
308 |
brctl delif ${iface} ${BRIDGE_INTERFACE} |
ifconfig ${bport} down |
309 |
|
# remove the interface from the bridge |
310 |
|
brctl delif ${iface} ${bport} |
311 |
|
done |
312 |
# bring the bridge down |
# bring the bridge down |
313 |
brctl delbr ${iface} |
brctl delbr ${iface} |
314 |
;; |
;; |
315 |
esac |
esac |
316 |
|
|
317 |
# unset the bridge variable to be safe |
# unset the bridge variable to be safe |
318 |
unset BRIDGE_INTERFACE |
unset BRIDGE_INTERFACES |
319 |
# continue to setup generic networking |
# continue to setup generic networking |
320 |
} |
} |
321 |
|
|
352 |
|
|
353 |
networking_start() |
networking_start() |
354 |
{ |
{ |
355 |
local iface dns routes |
local iface dns routes ALL_INTERFACES |
356 |
|
|
357 |
|
if [[ -z $1 ]] |
358 |
|
then |
359 |
|
ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) |
360 |
|
else |
361 |
|
if [[ -e ${network_settings}/net.$1 ]] |
362 |
|
then |
363 |
|
ALL_INTERFACES="$1" |
364 |
|
else |
365 |
|
${FAILURE} |
366 |
|
echo "Interface $1 does not exist. Aborting" |
367 |
|
${NORMAL} |
368 |
|
exit 1 |
369 |
|
fi |
370 |
|
fi |
371 |
|
|
372 |
# get list of all devices |
# get list of all devices |
373 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
374 |
do |
do |
375 |
# checkconfig |
# checkconfig |
376 |
source ${network_settings}/net.${iface} || exit 1 |
source ${network_settings}/net.${iface} || exit 1 |
421 |
echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." |
422 |
route add default gateway ${GATEWAY} metric 1 dev ${iface} |
route add default gateway ${GATEWAY} metric 1 dev ${iface} |
423 |
evaluate_retval |
evaluate_retval |
424 |
|
|
425 |
|
unset GATEWAY |
426 |
fi |
fi |
427 |
|
|
428 |
# setup /etc/resolv.conf |
# setup /etc/resolv.conf |
436 |
do |
do |
437 |
echo "nameserver ${dns}" >> /etc/resolv.conf |
echo "nameserver ${dns}" >> /etc/resolv.conf |
438 |
done |
done |
439 |
|
|
440 |
|
unset NAMESERVER |
441 |
fi |
fi |
442 |
done |
done |
443 |
|
|
447 |
|
|
448 |
networking_stop() |
networking_stop() |
449 |
{ |
{ |
450 |
|
if [[ -z $1 ]] |
451 |
|
then |
452 |
|
ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) |
453 |
|
else |
454 |
|
if [[ -e ${network_settings}/net.$1 ]] |
455 |
|
then |
456 |
|
ALL_INTERFACES="$1" |
457 |
|
else |
458 |
|
${FAILURE} |
459 |
|
echo "Interface $1 does not exist. Aborting" |
460 |
|
${NORMAL} |
461 |
|
exit 1 |
462 |
|
fi |
463 |
|
fi |
464 |
|
|
465 |
# get list of all devices |
# get list of all devices |
466 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
467 |
do |
do |
468 |
source ${network_settings}/net.${iface} || exit 1 |
source ${network_settings}/net.${iface} || exit 1 |
469 |
checkconfig |
checkconfig |
515 |
|
|
516 |
case $1 in |
case $1 in |
517 |
start) |
start) |
518 |
networking_start |
networking_start $2 |
519 |
update_svcstatus $1 |
update_svcstatus $1 |
520 |
splash svc_started "$(basename $0)" 0 |
splash svc_started "$(basename $0)" 0 |
521 |
;; |
;; |
522 |
|
|
523 |
stop) |
stop) |
524 |
networking_stop |
networking_stop $2 |
525 |
update_svcstatus $1 |
update_svcstatus $1 |
526 |
splash svc_stopped "$(basename $0)" 0 |
splash svc_stopped "$(basename $0)" 0 |
527 |
;; |
;; |
533 |
;; |
;; |
534 |
|
|
535 |
*) |
*) |
536 |
echo "Usage: $0 {start|stop|restart}" |
echo "Usage: $0 {start|stop|restart} [interface]" |
537 |
exit 1 |
exit 1 |
538 |
;; |
;; |
539 |
esac |
esac |