Magellan Linux

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

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

revision 506 by niro, Sat Jul 21 19:31:11 2007 UTC revision 872 by niro, Thu May 21 13:41:38 2009 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.12 2007-07-21 19:31:11 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.19 2008-12-22 22:01:15 niro Exp $
3    
4  #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k  #%rlevels: 0:k 1:k 2:k 3:s 4:s 5:s 6:k
5  #%start: 20  #%start: 20
# Line 10  Line 10 
10  #%before:  #%before:
11  #%after:  #%after:
12    
13  source /etc/sysconfig/rc  source /etc/conf.d/rc
14  source ${rc_functions}  source ${rc_functions}
15    
16  # read values from files  # read values from files
# Line 24  read_value() Line 24  read_value()
24   # global   # global
25   local ONBOOT   local ONBOOT
26   local NETWORKING   local NETWORKING
27    
28   # static   # static
29   local IP   local IP
30   local NETMASK   local NETMASK
# Line 60  read_value() Line 60  read_value()
60   local WIRELESS_NICK   local WIRELESS_NICK
61   local WIRELESS_NWID   local WIRELESS_NWID
62   local WIRELESS_POWER   local WIRELESS_POWER
63     local WIRELESS_WPA_DRIVER
64    
65     local BRIDGE_INTERFACES
66     local BRIDGE_STP
67    
68   source ${file}   source ${file}
69   eval value=\$$(echo ${var})   eval value=\$$(echo ${var})
# Line 68  read_value() Line 72  read_value()
72    
73  checkconfig()  checkconfig()
74  {  {
75   if [ -z "${NETWORKING}" ]   if [[ -z ${NETWORKING} ]]
76   then   then
77   echo "NETWORKING missing in net.${interface}, aborted"   echo "NETWORKING missing in net.${interface}, aborted"
78   exit 1   exit 1
# Line 76  checkconfig() Line 80  checkconfig()
80    
81   case "${NETWORKING}" in   case "${NETWORKING}" in
82   static)   static)
83   if [ -z "${IP}" ]   if [[ -z ${IP} ]]
84   then   then
85   echo "IP missing in net.${interface}, aborted"   echo "IP missing in net.${interface}, aborted"
86   exit 1   exit 1
87   fi   fi
88    
89   if [ -z "${NETMASK}" ]   if [[ -z ${NETMASK} ]]
90   then   then
91   echo -n "NETMASK missing in net.${interface}, "   echo -n "NETMASK missing in net.${interface}, "
92   echo "using 255.255.255.0"   echo "using 255.255.255.0"
93   NETMASK=255.255.255.0   NETMASK=255.255.255.0
94   fi   fi
95    
96   if [ -z "${BROADCAST}" ]   if [[ -z ${BROADCAST} ]]
97   then   then
98   echo -n "BROADCAST missing in net.${interface}, "   echo -n "BROADCAST missing in net.${interface}, "
99   echo "using default address"   echo "using default address"
# Line 97  checkconfig() Line 101  checkconfig()
101   ;;   ;;
102    
103   dhcp)   dhcp)
104   if [ -z "${DHCP_PROG}" ]   if [[ -z ${DHCP_PROG} ]]
105   then   then
106   echo "DHCP_PROG missing in net.${interface}, aborted"   echo "DHCP_PROG missing in net.${interface}, aborted"
107   exit 1   exit 1
# Line 178  config_wireless_wpa() Line 182  config_wireless_wpa()
182   # check the configuration   # check the configuration
183   [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto   [[ -z ${WIRELESS_WPA_CONFIG} ]] && WIRELESS_WPA_CONFIG=/etc/wpa_supplicant.auto
184   [[ -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
185   if [[ -z ${WIRELESS_WPA_DRIVER} ]]  
186   then   # use wext as default driver, do not abort here anymore
187   echo "WPA: WIRELESS_WPA_DRIVER given. Aborting setup."   [[ -z ${WIRELESS_WPA_DRIVER} ]] && WIRELESS_WPA_DRIVER=wext
  return 1  
  fi  
188    
189   # write a config with the settings from net.${iface}   # write a config with the settings from net.${iface}
190   # only wpa-psk ! all other needs manual setup   # only wpa-psk ! all other needs manual setup
# Line 191  config_wireless_wpa() Line 193  config_wireless_wpa()
193   # write default cfg from skeleton   # write default cfg from skeleton
194   cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG}   cat ${WIRELESS_WPA_SKEL} > ${WIRELESS_WPA_CONFIG}
195    
196     local wpa_proto
197     case ${WIRELESS_AUTH_MODE} in
198     wpa) wpa_proto="WPA" ;;
199     wpa2) wpa_proto="WPA2" ;;
200     esac
201    
202   # setup the network entry   # setup the network entry
203   sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \   sed -i -e "s:@WIRELESS_ESSID@:${WIRELESS_ESSID}:g" \
204   -e "s:@WIRELESS_KEY@:${WIRELESS_KEY}:g" \   -e "s:@WIRELESS_KEY@:${WIRELESS_KEY_ASCII}:g" \
205     -e "s:@WIRELESS_AUTH_MODE@:${wpa_proto}:g" \
206   ${WIRELESS_WPA_CONFIG}   ${WIRELESS_WPA_CONFIG}
207   fi   fi
208    
# Line 241  setup_wireless_extensions() Line 250  setup_wireless_extensions()
250   [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}"   [[ -n ${WIRELESS_NICK} ]] && iwconfig "${iface}" nick "${WIRELESS_NICK}"
251    
252   case "${WIRELESS_AUTH_MODE}" in   case "${WIRELESS_AUTH_MODE}" in
253   wpa) config_wireless_wpa "${iface}" ;;   wpa|wpa2) config_wireless_wpa "${iface}" ;;
254   wep|on) config_wireless_wep "${iface}" ;;   wep|on) config_wireless_wep "${iface}" ;;
255   off) iwconfig "${iface}" enc off ;;   off) iwconfig "${iface}" enc off ;;
256   esac   esac
257  }  }
258    
# Line 251  config_bridge_devices() Line 260  config_bridge_devices()
260  {  {
261   local iface="$1"   local iface="$1"
262   local method="$2"   local method="$2"
263     local bport
264    
265   if [[ -z ${iface} ]]   if [[ -z ${iface} ]]
266   then   then
# Line 272  config_bridge_devices() Line 282  config_bridge_devices()
282   fi   fi
283    
284   # check the config   # check the config
285   if [[ -z ${BRIDGE_INTERFACE} ]]   if [[ -z ${BRIDGE_INTERFACES} ]]
286   then   then
287   echo "BRIDGE: no \$BRIDGE_INTERFACE given. Aborting setup."   echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."
288   return 1   return 1
289   fi   fi
290    
# Line 282  config_bridge_devices() Line 292  config_bridge_devices()
292   add)   add)
293   # setup the bridge device   # setup the bridge device
294   brctl addbr ${iface}   brctl addbr ${iface}
295   # enter promiscous mode   for bport in ${BRIDGE_INTERFACES}
296   ifconfig ${BRIDGE_INTERFACE} 0.0.0.0 promisc   do
297   # now setup the bridge   # enter promiscous mode
298   brctl addif ${iface} ${BRIDGE_INTERFACE}   ifconfig ${bport} 0.0.0.0 promisc
299     # now setup the bridge
300     brctl addif ${iface} ${bport}
301     done
302     # enable spanning-tree protocol
303     case ${BRIDGE_STP} in
304     on|off) brctl stp ${iface} ${BRIDGE_STP} ;;
305     *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;
306     esac
307   ;;   ;;
308    
309   remove)   remove)
310   # bring the interface down   for bport in ${BRIDGE_INTERFACE}
311   ifconfig ${BRIDGE_INTERFACE} down   do
312   # remove the interface from the bridge   # bring the interface down
313   brctl delif ${iface} ${BRIDGE_INTERFACE}   ifconfig ${bport} down
314     # remove the interface from the bridge
315     brctl delif ${iface} ${bport}
316     done
317   # bring the bridge down   # bring the bridge down
318   brctl delbr ${iface}   brctl delbr ${iface}
319   ;;   ;;
320   esac   esac
321    
322   # unset the bridge variable to be safe   # unset the bridge variable to be safe
323   unset BRIDGE_INTERFACE   unset BRIDGE_INTERFACES
324   # continue to setup generic networking   # continue to setup generic networking
325  }  }
326    
# Line 335  config_routes() Line 357  config_routes()
357    
358  networking_start()  networking_start()
359  {  {
360   local iface dns routes   local iface dns routes ALL_INTERFACES
361    
362     if [[ -z $1 ]]
363     then
364     ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*)
365     else
366     if [[ -e ${network_settings}/net.$1 ]]
367     then
368     ALL_INTERFACES="$1"
369     else
370     ${FAILURE}
371     echo "Interface $1 does not exist. Aborting"
372     ${NORMAL}
373     exit 1
374     fi
375     fi
376    
377   # get list of all devices   # get list of all devices
378   for iface in $(onboot_interface_list ${network_settings}/net.*)   for iface in ${ALL_INTERFACES}
379   do   do
380   # checkconfig   # checkconfig
381   source ${network_settings}/net.${iface} || exit 1   source ${network_settings}/net.${iface} || exit 1
# Line 358  networking_start() Line 395  networking_start()
395   config_bridge_devices ${iface} add   config_bridge_devices ${iface} add
396   fi   fi
397    
  # activate the interface  
  ifconfig "${iface}" up  
   
398   # now configure wireless_extensions   # now configure wireless_extensions
399   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"   [ -x /usr/sbin/iwconfig ] && setup_wireless_extensions "${iface}"
400    
401   echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."   echo -e ${COLOREDSTAR}"Bringing up interface ${COLBLUE}${iface}${COLDEFAULT} ..."
402    
403     # activate the interface
404     ifconfig "${iface}" up
405    
406   # setup static or dhcp   # setup static or dhcp
407   case ${NETWORKING} in   case ${NETWORKING} in
408   dhcp|DHCP)   dhcp|DHCP)
# Line 389  networking_start() Line 426  networking_start()
426   echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."   echo -e ${COLOREDSTAR}"Setting up default gateway for ${COLBLUE}${iface}${COLDEFAULT} ..."
427   route add default gateway ${GATEWAY} metric 1 dev ${iface}   route add default gateway ${GATEWAY} metric 1 dev ${iface}
428   evaluate_retval   evaluate_retval
429    
430     unset GATEWAY
431   fi   fi
432    
433   # setup /etc/resolv.conf   # setup /etc/resolv.conf
# Line 402  networking_start() Line 441  networking_start()
441   do   do
442   echo "nameserver ${dns}" >> /etc/resolv.conf   echo "nameserver ${dns}" >> /etc/resolv.conf
443   done   done
444    
445     unset NAMESERVER
446   fi   fi
447   done   done
448    
# Line 411  networking_start() Line 452  networking_start()
452    
453  networking_stop()  networking_stop()
454  {  {
455     if [[ -z $1 ]]
456     then
457     ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*)
458     else
459     if [[ -e ${network_settings}/net.$1 ]]
460     then
461     ALL_INTERFACES="$1"
462     else
463     ${FAILURE}
464     echo "Interface $1 does not exist. Aborting"
465     ${NORMAL}
466     exit 1
467     fi
468     fi
469    
470   # get list of all devices   # get list of all devices
471   for iface in $(onboot_interface_list ${network_settings}/net.*)   for iface in ${ALL_INTERFACES}
472   do   do
473   source ${network_settings}/net.${iface} || exit 1   source ${network_settings}/net.${iface} || exit 1
474   checkconfig   checkconfig
# Line 464  networking_stop() Line 520  networking_stop()
520    
521  case $1 in  case $1 in
522   start)   start)
523   networking_start   networking_start $2
524   update_svcstatus $1   update_svcstatus $1
525   splash svc_started "$(basename $0)" 0   splash svc_started "$(basename $0)" 0
526   ;;   ;;
527    
528   stop)   stop)
529   networking_stop   networking_stop $2
530   update_svcstatus $1   update_svcstatus $1
531   splash svc_stopped "$(basename $0)" 0   splash svc_stopped "$(basename $0)" 0
532   ;;   ;;
# Line 482  case $1 in Line 538  case $1 in
538   ;;   ;;
539    
540   *)   *)
541   echo "Usage: $0 {start|stop|restart}"   echo "Usage: $0 {start|stop|restart} [interface]"
542   exit 1   exit 1
543   ;;   ;;
544  esac  esac

Legend:
Removed from v.506  
changed lines
  Added in v.872