Magellan Linux

Diff of /trunk/initscripts/sysvinit/rc/network

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

trunk/magellan-initscripts/etc/rc.d/init.d/network revision 1092 by niro, Wed Jul 14 11:02:11 2010 UTC trunk/initscripts/sysvinit/rc/network revision 2382 by niro, Tue Jan 7 12:02:04 2014 UTC
# Line 12  Line 12 
12    
13  source /etc/conf.d/rc  source /etc/conf.d/rc
14  source ${rc_functions}  source ${rc_functions}
15    source /etc/conf.d/network
16    
17    iface_wait_online()
18    {
19     local timeout="$1"
20     local iface="$2"
21    
22     (( timeout *= 10 ))
23    
24     while [ ! -e /sys/class/net/${iface} ]
25     do
26     (( timeout-- > 0 )) || return 1
27     sleep 0.1
28     done
29    
30     return 0
31    }
32    
33  # read values from files  # read values from files
34  read_value()  read_value()
# Line 81  checkconfig() Line 98  checkconfig()
98  {  {
99   if [[ -z ${NETWORKING} ]]   if [[ -z ${NETWORKING} ]]
100   then   then
101   echo "NETWORKING missing in net.${interface}, aborted"   rc_echo "NETWORKING missing in net.${iface}, aborted"
102   exit 1   exit 1
103   fi   fi
104    
# Line 89  checkconfig() Line 106  checkconfig()
106   static)   static)
107   if [[ -z ${IP} ]]   if [[ -z ${IP} ]]
108   then   then
109   echo "IP missing in net.${interface}, aborted"   rc_echo "IP missing in net.${iface}, aborted"
110   exit 1   exit 1
111   fi   fi
112    
113   if [[ -z ${NETMASK} ]]   if [[ -z ${NETMASK} ]]
114   then   then
115   echo -n "NETMASK missing in net.${interface}, "   rc_echo -n "NETMASK missing in net.${iface}, "
116   echo "using 255.255.255.0"   rc_echo "using ${DEFAULT_NETMASK}"
117   NETMASK=255.255.255.0   NETMASK="${DEFAULT_NETMASK}"
118   fi   fi
119    
120   if [[ -z ${BROADCAST} ]]   if [[ -z ${BROADCAST} ]]
121   then   then
122   echo -n "BROADCAST missing in net.${interface}, "   rc_echo -n "BROADCAST missing in net.${iface}, "
123   echo "using default address"   rc_echo "using default address"
124   fi   fi
125   ;;   ;;
126    
127   dhcp)   dhcp)
128   if [[ -z ${DHCP_PROG} ]]   if [[ -z ${DHCP_PROG} ]]
129   then   then
130   echo -n "DHCP_PROG missing in net.${interface},"   rc_echo -n "DHCP_PROG missing in net.${iface},"
131   echo "using default programm"   rc_echo "using default programm ${DEFAULT_DHCP_PROG}"
132   DHCP_PROG="/sbin/dhcpcd"   DHCP_PROG="${DEFAULT_DHCP_PROG}"
133   fi   fi
134   [[ -z ${DHCP_START} ]] && DHCP_START="-t 10"   [[ -z ${DHCP_START} ]] && DHCP_START="${DEFAULT_DHCP_START}"
135   [[ -z ${DHCP_STOP} ]] && DHCP_STOP="-k"   [[ -z ${DHCP_STOP} ]] && DHCP_STOP="${DEFAULT_DHCP_STOP}"
136   ;;   ;;
137    
138   esac   esac
# Line 131  onboot_interface_list() Line 148  onboot_interface_list()
148   # get list of all devices   # get list of all devices
149   for file in $@   for file in $@
150   do   do
151     iface="$(basename ${file} | sed s/net.//)"
152    
153     # exclude backup files and exclude net.routes and net.sample too
154     case "${iface}" in
155     *~) continue ;;
156     routes) continue ;;
157     sample) continue ;;
158     esac
159    
160   if [[ $(read_value ONBOOT ${file}) = yes ]]   if [[ $(read_value ONBOOT ${file}) = yes ]]
161   then   then
162   iface="$(basename ${file} | sed s/net.//)"   devices="${devices} ${iface}"
  # exclude backup files and exclude net.routes too  
  case "${iface}" in  
  *~) ;;  
  */net.routes) ;;  
  *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;  
  esac  
