--- trunk/busybox-initscripts/rc/network 2010/12/15 17:44:36 1168 +++ trunk/busybox-initscripts/rc/network 2011/01/27 20:41:29 1193 @@ -64,6 +64,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 +81,7 @@ { if [[ -z ${NETWORKING} ]] then - rc_echo "NETWORKING missing in net.${interface}, aborted" + rc_echo "NETWORKING missing in net.${iface}, aborted" exit 1 fi @@ -82,20 +89,20 @@ static) if [[ -z ${IP} ]] then - rc_echo "IP missing in net.${interface}, aborted" + rc_echo "IP missing in net.${iface}, aborted" exit 1 fi if [[ -z ${NETMASK} ]] then - rc_echo -n "NETMASK missing in net.${interface}, " + rc_echo -n "NETMASK missing in net.${iface}, " rc_echo "using 255.255.255.0" NETMASK=255.255.255.0 fi if [[ -z ${BROADCAST} ]] then - rc_echo -n "BROADCAST missing in net.${interface}, " + rc_echo -n "BROADCAST missing in net.${iface}, " rc_echo "using default address" fi ;; @@ -103,9 +110,12 @@ dhcp) if [[ -z ${DHCP_PROG} ]] then - rc_echo "DHCP_PROG missing in net.${interface}, aborted" - exit 1 - fi + rc_echo -n "DHCP_PROG missing in net.${iface}," + rc_echo "using default programm /sbin/udhcpc" + DHCP_PROG="/sbin/udhcpc" + fi + [[ -z ${DHCP_START} ]] && DHCP_START="-T 10" + [[ -z ${DHCP_STOP} ]] && DHCP_STOP="-k" ;; esac @@ -182,11 +192,9 @@ # check the configuration [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel - if [[ -z ${WIRELESS_WPA_DRIVER} ]] - then - rc_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,9 +203,16 @@ # 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 @@ -245,12 +260,79 @@ [[ -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() { local iface="$1" @@ -286,31 +368,28 @@ 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} ;; - *) rc_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 @@ -344,7 +423,7 @@ \#*|"") continue ;; esac rc_print "${message}" - route ${method} ${route} + route "${method}" "${route}" evaluate_retval done fi @@ -356,9 +435,9 @@ 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 @@ -373,11 +452,11 @@ 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 rc_print "Faking MAC to ${FORCE_MAC_TO} for ${COLBLUE}${iface}${COLDEFAULT} ... " ifconfig "${iface}" hw ether "${FORCE_MAC_TO}" @@ -387,24 +466,24 @@ # 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}" 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} rc_echo "[DHCP]" - loadproc ${DHCP_PROG} ${DHCP_START} "${iface}" + loadproc "${DHCP_PROG}" "${DHCP_START}" "${iface}" ;; static|STATIC) ${CURS_UP} @@ -419,24 +498,41 @@ if [[ -n ${GATEWAY} ]] then rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..." - route add default gateway ${GATEWAY} metric 1 dev ${iface} + 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 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 @@ -449,9 +545,9 @@ { 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 @@ -465,7 +561,7 @@ # 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} ]] @@ -476,13 +572,13 @@ fi rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..." - ifconfig ${iface} down + 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 @@ -533,7 +629,7 @@ ;; *) - echo "Usage: $0 {start|stop|restart} [interface]" + rc_echo "Usage: $0 {start|stop|restart} [interface]" exit 1 ;; esac