diff --git a/sbin/if_down b/sbin/if_down index 88338d2..f88fa93 100755 --- a/sbin/if_down +++ b/sbin/if_down @@ -35,15 +35,25 @@ if [ ! "$DEV" ]; then echo "Usage: $0 " exit 10 fi +if pgrep vtun >/dev/null; then + /etc/init.d/vtund stop +fi if [ -f /etc/sysconfig/net/${DEV}.dhcp ]; then - kill `ps -ef|grep dhclient|grep ${DEV}|awk '{print $2}'` + echo -n "Stopping dhclient for $DEV" + DHPID=`ps -ef|grep dhclient|grep ${DEV}|awk '{print $2}'` + if [ "$DHPID" ]; then + kill $DHPID + fi + evaluate_retval + echo -n "Shutting down Interface $DEV" ifconfig $DEV 0.0.0.0 down + evaluate_retval elif [ -f /etc/sysconfig/net/hostname.${DEV} ]; then HOST=`cat /etc/sysconfig/net/hostname.${DEV}|awk '{print $1}'` IP=`grep $HOST /etc/hosts|awk '{print $1}'` NETMASK=`getmask $IP` SHMASK=`GetShortMask $NETMASK` - echo -n "setting up interface $i:IP=$IP NMASK=$NETMASK" + echo -n "shutting down interface $i:IP=$IP NMASK=$NETMASK" if [ "$NETMASK" = "" ]; then DEV=`echo $i|cut -d ":" -f 1` $DEBUG ip addr del $IP broadcast + dev $DEV @@ -55,3 +65,31 @@ elif [ -f /etc/sysconfig/net/hostname.${DEV} ]; then fi evaluate_retval fi +if [ -f /var/run/shutdown/wlan_nis ]; then + if [ -f /etc/sysconfig/nis/defaultdomain.wlan ]; then + echo -n "Restoring nis defaultdomain" + mv /etc/sysconfig/nis/defaultdomain.wlan \ + /etc/sysconfig/nis/defaultdomain + evaluate_retval + fi + if [ -f /etc/yp.conf.wlan ]; then + echo -n "Restoring nis yp.conf" + mv /etc/yp.conf.wlan \ + /etc/yp.conf + evaluate_retval + fi + rm /var/run/shutdown/wlan_nis + if [ -f /var/run/shutdown/wlan_dns ]; then + if [ -f /etc/resolv.conf.wlan ]; then + echo -n "Restoring resolv.conf" + mv /etc/resolv.conf.wlan /etc/resolv.conf + evaluate_retval + fi + rm /var/run/shutdown/wlan_dns + fi +fi +if pgrep wpa_supplicant >/dev/null; then + echo -n "Stopping wpa_supplicant" + pkill wpa_supplicant + evaluate_retval +fi diff --git a/sbin/if_up b/sbin/if_up index 4e5110b..f9233e3 100755 --- a/sbin/if_up +++ b/sbin/if_up @@ -30,31 +30,96 @@ # source /etc/init.d/functions + DEV=$1 + +CheckForLink() { + NETDEVICE=$1 + if [ -f /usr/sbin/ethtool ]; then + #Einige Dumme Interfaces (z.B. die VMware Emulationen) Zeiten + #den korrekten Status erst nach einem ifconfig up + WAITTIME=7 + ZAHLER=0 + if ! ethtool $NETDEVICE|grep -q "No data available"; then + while [ ${ZAHLER} -le ${WAITTIME} ]; do + if [ ! `ethtool $NETDEVICE|grep Link|awk '{print $3}'` == "yes" ]; then + (( ZAHLER++ )) + else + break + fi + sleep 1 + done + if [ `ethtool $NETDEVICE|grep Link|awk '{print $3}'` == "yes" ]; then + touch /var/run/net_up + return 0 + else + return 1 + fi + else + touch /var/run/net_up + return 0 + fi + else + touch /var/run/net_up + return 0 + fi +} + if [ ! "$DEV" ]; then echo "Usage: $0 " exit 10 fi + +#Check for files in /etc/sysconfig/net +#hostname. will setup static ip for the interfaces, based +#on /etc/hosts (hostname) and /etc/networks (netmask/Broadcast) +#.dhcp will do a dynamic setup for the interface with dhcp + if [ -f /etc/sysconfig/net/${DEV}.dhcp ]; then - echo -n "Setting up ${DEV} with dhcp" - dhclient -q ${DEV} - evaluate_retval + #ok this is the dynamic part for setup ${DEV} + #first we have to startup interface to check interface type + ifconfig ${DEV} up + #Let check in /sys if the interface is a wireless interface + if [ -d /sys/class/net/${DEV}/wireless ]; then + #wireless interface need special setup.. + /sbin/wlan_setup ${DEV} + #give wlan time to startup and create a link + sleep 1 + fi + #let check if there is a link on the interface. + #only if there is a link, we will setup the interface.. + if CheckForLink ${DEV}; then + echo -n "Setting up ${DEV} with dhcp" + dhclient -q ${DEV} + evaluate_retval + else + ifconfig ${DEV} down + fi elif ls /etc/sysconfig/net/hostname.${DEV}* &>/dev/null; then - for NETDEV in `ls /etc/sysconfig/net/hostname.${DEV}*|awk -F "." '{print $2}'`; do - HOST=`cat /etc/sysconfig/net/hostname.${NETDEV}|awk '{print $1}'` - IP=`grep $HOST /etc/hosts|awk '{print $1}'` - NETMASK=`getmask $IP` - SHMASK=`GetShortMask $NETMASK` - echo -n "setting up interface $NETDEV:IP=$IP NMASK=$NETMASK" - if [ "$NETMASK" = "" ]; then - DEV=`echo $NETDEV|cut -d ":" -f 1` - $DEBUG ip addr add $IP broadcast + dev $DEV - $DEBUG ip link set $DEV up - else - DEV=`echo $NETDEV|cut -d ":" -f 1` - $DEBUG ip addr add $IP/$SHMASK broadcast + dev $DEV - $DEBUG ip link set $DEV up - fi - done - evaluate_retval + ifconfig ${DEV} up + if [ -d /sys/class/net/${DEV}/wireless ]; then + /sbin/wlan_setup ${DEV} + #give wlan time to startup and create a link + sleep 1 + fi + if CheckForLink ${DEV}; then + for NETDEV in `ls /etc/sysconfig/net/hostname.${DEV}*|awk -F "." '{print $2}'`; do + HOST=`cat /etc/sysconfig/net/hostname.${NETDEV}|awk '{print $1}'` + IP=`grep $HOST /etc/hosts|awk '{print $1}'` + NETMASK=`getmask $IP` + SHMASK=`GetShortMask $NETMASK` + echo -n "setting up interface $NETDEV:IP=$IP NMASK=$NETMASK" + if [ "$NETMASK" = "" ]; then + DEV=`echo $NETDEV|cut -d ":" -f 1` + $DEBUG ip addr add $IP broadcast + dev $DEV + $DEBUG ip link set $DEV up + else + DEV=`echo $NETDEV|cut -d ":" -f 1` + $DEBUG ip addr add $IP/$SHMASK broadcast + dev $DEV + $DEBUG ip link set $DEV up + fi + done + else + ifconfig ${DEV} down + fi fi diff --git a/sbin/wlan_setup b/sbin/wlan_setup index 97cf406..b39df83 100755 --- a/sbin/wlan_setup +++ b/sbin/wlan_setup @@ -39,6 +39,9 @@ if [ ! -f /var/state/ldap_disable ]; then touch /var/state/ldap_disable fi +if [ ! -d /var/run/shutdown ]; then + mkdir -p /var/run/shutdown +fi NSSWITCH=/etc/nsswitch.conf DEV=$1 if [ ! "$DEV" ]; then @@ -64,6 +67,9 @@ for AP in `iwlist $DEV scan 2>/dev/null|\ read <&3 OPTION ARG1 ARG2 while [ $OPTION ]; do case $OPTION in + WPA2|WPA) + wpa_supplicant -i ${DEV} -D ${ARG1} -c /etc/sysconfig/wpa_supplicant/${AP} -B + ;; KEY) echo -n "Configuring Wireless Interface KEY" $DEBUG iwconfig $DEV key $ARG1 $ARG2 @@ -73,18 +79,58 @@ for AP in `iwlist $DEV scan 2>/dev/null|\ $DEBUG iwconfig $DEV txpower $ARG1 ;; YP) - echo "domain $ARG1 server $ARG2" >/etc/yp.conf - NISSTR="nis" - ;; + if [ -f /var/run/shutdown/wlan_nis ]; then + echo "No Clean Shutdown, cleaning up" + if [ -f /etc/sysconfig/nis/defaultdomain.wlan ]; then + mv /etc/sysconfig/nis/defaultdomain.wlan \ + /etc/sysconfig/nis/defaultdomain + elif [ -f /etc/sysconfig/nis/defaultdomain ]; then + rm /etc/sysconfig/nis/defaultdomain + fi + if [ -f /etc/yp.conf.wlan ]; then + mv /etc/yp.conf.wlan /etc/yp.conf + elif [ -f /etc/yp.conf ]; then + rm /etc/yp.conf + fi + fi + touch /var/run/shutdown/wlan_nis + if [ "$ARG1" ]; then + if [ -f /etc/sysconfig/nis/defaultdomain ]; then + mv /etc/sysconfig/nis/defaultdomain{,.wlan} + fi + echo "$ARG1" >/etc/sysconfig/nis/defaultdomain + fi + if [ "$ARG2" ]; then + if [ -f /etc/yp.conf ]; then + mv /etc/yp.conf{,.wlan} + fi + echo "domain $ARG1 server $ARG2" >/etc/yp.conf + fi + NISSTR="nis" + ;; LDAP) export USE_LDAP=1 LDAPSTR="ldap" rm /var/state/ldap_disable ;; DNS) + if [ -f /var/run/shutdown/wlan_dns ]; then + echo "No Clean Shutdown, cleaning up" + if [ -f /etc/resolv.conf.wlan ]; then + mv /etc/resolv.conf.wlan /etc/resolv.conf + fi + fi + touch /var/run/shutdown/wlan_dns + if [ -f /etc/resolv.conf ]; then + mv /etc/resolv.conf{,.wlan} + fi echo "#Resolv.conf generatet by wlan_setup" >/etc/resolv.conf echo "nameserver $ARG1" >>/etc/resolv.conf ;; + VTUN) + echo "Starting vtun client" + /etc/init.d/vtund start + ;; esac read <&3 OPTION ARG1 ARG2 done