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 2911 by niro, Thu Nov 26 14:14:05 2015 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    iface_has_link()
34    {
35     local interface="$1"
36     local flags
37    
38     [[ -n ${interface} ]] || return 2
39     interface="/sys/class/net/${interface}"
40     [[ -d ${interface} ]] || return 2
41     flags=$(cat ${interface}/flags)
42     echo $((${flags}|0x41)) > ${interface}/flags # 0x41: IFF_UP|IFF_RUNNING
43     [ "$(cat ${interface}/carrier)" = 1 ] || return 1
44    }
45    
46  # read values from files  # read values from files
47  read_value()  read_value()
# Line 72  read_value() Line 102  read_value()
102   local BRIDGE_PATH_COST   local BRIDGE_PATH_COST
103   local BRIDGE_PORT_PRIORITY   local BRIDGE_PORT_PRIORITY
104    
105     # point-to-point support
106     local POINTOPOINT
107    
108   source ${file}   source ${file}
109   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
110   echo "${value}"   echo "${value}"
# Line 81  checkconfig() Line 114  checkconfig()
114  {  {
115   if [[ -z ${NETWORKING} ]]   if [[ -z ${NETWORKING} ]]
116   then   then
117   echo "NETWORKING missing in net.${interface}, aborted"   rc_echo "NETWORKING missing in net.${iface}, aborted"
118   exit 1   exit 1
119   fi   fi
120    
# Line 89  checkconfig() Line 122  checkconfig()
122   static)   static)
123   if [[ -z ${IP} ]]   if [[ -z ${IP} ]]
124   then   then
125   echo "IP missing in net.${interface}, aborted"   rc_echo "IP missing in net.${iface}, aborted"
126   exit 1   exit 1
127   fi   fi
128    
129   if [[ -z ${NETMASK} ]]   if [[ -z ${NETMASK} ]]
130   then   then
131   echo -n "NETMASK missing in net.${interface}, "   rc_echo -n "NETMASK missing in net.${iface}, "
132   echo "using 255.255.255.0"   rc_echo "using ${DEFAULT_NETMASK}"
133   NETMASK=255.255.255.0   NETMASK="${DEFAULT_NETMASK}"
134   fi   fi
135    
136   if [[ -z ${BROADCAST} ]]   if [[ -z ${BROADCAST} ]]
137   then   then
138   echo -n "BROADCAST missing in net.${interface}, "   rc_echo -n "BROADCAST missing in net.${iface}, "
139   echo "using default address"   rc_echo "using default address"
140   fi   fi
141   ;;   ;;
142    
143   dhcp)   dhcp)
144   if [[ -z ${DHCP_PROG} ]]   if [[ -z ${DHCP_PROG} ]]
145   then   then
146   echo -n "DHCP_PROG missing in net.${interface},"   rc_echo -n "DHCP_PROG missing in net.${iface},"
147   echo "using default programm"   rc_echo "using default programm ${DEFAULT_DHCP_PROG}"
148   DHCP_PROG="/sbin/dhcpcd"   DHCP_PROG="${DEFAULT_DHCP_PROG}"
149   fi   fi
150   [[ -z ${DHCP_START} ]] && DHCP_START="-t 10"   [[ -z ${DHCP_START} ]] && DHCP_START="${DEFAULT_DHCP_START}"
151   [[ -z ${DHCP_STOP} ]] && DHCP_STOP="-k"   [[ -z ${DHCP_STOP} ]] && DHCP_STOP="${DEFAULT_DHCP_STOP}"
152   ;;   ;;
153    
154   esac   esac
# Line 131  onboot_interface_list() Line 164  onboot_interface_list()
164   # get list of all devices   # get list of all devices
165   for file in $@   for file in $@
166   do   do
167     iface="$(basename ${file} | sed s/net.//)"
168    
169     # exclude backup files and exclude net.routes and net.sample too
170     case "${iface}" in
171     *~) continue ;;
172     routes) continue ;;
173     sample) continue ;;
174     esac
175    
176   if [[ $(read_value ONBOOT ${file}) = yes ]]   if [[ $(read_value ONBOOT ${file}) = yes ]]
177   then   then
178   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  
179   fi   fi
180   done   done
181    
# Line 152  config_wireless_wep() Line 188  config_wireless_wep()
188    
189   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
190   then   then
191   echo "WEP: no \$iface given. Aborting setup."   rc_echo "WEP: no \$iface given. Aborting setup."
192   return 1   return 1
193   fi   fi
194    
195   ${CURS_UP}   ${CURS_UP}
196   ${SET_WWCOL}   ${SET_WWCOL}
197   echo "[AUTH: WEP]"   rc_echo "[AUTH: WEP]"
198    
199   iwconfig "${iface}" enc on   iwconfig "${iface}" enc on
200   [[ -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 208  config_wireless_wpa()
208    
209   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
210   then   then
211   echo "WPA: no \$iface given. Aborting setup."   rc_echo "WPA: no \$iface given. Aborting setup."
212   return 1   return 1
213   fi   fi
214    
215   if [ ! -x /sbin/wpa_supplicant ]   if [ ! -x $(type -P wpa_supplicant) ]
216   then   then
217   echo "WPA: wpa_supplicant not installed. Aborting setup."   rc_echo "WPA: wpa_supplicant not installed. Aborting setup."
218   return 1   return 1
219   fi   fi
220    
221   ${CURS_UP}   ${CURS_UP}
222   ${SET_WWCOL}   ${SET_WWCOL}
223   echo "[AUTH: WPA]"   rc_echo "[AUTH: WPA]"
224    
225   # get default settings   # get default settings
226   [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant   [[ -f /etc/conf.d/wpa_supplicant ]] && source /etc/conf.d/wpa_supplicant
227    
228   # check the configuration   # check the configuration
229   [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto   [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant/wpa_supplicant.auto
230   [[ -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
231    
232   # 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 253  config_wireless_wpa()
253   fi   fi
254    
255   # remove old state dir   # remove old state dir
256   [ -d /var/run/wpa_supplicant ] && rm -rf /var/run/wpa_supplicant   [ -d /run/wpa_supplicant ] && rm -rf /run/wpa_supplicant
257    
258   # now run the wpa_supplicant dameon   # now run the wpa_supplicant dameon
259   wpa_supplicant -B \   wpa_supplicant -B \
# Line 227  config_wireless_wpa() Line 263  config_wireless_wpa()
263   ${WIRELESS_WPA_OPTS}   ${WIRELESS_WPA_OPTS}
264    
265   # echo wait 5 seconds   # echo wait 5 seconds
266   echo "    Waiting 5 seconds to retrieve authentification reply ... "   rc_echo "    Waiting 5 seconds to retrieve authentification reply ... "
267   sleep 5   sleep 5
268  }  }
269    
# Line 237  setup_wireless_extensions() Line 273  setup_wireless_extensions()
273    
274   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
275   then   then
276   echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."   rc_echo "WIRELESS_EXTENSIONS: no \$iface given. Aborting setup."
277   return 1   return 1
278   fi   fi
279    
# Line 249  setup_wireless_extensions() Line 285  setup_wireless_extensions()
285   [[ -n ${WIRELESS_NICK} ]] ||   [[ -n ${WIRELESS_NICK} ]] ||
286   [[ -n ${WIRELESS_AUTH_MODE} ]]   [[ -n ${WIRELESS_AUTH_MODE} ]]
287   then   then
288   echo -e ${COLOREDSTAR}"Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "   rc_print "Setting up wlan-ext for ${COLBLUE}${iface}${COLDEFAULT} ... "
289   fi   fi
290    
291   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"   [[ -n ${WIRELESS_BITRATE} ]] && iwconfig "${iface}" rate "${WIRELESS_BITRATE}"
# Line 277  config_bridge_options() Line 313  config_bridge_options()
313   # enable spanning-tree protocol   # enable spanning-tree protocol
314   case ${BRIDGE_STP} in   case ${BRIDGE_STP} in
315   on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;;   on|off) brctl stp "${iface}" "${BRIDGE_STP}" ;;
316   *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;   *) rc_echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;
317   esac   esac
318    
319   # configure ageing time   # configure ageing time
# Line 341  config_bridge_devices() Line 377  config_bridge_devices()
377    
378   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
379   then   then
380   echo "BRIDGE: no \$iface given. Aborting setup."   rc_echo "BRIDGE: no \$iface given. Aborting setup."
381   return 1   return 1
382   fi   fi
383    
384   if [[ -z ${method} ]]   if [[ -z ${method} ]]
385   then   then
386   echo "BRIDGE: no \$method given. Aborting setup."   rc_echo "BRIDGE: no \$method given. Aborting setup."
387   return 1   return 1
388   fi   fi
389    
390   # first check for brctl   # first check for brctl
391   if [[ -z $(which brctl) ]]   if [[ -z $(type -P brctl) ]]
392   then   then
393   echo "brctl not found! Please install 'net-misc/bridge-utils'."   rc_echo "brctl not found! Please install 'net-misc/bridge-utils'."
394   return 1   return 1
395   fi   fi
396    
397   # check the config   # check the config
398   if [[ -z ${BRIDGE_INTERFACES} ]]   if [[ -z ${BRIDGE_INTERFACES} ]]
399   then   then
400   echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."   rc_echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."
401   return 1   return 1
402   fi   fi
403    
# Line 405  config_routes() Line 441  config_routes()
441    
442   # only add and del are allowed   # only add and del are allowed
443   case ${method} in   case ${method} in
444   add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;;   add) message="Adding" ;;
445   del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;;   del) message="Removing" ;;
446   *)   *)
447   echo "config_routes: unsupported \$method '${method}'."   rc_echo "config_routes: unsupported \$method '${method}'."
448   exit 1   exit 1
449   ;;   ;;
450   esac   esac
# Line 422  config_routes() Line 458  config_routes()
458   case "${route}" in   case "${route}" in
459   \#*|"") continue ;;   \#*|"") continue ;;
460   esac   esac
461   echo -e ${COLOREDSTAR}"${message}"   rc_print "${message} route ${COLBLUE}${route}${COLDEFAULT} ..."
462   route "${method}" "${route}"   # do not esacpe ${route} or it breaks!
463     route "${method}" ${route}
464   evaluate_retval   evaluate_retval
465   done   done
466   fi   fi
# Line 442  networking_start() Line 479  networking_start()
479   ALL_INTERFACES="$1"   ALL_INTERFACES="$1"
480   else   else
481   ${FAILURE}   ${FAILURE}
482   echo "Interface $1 does not exist. Aborting"   rc_echo "Interface $1 does not exist. Aborting"
483   ${NORMAL}   ${NORMAL}
484   exit 1   exit 1
485   fi   fi
# Line 455  networking_start() Line 492  networking_start()
492   source ${rc_network_settings}/net.${iface} || exit 1   source ${rc_network_settings}/net.${iface} || exit 1
493   checkconfig   checkconfig
494    
495     # wait until the device is created
496     iface_wait_online 5 "${iface}" || { rc_echo "device '${iface}' does not exist"; continue; }
497    
498   # setup mac   # setup mac
499   if [[ -n ${FORCE_MAC_TO} ]]   if [[ -n ${FORCE_MAC_TO} ]]
500   then   then
501   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} ... "
502   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"   ifconfig "${iface}" hw ether "${FORCE_MAC_TO}"
503   evaluate_retval   evaluate_retval
504   fi   fi
# Line 470  networking_start() Line 510  networking_start()
510   fi   fi
511    
512   # now configure wireless_extensions   # now configure wireless_extensions
513   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"   [ -x $(type -P iwconfig) ] && setup_wireless_extensions "${iface}"
514    
515   echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
516    
517   # activate the interface   # activate the interface
518   ifconfig "${iface}" up   ifconfig "${iface}" up
# Line 482  networking_start() Line 522  networking_start()
522   dhcp|DHCP)   dhcp|DHCP)
523   ${CURS_UP}   ${CURS_UP}
524   ${SET_WWCOL}   ${SET_WWCOL}
525   echo "[DHCP]"   rc_echo "[DHCP]"
526   loadproc "${DHCP_PROG}" "${DHCP_START}" "${iface}"   if iface_has_link "${iface}"
527     then
528     loadproc ${DHCP_PROG} ${DHCP_START} "${iface}"
529     else
530     rc_echo "Interface '${iface}' has no link. Not running '${DHCP_PROG}'."
531     fi
532   ;;   ;;
533   static|STATIC)   static|STATIC)
534   ${CURS_UP}   ${CURS_UP}
535   ${SET_WWCOL}   ${SET_WWCOL}
536   echo "[STATIC]"   rc_echo "[STATIC]"
537   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"   ifconfig "${iface}" "${IP}" netmask "${NETMASK}" broadcast "${BROADCAST}"
538   evaluate_retval   evaluate_retval
539     if [[ -n ${POINTOPOINT} ]]
540     then
541     rc_echo "Adding point-to-point route to '${POINTOPOINT}' on interface '${iface}'"
542     ifconfig "${iface}" "${IP}" pointopoint "${POINTOPOINT}"
543     evaluate_retval
544     fi
545   ;;   ;;
546   esac   esac
547    
548   # setup def gw   # setup def gw
549   if [[ -n ${GATEWAY} ]]   if [[ -n ${GATEWAY} ]]
550   then   then
551   echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
552   route add default gateway "${GATEWAY}" metric 1 dev "${iface}"   route add default gateway "${GATEWAY}" metric 1 dev "${iface}"
553   evaluate_retval   evaluate_retval
554    
# Line 505  networking_start() Line 556  networking_start()
556   fi   fi
557    
558   # 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  
559   # add given nameserver   # add given nameserver
560   if [[ -n ${NAMESERVER} ]]   if [[ -n ${NAMESERVER} ]]
561   then   then
562   echo -e ${COLOREDSTAR}"Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Setting up all nameserver for ${COLBLUE}${iface}${COLDEFAULT} ..."
563    
564     # wipe out the old one
565     echo "# Generated by the magellan-initscripts for ${iface}" > /etc/resolv.conf
566     # include head
567     if [ -f /etc/resolv.conf.head ]
568     then
569     cat /etc/resolv.conf.head >> /etc/resolv.conf
570     else
571     echo "# /etc/resolv.conf.head can replace this line" >> /etc/resolv.conf
572     fi
573    
574   for dns in ${NAMESERVER}   for dns in ${NAMESERVER}
575   do   do
576   echo "nameserver ${dns}" >> /etc/resolv.conf   echo "nameserver ${dns}" >> /etc/resolv.conf
577   done   done
578    
579     # include tail
580     if [ -f /etc/resolv.conf.tail ]
581     then
582     cat /etc/resolv.conf.tail >> /etc/resolv.conf
583     else
584     echo "# /etc/resolv.conf.tail can replace this line" >> /etc/resolv.conf
585     fi
586    
587   unset NAMESERVER   unset NAMESERVER
588   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  
589   done   done
590    
591   # setup user routes   # setup user routes
# Line 550  networking_stop() Line 603  networking_stop()
603   ALL_INTERFACES="$1"   ALL_INTERFACES="$1"
604   else   else
605   ${FAILURE}   ${FAILURE}
606   echo "Interface $1 does not exist. Aborting"   rc_echo "Interface $1 does not exist. Aborting"
607   ${NORMAL}   ${NORMAL}
608   exit 1   exit 1
609   fi   fi
# Line 564  networking_stop() Line 617  networking_stop()
617    
618   if [[ -n ${GATEWAY} ]]   if [[ -n ${GATEWAY} ]]
619   then   then
620   echo -e ${COLOREDSTAR}"Removing default gateway ..."   rc_print "Removing default gateway ..."
621   route del -net default   route del -net default
622   evaluate_retval   evaluate_retval
623   fi   fi
624    
625   echo -e ${COLOREDSTAR}"Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."   rc_print "Bringing down interface ${COLBLUE}${iface}${COLDEFAULT} ..."
626   ifconfig ${iface} down   ifconfig "${iface}" down
627   evaluate_retval   evaluate_retval
628    
629   # remove bridges   # remove bridges
# Line 580  networking_stop() Line 633  networking_stop()
633   fi   fi
634    
635   # shutdown dhcp-daemon   # shutdown dhcp-daemon
636   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof $(basename ${DHCP_PROG})) ]]
637   then   then
638   echo -e ${COLOREDSTAR}"Stopping the dhcp-daemon ..."   rc_print "Stopping the dhcp-daemon ..."
639   ${CURS_UP}   ${CURS_UP}
640   ${SET_WWCOL}   ${SET_WWCOL}
641   echo "[$(basename ${DHCP_PROG})]"   rc_echo "[$(basename ${DHCP_PROG})]"
642   ${DHCP_PROG} ${DHCP_STOP} "${iface}"   if [[ -z ${DHCP_STOP} ]]
643   evaluate_retval   then
644     killproc ${DHCP_PROG}
645     evaluate_retval
646     else
647     ${DHCP_PROG} ${DHCP_STOP} "${iface}"
648     evaluate_retval
649     fi
650   fi   fi
651    
652   # shutdown wpa_supplicant daemon   # shutdown wpa_supplicant daemon
# Line 598  networking_stop() Line 657  networking_stop()
657   done   done
658    
659   # remove state dir   # remove state dir
660   if [ -d /var/run/wpa_supplicant ]   if [ -d /run/wpa_supplicant ]
661   then   then
662   rm -rf /var/run/wpa_supplicant   rm -rf /run/wpa_supplicant
663   fi   fi
664    
665   # delete user routes   # delete user routes
# Line 627  case $1 in Line 686  case $1 in
686   ;;   ;;
687    
688   *)   *)
689   echo "Usage: $0 {start|stop|restart} [interface]"   rc_echo "Usage: $0 {start|stop|restart} [interface]"
690   exit 1   exit 1
691   ;;   ;;
692  esac  esac

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