163   fi   fi
164   done   done
165    
# Line 152  config_wireless_wep() Line 172  config_wireless_wep()
172    
173   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
174   then   then
175   echo "WEP: no \$iface given. Aborting setup."   rc_echo "WEP: no \$iface given. Aborting setup."
176   return 1   return 1
177   fi   fi
178    
179   ${CURS_UP}   ${CURS_UP}
180   ${SET_WWCOL}   ${SET_WWCOL}
181   echo "[AUTH: WEP]"   rc_echo "[AUTH: WEP]"
182    
183   iwconfig "${iface}" enc on   iwconfig "${iface}" enc on
184   [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"   [[ -n ${WIRELESS_KEY_LENGTH} ]] && iwconfig "${iface}" enc "${WIRELESS_KEY_LENGTH}"
# Line 172  config_wireless_wpa() Line 192  config_wireless_wpa()
192    
193   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
194   then   then
195   echo "WPA: no \$iface given. Aborting setup."   rc_echo "WPA: no \$iface given. Aborting setup."
196   return 1   return 1
197   fi   fi
198    
199   if [ ! -x /sbin/wpa_supplicant ]   if [ ! -x $(type -P wpa_supplicant) ]
200   then   then
201   echo "WPA: wpa_supplicant not installed. Aborting setup."   rc_echo "WPA: wpa_supplicant not installed. Aborting setup."
202   return 1   return 1
203   fi   fi
204    
205   ${CURS_UP}   ${CURS_UP}
206   ${SET_WWCOL}   ${SET_WWCOL}
207   echo "[AUTH: WPA]"   rc_echo "[AUTH: WPA]"
208    
209   # get default settings   # get default settings
210   [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant   [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant
211    
212   # check the configuration   # check the configuration
213   [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto   [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant/wpa_supplicant.auto
214   [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel   [[ -z ${WIRELESS_WPA_SKEL} ]] && WIRELESS_WPA_SKEL=/etc/conf.d/wpa_supplicant.skel
215    
216   # use wext as default driver, do not abort here anymore   # use wext as default driver, do not abort here anymore
# Line 217  config_wireless_wpa() Line 237  config_wireless_wpa()
237   fi   fi
238    
239   # remove old state dir   # remove old state dir
240   [ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant   [ -d /run/wpa_supplicant ] && rm -rf /run/wpa_supplicant
241    
242   # now run the wpa_supplicant dameon   # now run the wpa_supplicant dameon
243   wpa_supplicant -B \   wpa_supplicant -B \
# Line 227  config_wireless_wpa() Line 247  config_wireless_wpa()
247   ${WIRELESS_WPA_OPTS}   ${WIRELESS_WPA_OPTS}
248    
249   # echo wait 5 seconds   # echo wait 5 seconds
250   echo "    Waiting 5 seconds to retrieve authentification reply ... "   rc_echo "    Waiting 5 seconds to retrieve authentification reply ... "
251   sleep 5   sleep 5
252  }  }
253    
# Line 237  setup_wireless_extensions() Line 257  setup_wireless_extensions()
257    
258   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
259   then   then
260   echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."   rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."
261   return 1   return 1
262   fi   fi
263    
# Line 249  setup_wireless_extensions() Line 269  setup_wireless_extensions()
269   [[ -n ${WIRELESS_NICK} ]] ||   [[ -n ${WIRELESS_NICK} ]] ||
270   [[ -n ${WIRELESS_AUTH_MODE} ]]   [[ -n ${WIRELESS_AUTH_MODE} ]]
271   then   then
272   echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "   rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "
273   fi   fi
274    
275   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"
# Line 277  config_bridge_options() Line 297  config_bridge_options()
297   # enable spanning-tree protocol   # enable spanning-tree protocol
298   case ${BRIDGE_STP} in   case ${BRIDGE_STP} in
299   on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;;   on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;;
300   *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;   *) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;
301   esac   esac
302    
303   # configure ageing time   # configure ageing time
# Line 341  config_bridge_devices() Line 361  config_bridge_devices()
361    
362   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
363   then   then
364   echo "BRIDGE: no \$iface given. Aborting setup."   rc_echo "BRIDGE: no \$iface given. Aborting setup."
365   return 1   return 1
366   fi   fi
367    
368   if [[ -z ${method} ]]   if [[ -z ${method} ]]
369   then   then
370   echo "BRIDGE: no \$method given. Aborting setup."   rc_echo "BRIDGE: no \$method given. Aborting setup."
371   return 1   return 1
372   fi   fi
373    
374   # first check for brctl   # first check for brctl
375   if [[ -z $(which brctl) ]]   if [[ -z $(type -P brctl) ]]
376   then   then
377   echo "brctl not found! Please install 'net-misc/bridge-utils'."   rc_echo "brctl not found! Please install 'net-misc/bridge-utils'."
378   return 1   return 1
379   fi   fi
380    
381   # check the config   # check the config
382   if [[ -z ${BRIDGE_INTERFACES} ]]   if [[ -z ${BRIDGE_INTERFACES} ]]
383   then   then
384   echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."   rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."
385   return 1   return 1
386   fi   fi
387    
# Line 405  config_routes() Line 425  config_routes()
425    
426   # only add and del are allowed   # only add and del are allowed
427   case ${method} in   case ${method} in
428   add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;;   add) message="Adding" ;;
429   del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;;   del) message="Removing" ;;
430   *)   *)
431   echo "config_routes: unsupported \$method '${method}'."   rc_echo "config_routes: unsupported \$method '${method}'."
432   exit 1   exit 1
433   ;;   ;;
434   esac   esac
# Line 422  config_routes() Line 442  config_routes()
442   case "${route}" in   case "${route}" in
443   \#*|"") continue ;;   \#*|"") continue ;;
444   esac   esac
445   echo -e ${COLOREDSTAR}"${message}"   rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..."
446   route "${method}" "${route}"   # do not esacpe ${route} or it breaks!
447     route "${method}" ${route}
448   evaluate_retval   evaluate_retval
449   done   done
450   fi   fi
# Line 442  networking_start() Line 463  networking_start()
463   ALL_INTERFACES="$1"   ALL_INTERFACES="$1"
464   else   else
465   ${FAILURE}   ${FAILURE}
466   echo "Interface $1 does not exist. Aborting"   rc_echo "Interface $1 does not exist. Aborting"
467   ${NORMAL}   ${NORMAL}
468   exit 1   exit 1
469   fi   fi
# Line 455  networking_start() Line 476  networking_start()
476   source ${rc_network_settings}/net.${iface} || exit 1   source ${rc_network_settings}/net.${iface} || exit 1
477   checkconfig   checkconfig
478    
479     # wait until the device is created
480     iface_wait_online 5 "${iface}" || { rc_echo "device '${iface}' does not exist"; continue; }
481    
482   # setup mac   # setup mac
483   if [[ -n ${FORCE_MAC_TO} ]]   if [[ -n ${FORCE_MAC_TO} ]]
484   then   then
485   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} ... "
486   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"
487   evaluate_retval   evaluate_retval
488   fi   fi
# Line 470  networking_start() Line 494  networking_start()
494   fi   fi
495    
496   # now configure wireless_extensions   # now configure wireless_extensions
497   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"   [ -x $(type -P iwconfig) ] && setup_wireless_extensions "${iface}"
498    
499   echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
500    
501   # activate the interface   # activate the interface
502   ifconfig "${iface}" up   ifconfig "${iface}" up
# Line 482  networking_start() Line 506  networking_start()
506   dhcp|DHCP)   dhcp|DHCP)
507   ${CURS_UP}   ${CURS_UP}
508   ${SET_WWCOL}   ${SET_WWCOL}
509   echo "[DHCP]"   rc_echo "[DHCP]"
510   loadproc "${DHCP_PROG}" "${DHCP_START}" "${iface}"   loadproc ${DHCP_PROG} ${DHCP_START} "${iface}"
511   ;;   ;;
512   static|STATIC)   static|STATIC)
513   ${CURS_UP}   ${CURS_UP}
514   ${SET_WWCOL}   ${SET_WWCOL}
515   echo "[STATIC]"   rc_echo "[STATIC]"
516   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"
517   evaluate_retval   evaluate_retval
518   ;;   ;;
# Line 497  networking_start() Line 521  networking_start()
521   # setup def gw   # setup def gw
522   if [[ -n ${GATEWAY} ]]   if [[ -n ${GATEWAY} ]]
523   then   then
524   echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
525   route add default gateway "${GATEWAY}" metric 1 dev "${iface}"   route add default gateway "${GATEWAY}" metric 1 dev "${iface}"
526   evaluate_retval   evaluate_retval
527    
# Line 505  networking_start() Line 529  networking_start()
529   fi   fi
530    
531   # setup /etc/resolv.conf   # setup /etc/resolv.conf
  # 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  
