--- trunk/magellan-initscripts/etc/rc.d/init.d/network 2007/12/13 12:18:23 638 +++ trunk/initscripts/sysvinit/rc/network 2013/01/24 14:33:31 2031 @@ -1,5 +1,5 @@ #!/bin/bash -# $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.15 2007-12-13 12:18:23 niro Exp $ +# $Id$ #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k #%start: 20 @@ -10,8 +10,9 @@ #%before: #%after: -source /etc/sysconfig/rc +source /etc/conf.d/rc source ${rc_functions} +source /etc/conf.d/network # read values from files read_value() @@ -24,7 +25,7 @@ # global local ONBOOT local NETWORKING - + # static local IP local NETMASK @@ -64,6 +65,13 @@ local BRIDGE_INTERFACES local BRIDGE_STP + local BRIDGE_AGEING_TIME + local BRIDGE_PRIORITY + local BRIDGE_FORWARD_DELAY + local BRIDGE_HELLO_TIME + local BRIDGE_MAX_MESSAGE_AGE + local BRIDGE_PATH_COST + local BRIDGE_PORT_PRIORITY source ${file} eval value=\$$(echo ${var}) @@ -74,7 +82,7 @@ { if [[ -z ${NETWORKING} ]] then - echo "NETWORKING missing in net.${interface}, aborted" + rc_echo "NETWORKING missing in net.${iface}, aborted" exit 1 fi @@ -82,30 +90,33 @@ static) if [[ -z ${IP} ]] then - echo "IP missing in net.${interface}, aborted" + rc_echo "IP missing in net.${iface}, aborted" exit 1 fi if [[ -z ${NETMASK} ]] then - echo -n "NETMASK missing in net.${interface}, " - echo "using 255.255.255.0" - NETMASK=255.255.255.0 + rc_echo -n "NETMASK missing in net.${iface}, " + rc_echo "using ${DEFAULT_NETMASK}" + NETMASK="${DEFAULT_NETMASK}" fi if [[ -z ${BROADCAST} ]] then - echo -n "BROADCAST missing in net.${interface}, " - echo "using default address" + rc_echo -n "BROADCAST missing in net.${iface}, " + rc_echo "using default address" fi ;; dhcp) if [[ -z ${DHCP_PROG} ]] then - echo "DHCP_PROG missing in net.${interface}, aborted" - exit 1 + rc_echo -n "DHCP_PROG missing in net.${iface}," + rc_echo "using default programm ${DEFAULT_DHCP_PROG}" + DHCP_PROG="${DEFAULT_DHCP_PROG}" fi + [[ -z ${DHCP_START} ]] && DHCP_START="${DEFAULT_DHCP_START}" + [[ -z ${DHCP_STOP} ]] && DHCP_STOP="${DEFAULT_DHCP_STOP}" ;; esac @@ -121,15 +132,18 @@ # get list of all devices for file in $@ do + iface="$(basename ${file} | sed s/net.//)" + + # exclude backup files and exclude net.routes and net.sample too + case "${iface}" in + *~) continue ;; + routes) continue ;; + sample) continue ;; + esac + if [[ $(read_value ONBOOT ${file}) = yes ]] then - iface="$(basename ${file} | sed s/net.//)" - # exclude backup files and exclude net.routes too - case "${iface}" in - *~) ;; - */net.routes) ;; - *) devices="${devices} $(basename ${file} | sed s/net.//)" ;; - esac + devices="${devices} ${iface}" fi done @@ -142,13 +156,13 @@ if [[ -z ${iface} ]] then - echo "WEP: no \$iface given. Aborting setup." + rc_echo "WEP: no \$iface given. Aborting setup." return 1 fi ${CURS_UP} ${SET_WWCOL} - echo "[AUTH: WEP]" + rc_echo "[AUTH: WEP]" iwconfig "${iface}" enc on [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}" @@ -162,31 +176,29 @@ if [[ -z ${iface} ]] then - echo "WPA: no \$iface given. Aborting setup." + rc_echo "WPA: no \$iface given. Aborting setup." return 1 fi if [ ! -x /sbin/wpa_supplicant ] then - echo "WPA: wpa_supplicant not installed. Aborting setup." + rc_echo "WPA: wpa_supplicant not installed. Aborting setup." return 1 fi ${CURS_UP} ${SET_WWCOL} - echo "[AUTH: WPA]" + rc_echo "[AUTH: WPA]" # get default settings [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant # check the configuration - [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto + [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant/wpa_supplicant.auto [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel - if [[ -z ${WIRELESS_WPA_DRIVER} ]] - then - echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup." - return 1 - fi + + # use wext as default driver, do not abort here anymore + [[ -z ${WIRELESS_WPA_DRIVER} ]] && WIRELESS_WPA_DRIVER=wext # write a config with the settings from net.${iface} # only wpa-psk ! all other needs manual setup @@ -195,14 +207,21 @@ # write default cfg from skeleton cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG} + local wpa_proto + case ${WIRELESS_AUTH_MODE} in + wpa) wpa_proto="WPA" ;; + wpa2) wpa_proto="WPA2" ;; + esac + # setup the network entry sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \ - -e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \ + -e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \ + -e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \ ${WIRELESS_WPA_CONFIG} fi # remove old state dir - [ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant + [ -d /run/wpa_supplicant ] && rm -rf /run/wpa_supplicant # now run the wpa_supplicant dameon wpa_supplicant -B \ @@ -212,7 +231,7 @@ ${WIRELESS_WPA_OPTS} # echo wait 5 seconds - echo " Waiting 5 seconds to retrieve authentification reply ... " + rc_echo " Waiting 5 seconds to retrieve authentification reply ... " sleep 5 } @@ -222,7 +241,7 @@ if [[ -z ${iface} ]] then - echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." + rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup." return 1 fi @@ -234,7 +253,7 @@ [[ -n ${WIRELESS_NICK} ]] || [[ -n ${WIRELESS_AUTH_MODE} ]] then - echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " + rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... " fi [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}" @@ -245,10 +264,77 @@ [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}" case "${WIRELESS_AUTH_MODE}" in - wpa) config_wireless_wpa "${iface}" ;; - wep|on) config_wireless_wep "${iface}" ;; - off) iwconfig "${iface}" enc off ;; + wpa|wpa2) config_wireless_wpa "${iface}" ;; + wep|on) config_wireless_wep "${iface}" ;; + off) iwconfig "${iface}" enc off ;; + esac +} + +config_bridge_options() +{ + local iface="$1" + local i + local port + local cost + local prio + + # enable spanning-tree protocol + case ${BRIDGE_STP} in + on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;; + *) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;; esac + + # configure ageing time + if [[ ! -z ${BRIDGE_AGEING_TIME} ]] + then + brctl setageing "${iface}" "${BRIDGE_AGEING_TIME}" + fi + + # configure bridge priority + if [[ ! -z ${BRIDGE_PRIORITY} ]] + then + brctl setbridgeprio "${iface}" "${BRIDGE_PRIORITY}" + fi + + # configure forward delay + if [[ ! -z ${BRIDGE_FORWARD_DELAY} ]] + then + brctl setfd "${iface}" "${BRIDGE_FORWARD_DELAY}" + fi + + # configure hello time + if [[ ! -z ${BRIDGE_HELLO_TIME} ]] + then + brctl sethello "${iface}" "${BRIDGE_HELLO_TIME}" + fi + + # configure maximal message age + if [[ ! -z ${BRIDGE_MAX_MESSAGE_AGE} ]] + then + brctl setmaxage "${iface}" "${BRIDGE_MAX_MESSAGE_AGE}" + fi + + # configure path cost for every port + if [[ ! -z ${BRIDGE_PATH_COST} ]] + then + for i in ${BRIDGE_PATH_COST} + do + port="${i%=*}" + cost="${i#*=}" + [[ ! -z ${port} ]] && brctl pathcost "${iface}" "${port}" "${cost}" + done + fi + + # configure port priority for every port + if [[ ! -z ${BRIDGE_PORT_PRIORITY} ]] + then + for i in ${BRIDGE_PORT_PRIORITY} + do + port="${i%=*}" + prio="${i#*=}" + [[ ! -z ${port} ]] && brctl setportprio "${iface}" "${port}" "${prio}" + done + fi } config_bridge_devices() @@ -259,58 +345,55 @@ if [[ -z ${iface} ]] then - echo "BRIDGE: no \$iface given. Aborting setup." + rc_echo "BRIDGE: no \$iface given. Aborting setup." return 1 fi if [[ -z ${method} ]] then - echo "BRIDGE: no \$method given. Aborting setup." + rc_echo "BRIDGE: no \$method given. Aborting setup." return 1 fi # first check for brctl - if [[ -z $(which brctl) ]] + if [[ -z $(type -P brctl) ]] then - echo "brctl not found! Please install 'net-misc/bridge-utils'." + rc_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." + rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup." return 1 fi case ${method} in add) # setup the bridge device - brctl addbr ${iface} + brctl addbr "${iface}" for bport in ${BRIDGE_INTERFACES} do # enter promiscous mode - ifconfig ${bport} 0.0.0.0 promisc + ifconfig "${bport}" 0.0.0.0 promisc # now setup the bridge - brctl addif ${iface} ${bport} + 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 + # configure all other options + config_bridge_options "${iface}" ;; remove) for bport in ${BRIDGE_INTERFACE} do # bring the interface down - ifconfig ${bport} down + ifconfig "${bport}" down # remove the interface from the bridge - brctl delif ${iface} ${bport} + brctl delif "${iface}" "${bport}" done # bring the bridge down - brctl delbr ${iface} + brctl delbr "${iface}" ;; esac @@ -326,10 +409,10 @@ # only add and del are allowed case ${method} in - add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;; - del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;; + add) message="Adding" ;; + del) message="Removing" ;; *) - echo "config_routes: unsupported \$method '${method}'." + rc_echo "config_routes: unsupported \$method '${method}'." exit 1 ;; esac @@ -343,8 +426,9 @@ case "${route}" in \#*|"") continue ;; esac - echo -e ${COLOREDSTAR}"${message}" - route ${method} ${route} + rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..." + # do not esacpe ${route} or it breaks! + route "${method}" ${route} evaluate_retval done fi @@ -356,14 +440,14 @@ if [[ -z $1 ]] then - ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) + ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) else - if [[ -e ${network_settings}/net.$1 ]] + if [[ -e ${rc_network_settings}/net.$1 ]] then ALL_INTERFACES="$1" else ${FAILURE} - echo "Interface $1 does not exist. Aborting" + rc_echo "Interface $1 does not exist. Aborting" ${NORMAL} exit 1 fi @@ -373,13 +457,13 @@ for iface in ${ALL_INTERFACES} do # checkconfig - source ${network_settings}/net.${iface} || exit 1 + source ${rc_network_settings}/net.${iface} || exit 1 checkconfig # setup mac - if [ -n "${FORCE_MAC_TO}" ] + if [[ -n ${FORCE_MAC_TO} ]] then - echo -e ${COLOREDSTAR}"Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " + rc_print "Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" evaluate_retval fi @@ -387,29 +471,29 @@ # setup bridges if [[ ${iface} = br[0-9]* ]] then - config_bridge_devices ${iface} add + config_bridge_devices "${iface}" add fi - # activate the interface - ifconfig "${iface}" up - # now configure wireless_extensions [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}" - echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." + rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..." + + # activate the interface + ifconfig "${iface}" up # setup static or dhcp case ${NETWORKING} in dhcp|DHCP) ${CURS_UP} ${SET_WWCOL} - echo "[DHCP]" + rc_echo "[DHCP]" loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" ;; static|STATIC) ${CURS_UP} ${SET_WWCOL} - echo "[STATIC]" + rc_echo "[STATIC]" ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" evaluate_retval ;; @@ -418,22 +502,43 @@ # setup def gw if [[ -n ${GATEWAY} ]] then - echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." - route add default gateway ${GATEWAY} metric 1 dev ${iface} + rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." + route add default gateway "${GATEWAY}" metric 1 dev "${iface}" evaluate_retval + + unset GATEWAY fi # setup /etc/resolv.conf + # add given nameserver if [[ -n ${NAMESERVER} ]] then - echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." - + rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..." + # whipe out the old one echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf + # include head + if [ -f /etc/resolv.conf.head ] + then + cat /etc/resolv.conf.head >> /etc/resolv.conf + else + echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf + fi + for dns in ${NAMESERVER} do echo "nameserver ${dns}" >> /etc/resolv.conf done + + # include tail + if [ -f /etc/resolv.conf.tail ] + then + cat /etc/resolv.conf.tail >> /etc/resolv.conf + else + echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf + fi + + unset NAMESERVER fi done @@ -445,14 +550,14 @@ { if [[ -z $1 ]] then - ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*) + ALL_INTERFACES=$(onboot_interface_list ${rc_network_settings}/net.*) else - if [[ -e ${network_settings}/net.$1 ]] + if [[ -e ${rc_network_settings}/net.$1 ]] then ALL_INTERFACES="$1" else ${FAILURE} - echo "Interface $1 does not exist. Aborting" + rc_echo "Interface $1 does not exist. Aborting" ${NORMAL} exit 1 fi @@ -461,35 +566,41 @@ # get list of all devices for iface in ${ALL_INTERFACES} do - source ${network_settings}/net.${iface} || exit 1 + source ${rc_network_settings}/net.${iface} || exit 1 checkconfig if [[ -n ${GATEWAY} ]] then - echo -e ${COLOREDSTAR}"Removing default gateway ..." + rc_print "Removing default gateway ..." route del -net default evaluate_retval fi - echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." - ifconfig ${iface} down + rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." + ifconfig "${iface}" down evaluate_retval # remove bridges if [[ ${iface} = br[0-9]* ]] then - config_bridge_devices ${iface} remove + config_bridge_devices "${iface}" remove fi # shutdown dhcp-daemon - if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]] + if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]] then - echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..." + rc_print "Stopping the dhcp-daemon ..." ${CURS_UP} ${SET_WWCOL} - echo "[$(basename ${DHCP_PROG})]" - ${DHCP_PROG} ${DHCP_STOP} "${iface}" - evaluate_retval + rc_echo "[$(basename ${DHCP_PROG})]" + if [[ -z ${DHCP_STOP} ]] + then + killproc ${DHCP_PROG} + evaluate_retval + else + ${DHCP_PROG} ${DHCP_STOP} "${iface}" + evaluate_retval + fi fi # shutdown wpa_supplicant daemon @@ -500,9 +611,9 @@ done # remove state dir - if [ -d /var/run/wpa_supplicant ] + if [ -d /run/wpa_supplicant ] then - rm -rf /var/run/wpa_supplicant + rm -rf /run/wpa_supplicant fi # delete user routes @@ -529,7 +640,7 @@ ;; *) - echo "Usage: $0 {start|stop|restart} [interface]" + rc_echo "Usage: $0 {start|stop|restart} [interface]" exit 1 ;; esac