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 $ |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.14 2007-12-13 12:06:22 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 |
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 |
124 |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
125 |
then |
then |
126 |
iface="$(basename ${file} | sed s/net.//)" |
iface="$(basename ${file} | sed s/net.//)" |
127 |
# exclude backup files |
# exclude backup files and exclude net.routes too |
128 |
case "${iface}" in |
case "${iface}" in |
129 |
*~) ;; |
*~) ;; |
130 |
|
*/net.routes) ;; |
131 |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
132 |
esac |
esac |
133 |
fi |
fi |
146 |
return 1 |
return 1 |
147 |
fi |
fi |
148 |
|
|
149 |
|
${CURS_UP} |
150 |
|
${SET_WWCOL} |
151 |
|
echo "[AUTH: WEP]" |
152 |
|
|
153 |
iwconfig "${iface}" enc on |
iwconfig "${iface}" enc on |
154 |
[[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
[[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" |
155 |
[[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
[[ -n ${WIRELESS_KEY} ]] && iwconfig "${iface}" key "${WIRELESS_KEY}" |
172 |
return 1 |
return 1 |
173 |
fi |
fi |
174 |
|
|
175 |
|
${CURS_UP} |
176 |
|
${SET_WWCOL} |
177 |
|
echo "[AUTH: WPA]" |
178 |
|
|
179 |
# get default settings |
# get default settings |
180 |
[[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant |
[[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant |
181 |
|
|
201 |
${WIRELESS_WPA_CONFIG} |
${WIRELESS_WPA_CONFIG} |
202 |
fi |
fi |
203 |
|
|
204 |
|
# remove old state dir |
205 |
|
[ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant |
206 |
|
|
207 |
# now run the wpa_supplicant dameon |
# now run the wpa_supplicant dameon |
208 |
wpa_supplicant -B \ |
wpa_supplicant -B \ |
209 |
-D"${WIRELESS_WPA_DRIVER}" \ |
-D"${WIRELESS_WPA_DRIVER}" \ |
210 |
-c"${WIRELESS_WPA_CONFIG}" \ |
-c"${WIRELESS_WPA_CONFIG}" \ |
211 |
-i"${iface}" \ |
-i"${iface}" \ |
212 |
${WIRELESS_WPA_OPTS} |
${WIRELESS_WPA_OPTS} |
213 |
|
|
214 |
|
# echo wait 5 seconds |
215 |
|
echo " Waiting 5 seconds to retrieve authentification reply ... " |
216 |
|
sleep 5 |
217 |
} |
} |
218 |
|
|
219 |
setup_wireless_extensions() |
setup_wireless_extensions() |
226 |
return 1 |
return 1 |
227 |
fi |
fi |
228 |
|
|
229 |
|
if [[ -n ${WIRELESS_BITRATE} ]] || |
230 |
|
[[ -n ${WIRELESS_CHANNEL} ]] || |
231 |
|
[[ -n ${WIRELESS_ESSID} ]] || |
232 |
|
[[ -n ${WIRELESS_FREQUENCY} ]] || |
233 |
|
[[ -n ${WIRELESS_MODE} ]] || |
234 |
|
[[ -n ${WIRELESS_NICK} ]] || |
235 |
|
[[ -n ${WIRELESS_AUTH_MODE} ]] |
236 |
|
then |
237 |
|
echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " |
238 |
|
fi |
239 |
|
|
240 |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
[[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" |
241 |
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
[[ -n ${WIRELESS_CHANNEL} ]] && iwconfig "${iface}" channel "${WIRELESS_CHANNEL}" |
242 |
[[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" |
[[ -n ${WIRELESS_ESSID} ]] && iwconfig "${iface}" essid "${WIRELESS_ESSID}" |
251 |
esac |
esac |
252 |
} |
} |
253 |
|
|
254 |
|
config_bridge_devices() |
255 |
|
{ |
256 |
|
local iface="$1" |
257 |
|
local method="$2" |
258 |
|
local bport |
259 |
|
|
260 |
|
if [[ -z ${iface} ]] |
261 |
|
then |
262 |
|
echo "BRIDGE: no \$iface given. Aborting setup." |
263 |
|
return 1 |
264 |
|
fi |
265 |
|
|
266 |
|
if [[ -z ${method} ]] |
267 |
|
then |
268 |
|
echo "BRIDGE: no \$method given. Aborting setup." |
269 |
|
return 1 |
270 |
|
fi |
271 |
|
|
272 |
|
# first check for brctl |
273 |
|
if [[ -z $(which brctl) ]] |
274 |
|
then |
275 |
|
echo "brctl not found! Please install 'net-misc/bridge-utils'." |
276 |
|
return 1 |
277 |
|
fi |
278 |
|
|
279 |
|
# check the config |
280 |
|
if [[ -z ${BRIDGE_INTERFACE} ]] |
281 |
|
then |
282 |
|
echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup." |
283 |
|
return 1 |
284 |
|
fi |
285 |
|
|
286 |
|
case ${method} in |
287 |
|
add) |
288 |
|
# setup the bridge device |
289 |
|
brctl addbr ${iface} |
290 |
|
for bport in ${BRIDGE_INTERFACES} |
291 |
|
do |
292 |
|
# enter promiscous mode |
293 |
|
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) |
305 |
|
for bport in ${BRIDGE_INTERFACE} |
306 |
|
do |
307 |
|
# bring the interface down |
308 |
|
ifconfig ${bport} down |
309 |
|
# remove the interface from the bridge |
310 |
|
brctl delif ${iface} ${bport} |
311 |
|
done |
312 |
|
# bring the bridge down |
313 |
|
brctl delbr ${iface} |
314 |
|
;; |
315 |
|
esac |
316 |
|
|
317 |
|
# unset the bridge variable to be safe |
318 |
|
unset BRIDGE_INTERFACES |
319 |
|
# continue to setup generic networking |
320 |
|
} |
321 |
|
|
322 |
|
config_routes() |
323 |
|
{ |
324 |
|
local method="$1" |
325 |
|
local message |
326 |
|
|
327 |
|
# only add and del are allowed |
328 |
|
case ${method} in |
329 |
|
add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;; |
330 |
|
del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;; |
331 |
|
*) |
332 |
|
echo "config_routes: unsupported \$method '${method}'." |
333 |
|
exit 1 |
334 |
|
;; |
335 |
|
esac |
336 |
|
|
337 |
|
# adds/delete user routes |
338 |
|
if [[ -f /etc/conf.d/net.routes ]] |
339 |
|
then |
340 |
|
( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end |
341 |
|
while read route |
342 |
|
do |
343 |
|
case "${route}" in |
344 |
|
\#*|"") continue ;; |
345 |
|
esac |
346 |
|
echo -e ${COLOREDSTAR}"${message}" |
347 |
|
route ${method} ${route} |
348 |
|
evaluate_retval |
349 |
|
done |
350 |
|
fi |
351 |
|
} |
352 |
|
|
353 |
networking_start() |
networking_start() |
354 |
{ |
{ |
355 |
local iface dns |
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 |
377 |
checkconfig |
checkconfig |
378 |
|
|
|
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
|
|
|
|
379 |
# setup mac |
# setup mac |
380 |
[ -n "${FORCE_MAC_TO}" ] && ifconfig ${iface} hw ether "${FORCE_MAC_TO}" |
if [ -n "${FORCE_MAC_TO}" ] |
381 |
|
then |
382 |
|
echo -e ${COLOREDSTAR}"Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " |
383 |
|
ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" |
384 |
|
evaluate_retval |
385 |
|
fi |
386 |
|
|
387 |
|
# setup bridges |
388 |
|
if [[ ${iface} = br[0-9]* ]] |
389 |
|
then |
390 |
|
config_bridge_devices ${iface} add |
391 |
|
fi |
392 |
|
|
393 |
|
# activate the interface |
394 |
|
ifconfig "${iface}" up |
395 |
|
|
396 |
|
# now configure wireless_extensions |
397 |
|
[ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" |
398 |
|
|
399 |
|
echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." |
400 |
|
|
401 |
# setup static or dhcp |
# setup static or dhcp |
402 |
case ${NETWORKING} in |
case ${NETWORKING} in |
404 |
${CURS_UP} |
${CURS_UP} |
405 |
${SET_WWCOL} |
${SET_WWCOL} |
406 |
echo "[DHCP]" |
echo "[DHCP]" |
407 |
loadproc ${DHCP_PROG} ${DHCP_START} |
loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" |
408 |
;; |
;; |
409 |
static|STATIC) |
static|STATIC) |
410 |
${CURS_UP} |
${CURS_UP} |
435 |
echo "nameserver ${dns}" >> /etc/resolv.conf |
echo "nameserver ${dns}" >> /etc/resolv.conf |
436 |
done |
done |
437 |
fi |
fi |
|
|
|
|
# setup wlan extensions |
|
|
if [ -x /usr/sbin/iwconfig ] |
|
|
then |
|
|
setup_wireless_extensions "${iface}" |
|
|
fi |
|
438 |
done |
done |
439 |
|
|
440 |
|
# setup user routes |
441 |
|
config_routes add |
442 |
} |
} |
443 |
|
|
444 |
networking_stop() |
networking_stop() |
445 |
{ |
{ |
446 |
|
if [[ -z $1 ]] |
447 |
|
then |
448 |
|
ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) |
449 |
|
else |
450 |
|
if [[ -e ${network_settings}/net.$1 ]] |
451 |
|
then |
452 |
|
ALL_INTERFACES="$1" |
453 |
|
else |
454 |
|
${FAILURE} |
455 |
|
echo "Interface $1 does not exist. Aborting" |
456 |
|
${NORMAL} |
457 |
|
exit 1 |
458 |
|
fi |
459 |
|
fi |
460 |
|
|
461 |
# get list of all devices |
# get list of all devices |
462 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in ${ALL_INTERFACES} |
463 |
do |
do |
464 |
source ${network_settings}/net.${iface} || exit 1 |
source ${network_settings}/net.${iface} || exit 1 |
465 |
checkconfig |
checkconfig |
475 |
ifconfig ${iface} down |
ifconfig ${iface} down |
476 |
evaluate_retval |
evaluate_retval |
477 |
|
|
478 |
|
# remove bridges |
479 |
|
if [[ ${iface} = br[0-9]* ]] |
480 |
|
then |
481 |
|
config_bridge_devices ${iface} remove |
482 |
|
fi |
483 |
|
|
484 |
# shutdown dhcp-daemon |
# shutdown dhcp-daemon |
485 |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
486 |
then |
then |
488 |
${CURS_UP} |
${CURS_UP} |
489 |
${SET_WWCOL} |
${SET_WWCOL} |
490 |
echo "[$(basename ${DHCP_PROG})]" |
echo "[$(basename ${DHCP_PROG})]" |
491 |
${DHCP_PROG} ${DHCP_STOP} |
${DHCP_PROG} ${DHCP_STOP} "${iface}" |
492 |
evaluate_retval |
evaluate_retval |
493 |
fi |
fi |
494 |
|
|
498 |
killall wpa_supplicant |
killall wpa_supplicant |
499 |
fi |
fi |
500 |
done |
done |
501 |
|
|
502 |
|
# remove state dir |
503 |
|
if [ -d /var/run/wpa_supplicant ] |
504 |
|
then |
505 |
|
rm -rf /var/run/wpa_supplicant |
506 |
|
fi |
507 |
|
|
508 |
|
# delete user routes |
509 |
|
config_routes del |
510 |
} |
} |
511 |
|
|
512 |
case $1 in |
case $1 in |
513 |
start) |
start) |
514 |
networking_start |
networking_start $2 |
515 |
update_svcstatus $1 |
update_svcstatus $1 |
516 |
splash svc_started "$(basename $0)" 0 |
splash svc_started "$(basename $0)" 0 |
517 |
;; |
;; |
518 |
|
|
519 |
stop) |
stop) |
520 |
networking_stop |
networking_stop $2 |
521 |
update_svcstatus $1 |
update_svcstatus $1 |
522 |
splash svc_stopped "$(basename $0)" 0 |
splash svc_stopped "$(basename $0)" 0 |
523 |
;; |
;; |
529 |
;; |
;; |
530 |
|
|
531 |
*) |
*) |
532 |
echo "Usage: $0 {start|stop|restart}" |
echo "Usage: $0 {start|stop|restart} [interface]" |
533 |
exit 1 |
exit 1 |
534 |
;; |
;; |
535 |
esac |
esac |