home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20101108.etc.tar.gz / bradford.20101108.etc.tar / etc / init.d / network < prev    next >
Text File  |  2007-02-24  |  25KB  |  951 lines

  1. #!/bin/bash
  2. #
  3. # Network interface configuration
  4. #
  5. # Copyright (c) 2001-2002 SuSE Linux AG, Nuernberg, Germany.
  6. # This program is free software; you can redistribute it and/or modify it under
  7. # the terms of the GNU General Public License as published by the Free Software
  8. # Foundation; either version 2 of the License, or (at your option) any later
  9. # version.
  10. #
  11. # This program is distributed in the hope that it will be useful, but WITHOUT
  12. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  14. # details.
  15. #
  16. # You should have received a copy of the GNU General Public License along with
  17. # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. # Place, Suite 330, Boston, MA 02111-1307 USA
  19. #
  20. # Author: Michal Svec <msvec@suse.cz>
  21. #         Christian Zoz <zoz@suse.de>
  22. #         Mads Martin J°rgensen <mmj@suse.de>
  23. #
  24. # $Id: network 1491 2006-06-02 11:51:44Z zoz $
  25. #
  26. # /etc/init.d/network
  27. #
  28. ### BEGIN INIT INFO
  29. # Provides:       network
  30. # Required-Start: $local_fs dbus haldaemon
  31. # Should-Start: isdn
  32. # Required-Stop:
  33. # Should-Stop:
  34. # Default-Start:  2 3 5
  35. # Default-Stop:
  36. # Description:    Configure the network interfaces and set up routing
  37. ### END INIT INFO
  38. . /etc/rc.status
  39. rc_reset
  40. /bsc/services/network/etc/init.d/network
  41. cd /etc/sysconfig/network
  42. test -f ./config && . ./config
  43. if ! . scripts/functions 2>/dev/null; then
  44.     echo -n "Network: file /etc/sysconfig/network/scripts/functions is missing."
  45.     rc_failed
  46.     rc_status -v
  47.     rc_exit
  48. fi
  49.  
  50. # . scripts/extradebug
  51.  
  52. # Only use ifup option 'onboot' if booting or changing runlevel
  53. # Therefore we check if we were called from init
  54. if [ -n "$INIT_VERSION" ] ; then
  55.     MODE=onboot
  56. fi
  57.  
  58. ######################################################################
  59. # Commandline parsing
  60. #
  61. SCRIPTNAME=${0##*/}
  62. debug $*
  63. ACTION=$1
  64. shift
  65. if [ "$1" != "-o" ] ; then INTERFACE=$1; shift; fi
  66. if [ -n "$1" -a "$1" != "-o" ] ; then CONFIG=$INTERFACE; INTERFACE=$1; shift; fi
  67. test "$1" = "-o" && shift
  68. OPTIONS=$@
  69. while [ $# -gt 0 ]; do
  70.     case $1 in
  71.         boot|onboot) MODE=onboot ;;
  72.         hotplug)     MODE=hotplug ;;
  73.         manual)      MODE=manual ;;
  74.         check)       CHECK=check ;;
  75.         quiet)       be_quiet_has_gone ;;
  76.         debug)       DEBUG=yes ;;
  77.         type*)       TYPE=${1#type=} ;;
  78.         fake)        FAKE=echo ;;
  79.         skip*)       SKIP=${1#skip=} ;;
  80.         nm)          NETWORKMANAGER=yes ;;
  81.         netcontrol)  NETWORKMANAGER=no ;;
  82.         *)           mesg "Unknown option $1"
  83.                      mesg "options: {[on]boot,hotplug,check,debug,type=<typelist>,fake}"
  84.                  exit 1 ;;
  85.     esac
  86.     shift
  87. done
  88. # Source functions.common again, because values of DEBUG and BE_QUIET might
  89. # have changed. These variable will be evaluated while sourcing the file.
  90. test -f scripts/functions.common \
  91.    && . scripts/functions.common \
  92.    || exit $R_INTERNAL
  93.  
  94.  
  95. ######################################################################
  96. # Start NetworkManager if wanted
  97. #
  98. # Some variables and functions are defined in
  99. # /etc/sysconfig/network/scripts/functions
  100. # because they are also used in ifup
  101. #
  102. if [ ! -x "$NETWORKMANAGER_BIN" -a "$NETWORKMANAGER" == yes ] ; then
  103.     err_mesg "NetworkManager is not installed, thus using NetControl." \
  104.              "Please set" \
  105.              "\n/etc/sysconfig/network/config:NetworkManager=no" \
  106.              "or install NetworkManager."
  107.     NETWORKMANAGER=no
  108. fi
  109. if [ "$NETWORKMANAGER" != yes ] ; then
  110.     NM_DISPATCHER=no
  111. fi
  112. if [ ! -x "$NM_DISPATCHER_BIN" -a "$NM_DISPATCHER" == yes ] ; then
  113.     err_mesg "NetworkManagerDispatcher is not installed, skipping it." \
  114.              "Please set" \
  115.              "\n/etc/sysconfig/network/config:NetworkManagerDispatcher=no" \
  116.              "or install NetworkManagerDispatcher."
  117.     NM_DISPATCHER=no
  118. fi
  119.  
  120. reload_firewall() {
  121.     test "$1" = not_on_boot -a "$MODE" = onboot && return -1
  122.     test "$FIREWALL" != yes && return -2
  123.     local NIX RL
  124.     read NIX RL < <(runlevel) 
  125.     test -z "$RL" && RL=`sed -n 's=^id:\(.\):initdefault.*$=\1=p' /etc/inittab`
  126.     ls /etc/init.d/rc${RL}.d/S*SuSEfirewall2_setup &>/dev/null || return -3
  127.     /sbin/SuSEfirewall2 start
  128. }
  129.  
  130. start_nm_online() {
  131.     test -x "$NM_ONLINE_BIN" || return 0
  132.     if [ "$NM_ONLINE_TIMEOUT" == 0 ] ; then
  133.         mesg "If service network should wait until connection is established"
  134.         mesg "then set /etc/sysconfig/network/config:NM_ONLINE_TIMEOUT"
  135.         return 0
  136.     fi
  137.     local rc_startmode="${stat}${attn}waiting${norm}"
  138.     $NM_ONLINE_BIN $NM_ONLINE_TIMEOUT
  139.     case $? in
  140.         0) rc_status -v ;;
  141.         1) echo -e "$rc_startmode" 1>&2 ;;
  142.         *) rc_status -v ;;
  143.     esac
  144. }
  145.  
  146. start_nm_dispatcher() {
  147.     test "$NM_DISPATCHER" == yes || return
  148.     checkproc $NM_DISPATCHER_BIN
  149.     if [ $? = 0 ]; then
  150.         mesg_n "NetworkManagerDispatcher already running"
  151.     else
  152.         mesg_n "Starting the NetworkManagerDispatcher"
  153.         startproc $NM_DISPATCHER_BIN
  154.     fi
  155.     rc_status -v
  156. }
  157.  
  158. stop_nm_dispatcher() {
  159.     test -x "$NM_DISPATCHER_BIN" || return 0
  160.     checkproc $NM_DISPATCHER_BIN 2>/dev/null
  161.     if [ $? = 0 ]; then
  162.         mesg_n "Shutting down the NetworkManagerDispatcher"
  163.         killproc -TERM $NM_DISPATCHER_BIN
  164.         rc_status -v
  165.     fi
  166. }
  167.  
  168. check_nm_dispatcher() {
  169.     test -x "$NM_DISPATCHER_BIN" || return 0
  170.     rc_status
  171.     NM_STATUS=$?
  172.     mesg_n "Checking for the NetworkManagerDispatcher: "
  173.     checkproc $NM_DISPATCHER_BIN
  174.     rc_status -v
  175.     NMD_STATUS=$?
  176.     if [ "$NM_DISPATCHER" != yes ] ; then
  177.         rc_reset
  178.         rc_failed $NM_STATUS
  179.     fi
  180.     return $NMD_STATUS
  181. }
  182.  
  183. start_dhcdbd() {
  184.     test -x "$DHCDBD_BIN" || return 0
  185.     checkproc $DHCDBD_BIN
  186.     if [ $? = 0 ]; then
  187.         mesg_n "DHCP DBUS Daemon already running"
  188.     else
  189.         mesg_n "Starting the DHCP DBUS Daemon"
  190.         startproc $DHCDBD_BIN --system
  191.     fi
  192.     rc_status -v
  193.  
  194. }
  195.  
  196. stop_dhcdbd() {
  197.     test -x "$DHCDBD_BIN" || return 0
  198.     checkproc $DHCDBD_BIN 2>/dev/null
  199.     if [ $? = 0 ]; then
  200.         mesg_n "Shutting down the DHCP DBUS Daemon"
  201.         killproc -TERM $DHCDBD_BIN
  202.         rc_status -v
  203.     else
  204.         return 0
  205.     fi
  206. }
  207.  
  208. check_dhcdbd() {
  209.     test -x "$DHCDBD_BIN" || return 0
  210.     rc_status
  211.     NM_STATUS=$?
  212.     mesg_n "Checking for the DHCP DBUS Daemon: "
  213.     checkproc $DHCDBD_BIN
  214.     rc_status -v
  215.     DHCDBD_STATUS=$?
  216.     return $DHCDBD_STATUS
  217. }
  218.  
  219. cd "$OLDPWD"
  220. case "$ACTION" in
  221.     start)
  222.         if [ "$NETWORKMANAGER" == yes ] ; then
  223.             if nm_running; then
  224.                 mesg_n "NetworkManager already running"
  225.                 rc_status -v
  226.                 start_nm_dispatcher
  227.             elif netcontrol_running; then
  228.                 mesg "'NetControl' is active but" \
  229.                      "configuration says 'NetworkManager'."
  230.                 mesg_n "Call $SCRIPTNAME restart instead".
  231.                 rc_failed 7
  232.                 rc_status -v
  233.             else
  234.                 start_dhcdbd
  235.                 start_nm_dispatcher
  236.                 mesg_n "Starting the NetworkManager"
  237.                 $FAKE startproc $NETWORKMANAGER_BIN
  238.                 rc_status -v
  239.                 start_nm_online
  240.             fi
  241.             rc_exit
  242.         else
  243.             if nm_running; then
  244.                 mesg "'NetworkManager' is active but configuration" \
  245.                      "says 'NetControl'."
  246.                 mesg_n "Call $SCRIPTNAME restart instead".
  247.                 rc_failed 7
  248.                 rc_status -v
  249.                 rc_exit
  250.             fi
  251.         fi
  252.         # else fall through to NetControl
  253.         ;;
  254.     stop)
  255.         if nm_running; then
  256.             mesg_n "Shutting down the NetworkManager"
  257.             $FAKE killproc -TERM $NETWORKMANAGER_BIN
  258.             rc_status -v
  259.             stop_dhcdbd
  260.         fi
  261.         stop_nm_dispatcher
  262.         if ! netcontrol_running ; then
  263.             rc_exit
  264.         fi
  265.         # else fall through to NetControl
  266.         ;;
  267.     try-restart)
  268.         $0 status >/dev/null && \
  269.             $0 restart $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  270.         rc_status
  271.         rc_exit
  272.         ;;
  273.     restart|force-reload)
  274.         $0 stop $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  275.         $0 start $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  276.         rc_status
  277.         rc_exit
  278.         ;;
  279.     stop-all-dhcp-clients)
  280.         if nm_running; then
  281.             mesg "$ACTION not avaliable when running NetworkManager"
  282.             exit 1
  283.         fi
  284.         DHCP_INTERFACES=$(dhcp-interfaces)
  285.         for IFACE in $DHCP_INTERFACES; do
  286.             $0 stop $IFACE ${OPTIONS:+-o $OPTIONS}
  287.         done
  288.         rc_status
  289.         rc_exit
  290.         ;;
  291.     restart-all-dhcp-clients)
  292.         if nm_running; then
  293.             mesg "$ACTION not avaliable when running NetworkManager"
  294.             exit 1
  295.         fi
  296.         DHCP_INTERFACES=$(dhcp-interfaces)
  297.         for IFACE in $DHCP_INTERFACES; do
  298.             $0 stop  $IFACE ${OPTIONS:+-o $OPTIONS}
  299.         done
  300.         for IFACE in $DHCP_INTERFACES; do
  301.             $0 start $IFACE ${OPTIONS:+-o $OPTIONS}
  302.         done
  303.         rc_status
  304.         reload_firewall not_on_boot
  305.         rc_exit
  306.         ;;
  307.     reload)
  308.         # NetworkManager does not support reload (2005.01.15).
  309.         # If configuration and running system do not match exec restart.
  310.         # Fall through if NetControl is confiured and NM not active.
  311.         if [ "$NETWORKMANAGER" == yes ] ; then
  312.             if netcontrol_running; then
  313.                 mesg "Changing Network Control System. Calling $0 restart"
  314.                 exec $0 restart $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  315.             else
  316.                 # NetworkManager doesn't support signaling --> restarting
  317.                 exec $0 restart $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  318.             fi
  319.         else
  320.             if nm_running; then
  321.                 mesg "Changing Network Control System. Calling $0 restart"
  322.                 shift
  323.                 exec $0 restart $*
  324.             fi
  325.         fi
  326.         ;;
  327.     status)
  328.         if [ "$NETWORKMANAGER" == yes ] ; then
  329.             mesg_n "Checking for the NetworkManager: "
  330.             nm_running
  331.             rc_status -v
  332.             check_nm_dispatcher
  333.             check_dhcdbd
  334.             NM_STATUS=$?
  335.             if netcontrol_running; then
  336.                 mesg "NetControl System is active as well." \
  337.                      "Check your config or restart network."
  338.             else
  339.                 rc_exit
  340.             fi
  341.         else
  342.             if nm_running; then
  343.                 mesg "NetworkManager is active even though not configured." \
  344.                      "\nCheck your config or restart network."
  345.             fi
  346.         fi
  347.         ;;
  348.     *)
  349.         echo "Usage: $0 <action> [<config>] [<interface>] [-o <options>]"
  350.         echo "  actions: start|stop|status|reload|force-reload|try-restart"
  351.         echo "           restart|stop-all-dhcp-clients|restart-all-dhcp-clients"
  352.         echo "  options: [on]boot,hotplug,manual,check,debug,fake,nm,netcontrol"
  353.         echo "           type=<typelist>,skip=<skiplist>"
  354.         echo "  typelist: space seperated list of interface types"
  355.         echo "  skiplist: space seperated list of interfaces to skip for 'start'"
  356.         if [ "$NETWORKMANAGER" == yes ] ; then
  357.         echo
  358.             echo "Note:"
  359.             echo "  <config>, <interface> and options [on]boot,hotplug,manual" \
  360.                  "have no effect"
  361.             echo "  if service network is controlled by NetworkManager."
  362.         fi
  363.         exit 1
  364.         ;;
  365. esac
  366. cd /etc/sysconfig/network
  367.  
  368.  
  369. ######################################################################
  370.  
  371.  
  372. if [ "$MODE" = onboot -a "$ACTION" = start ] ; then
  373.     rm -f  ${RUN_FILES_BASE}/if-*
  374.     rm -f  ${RUN_FILES_BASE}/ifup-*
  375.     rm -Rf ${RUN_FILES_BASE}/tmp
  376.     rm -f  ${RUN_FILES_BASE}/route-stack-* 2>/dev/null
  377. fi
  378. mkdir -p ${RUN_FILES_BASE}/tmp
  379.  
  380. # This has to happen early; don't move that into start section below!!!
  381. # (Writing NETWORK_RUNFILE means that service network is started. And only if
  382. # service network was started interfaces will be set up via hotplug. And it must
  383. # be started before checking which interfaces are already available and might
  384. # still have to be set up because the were registered to early. Bug 39005)
  385. if [ "$ACTION" = start ] ; then
  386.     date +%s > $NETWORK_RUNFILE
  387. #    # We need that later to find out if an interface was just registered
  388. #    touch -d "`date -d "-20sec"`" $NETWORK_RUNFILE
  389. fi
  390.  
  391. if [ -n "$TYPE" ] ; then
  392.     type_filter() {
  393.         for i in $*; do
  394.             for t in $TYPE; do
  395.                 case $i in
  396.                     # $t*) echo -n "$i "; continue 2;;
  397.                     $t*) echo $i; continue 2;;
  398.                 esac
  399.             done
  400.         done
  401.         echo
  402.     }
  403. else
  404.     LO=lo
  405.     type_filter() {
  406.         echo $*
  407.     }
  408. fi
  409.  
  410.  
  411.  
  412. ######################################################################
  413. # Get interfaces to handle
  414. #
  415. # Seperate this interfaces into several sets, not all mutually exclisive;
  416. # none of them may contain lo, because it will always handled separately
  417. #
  418. # AVAILABLE_IFACES are all interfaces from /sys/class/net
  419. #                  these have to be shut down when stopping
  420. #
  421. # PHYSICAL_IFACES  are interfaces to present physical devices, they will be
  422. #                  derived from AVAILABLE_IFACES
  423. #
  424. # DIALUP_IFACES    are modemX, dslX, etc., they are derived from ifcfg-* files
  425. #
  426. # TUNNEL_IFACES    are interfaces that do not fit into PHYSICAL and DIALUP and
  427. #                  are as well derived from ifcfg-* files
  428. #
  429. #    PHYSICAL, DIALUP and TUNNEL are mutually exclusive. Their union contains
  430. #    AVAILABLE and MANDATORY and all of them have to be set up when starting
  431. #
  432. # MANDATORY_IFACES these must be up and well configured for success
  433.  
  434. # At first get DIALUP and TUNNEL
  435. # these are all configurations without '-' in the configuration name (because
  436. # then 'config name' == 'interface name'), except those, which start with a
  437. # string known for real physical interfaces (eth, tr, ...) and except those,
  438. # which don't end in a number (those are special configs for manual usage or
  439. # backup files)
  440. while IFS=- read a b c; do
  441.     test -n "$c" && continue
  442.     b=`type_filter $b`
  443.     test -z "$b" && continue
  444.     case $b in
  445.         eth*[0-9]|tr*[0-9]|wlan[0-9]|ath[0-9]|ip6tnl*[0-9]|mip6mnha*[0-9])
  446.             continue
  447.             ;;
  448.         *ppp*[0-9]|dsl*[0-9]|modem*[0-9])
  449.             DIALUP_IFACES="$DIALUP_IFACES $b"
  450.             ;;
  451.         *[0-9])
  452.             TUNNEL_IFACES="$TUNNEL_IFACES $b"
  453.             ;;
  454.     esac
  455. done < <(ls -d /etc/sysconfig/network/ifcfg-*)
  456.  
  457. # Now get all available interfaces drop lo and separate them into physical and
  458. # not physical. Then get AVAILABLE_IFACES sorted to shutdown the not physical
  459. # first.
  460. for a in $(type_filter `ls -A /sys/class/net/`); do
  461.     test "$a" = lo && continue;
  462.     test "$a" = sit0 && continue;
  463.     test "$a" = bonding_masters && continue;
  464.     test "${a#wifi}" != "$a" && continue
  465.     case $a in
  466.         eth*|ath*|wlan*|ra*)
  467.             # Skip these which are too new, they will come via hotplug
  468. #Stempeln in rename_netiface
  469. #- am Anfang: virgin
  470. #- wΣhrend dem Schleifen: looping
  471. #- am Ende: renamed
  472. #ifup bricht gleich ab, wenn kein service network
  473. #Wenns keinen Stempel gibt dann Stempeln unknown --> skip
  474. #Wenn Stempel virgin --> skip
  475. #            looping --> skip
  476. #            renamed --> set up
  477. #In Statusschleife, wenn mandatory devices gecheckt werden:
  478. #  wenn status failed
  479. #    STEMPEL == unknown && halbe Wartezeit vorbei -> ifup
  480. #            == virgin/looping/renamed -> nix
  481.             STAMPFILE=$STAMPFILE_STUB`cat /sys/class/net/$a/ifindex`
  482.             if [ "$MODE" == onboot -a "$ACTION" == start ] ; then
  483.                 if [ -r "$STAMPFILE" ] ; then
  484.                     case "`cat $STAMPFILE`" in
  485.                         virgin|looping) continue ;;
  486.                     esac
  487.                 else
  488.                     echo unknown > $STAMPFILE
  489.                     continue
  490.                 fi
  491.             fi
  492.             ;;
  493.     esac
  494.     for b in $DIALUP_IFACES $TUNNEL_IFACES; do
  495.         if [ "$a" = "$b" ] ; then
  496.             NOT_PHYSICAL_IFACES="$NOT_PHYSICAL_IFACES $a"
  497.             continue 2
  498.         fi
  499.     done
  500.     case $a in
  501.         sit*)
  502.             NOT_PHYSICAL_IFACES="$NOT_PHYSICAL_IFACES $a"
  503.             continue 2
  504.             ;;
  505.     esac
  506.     PHYSICAL_IFACES="$PHYSICAL_IFACES $a"
  507. done
  508. AVAILABLE_IFACES="$NOT_PHYSICAL_IFACES $PHYSICAL_IFACES"
  509.  
  510. # # mandatory interfaces are specified in /etc/sysconfig/network/config
  511. # Hack for 9.1/SLES9: YaST does still not write MANDATORY_DEVICES
  512. # therfore we take all PHYSICAL_IFACES, which are configured, as mandatory
  513. if [ -z "$MANDATORY_DEVICES" ] ; then
  514.     # take all configurations except these
  515.     # -  which seem to be backup files
  516.     # -  which are mostly real hotplug or
  517.     # -  which have STARTMODE != onboot/auto
  518.     # -  which are dialup or tunnel interfaces
  519.     # -  which serve as slave interfaces for bonding, vlan or tunnels
  520.     while IFS=- read a b; do
  521.         test -z "$b" && continue
  522.         case $b in
  523.             *~|*rpmnew|*rpmsave)
  524.                 continue;
  525.                 ;;
  526.             *bus-pcmcia*|*bus-usb*|lo|type-*)
  527.                 continue;
  528.                 ;;
  529.         esac
  530.         case "`get_startmode $b`" in
  531.             on|boot|onboot|auto|ifplugd) : ;;
  532.             *) continue ;;
  533.         esac
  534.         for d in $DIALUP_IFACES; do
  535.             if [ "$b" = "$d" ] ; then
  536.                 continue 2
  537.             fi
  538.         done
  539.         for d in $TUNNEL_IFACES; do
  540.             if [ "$b" = "$d" ] ; then
  541.                 b="`get_slaves $b`"
  542.                 test $? = 0 || continue 2
  543.                 TUNNEL_SLAVES="$TUNNEL_SLAVES $b"
  544.                 continue 2
  545.             fi
  546.         done
  547.         MANDATORY_DEVICES="$MANDATORY_DEVICES $b"
  548.     done < <(ls -d /etc/sysconfig/network/ifcfg-*)
  549.     if [    -n "$MANDATORY_DEVICES" \
  550.          -a "$MODE" != onboot \
  551.          -a "$ACTION" = start ] ; then
  552.         echo "Hint: you may set mandatory devices in" \
  553.              "/etc/sysconfig/network/config"
  554.     fi
  555. fi
  556. MANDATORY_DEVICES="$MANDATORY_DEVICES __NSC__ $TUNNEL_SLAVES"
  557. # Check for mandatory devices only when booting
  558. test "$MODE" = onboot || MANDATORY_DEVICES=""
  559.  
  560. debug "CONFIG      = $CONFIG"
  561. debug "INTERFACE   = $INTERFACE"
  562. debug "AVAILABLE_IFACES = $AVAILABLE_IFACES"
  563. debug "PHYSICAL_IFACES  = $PHYSICAL_IFACES"
  564. debug "DIALUP_IFACES    = $DIALUP_IFACES"
  565. debug "TUNNEL_IFACES    = $TUNNEL_IFACES"
  566. debug "MANDATORY_DEVICES = $MANDATORY_DEVICES"
  567. debug "SKIP             = $SKIP"
  568.  
  569. status() {
  570.     local M IFACE
  571.     # declare -i R=0 F=0
  572.     declare -i F=0
  573.     if [ "$1" = "-m" ]; then
  574.         M=yes
  575.         shift
  576.     fi
  577.     for IFACE in $@; do
  578.         $FAKE ifstatus $CONFIG $IFACE -o rc $CHECK $MODE
  579.         RET=$?
  580.         debug && printf "    %-9s returned %s\n" $IFACE $RET
  581.         case $RET in
  582.             $R_SUCCESS|$R_BUSY)
  583.                 # : $((R++))
  584.                 rc_failed 0
  585.                 rc_status -v1
  586.                 ;;
  587.             $R_DHCP_BG)
  588.                 if [ -f "$NETWORK_RUNFILE" -a "$M" = yes ] ; then
  589.                     : $((F++))
  590.                 fi
  591.                  rc_startmode="${esc}[1A${stat}${attn}waiting${norm}"
  592.                  echo -e "$rc_startmode" 1>&2
  593.                 ;;
  594.             $R_INACTIVE|$R_NOTCONFIGURED)
  595.                 rc_failed 3
  596.                 rc_status -v1
  597.                 ;;
  598.             $R_NOCONFIG)
  599.                 if [ -f "$NETWORK_RUNFILE" -a "$M" = yes ] ; then
  600.                     : $((F++))
  601.                     rc_failed 1
  602.                 else
  603.                     rc_failed 3
  604.                 fi
  605.                 rc_status -v1
  606.                 ;;
  607.             *)
  608.                 if [ -f "$NETWORK_RUNFILE" ] ; then
  609.                     test "$M" = yes && : $((F++))
  610.                     rc_failed 1
  611.                 else
  612.                     rc_failed 3
  613.                 fi
  614.                 rc_status -v1
  615.                 ;;
  616.         esac
  617.         rc_reset
  618.     done
  619.     test "$F" -gt 0 && return 1
  620.     # test "$R" = 0 && return 3
  621.     return 0
  622. }
  623.  
  624. rc_reset
  625. declare -i FAILED=0
  626. if [ "$NETWORKMANAGER" == yes -a ${NM_STATUS:-0} -ne 0 ] ; then
  627.     FAILED=1
  628. fi
  629.  
  630. case "$ACTION" in
  631.     start)
  632.         echo Setting up network interfaces:
  633.         /sbin/ifstatus $LO &>/dev/null && unset $LO;
  634.         for IFACE in ${INTERFACE:- $LO
  635.                                    $PHYSICAL_IFACES   }; do
  636.             for SI in $SKIP; do
  637.                 test "$IFACE" = "$SI" && continue 2
  638.             done
  639.             $FAKE ifup $CONFIG $IFACE -o rc $MODE
  640.             RET=$?
  641.             debug && printf "    %-9s returned %s\n" $IFACE $RET
  642.             case "$RET" in
  643.                  $R_SUCCESS)
  644.                      SUCCESS_IFACES="$SUCCESS_IFACES $IFACE"
  645.                      rc_status -v1
  646.                      ;;
  647.                 $R_DHCP_BG)
  648.                      startmode=waiting
  649.                      rc_startmode="${esc}[1A${stat}${attn}$startmode${norm}"
  650.                      echo -en "$rc_startmode" 1>&2
  651.                      echo
  652.                     ;;
  653.                 $R_NOCONFIG)
  654.                     rc_failed 6
  655.                     rc_status -v1
  656.                     ;;
  657.                  $R_NOTCONFIGURED|$R_INACTIVE)
  658.                      SUCCESS_IFACES="$SUCCESS_IFACES $IFACE"
  659.                     rc_failed 5
  660.                     rc_status -v1
  661.                      ;;
  662.                  *)
  663.                      rc_failed 7
  664.                      rc_status -v1
  665.                      ;;
  666.             esac
  667.             rc_reset
  668.         done
  669.  
  670.         # Wait $WAIT_FOR_INTERFACES seconds after interface setup started for
  671.         # hotplug interfaces to become available
  672.         NEWLINE=no
  673.         while true; do
  674.  
  675.             debug ... still waiting for hotplug devices:
  676.             debug SUCCESS_IFACES=$SUCCESS_IFACES
  677.             debug MANDATORY_DEVICES=$MANDATORY_DEVICES
  678.             TMP=$MANDATORY_DEVICES
  679.             MANDATORY_DEVICES=
  680.             STATUS_CHECK=yes
  681.             for D in $TMP; do
  682.                 if [ "$D" = "__NSC__" ] ; then
  683.                     STATUS_CHECK=no
  684.                     MANDATORY_DEVICES="$MANDATORY_DEVICES $D"
  685.                     continue
  686.                 fi
  687.                 IFACE=`/sbin/getcfg-interface -- $D 2>/dev/null`
  688.                 if [ $? != 0 -o ! -d /sys/class/net/$IFACE ] ; then
  689.                     MANDATORY_DEVICES="$MANDATORY_DEVICES $D"
  690.                     continue    
  691.                 fi
  692.                 for S in $SUCCESS_IFACES; do
  693.                     test "$IFACE" = "$S" && continue 2
  694.                 done
  695.                 if [ "$STATUS_CHECK" = no ] ; then
  696.                     echo
  697.                     NEWLINE=no
  698.                     continue
  699.                 fi
  700.                 IFACE="`type_filter $IFACE`"
  701.                 test -z "$IFACE" && continue
  702.                 status -m $IFACE &>/dev/null
  703.                 RET=$?
  704.                 if [ $RET = 0 ] ; then
  705.                     SUCCESS_IFACES="$SUCCESS_IFACES $IFACE"
  706.                     if [ "$NEWLINE" = yes ] ; then
  707.                         echo
  708.                         NEWLINE=no
  709.                     fi
  710.                     status -m $IFACE
  711.                     continue
  712.                 fi    
  713.                 if [ "$((WAIT_FOR_INTERFACES/3 - TTWAIT))" -le 0 ] ; then
  714.                     STAMPFILE=$STAMPFILE_STUB`cat /sys/class/net/$IFACE/ifindex`
  715.                     if [ "$MODE" == onboot -a "$ACTION" == start \
  716.                          -a -r "$STAMPFILE" ] ; then
  717.                         case "`cat $STAMPFILE`" in
  718.                             unknown)
  719.                                 $FAKE ifup $IFACE -o hotplug &>/dev/null
  720.                                 echo renamed > $STAMPFILE
  721.                                 ;;
  722.                         esac
  723.                     fi
  724.                 fi
  725.                 MANDATORY_DEVICES="$MANDATORY_DEVICES $D"
  726.             done
  727.  
  728.             # If only the seperator remains we are done and thus remove it
  729.             test "`echo $MANDATORY_DEVICES`" = __NSC__ && MANDATORY_DEVICES=
  730.  
  731.             TTWAIT=$((`date +%s` - `cat $NETWORK_RUNFILE`))
  732.             test $TTWAIT -gt $((WAIT_FOR_INTERFACES)) \
  733.                  -o -z "$MANDATORY_DEVICES" && break
  734.  
  735.             debug "Time to wait: $((WAIT_FOR_INTERFACES - TTWAIT))"
  736.             if [ "$NEWLINE" != yes ] ; then
  737.                 echo "Waiting for mandatory devices: $MANDATORY_DEVICES"
  738.             fi
  739.             echo -n "$((WAIT_FOR_INTERFACES - TTWAIT)) "
  740.             NEWLINE=yes
  741.             sleep 1
  742.         done
  743.  
  744.         if [ "$NEWLINE" = yes ] ; then
  745.             echo
  746.         fi
  747.  
  748.         for D in $MANDATORY_DEVICES; do
  749.             # Don't check the seperator
  750.             test "$D" = __NSC__ && continue
  751.             IFACE=`/sbin/getcfg-interface -- $D 2>/dev/null`
  752.             if [ $? = 0 -a -d /sys/class/net/$IFACE ] ; then
  753.                 status -m $IFACE && continue
  754.                 printf "    %-9s interface could not be set up until now\n" $IFACE
  755.             else
  756.                 printf "    %-35s No interface found\n" $D
  757.             fi
  758.             rc_failed
  759.             rc_status -v1
  760.             : $((FAILED++))
  761.         done
  762.  
  763.         debug ... final
  764.         debug SUCCESS_IFACES=$SUCCESS_IFACES
  765.         debug MANDATORY_DEVICES=$MANDATORY_DEVICES
  766.         debug FAILED=$FAILED
  767.  
  768.  
  769.         if [ -z "$INTERFACE" ] ; then
  770.             for IFACE in $DIALUP_IFACES $TUNNEL_IFACES ; do
  771.                 $FAKE ifup $CONFIG $IFACE -o rc $MODE
  772.                 RET=$?
  773.                 debug && printf "    %-9s returned %s\n" $IFACE $RET
  774.                 case "$RET" in
  775.                      $R_SUCCESS)
  776.                          SUCCESS_IFACES="$SUCCESS_IFACES $IFACE"
  777.                          rc_status -v1
  778.                          ;;
  779.                     $R_DHCP_BG)
  780.                          startmode=waiting
  781.                          rc_startmode="${esc}[1A${stat}${attn}$startmode${norm}"
  782.                          echo -en "$rc_startmode" 1>&2
  783.                          echo
  784.                         ;;
  785.                     $R_NOCONFIG)
  786.                         rc_failed 6
  787.                         rc_status -v1
  788.                         : $((FAILED++))
  789.                         ;;
  790.                      $R_NOTCONFIGURED|$R_INACTIVE)
  791.                          SUCCESS_IFACES="$SUCCESS_IFACES $IFACE"
  792.                         rc_failed 5
  793.                         rc_status -v1
  794.                          ;;
  795.                      *)
  796.                          rc_failed 7
  797.                          rc_status -v1
  798.                         : $((FAILED++))
  799.                          ;;
  800.                 esac
  801.                 rc_reset
  802.             done
  803.         fi
  804.  
  805.  
  806.         rc_reset
  807.         if [ -z "$INTERFACE" ] ; then
  808.             $FAKE ifup-route noiface -o rc $MODE
  809.             rc_status
  810.             test $FAILED -gt 0 && rc_failed 7
  811.             echo -n "Setting up service network  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  ."
  812.             rc_status -v
  813.         fi
  814.  
  815.         reload_firewall not_on_boot
  816.  
  817.         ;;
  818.  
  819.     stop)
  820.  
  821.         echo Shutting down network interfaces:
  822.  
  823.         if [ -z "$INTERFACE" ] ; then
  824.             $FAKE ifdown-route noiface -o rc $MODE
  825.         fi
  826.  
  827.         for IFACE in ${INTERFACE:-$AVAILABLE_IFACES} ; do
  828.             # printf "    %-9s " $IFACE
  829.             $FAKE ifdown $CONFIG $IFACE -o rc $MODE
  830.             RET=$?
  831.             debug && printf "    %-9s returned %s\n" $IFACE $RET
  832.             rc_failed $RET
  833.             case "$RET" in
  834.                 $R_NODEV|$R_NOTCONFIGURED|$R_INACTIVE)
  835.                     rc_failed 5
  836.                     rc_status -v1 ;;
  837.                 *)
  838.                     rc_status -v1 ;;
  839.             esac
  840.             rc_reset
  841.         done
  842.  
  843.         if [ -z "$INTERFACE" -a -z "$TYPE" ] ; then
  844.             # At last stop any remaining dhcp client
  845.             $FAKE ifdown-dhcp all -o rc
  846.             rc_status
  847.             rm -f $RUN_FILES_BASE/if-*
  848.             rm -f $NETWORK_RUNFILE
  849.             echo -n "Shutting down service network  .  .  .  .  .  .  .  .  .  .  .  .  .  .  ."
  850.             rc_status -v
  851.         fi
  852.  
  853.         ;;
  854.  
  855.     reload)
  856.         if ! $0 status >/dev/null; then
  857.             echo -n service network not active
  858.             rc_failed 7
  859.             rc_status -v
  860.             rc_exit
  861.         fi
  862.         if [ -z "$INTERFACE" -a routes -nt $NETWORK_RUNFILE ] ; then
  863.             $FAKE ifdown-route noiface -o rc $MODE
  864.         fi
  865.         UP2DATE_IFACES=lo
  866.         for IFACE in ${INTERFACE:-$AVAILABLE_IFACES} ; do
  867.             # ifprobe checks if iface configuration changed
  868.             if ifprobe $IFACE ; then
  869.                 UP2DATE_IFACES="$UP2DATE_IFACES $IFACE"
  870.                 continue
  871.             fi
  872.             $FAKE ifdown $CONFIG $IFACE -o rc $MODE
  873.             RET=$?
  874.             debug && printf "    %-9s returned %s\n" $IFACE $RET
  875.             rc_failed $RET
  876.             case "$RET" in
  877.                 $R_NODEV|$R_NOTCONFIGURED|$R_INACTIVE)
  878.                     rc_failed 5
  879.                     rc_status -v1 ;;
  880.                 *)
  881.                     rc_status -v1 ;;
  882.             esac
  883.             rc_reset
  884.         done
  885.         # And we we start all interfaces to catch also new virtual interfaces
  886.         cd "$OLDPWD" # we went to /etc/sysconfig/network, so we have to go back.
  887.         $0 start $CONFIG $INTERFACE -o $OPTIONS skip="$UP2DATE_IFACES"
  888.         rc_status
  889.         ;;
  890.  
  891.     status)
  892.  
  893.         if [ -z "$INTERFACE" ] ; then
  894.               for D in $LO $MANDATORY_DEVICES; do
  895.                 test "$D" = __NSC__ && continue
  896.                   IFACE=`/sbin/getcfg-interface -- $D 2>/dev/null`
  897.                   if [ $? != 0 ] ; then
  898.                     printf "    %-35s No interface found\n" $D
  899.                       : $((FAILED++))
  900.                       continue
  901.                   fi
  902.                   MANDATORY_IFACES="$MANDATORY_IFACES `type_filter $IFACE`"
  903.               done
  904.             debug getting MANDATORY_IFACES: FAILED=$FAILED
  905.       
  906.               for IFACE in $AVAILABLE_IFACES $DIALUP_IFACES $TUNNEL_IFACES; do
  907.                   for MI in $MANDATORY_IFACES $TOCHECK_IFACES; do
  908.                       test "$IFACE" = "$MI" && continue 2
  909.                   done
  910.                   TOCHECK_IFACES="$TOCHECK_IFACES $IFACE"
  911.               done
  912.       
  913.              debug MANDATORY_DEVICES=$MANDATORY_DEVICES
  914.              debug MANDATORY_IFACES=$MANDATORY_IFACES
  915.              debug TOCHECK_IFACES=$TOCHECK_IFACES
  916.  
  917.             if [ -n "$TOCHECK_IFACES" ] ; then
  918.                 echo Checking optional network interfaces:
  919.                   status $TOCHECK_IFACES
  920.             fi
  921.             if [ -n "$MANDATORY_IFACES" ] ; then
  922.                 echo Checking mandatory network interfaces:
  923.                   status -m $MANDATORY_IFACES
  924.                   test $? != 0 && : $((FAILED++))
  925.                 debug checking MANDATORY_IFACES: FAILED=$FAILED
  926.             else
  927.                 echo No interfaces declared as mandatory
  928.             fi
  929.  
  930.              $FAKE ifstatus-route noiface -o rc $MODE
  931.              rc_status 
  932.             test $FAILED -gt 0 && rc_failed 1
  933.         else
  934.             status $INTERFACE
  935.             rc_status
  936.         fi
  937.  
  938.         if [ ! -f $NETWORK_RUNFILE ] ; then
  939.             rc_failed 3 # unused
  940.         fi
  941.  
  942.         echo -n "Checking service network .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  .  ."
  943.         rc_status -v
  944.  
  945.         ;;
  946.  
  947. esac
  948.  
  949. rc_exit
  950.  
  951.