--- trunk/magellan-initscripts/etc/rc.d/init.d/network 2005/10/21 15:24:25 275 +++ trunk/magellan-initscripts/etc/rc.d/init.d/network 2007/12/17 14:30:25 640 @@ -1,5 +1,5 @@ #!/bin/bash -# $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.16 2007-12-17 14:30:25 niro Exp $ #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k #%start: 20 @@ -60,6 +60,10 @@ local WIRELESS_NICK local WIRELESS_NWID local WIRELESS_POWER + local WIRELESS_WPA_DRIVER + + local BRIDGE_INTERFACES + local BRIDGE_STP source ${file} eval value=\$$(echo ${var}) @@ -68,7 +72,7 @@ checkconfig() { - if [ -z "${NETWORKING}" ] + if [[ -z ${NETWORKING} ]] then echo "NETWORKING missing in net.${interface}, aborted" exit 1 @@ -76,20 +80,20 @@ case "${NETWORKING}" in static) - if [ -z "${IP}" ] + if [[ -z ${IP} ]] then echo "IP missing in net.${interface}, aborted" exit 1 fi - if [ -z "${NETMASK}" ] + if [[ -z ${NETMASK} ]] then echo -n "NETMASK missing in net.${interface}, " echo "using 255.255.255.0" NETMASK=255.255.255.0 fi - if [ -z "${BROADCAST}" ] + if [[ -z ${BROADCAST} ]] then echo -n "BROADCAST missing in net.${interface}, " echo "using default address" @@ -97,7 +101,7 @@ ;; dhcp) - if [ -z "${DHCP_PROG}" ] + if [[ -z ${DHCP_PROG} ]] then echo "DHCP_PROG missing in net.${interface}, aborted" exit 1 @@ -120,9 +124,10 @@ if [[ $(read_value ONBOOT ${file}) = yes ]] then iface="$(basename ${file} | sed s/net.//)" - # exclude backup files + # exclude backup files and exclude net.routes too case "${iface}" in *~) ;; + */net.routes) ;; *) devices="${devices} $(basename ${file} | sed s/net.//)" ;; esac fi @@ -246,12 +251,126 @@ esac } +config_bridge_devices() +{ + local iface="$1" + local method="$2" + local bport + + if [[ -z ${iface} ]] + then + echo "BRIDGE: no \$iface given. Aborting setup." + return 1 + fi + + if [[ -z ${method} ]] + then + echo "BRIDGE: no \$method given. Aborting setup." + return 1 + fi + + # first check for brctl + if [[ -z $(which brctl) ]] + then + echo "brctl not found! Please install 'net-misc/bridge-utils'." + return 1 + fi + + # check the config + if [[ -z ${BRIDGE_INTERFACES} ]] + then + echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." + return 1 + fi + + case ${method} in + add) + # setup the bridge device + brctl addbr ${iface} + for bport in ${BRIDGE_INTERFACES} + do + # enter promiscous mode + ifconfig ${bport} 0.0.0.0 promisc + # now setup the bridge + brctl addif ${iface} ${bport} + done + # enable spanning-tree protocol + case ${BRIDGE_STP} in + on|off) brctl stp ${iface} ${BRIDGE_STP} ;; + *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; + esac + ;; + + remove) + for bport in ${BRIDGE_INTERFACE} + do + # bring the interface down + ifconfig ${bport} down + # remove the interface from the bridge + brctl delif ${iface} ${bport} + done + # bring the bridge down + brctl delbr ${iface} + ;; + esac + + # unset the bridge variable to be safe + unset BRIDGE_INTERFACES + # continue to setup generic networking +} + +config_routes() +{ + local method="$1" + local message + + # only add and del are allowed + case ${method} in + add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;; + del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;; + *) + echo "config_routes: unsupported \$method '${method}'." + exit 1 + ;; + esac + + # adds/delete user routes + if [[ -f /etc/conf.d/net.routes ]] + then + ( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end + while read route + do + case "${route}" in + \#*|"") continue ;; + esac + echo -e ${COLOREDSTAR}"${message}" + route ${method} ${route} + evaluate_retval + done + fi +} + networking_start() { - local iface dns + local iface dns routes ALL_INTERFACES + + if [[ -z $1 ]] + then + ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) + else + if [[ -e ${network_settings}/net.$1 ]] + then + ALL_INTERFACES="$1" + else + ${FAILURE} + echo "Interface $1 does not exist. Aborting" + ${NORMAL} + exit 1 + fi + fi # get list of all devices - for iface in $(onboot_interface_list ${network_settings}/net.*) + for iface in ${ALL_INTERFACES} do # checkconfig source ${network_settings}/net.${iface} || exit 1 @@ -265,6 +384,12 @@ evaluate_retval fi + # setup bridges + if [[ ${iface} = br[0-9]* ]] + then + config_bridge_devices ${iface} add + fi + # activate the interface ifconfig "${iface}" up @@ -311,12 +436,30 @@ done fi done + + # setup user routes + config_routes add } networking_stop() { + if [[ -z $1 ]] + then + ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) + else + if [[ -e ${network_settings}/net.$1 ]] + then + ALL_INTERFACES="$1" + else + ${FAILURE} + echo "Interface $1 does not exist. Aborting" + ${NORMAL} + exit 1 + fi + fi + # get list of all devices - for iface in $(onboot_interface_list ${network_settings}/net.*) + for iface in ${ALL_INTERFACES} do source ${network_settings}/net.${iface} || exit 1 checkconfig @@ -332,6 +475,12 @@ ifconfig ${iface} down evaluate_retval + # remove bridges + if [[ ${iface} = br[0-9]* ]] + then + config_bridge_devices ${iface} remove + fi + # shutdown dhcp-daemon if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] then @@ -355,17 +504,20 @@ then rm -rf /var/run/wpa_supplicant fi + + # delete user routes + config_routes del } case $1 in start) - networking_start + networking_start $2 update_svcstatus $1 splash svc_started "$(basename $0)" 0 ;; stop) - networking_stop + networking_stop $2 update_svcstatus $1 splash svc_stopped "$(basename $0)" 0 ;; @@ -377,7 +529,7 @@ ;; *) - echo "Usage: $0 {start|stop|restart}" + echo "Usage: $0 {start|stop|restart} [interface]" exit 1 ;; esac