Magellan Linux

Diff of /trunk/magellan-initscripts/etc/rc.d/init.d/network

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

revision 275 by niro, Fri Oct 21 15:24:25 2005 UTC revision 640 by niro, Mon Dec 17 14:30:25 2007 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.11 2005-10-21 15:24:25 niro Exp $  # $Header: /home/cvsd/magellan-cvs/magellan-src/magellan-initscripts/etc/rc.d/init.d/network,v 1.16 2007-12-17 14:30:25 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 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 120  onboot_interface_list() Line 124  onboot_interface_list()
124   if [[ $(read_value ONBOOT ${file}) = yes ]]   if [[ $(read_value ONBOOT ${file}) = yes ]]
125   then   then
126   iface="$(basename ${file} | sed s/net.//)"   iface="$(basename ${file} | sed s/net.//)"
127   # exclude backup files   # exclude backup files and exclude net.routes too
128   case "${iface}" in   case "${iface}" in
129   *~) ;;   *~) ;;
130     */net.routes) ;;
131   *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;   *) devices="${devices} $(basename ${file} | sed s/net.//)" ;;
132   esac   esac
133   fi   fi
# Line 246  setup_wireless_extensions() Line 251  setup_wireless_extensions()
251   esac   esac
252  }  }
253    
254    config_bridge_devices()
255    {
256     local iface="$1"
257     local method="$2"
258     local bport
259    
260     if [[ -z ${iface} ]]
261     then
262     echo "BRIDGE: no \$iface given. Aborting setup."
263     return 1
264     fi
265    
266     if [[ -z ${method} ]]
267     then
268     echo "BRIDGE: no \$method given. Aborting setup."
269     return 1
270     fi
271    
272     # first check for brctl
273     if [[ -z $(which brctl) ]]
274     then
275     echo "brctl not found! Please install 'net-misc/bridge-utils'."
276     return 1
277     fi
278    
279     # check the config
280     if [[ -z ${BRIDGE_INTERFACES} ]]
281     then
282     echo "BRIDGE: no \$BRIDGE_INTERFACES given. Aborting setup."
283     return 1
284     fi
285    
286     case ${method} in
287     add)
288     # setup the bridge device
289     brctl addbr ${iface}
290     for bport in ${BRIDGE_INTERFACES}
291     do
292     # enter promiscous mode
293     ifconfig ${bport} 0.0.0.0 promisc
294     # now setup the bridge
295     brctl addif ${iface} ${bport}
296     done
297     # enable spanning-tree protocol
298     case ${BRIDGE_STP} in
299     on|off) brctl stp ${iface} ${BRIDGE_STP} ;;
300     *) echo "BRIDGE: unkown value \$BRIDGE_STP='$BRIDGE_STP'."; return 1 ;;
301     esac
302     ;;
303    
304     remove)
305     for bport in ${BRIDGE_INTERFACE}
306     do
307     # bring the interface down
308     ifconfig ${bport} down
309     # remove the interface from the bridge
310     brctl delif ${iface} ${bport}
311     done
312     # bring the bridge down
313     brctl delbr ${iface}
314     ;;
315     esac
316    
317     # unset the bridge variable to be safe
318     unset BRIDGE_INTERFACES
319     # continue to setup generic networking
320    }
321    
322    config_routes()
323    {
324     local method="$1"
325     local message
326    
327     # only add and del are allowed
328     case ${method} in
329     add) message="Adding route ${COLBLUE}${route}${COLDEFAULT} ..." ;;
330     del) message="Removing route ${COLBLUE}${route}${COLDEFAULT} ..." ;;
331     *)
332     echo "config_routes: unsupported \$method '${method}'."
333     exit 1
334     ;;
335     esac
336    
337     # adds/delete user routes
338     if [[ -f /etc/conf.d/net.routes ]]
339     then
340     ( cat /etc/conf.d/net.routes; echo ) | # make sure there is a LF at the end
341     while read route
342     do
343     case "${route}" in
344     \#*|"") continue ;;
345     esac
346     echo -e ${COLOREDSTAR}"${message}"
347     route ${method} ${route}
348     evaluate_retval
349     done
350     fi
351    }
352    
353  networking_start()  networking_start()
354  {  {
355   local iface dns   local iface dns routes ALL_INTERFACES
356    
357     if [[ -z $1 ]]
358     then
359     ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*)
360     else
361     if [[ -e ${network_settings}/net.$1 ]]
362     then
363     ALL_INTERFACES="$1"
364     else
365     ${FAILURE}
366     echo "Interface $1 does not exist. Aborting"
367     ${NORMAL}
368     exit 1
369     fi
370     fi
371    
372   # get list of all devices   # get list of all devices
373   for iface in $(onboot_interface_list ${network_settings}/net.*)   for iface in ${ALL_INTERFACES}
374   do   do
375   # checkconfig   # checkconfig
376   source ${network_settings}/net.${iface} || exit 1   source ${network_settings}/net.${iface} || exit 1
# Line 265  networking_start() Line 384  networking_start()
384   evaluate_retval   evaluate_retval
385   fi   fi
386    
387     # setup bridges
388     if [[ ${iface} = br[0-9]* ]]
389     then
390     config_bridge_devices ${iface} add
391     fi
392    
393   # activate the interface   # activate the interface
394   ifconfig "${iface}" up   ifconfig "${iface}" up
395    
# Line 311  networking_start() Line 436  networking_start()
436   done   done
437   fi   fi
438   done   done
439    
440     # setup user routes
441     config_routes add
442  }  }
443    
444  networking_stop()  networking_stop()
445  {  {
446     if [[ -z $1 ]]
447     then
448     ALL_INTERFACES=$(onboot_interface_list ${network_settings}/net.*)
449     else
450     if [[ -e ${network_settings}/net.$1 ]]
451     then
452     ALL_INTERFACES="$1"
453     else
454     ${FAILURE}
455     echo "Interface $1 does not exist. Aborting"
456     ${NORMAL}
457     exit 1
458     fi
459     fi
460    
461   # get list of all devices   # get list of all devices
462   for iface in $(onboot_interface_list ${network_settings}/net.*)   for iface in ${ALL_INTERFACES}
463   do   do
464   source ${network_settings}/net.${iface} || exit 1   source ${network_settings}/net.${iface} || exit 1
465   checkconfig   checkconfig
# Line 332  networking_stop() Line 475  networking_stop()
475   ifconfig ${iface} down   ifconfig ${iface} down
476   evaluate_retval   evaluate_retval
477    
478     # remove bridges
479     if [[ ${iface} = br[0-9]* ]]
480     then
481     config_bridge_devices ${iface} remove
482     fi
483    
484   # shutdown dhcp-daemon   # shutdown dhcp-daemon
485   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]   if [[ ${NETWORKING} = dhcp ]] && [[ -n $(pidof ${DHCP_PROG}) ]]
486   then   then
# Line 355  networking_stop() Line 504  networking_stop()
504   then   then
505   rm -rf /var/run/wpa_supplicant   rm -rf /var/run/wpa_supplicant
506   fi   fi
507    
508     # delete user routes
509     config_routes del
510  }  }
511    
512  case $1 in  case $1 in
513   start)   start)
514   networking_start   networking_start $2
515   update_svcstatus $1   update_svcstatus $1
516   splash svc_started "$(basename $0)" 0   splash svc_started "$(basename $0)" 0
517   ;;   ;;
518    
519   stop)   stop)
520   networking_stop   networking_stop $2
521   update_svcstatus $1   update_svcstatus $1
522   splash svc_stopped "$(basename $0)" 0   splash svc_stopped "$(basename $0)" 0
523   ;;   ;;
# Line 377  case $1 in Line 529  case $1 in
529   ;;   ;;
530    
531   *)   *)
532   echo "Usage: $0 {start|stop|restart}"   echo "Usage: $0 {start|stop|restart} [interface]"
533   exit 1   exit 1
534   ;;   ;;
535  esac  esac

Legend:
Removed from v.275  
changed lines
  Added in v.640