1 |
#!/bin/bash |
#!/bin/bash |
2 |
# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.11 2005-10-21 15:24:25 niro Exp $ |
# $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 $ |
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 |
120 |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
if [[ $(read_value ONBOOT ${file}) = yes ]] |
121 |
then |
then |
122 |
iface="$(basename ${file} | sed s/net.//)" |
iface="$(basename ${file} | sed s/net.//)" |
123 |
# exclude backup files |
# exclude backup files and exclude net.routes too |
124 |
case "${iface}" in |
case "${iface}" in |
125 |
*~) ;; |
*~) ;; |
126 |
|
*/net.routes) ;; |
127 |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
*) devices="${devices} $(basename ${file} | sed s/net.//)" ;; |
128 |
esac |
esac |
129 |
fi |
fi |
247 |
esac |
esac |
248 |
} |
} |
249 |
|
|
250 |
|
config_bridge_devices() |
251 |
|
{ |
252 |
|
local iface="$1" |
253 |
|
local method="$2" |
254 |
|
|
255 |
|
if [[ -z ${iface} ]] |
256 |
|
then |
257 |
|
echo "BRIDGE: no \$iface given. Aborting setup." |
258 |
|
return 1 |
259 |
|
fi |
260 |
|
|
261 |
|
if [[ -z ${method} ]] |
262 |
|
then |
263 |
|
echo "BRIDGE: no \$method given. Aborting setup." |
264 |
|
return 1 |
265 |
|
fi |
266 |
|
|
267 |
|
# first check for brctl |
268 |
|
if [[ -z $(which brctl) ]] |
269 |
|
then |
270 |
|
echo "brctl not found! Please install 'net-misc/bridge-utils'." |
271 |
|
return 1 |
272 |
|
fi |
273 |
|
|
274 |
|
# check the config |
275 |
|
if [[ -z ${BRIDGE_INTERFACE} ]] |
276 |
|
then |
277 |
|
echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup." |
278 |
|
return 1 |
279 |
|
fi |
280 |
|
|
281 |
|
case ${method} in |
282 |
|
add) |
283 |
|
# setup the bridge device |
284 |
|
brctl addbr ${iface} |
285 |
|
# enter promiscous mode |
286 |
|
ifconfig ${BRIDGE_INTERFACE} 0.0.0.0 promisc |
287 |
|
# now setup the bridge |
288 |
|
brctl addif ${iface} ${BRIDGE_INTERFACE} |
289 |
|
;; |
290 |
|
remove) |
291 |
|
# bring the interface down |
292 |
|
ifconfig ${BRIDGE_INTERFACE} down |
293 |
|
# remove the interface from the bridge |
294 |
|
brctl delif ${iface} ${BRIDGE_INTERFACE} |
295 |
|
# bring the bridge down |
296 |
|
brctl delbr ${iface} |
297 |
|
;; |
298 |
|
esac |
299 |
|
|
300 |
|
# unset the bridge variable to be safe |
301 |
|
unset BRIDGE_INTERFACE |
302 |
|
# continue to setup generic networking |
303 |
|
} |
304 |
|
|
305 |
|
config_routes() |
306 |
|
{ |
307 |
|
local method="$1" |
308 |
|
local message |
309 |
|
|
310 |
|
# only add and del are allowed |
311 |
|
case ${method} in |
312 |
|
add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;; |
313 |
|
del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;; |
314 |
|
*) |
315 |
|
echo "config_routes: unsupported \$method '${method}'." |
316 |
|
exit 1 |
317 |
|
;; |
318 |
|
esac |
319 |
|
|
320 |
|
# adds/delete user routes |
321 |
|
if [[ -f /etc/conf.d/net.routes ]] |
322 |
|
then |
323 |
|
( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end |
324 |
|
while read route |
325 |
|
do |
326 |
|
case "${route}" in |
327 |
|
\#*|"") continue ;; |
328 |
|
esac |
329 |
|
echo -e ${COLOREDSTAR}"${message}" |
330 |
|
route ${method} ${route} |
331 |
|
evaluate_retval |
332 |
|
done |
333 |
|
fi |
334 |
|
} |
335 |
|
|
336 |
networking_start() |
networking_start() |
337 |
{ |
{ |
338 |
local iface dns |
local iface dns routes |
339 |
|
|
340 |
# get list of all devices |
# get list of all devices |
341 |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
for iface in $(onboot_interface_list ${network_settings}/net.*) |
352 |
evaluate_retval |
evaluate_retval |
353 |
fi |
fi |
354 |
|
|
355 |
|
# setup bridges |
356 |
|
if [[ ${iface} = br[0-9]* ]] |
357 |
|
then |
358 |
|
config_bridge_devices ${iface} add |
359 |
|
fi |
360 |
|
|
361 |
# activate the interface |
# activate the interface |
362 |
ifconfig "${iface}" up |
ifconfig "${iface}" up |
363 |
|
|
404 |
done |
done |
405 |
fi |
fi |
406 |
done |
done |
407 |
|
|
408 |
|
# setup user routes |
409 |
|
config_routes add |
410 |
} |
} |
411 |
|
|
412 |
networking_stop() |
networking_stop() |
428 |
ifconfig ${iface} down |
ifconfig ${iface} down |
429 |
evaluate_retval |
evaluate_retval |
430 |
|
|
431 |
|
# remove bridges |
432 |
|
if [[ ${iface} = br[0-9]* ]] |
433 |
|
then |
434 |
|
config_bridge_devices ${iface} remove |
435 |
|
fi |
436 |
|
|
437 |
# shutdown dhcp-daemon |
# shutdown dhcp-daemon |
438 |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] |
439 |
then |
then |
457 |
then |
then |
458 |
rm -rf /var/run/wpa_supplicant |
rm -rf /var/run/wpa_supplicant |
459 |
fi |
fi |
460 |
|
|
461 |
|
# delete user routes |
462 |
|
config_routes del |
463 |
} |
} |
464 |
|
|
465 |
case $1 in |
case $1 in |