532   # add given nameserver   # add given nameserver
533   if [[ -n ${NAMESERVER} ]]   if [[ -n ${NAMESERVER} ]]
534   then   then
535   echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."
536    
537     # wipe out the old one
538     echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf
539     # include head
540     if [ -f /etc/resolv.conf.head ]
541     then
542     cat /etc/resolv.conf.head >> /etc/resolv.conf
543     else
544     echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf
545     fi
546    
547   for dns in ${NAMESERVER}   for dns in ${NAMESERVER}
548   do   do
549   echo "nameserver ${dns}" >> /etc/resolv.conf   echo "nameserver ${dns}" >> /etc/resolv.conf
550   done   done
551    
552     # include tail
553     if [ -f /etc/resolv.conf.tail ]
554     then
555     cat /etc/resolv.conf.tail >> /etc/resolv.conf
556     else
557     echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf
558     fi
559    
560   unset NAMESERVER   unset NAMESERVER
561   fi   fi
  # 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  
562   done   done
563    
564   # setup user routes   # setup user routes
# Line 550  networking_stop() Line 576  networking_stop()
576   ALL_INTERFACES="$1"   ALL_INTERFACES="$1"
577   else   else
578   ${FAILURE}   ${FAILURE}
579   echo "Interface $1 does not exist. Aborting"   rc_echo "Interface $1 does not exist. Aborting"
580   ${NORMAL}   ${NORMAL}
581   exit 1   exit 1
582   fi   fi
# Line 564  networking_stop() Line 590  networking_stop()
590    
591   if [[ -n ${GATEWAY} ]]   if [[ -n ${GATEWAY} ]]
592   then   then
593   echo -e ${COLOREDSTAR}"Removing default gateway ..."   rc_print "Removing default gateway ..."
594   route del -net default   route del -net default
595   evaluate_retval   evaluate_retval
596   fi   fi
597    
598   echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."
599   ifconfig ${iface} down   ifconfig "${iface}" down
600   evaluate_retval   evaluate_retval
601    
602   # remove bridges   # remove bridges
# Line 580  networking_stop() Line 606  networking_stop()
606   fi   fi
607    
608   # shutdown dhcp-daemon   # shutdown dhcp-daemon
609   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]]
610   then   then
611   echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."   rc_print "Stopping the dhcp-daemon ..."
612   ${CURS_UP}   ${CURS_UP}
613   ${SET_WWCOL}   ${SET_WWCOL}
614   echo "[$(basename ${DHCP_PROG})]"   rc_echo "[$(basename ${DHCP_PROG})]"
615   ${DHCP_PROG} ${DHCP_STOP} "${iface}"   if [[ -z ${DHCP_STOP} ]]
616   evaluate_retval   then
617     killproc ${DHCP_PROG}
618     evaluate_retval
619     else
620     ${DHCP_PROG} ${DHCP_STOP} "${iface}"
621     evaluate_retval
622     fi
623   fi   fi
624    
625   # shutdown wpa_supplicant daemon   # shutdown wpa_supplicant daemon
# Line 598  networking_stop() Line 630  networking_stop()
630   done   done
631    
632   # remove state dir   # remove state dir
633   if [ -d /var/run/wpa_supplicant ]   if [ -d /run/wpa_supplicant ]
634   then   then
635   rm -rf /var/run/wpa_supplicant   rm -rf /run/wpa_supplicant
636   fi   fi
637    
638   # delete user routes   # delete user routes
# Line 627  case $1 in Line 659  case $1 in
659   ;;   ;;
660    
661   *)   *)
662   echo "Usage: $0 {start|stop|restart} [interface]"   rc_echo "Usage: $0 {start|stop|restart} [interface]"
663   exit 1   exit 1
664   ;;   ;;
665  esac  esac

Legend:
Removed from v.1092  
changed lines
  Added in v.2382