Magellan Linux

Diff of /trunk/initscripts/systemd/units/scripts/network.sh

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2031 by niro, Thu Jan 24 14:33:31 2013 UTC revision 2383 by niro, Tue Jan 7 12:13:29 2014 UTC
# Line 5  Line 5 
5  # get default settings  # get default settings
6  source /etc/conf.d/network  source /etc/conf.d/network
7    
8    iface_wait_online()
9    {
10     local timeout="$1"
11     local iface="$2"
12    
13     (( timeout *= 10 ))
14    
15     while [ ! -e /sys/class/net/${iface} ]
16     do
17     (( timeout-- > 0 )) || return 1
18     echo "waiting 0.1 seconds for device '${iface}' - timeout->'${timeout}'"
19     sleep 0.1
20     done
21    
22     return 0
23    }
24    
25    iface_has_link()
26    {
27     local interface="$1"
28     local flags
29    
30     [[ -n ${interface} ]] || return 2
31     interface="/sys/class/net/${interface}"
32     [[ -d ${interface} ]] || return 2
33     flags=$(cat ${interface}/flags)
34     echo $((${flags}|0x41)) > ${interface}/flags # 0x41: IFF_UP|IFF_RUNNING
35     [ "$(cat ${interface}/carrier)" = 1 ] || return 1
36    }
37    
38  # read values from files  # read values from files
39  read_value()  read_value()
40  {  {
# Line 167  config_wireless_wpa() Line 197  config_wireless_wpa()
197   return 1   return 1
198   fi   fi
199    
200   if [ ! -x /sbin/wpa_supplicant ]   if [ ! -x $(type -P wpa_supplicant) ]
201   then   then
202   echo "WPA: wpa_supplicant not installed. Aborting setup."   echo "WPA: wpa_supplicant not installed. Aborting setup."
203   return 1   return 1
# Line 428  networking_start() Line 458  networking_start()
458   source /etc/conf.d/net.${iface} || exit 1   source /etc/conf.d/net.${iface} || exit 1
459   checkconfig   checkconfig
460    
461     # wait until the device is created
462     iface_wait_online 5 "${iface}" || { echo "device '${iface}' does not exist"; continue; }
463    
464   # setup mac   # setup mac
465   if [[ -n ${FORCE_MAC_TO} ]]   if [[ -n ${FORCE_MAC_TO} ]]
466   then   then
# Line 441  networking_start() Line 474  networking_start()
474   fi   fi
475    
476   # now configure wireless_extensions   # now configure wireless_extensions
477   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"   [ -x $(type -P iwconfig) ] && setup_wireless_extensions "${iface}"
478    
479   # activate the interface   # activate the interface
480   ifconfig "${iface}" up   ifconfig "${iface}" up
# Line 449  networking_start() Line 482  networking_start()
482   # setup static or dhcp   # setup static or dhcp
483   case ${NETWORKING} in   case ${NETWORKING} in
484   dhcp|DHCP)   dhcp|DHCP)
485   ${DHCP_PROG} ${DHCP_START} "${iface}" ;;   if iface_has_link "${iface}"
486     then
487     ${DHCP_PROG} ${DHCP_START} "${iface}"
488     else
489     echo "Interface '${iface}' has no link. Not running '${DHCP_PROG}'."
490     fi
491     ;;
492   static|STATIC)   static|STATIC)
493   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" ;;   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}" ;;
494   esac   esac

Legend:
Removed from v.2031  
changed lines
  Added in v.2383