home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / sbin / ifup < prev    next >
Text File  |  2010-05-05  |  41KB  |  1,272 lines

  1. #!/bin/bash
  2. #
  3. # Network interface configuration
  4. #
  5. # Copyright (c) 2002-2006 SuSE Linux AG Nuernberg, Germany.
  6. # All rights reserved.
  7. #
  8. # This program is free software; you can redistribute it and/or modify it under
  9. # the terms of the GNU General Public License as published by the Free Software
  10. # Foundation; either version 2 of the License, or (at your option) any later
  11. # version.
  12. #
  13. # This program is distributed in the hope that it will be useful, but WITHOUT
  14. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
  16. # details.
  17. #
  18. # You should have received a copy of the GNU General Public License along with
  19. # this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  20. # Place, Suite 330, Boston, MA 02111-1307 USA
  21. #
  22. # Author: Michal Svec <msvec@suse.cz>
  23. #         Christian Zoz <zoz@suse.de>
  24. #         Mads Martin Joergensen <mmj@suse.de>
  25. #         Michal Ludvig <mludvig@suse.cz>
  26. #         Marius Tomaschewski <mt@suse.de>
  27. #         Bjoern Jacke
  28. #
  29. # $Id: ifup 2119 2010-03-12 13:02:33Z mt $
  30. #
  31.  
  32. usage () {
  33.     echo $@
  34.     echo "Usage: if{up,down,status} [<config>] <interface> [-o <options>]"
  35.     echo ""
  36.     echo "Options are:"
  37.     echo "    [on]boot : we are currently booting (or shutting down)"
  38.     echo "    auto     : alias for boot"
  39.     echo "    hotplug  : we are handling a hotplug event"
  40.     echo "    manual   : we do it manually (default, just needed with 'rc'"
  41.     echo "    rc       : we are called by a rc script (implies auto)"
  42.     echo "    dhcp     : we are called from dhcp client" 
  43.     echo "    prov=<n> : use provider <n> (for dial up interface)"
  44.     echo "    nodeps   : don't shut down interfaces depending on this" 
  45.     echo "    debug    : be verbose"
  46.     if [ "$SCRIPTNAME" = "ifstatus" ] ; then
  47.         echo "    syslog   : write to syslog if USE_SYSLOG=yes"
  48.         echo -e "    check    : return R_BUSY (=$R_BUSY) if there are" \
  49.               "\n               active connections on this interface"
  50.     else
  51.         echo "    nosyslog : don't write to syslog even if USE_SYSLOG=yes"
  52.     fi
  53.     echo "If options are contradictionary, last option wins. Unknown options"
  54.     echo "are simply ignored, so be careful."
  55.     echo
  56.     exit $R_USAGE
  57. }
  58.  
  59. exithook () {
  60.     RET_VAL=${1:-0}
  61.     if [ "$LOCK_RET_STATE" != yes ] ; then
  62.         case $RET_VAL in
  63.             $R_SUCCESS) RET_STATE=success ;;
  64.             $R_DHCP_BG) RET_STATE=progress ;;
  65.         esac
  66.     fi
  67.     RET_STATE=${2:-$RET_STATE}
  68.     exit $RET_VAL
  69. }
  70.  
  71. ######################################################################
  72. # change the working direcory and source some common files
  73. #
  74. R_INTERNAL=1      # internal error, e.g. no config or missing scripts
  75. cd /etc/sysconfig/network || exit $R_INTERNAL
  76. test -f ./config && . ./config
  77. test -f scripts/functions && . scripts/functions || exit $R_INTERNAL
  78.  
  79. test "$DEBUG" = "EXTRA" && . scripts/extradebug
  80.  
  81. ######################################################################
  82. # Commandline parsing
  83. #
  84. # if{up,down,status} [config] interface [-o options]
  85. SCRIPTNAME=${0##*/}
  86. debug $*
  87. case "$1" in ""|-h|*help*) usage; esac
  88. INTERFACE=$1
  89. shift
  90. if [ -n "$1" -a "$1" != "-o" ] ; then
  91.     CONFIG=$INTERFACE
  92.     INTERFACE=$1
  93. fi
  94. shift
  95. test "$1" = "-o" && shift
  96. OPTIONS=$@
  97. MODE=manual
  98. HOTPLUG=no
  99. CONTROL_IFPLUGD=yes # Start/Stop ifplugd?
  100. # Don't log messages from ifstatus in syslog by default (Bug 261350). This
  101. # overwrites the config variable /etc/sysconfig/network/config:USE_SYSLOG
  102. export DONT_USE_SYSLOG=no
  103. test "$SCRIPTNAME" == ifstatus && DONT_USE_SYSLOG=yes
  104. while [ $# -gt 0 ]; do
  105.     case $1 in
  106.         boot|onboot) MODE=auto ;;
  107.         auto)        MODE=auto ;;
  108.         hotplug)     MODE=auto
  109.                      HOTPLUG=yes ;;
  110.         rc)          RUN_FROM_RC=yes
  111.                      MODE=auto ;;
  112.         manual)      MODE=manual ;;
  113.         ifplugd)     CONTROL_IFPLUGD=no ;; # No, set up iface instead
  114.         check)       CHECK=yes ;;
  115.         quiet)       be_quiet_has_gone ;;
  116.         debug)       DEBUG=yes ;;
  117.         nosyslog)    DONT_USE_SYSLOG=yes ;;
  118.         syslog)      DONT_USE_SYSLOG=no ;;
  119.         prov=*)      PROVIDER=${1##*=} ;;
  120.         dhcp)        DHCP=yes; CONTROL_IFPLUGD=no ;;
  121.         nodeps)      NODEPS=yes ;;
  122.         *)           debug "unknown option $1 ignored" ;;
  123.     esac
  124.     shift
  125. done
  126. # Source functions.common again, because values of DEBUG and BE_QUIET might
  127. # have changed. These variable will be evaluated while sourcing the file.
  128. test -f scripts/functions.common \
  129.     && . scripts/functions.common \
  130.     || exit $R_INTERNAL
  131.  
  132.  
  133. ######################################################################
  134. # Get a configuration name
  135.  
  136. if [ -z "$CONFIG" ] ; then
  137.     read CONFIG < <(read_cached_config_data config $INTERFACE)
  138. fi
  139. if [ -z "$CONFIG" ] ; then
  140.     CONFIG=$INTERFACE
  141. fi
  142.  
  143. case $SCRIPTNAME in
  144.     ifprobe)
  145.         IFUPFILE=$RUN_FILES_BASE/ifup-$INTERFACE
  146.         if [ ! -e "$IFUPFILE" ] ; then
  147.             IFUPFILE=$RUN_FILES_BASE/if-$INTERFACE
  148.         fi
  149.         if [ -e $IFUPFILE ] ; then
  150.             if [ ! -e "ifcfg-$CONFIG" ] ; then
  151.                 message "`printf "    %-9s config file removed: %s" \
  152.                          $INTERFACE "--> restart interface!"`"
  153.                 exit $R_NOT_UP2DATE
  154.             fi
  155.             for FILE in if{cfg,route,services}-$CONFIG \
  156.                         config dhcp wireless routes; do
  157.                 test -e $FILE || continue
  158.                 test $FILE -nt $IFUPFILE || continue
  159.                 message "`printf "    %-9s changed config file: %s %s" \
  160.                          $INTERFACE "$FILE" "--> restart interface!"`"
  161.                 exit $R_NOT_UP2DATE
  162.             done
  163.         elif [ -e "ifcfg-$CONFIG" ] ; then
  164.             message "`printf "    %-9s config file created: %s" \
  165.                      $INTERFACE "--> restart interface!"`"
  166.             exit $R_NOT_UP2DATE
  167.         fi
  168.         exit $R_SUCCESS
  169.         ;;
  170. esac
  171.  
  172.  
  173. ######################################################################
  174. # Find out the type of the interface
  175. # This may be overwritten in the configuration file
  176. #
  177. test -z "$INTERFACETYPE" && INTERFACETYPE=`get_iface_type $INTERFACE`
  178. test -z "$INTERFACETYPE" && INTERFACETYPE=`get_iface_type_from_config $INTERFACE`
  179. # at least ifup-wireless needs $INTERFACETYPE, so we have to export it
  180. export INTERFACETYPE
  181. # Test for wlan helper interfaces and skip these
  182. if [ "$INTERFACETYPE" == wlan_aux ] ; then
  183.     message "interface '$INTERFACE' is a wlan helper interface. Exiting.";
  184.     exit $R_SUCCESS
  185. fi
  186.  
  187.  
  188. ######################################################################
  189. # Set renamed flag for this interface
  190. #
  191. # This is needed if ifup is called via udev before rcnetwork was started.
  192. # Without this flag rcnetwork does not know if renaming was completed and
  193. # will therefore wait unneccessarily. In older releases we did this in
  194. # rename_netiface, but since rename_netiface is gone we do it here.
  195. if [ "$SCRIPTNAME" = ifup ] ; then
  196.     if [ "$HOTPLUG" = yes ] ; then
  197.         # set renamed (ready to configure) flag
  198.         IFINDEX=/sys/$DEVPATH/ifindex
  199.         if [ -r "$IFINDEX" ] ; then
  200.             STAMPFILE=$STAMPFILE_STUB`cat $IFINDEX`
  201.             echo renamed > $STAMPFILE
  202.         fi
  203.         # don't continue on (creation) events for virtual interfaces;
  204.         # somebody created them and will configure them as well.
  205.         case $INTERFACETYPE in
  206.                     lo|dummy|bridge|bond|vlan|ibchild)
  207.                 exit $R_SUCCESS
  208.             ;;
  209.                     gre|sit|tap|tun|ipip|ip6tnl)
  210.                 exit $R_SUCCESS
  211.             ;;
  212.                     ppp|isdn|plip|irda|ipsec|mip6mnha)
  213.                 exit $R_SUCCESS
  214.             ;;
  215.         esac
  216.     fi
  217.     # check if service network was started and skip ifup in auto mode
  218.     if [ "$MODE" = auto ] && ! netcontrol_running ; then
  219.         message "Service network not started and mode 'auto' -> skipping"
  220.         exit $R_SUCCESS
  221.     fi
  222. fi
  223.  
  224.  
  225. ######################################################################
  226. # Now source the configuration file and check if we have an interface
  227. #
  228. if [ -n "$CONFIG" -a -r ifcfg-$CONFIG ] ; then
  229.     . ifcfg-$CONFIG
  230.     # Store config name persistently for use in ifplugd-selectif after
  231.     # interface has gone. Without that info it will not activate
  232.     # alternative interface in this case. Used in get_ifplugd_priority()
  233.     echo $CONFIG > $RUN_FILES_BASE/config-$INTERFACE
  234. fi
  235.  
  236. ######################################################################
  237. # Check if the interface is available
  238. #
  239. if ! is_iface_available $INTERFACE; then
  240.     if [ "$SCRIPTNAME" != ifdown ] ; then
  241.         retcode=$R_NODEV
  242.         retmesg="is not available"
  243.         case "$STARTMODE" in
  244.         off)
  245.             retcode=$R_INACTIVE
  246.             retmesg="is not active (startmode $STARTMODE)"
  247.         ;;
  248.         esac
  249.         if [ "$RUN_FROM_RC" = yes ] ; then
  250.             message "`printf "    %-9s $retmesg" $INTERFACE`"
  251.         else
  252.             logerror "Interface $INTERFACE $retmesg"
  253.         fi
  254.         exit $retcode
  255.     else
  256.         if [ "$RUN_FROM_RC" = yes -o "$HOTPLUG" = yes ] ; then
  257.             : just go on, there are things to clean up even if iface has gone
  258.         else
  259.             # message "There is no interface '$INTERFACE'"
  260.             MESS_NO_IFACE="no such interface"
  261.         fi
  262.     fi
  263. fi
  264.  
  265.  
  266. ######################################################################
  267. # Check if NetworkManager is running, inform the user and exit
  268. if [ "$NETWORKMANAGER" = yes ] && ! netcontrol_running ; then
  269.     if [ "$SCRIPTNAME" != ifdown -a "$INTERFACE" != lo ] ; then
  270.         mesg "Network interface is managed by the NetworkManager -> skipping"
  271.         exit $R_NOTIMPL
  272.     fi
  273. elif nm_running && [ "$INTERFACE" != lo ] ; then
  274.     mesg "Network interface is managed by the NetworkManager -> skipping"
  275.     exit $R_NOTIMPL
  276. fi
  277.  
  278.  
  279. ######################################################################
  280. # Normalize some values in the config
  281. #
  282. BOOTPROTO=$(echo "${BOOTPROTO}" | awk '{print tolower($0);}')
  283.  
  284.  
  285. ######################################################################
  286. # Parse iSCSI Boot Firmware Table (feature 308283, bnc 542225) to
  287. # either start dhcp client or keep anything untouched, because it
  288. # is already configured in the initrd.
  289. #
  290. if [ "${BOOTPROTO}" = "ibft" ] ; then
  291.     IBFT=yes # not used at the moment... remember before override
  292.     eval BOOTPROTO=none `parse_ifname_ibft_settings "$INTERFACE"`
  293. fi
  294.  
  295. ######################################################################
  296. # work around bug 85849
  297. # If interface is not configured for dhcp, but ifup/down -o dhcp was
  298. # called from dhcpcd, then exit. This case may happen when dhcpcd was
  299. # called directly.
  300. if [ "${BOOTPROTO:0:4}" != dhcp -a "$DHCP" = yes ] ; then
  301.     logerror "Interface $INTERFACE is not configured for dhcp." \
  302.          "So don't use '-o dhcp'."
  303.     exit $R_USAGE
  304. fi
  305.  
  306.  
  307. ######################################################################
  308. # If we were called via hotplug or from rc-script then start/stop ifplugd if
  309. # configured for this interface
  310. #
  311. IFPLUGD=/sbin/ifplugd
  312. #if [ \(    "$HOTPLUG"     = yes    \
  313. #        -o "$RUN_FROM_RC" = yes \) \
  314. #     -a -x "$IFPLUGD" ] ; then
  315. if [ "$CONTROL_IFPLUGD" == yes ] ; then
  316.     case $SCRIPTNAME in
  317.         ifup)
  318.             if [ $((IFPLUGD_PRIORITY)) -gt 0 ] ; then
  319.                 IFPLUGSCRIPT="-r $PWD/scripts/ifplugd-selectif"
  320.             fi
  321.             # -a do not set interface UP automatically
  322.             # -f ignore failure, treated as no link
  323.             # -F ignore failure, treated as link detected
  324.             # -I don't terminate when script returns error
  325.             # -q don't down iface when terminating
  326.             # -w wait on fork for link status
  327.             if [ "$STARTMODE" = ifplugd ] ; then
  328.                 if [ ! -x "$IFPLUGD" ] ; then
  329.                     logerror "Package ifplugd not installed: missing $IFPLUGD"
  330.                     exit $R_ERROR
  331.                 fi
  332.                 # ifplugd does get link status properly for wlan interfaces.
  333.                 # Therefore we don't start it for these. If multiple interfaces were
  334.                 # configured with ifplugd, wlan iface will be set up when no iface
  335.                 # with higher priority (== wired iface) has a link.
  336.                 if [ "$INTERFACETYPE" = "wlan" ]; then
  337.                     write_cached_config_data link yes $INTERFACE
  338.                 else
  339.                     $IFPLUGD -i $INTERFACE $IFPLUGSCRIPT \
  340.                         ${IFPLUGD_OPTIONS:- -f -I}
  341.                 fi
  342.  
  343.                 # We need this flag later for ifstatus, because we must avoid that
  344.                 # connection state is checked to early
  345.                 ( sleep 3; touch $RUN_FILES_BASE/ready-$INTERFACE; ) &
  346.             fi
  347.             ;;
  348.         ifdown)
  349.             if [ "$INTERFACETYPE" != "wlan" -a -f /var/run/ifplugd.$INTERFACE.pid ]; then
  350.                 $IFPLUGD -i $INTERFACE -k 2>/dev/null
  351.                 # When ifplug terminates it calls the down script which in turn
  352.                 # runs ifdown without '-o hotplug' or '-o rc' and writes status
  353.                 # information. But we must wait and ensure that all this info is
  354.                 # deleted afterwards.
  355.                 # Additionally ifdown must not return before ifplugd has terminated
  356.                 # so that a new ifplugd may be started when calling 'rcnetwork
  357.                 # restart' (See bug 129648).
  358.                 for ((count=0; count<800; count++)) ; do
  359.                     if [ ! -f /var/run/ifplugd.$INTERFACE.pid ] ; then
  360.                         debug "ifplugd terminated"
  361.                         break
  362.                     fi
  363.                     ((count%40 == 1)) && debug "waiting for ifplugd to terminate ($((count/40+1)))"
  364.                     usleep 25000
  365.                 done
  366.             fi
  367.             ;;
  368.     esac
  369. fi
  370.  
  371. ######################################################################
  372. # Shut down depending interfaces
  373. #
  374. # Check if there are interfaces which depend on this interface. If yes these
  375. # have to be shut down first.
  376. # For example these might be bonding or vlan interfaces. Note that we don't
  377. # catch all types of depending interfaces currently. See function
  378. # 'get_depending_ifaces' in file 'functions' for details.
  379. #
  380. test "$SCRIPTNAME" = ifdown && DEP_IFACES=`get_depending_ifaces $INTERFACE`
  381. if [ "$?" = 0 -a "$NODEPS" != yes ] ; then
  382.     message "`printf "    %-9s is still used from interfaces %s" \
  383.                      $INTERFACE "$DEP_IFACES"`"
  384.     for DI in $DEP_IFACES; do
  385.         ifdown $DI -o $OPTIONS    
  386.     done
  387.  
  388.     message "`printf "    %-9s now going down itself" $INTERFACE`"
  389.     # check if iface is (still) avaliable
  390.     # [bonding master may go down itself
  391.     #  while the last slave gets removed]
  392.     if ! is_iface_available $INTERFACE; then
  393.         exit $R_SUCCESS
  394.     fi
  395. fi
  396.  
  397. ######################################################################
  398. # write status information into the interface data cache
  399. #
  400.  
  401. setexitstate () {
  402.     case $SCRIPTNAME in
  403.         ifup)
  404.             case $RET_STATE in
  405.                 removed)
  406.                     delete_from_cached_config_data '*' '' $INTERFACE
  407.                     ;;
  408.                 success)
  409.                     write_cached_config_data status connected $INTERFACE
  410.                     write_cached_config_data up yes $INTERFACE PFX=ifup-
  411.                     ;;
  412.                 progress)
  413.                     write_cached_config_data status connecting $INTERFACE
  414.                     write_cached_config_data up yes $INTERFACE PFX=ifup-
  415.                     ;;
  416.                 failure|ifplugd)
  417.                     write_cached_config_data status disconnected $INTERFACE
  418.                     ;;
  419.                 *)
  420.                     write_cached_config_data status "$RET_STATE" $INTERFACE
  421.                     ;;
  422.             esac
  423.             commit_cached_config_data $INTERFACE
  424.             commit_cached_config_data $INTERFACE PFX=ifup-
  425.             ;;
  426.         ifdown)
  427.             test "$HOTPLUG" = yes && RET_STATE=removed
  428.             test "$RUN_FROM_RC" = yes && RET_STATE=removed
  429.             case $RET_STATE in
  430.                 removed)
  431.                     delete_from_cached_config_data '*' '' $INTERFACE
  432.                     ;;
  433.                 success)
  434.                     write_cached_config_data status disconnected $INTERFACE
  435.                     ;;
  436.                 progress)
  437.                     write_cached_config_data status disconnecting $INTERFACE
  438.                     ;;
  439.                 failure)
  440.                     write_cached_config_data status connected $INTERFACE
  441.                     ;;
  442.                 *)
  443.                     write_cached_config_data status "$RET_STATE" $INTERFACE
  444.                     ;;
  445.             esac
  446.             commit_cached_config_data $INTERFACE
  447.             delete_from_cached_config_data '*' '' $INTERFACE PFX=ifup-
  448.             commit_cached_config_data $INTERFACE PFX=ifup-
  449.             ;;
  450.     esac
  451. }
  452.  
  453. exittrap () {
  454.     if [ "$RET_STATE" != keep_state ] ; then
  455.         setexitstate
  456.     fi
  457. }
  458.  
  459. case $SCRIPTNAME in
  460.     ifup)
  461.         write_cached_config_data config "$CONFIG" $INTERFACE
  462.         write_cached_config_data status connecting $INTERFACE
  463.         if [ "$RUN_FROM_RC" != yes ] ; then
  464.             write_cached_config_data provider "$PROVIDER" $INTERFACE
  465.         fi
  466.         commit_cached_config_data $INTERFACE
  467.         RET_STATE=failure
  468.         trap exittrap EXIT
  469.         ;;
  470.     ifstatus)
  471.         :
  472.         ;;
  473.     ifdown)
  474.         write_cached_config_data status disconnecting $INTERFACE
  475.         if [ "$RUN_FROM_RC" != yes ] ; then
  476.             delete_from_cached_config_data provider "" $INTERFACE
  477.         fi
  478.         commit_cached_config_data $INTERFACE
  479.         RET_STATE=failure
  480.         trap exittrap EXIT
  481.         ;;
  482. esac
  483.  
  484.  
  485. ######################################################################
  486. # Print some info
  487. #
  488.  
  489. get_businfo() {
  490.     cd -P /sys/class/net/$1/device 2>/dev/null || return
  491.     echo BUSID=${PWD##*/}
  492.     echo VENDORID=`cat vendor 2>/dev/null`
  493.     echo PRODUCTID=`cat device 2>/dev/null`
  494.     cd -P subsystem 2>/dev/null || return
  495.     echo BUSNAME=${PWD##*/}
  496. }
  497.  
  498. eval `get_businfo $INTERFACE`
  499. DEVNAME=
  500. if [ -n "$VENDORID$PRODUCTID" -a "$BUSNAME" = pci -a -x /sbin/lspci ] ; then
  501.     DEVNAME=`lspci -d $VENDORID:$PRODUCTID 2>/dev/null | sed -n 1p`
  502.     DEVNAME=${DEVNAME#*: }
  503. elif [ "$BUSNAME" = pcmcia ] ; then
  504.     DEVNAME=`cat /sys/class/net/$INTERFACE/device/prod_id* 2>/dev/null`
  505. fi
  506. if [ -n "$DEVNAME" ] ; then
  507.     message "`printf "    %-9s device: %s" $INTERFACE "$DEVNAME"`"
  508. elif [ -n "$NAME" -a -z "$MESS_NO_IFACE" ] ; then
  509.     message "`printf "    %-9s name: %s" "$INTERFACE" "$NAME"`"
  510. else
  511.     message "`printf "    %-9s %s" "$INTERFACE" "$MESS_NO_IFACE"`"
  512. fi
  513.  
  514. ######################################################################
  515. # What shell we do if there is no configuration data?
  516. # - fail
  517. # - get it automatically
  518. # - ask the user
  519. if [    "$SCRIPTNAME" != ifdown  \
  520.      -a \(      -z "$CONFIG"     \
  521.            -o ! -r ifcfg-$CONFIG \) ] ; then
  522.     RET_STATE=removed
  523.     logerror "              No configuration found for $INTERFACE"
  524.     exit $R_NOCONFIG
  525. fi
  526. if [    "$SCRIPTNAME" = ifdown  \
  527.      -a \(      -z "$CONFIG"     \
  528.            -o ! -r ifcfg-$CONFIG \) ] ; then
  529.     RET_STATE=removed
  530.     LOCK_RET_STATE=yes
  531.     if is_iface_available $INTERFACE; then
  532.         logerror "              No configuration found for $INTERFACE" \
  533.                  "\n              Nevertheless the interface will be shut down."
  534.     else
  535.         logerror "Interface not available and no configuration found."
  536.         exit $R_NOCONFIG
  537.     fi
  538. fi
  539.  
  540.  
  541. ######################################################################
  542. # read possibly stored provider
  543. #
  544. # If we don't know a provider name, let's have a look if a provider was stored
  545. # in the runtime data cache for this configuration.
  546. if [ "$SCRIPTNAME" != ifdown -a -z "$PROVIDER" ] ; then
  547.     PROVIDER=`read_cached_config_data provider $INTERFACE`
  548. fi
  549.  
  550.  
  551. ######################################################################
  552. # check startmode (not for ifdown)
  553. #
  554. # STARTMODE is from config file; MODE is current mode
  555. #
  556. # Read temporary startmode
  557. if [ "$SCRIPTNAME" = ifdown ] ; then
  558.     tmp_startmode=`read_cached_config_data startmode $INTERFACE`
  559.     [ -n "$tmp_startmode" ] && STARTMODE="$tmp_startmode"
  560. fi
  561.  
  562. test "$STARTMODE" = "on"      && STARTMODE=auto
  563. test "$STARTMODE" = "boot"    && STARTMODE=auto
  564. test "$STARTMODE" = "onboot"  && STARTMODE=auto
  565. test "$STARTMODE" = "hotplug" && STARTMODE=auto
  566. if [ "$STARTMODE" = "nfsroot" ] ; then
  567.     STARTMODE=auto
  568.     # if this interface serves nfs root, then don't shut it down via rcnetwork
  569.     if [ "$SCRIPTNAME" = ifdown -a "$RUN_FROM_RC" = yes ] ; then
  570.         message "`printf "    %-9s serves root filesystem. Leave it up." \
  571.                          "$INTERFACE"`"
  572.         RET_STATE=keep_state
  573.         exit $R_NOTCONFIGURED
  574.     fi
  575. fi
  576. if [ "$STARTMODE" == ifplugd -a "$CONTROL_IFPLUGD" == yes ] ; then
  577.     if [ "$SCRIPTNAME" == ifup ] ; then
  578.         message "`printf "    %-9s is controlled by ifplugd" $INTERFACE`"
  579.         if [ "$INTERFACETYPE" = "wlan" ]; then
  580.             # Since exec deletes our traps we have to call
  581.             # exittrap explicitely to set connection state
  582.             RET_STATE=ifplugd
  583.             exittrap
  584.             exec scripts/ifplugd-selectif $INTERFACE up > /dev/null
  585.         fi
  586.         exit $R_DHCP_BG
  587.     fi
  588. fi
  589. test -z "$STARTMODE" && STARTMODE=manual
  590. if [ "$SCRIPTNAME" = ifup ] ; then
  591.     case "$MODE:$STARTMODE" in
  592.         force:*)       : go on ;;
  593.         manual:manual) : go on ;;
  594.         manual:auto)   : go on ;;
  595.         manual:ifplugd): go on ;;
  596.         auto:auto)     : go on ;;
  597.         auto:ifplugd)  : go on ;;
  598.         *:off)         : exit
  599.             message "`printf "    %-9s Startmode is 'off'" $INTERFACE`"
  600.             RET_STATE=removed # Don't write status information file in this case
  601.             exit $R_INACTIVE
  602.             ;;
  603.         *:*)           : exit
  604.             message "`printf "    %-9s Startmode is '%s'" $INTERFACE $STARTMODE`"
  605.             exit $R_NOTCONFIGURED
  606.             ;;
  607.     esac
  608. fi
  609.  
  610.  
  611. ######################################################################
  612. # call optional and individual scripts
  613. #
  614.  
  615. # DHCP special:
  616. #
  617. # When DHCP is used ifup runs twice. First it triggers the dhcp client. As soon
  618. # as the client got a valid ip address it calls ifup again with option 'dhcp' to
  619. # finish individual setup. ifdown is first called from dhcp client with option
  620. # 'dhcp' and then as usual.
  621. #
  622. # When called directly (from rcnetwork or manually, $DHCP!=yes) only PRE_UP
  623. # (ifup) and POST_DOWN (ifdown) scripts are called. And of course ifup-dhcp is
  624. # called.
  625. #
  626. # When called from dhcp client (with option "dhcp", $DHCP=yes) then POST_UP
  627. # (ifup) and PRE_DOWN (ifdown) are called. Additionally if{up,down}-route is
  628. # called to make it possible to set individual routes _after_ dhcp client
  629. # brought up the interface.
  630. #
  631. # PRE_DOWN is now called directly, because dhcpcd calls it hook script always
  632. # after removing the ip address (i.e. POST) (Bug 61842)
  633.  
  634. if [ "$SCRIPTNAME" = ifdown ] ; then
  635.  
  636.     # execute global down/stop scripts
  637.     if [ "$GLOBAL_PRE_DOWN_EXEC" = "yes" ]; then
  638.         for SCRIPT in if-down.d/*; do
  639.             [ -d $SCRIPT -o ! -x $SCRIPT ] && continue;
  640.             # ignore backup files and leftovers from rpm
  641.             echo $SCRIPT | grep -q '\(\.rpm\(save\|new\)$\)\|\(.~$\)' && continue;
  642.             debug "executing additional global stop script $SCRIPT"
  643.             $SCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  644.         done
  645.     fi
  646.  
  647.     # execute an individual prestop script if available
  648.     # NOTE: 'eval echo' in the next line is necessary to expand settings
  649.     # like PRE_DOWN_SCRIPT="~root/bin/foo"
  650.     for SCRIPT in `eval echo $PRE_DOWN_SCRIPT scripts/$PRE_DOWN_SCRIPT`; do
  651.         if [ -x "$SCRIPT" -a ! -d "$SCRIPT" ] ; then
  652.             debug "executing additional stop script $SCRIPT"
  653.             $SCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  654.         fi
  655.     done
  656.  
  657.     # shut down depending services first
  658.     scripts/${SCRIPTNAME}-services $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  659.  
  660. fi
  661.  
  662. # execute an individual prestart script if available
  663. if [ "$SCRIPTNAME" = ifup ] ; then
  664.      if [ "${BOOTPROTO:0:4}" != dhcp -o "$DHCP" != yes ] ; then
  665.     # NOTE: 'eval echo' in the next line is necessary to expand settings
  666.     # like PRE_UP_SCRIPT="~root/bin/foo"
  667.     for SCRIPT in `eval echo $PRE_UP_SCRIPT scripts/$PRE_UP_SCRIPT`; do
  668.         if [ -x "$SCRIPT" -a ! -d "$SCRIPT" ] ; then
  669.             debug "executing additional start script $SCRIPT"
  670.             $SCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  671.         fi
  672.     done
  673.      fi
  674. fi
  675.  
  676.  
  677. ######################################################################
  678. # call some default helper scripts
  679. #
  680.  
  681. # call them only if we are not in the second run for dhcp
  682. if [ "$DHCP" != yes ] ; then
  683.  
  684.     # perhaps we have to close some connections first when ifdown
  685.     if [ "$SCRIPTNAME" = ifdown ] ; then
  686.         scripts/${SCRIPTNAME}-connection $CONFIG $INTERFACE \
  687.                                          ${OPTIONS:+-o $OPTIONS}
  688.     fi
  689.  
  690.     if [ "$SCRIPTNAME" = ifup ] ; then
  691.         # apply (per interface) sysctl settings before anything else
  692.         scripts/${SCRIPTNAME}-sysctl $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  693.  
  694.         # before setting up interfaces we have to configure
  695.         # wireless NICs
  696.         scripts/${SCRIPTNAME}-wireless $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  697.         test "$?" -ne 0 && exit
  698.  
  699.         case "$INTERFACETYPE" in
  700.         vlan)
  701.             # Frob vlan interface
  702.             scripts/${SCRIPTNAME}-802.1q $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  703.             test "$?" -ne 0 && exit
  704.         ;;
  705.         ib|ibchild)
  706.             # Frob ib interface
  707.             scripts/${SCRIPTNAME}-infiniband $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  708.             test "$?" -ne 0 && exit
  709.         ;;
  710.         bond)
  711.             # Frob bond interface
  712.             scripts/${SCRIPTNAME}-bonding $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  713.             test "$?" -ne 0 && exit
  714.         ;;
  715.         bridge)
  716.             # Frob bridge interface
  717.             scripts/${SCRIPTNAME}-bridge $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  718.             test "$?" -ne 0 && exit
  719.         ;;
  720.         ipip|sit|gre|tun|tap)
  721.             # Frob tunnel interface
  722.             scripts/${SCRIPTNAME}-tunnel $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  723.             test "$?" -ne 0 && exit
  724.         ;;
  725.         esac
  726.     fi
  727.  
  728.     # exec if*-ppp for modem and dsl
  729.     case $INTERFACETYPE in
  730.         modem|dsl|ppp)
  731.             scripts/${SCRIPTNAME}-ppp $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  732.             retcode=$?
  733.             # If ifup, an exit value of 0 does just mean that smpppd will go to
  734.             # establish the connection, but it's still not connected.
  735.             if [ \( "$retcode" = "$R_SUCCESS" -a "$SCRIPTNAME" = ifup \) \
  736.                  -o "$retcode" = "$R_DHCP_BG" ] ; then
  737.                 RET_STATE=progress
  738.             else
  739.                 RET_STATE=success
  740.             fi
  741.             # We write the exit status immediately and leave it alone when we
  742.             # are finished, because smpppd may already change it while we are
  743.             # still running some POST_* scripts.
  744.             setexitstate
  745.             RET_STATE=keep_state
  746.             LOCK_RET_STATE=yes
  747.             # Don't execute maim part of ifup, but all helper scripts and hooks
  748.             SKIP_MAIN_PART=skip
  749.             ;;
  750.     esac
  751.  
  752.     # exec interface-type ifup if present
  753.     # If someone names an interface 'wireless', ifup-wirelss might be called
  754.     # here. To avoid this we check if INTERFACETYPE != wireless. ifup-wireless
  755.     # will be called later anyway. (bug 83786)
  756.     INTERFACESCRIPT="scripts/${SCRIPTNAME}-${INTERFACETYPE}"
  757.     # Some scripts will be called anyway. So we must avoid that they will be
  758.     # called a second time here.
  759.     case "$INTERFACETYPE" in
  760.         autoip)        : ;;
  761.         bond)          : ;;
  762.         bridge)        : ;;
  763.         dhcp)          : ;;
  764.         ib)            : ;;
  765.         ppp)           : ;;
  766.         route)         : ;;
  767.         services)      : ;;
  768.         skel)          : ;;
  769.         vlan|802.1q)   : ;;
  770.         wireless)      : ;;
  771.         tun|tap)       : ;;
  772.         ipip|sit|gre)  : ;;
  773.         *)
  774.             if [ -x "$INTERFACESCRIPT" ] ; then
  775.                 $INTERFACESCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  776.                 retcode=$?
  777.                 SKIP_MAIN_PART=skip
  778.             fi
  779.             ;;
  780.     esac
  781. fi
  782.  
  783.  
  784. ######################################################################
  785. # Change device settings via ethtool.
  786. #
  787. if [ "$SCRIPTNAME" = ifup -a -n "$ETHTOOL_OPTIONS" ]; then
  788.     # There were cases where interfaces were not ready for ethtool
  789.     # immediately after registration. 
  790.     test -n "$ETHTOOL_WAIT" && sleep $ETHTOOL_WAIT 2>/dev/null
  791.     case "$ETHTOOL_OPTIONS" in
  792.         -*) # got an option, replace second word with current interface name
  793.             read ETHTOOL_SWITCH xifacex ETHTOOL_SETTINGS < <(echo $ETHTOOL_OPTIONS)
  794.             ETHTOOL_OPTIONS="$ETHTOOL_SWITCH $INTERFACE $ETHTOOL_SETTINGS"
  795.             ;;
  796.         *)  # old style, setting a parameter...
  797.             ETHTOOL_OPTIONS="-s $INTERFACE $ETHTOOL_OPTIONS"
  798.             ;;
  799.     esac
  800.  
  801.     RETCODE=1
  802.     ETHTOOL=/sbin/ethtool
  803.     for tool in $ETHTOOL /usr$ETHTOOL ; do
  804.         [ -x "$tool" ] || continue
  805.         ETHTOOL=$tool ; RETCODE=0
  806.     done
  807.     if test $RETCODE != 0 ; then
  808.         MESSAGE="ethtool is not installed"
  809.     else
  810.         MESSAGE="`$ETHTOOL $ETHTOOL_OPTIONS 2>&1`"
  811.         RETCODE=$?
  812.     fi
  813.     test $RETCODE != 0 \
  814.         && err_mesg "Error while executing: $ethtool $ETHTOOL_OPTIONS" \
  815.         || info_mesg "$ethtool $ETHTOOL_OPTIONS"
  816.     test -n "$MESSAGE" && err_mesg "$MESSAGE"
  817. fi
  818.  
  819.  
  820. ######################################################################
  821. # obsolete 6to4 tunnel hack ?
  822. #
  823. if [ "$BOOTPROTO" = "6to4" -a "$SCRIPTNAME" != "ifup" ]; then
  824.     BOOTPROTO="static"
  825. fi
  826.  
  827.  
  828. ######################################################################
  829. # Check status of ifplugd first. If ifplugd is running the interface
  830. # need not to be up always.
  831. if [ "$SCRIPTNAME" == ifstatus -a "$STARTMODE" == ifplugd ] ; then
  832.     if [ ! -x "$IFPLUGD" ] ; then
  833.         logerror "Package ifplugd not installed: missing $IFPLUGD"
  834.         exit $R_ERROR
  835.     fi
  836.     debug "Checking ifplugd status"
  837.     ifplugd_retcode=$R_SUCCESS
  838.     NOT=""
  839.     if [ "$INTERFACETYPE" == "wlan" ]; then
  840.         # We don't run ifplugd on wlan interfaces, because link detection
  841.         # is not reliable there. Therefore we assume that there is always
  842.         # a link and take it up if all major interfaces are not linked.
  843.         # Nevertheless ifup need to be called initially on wlan interfaces.
  844.         # We check this by looking for the link flag in its status file.
  845.         if ! has_link $INTERFACE; then
  846.             ifplugd_retcode=$R_NO_IFPLUGD
  847.             NOT="not "
  848.         fi
  849.         message "`printf "    %-9s is ${NOT}prepared for use with ifplugd" \
  850.                          "$INTERFACE"`"
  851.     else
  852.         MESSAGE="`$IFPLUGD -c -i $INTERFACE 2>&1`"
  853.         if [ "$?" -ne 0 ] ; then
  854.             ifplugd_retcode=$R_NO_IFPLUGD
  855.             NOT="not "
  856.         fi
  857.         debug "$MESSAGE"
  858.         message "`printf "    %-9s ifplugd is ${NOT}running" "$INTERFACE"`"
  859.     fi
  860.     if [ "$ifplugd_retcode" == "$R_SUCCESS" ] &&
  861.        ifplugd-selectif $INTERFACE should_be_up $INTERFACETYPE; then
  862.         # if interface should be up and running then we unset ifplugd_retcode.
  863.         # Then the normal status section will decide if the interface is set up
  864.         # correctly.
  865.         if [ $ifplugd_retcode -eq 0 ] ; then
  866.             unset ifplugd_retcode
  867.             # If we check an interface to early after registration we might get
  868.             # wrong connection state. Therefore we will write check if flag 'ready'
  869.             # is already set. This flag was set in initial call of ifup (called
  870.             # from udev right after initialisation). 
  871.             if [ ! -f $RUN_FILES_BASE/ready-$INTERFACE ] ; then
  872.                 ifplugd_retcode=99
  873.             fi
  874.         fi
  875.     fi
  876. fi
  877.  
  878. dhcpretcode=$R_SUCCESS
  879. # switch type. If SKIP_MAIN_PART == skip, don't execute any section
  880. case "$BOOTPROTO$SKIP_MAIN_PART" in
  881.     dhcp+autoip|dhcp4+autoip|dhcp6+autoip|dhcp4+dhcp6+autoip)
  882.         if [ "$DHCP" = yes ] ; then      # called from dhcp client
  883.             SKIP_MAIN_PART=skip
  884.             ${SCRIPTNAME}-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  885.             retcode=$?
  886.         else                             # called from rcnetwork or manually
  887.             # TODO: dhcpcd supports autoip...
  888.             ${SCRIPTNAME}-autoip $CONFIG $INTERFACE -o prepare $OPTIONS
  889.             ${SCRIPTNAME}-dhcp $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  890.             dhcpretcode=$?
  891.             ${SCRIPTNAME}-autoip $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  892.             retcode=$?
  893.         fi
  894.     ;;
  895.     autoip)
  896.         ${SCRIPTNAME}-autoip $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  897.         retcode=$?
  898.     ;;
  899.     dhcp|dhcp4|dhcp6|dhcp4+dhcp6)
  900.         # With dhcp if{up,down} is called twice. See comment "DHCP special" above
  901.         if [ "$DHCP" = yes ] ; then      # called from dhcp client
  902.             SKIP_MAIN_PART=skip
  903.             ${SCRIPTNAME}-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  904.             retcode=$?
  905.         else                             # called from rcnetwork or manually
  906.             ${SCRIPTNAME}-dhcp $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  907.             dhcpretcode=$?
  908.         fi
  909.     ;;
  910. esac
  911. case "$BOOTPROTO$SKIP_MAIN_PART" in
  912.     # Skip it
  913.     *skip)
  914.         :
  915.     ;;
  916.     6to4)
  917.         # just route, configuration handled in $SCRIPTNAME-tunnel
  918.         ifup-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  919.         retcode=$?
  920.     ;;
  921.     none)
  922.         # stop dhcp client, ... on slaves or it may continue
  923.         # running and have IPs, when the config changed ...
  924.         case $SCRIPTNAME in
  925.             ifdown)
  926.                 ifdown-dhcp $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  927.                 ifdown-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  928.                 # Calling 'ip' if there is no interface (ifdown called from udev for
  929.                 # remove event) would trigger automatic module loading (Bug 199456)
  930.                 if [ -d /sys/class/net/$INTERFACE ] ; then
  931.                     ip addr flush dev $INTERFACE &>/dev/null
  932.                     ip link set dev $INTERFACE down &>/dev/null
  933.                 fi
  934.                 retcode=0 # $?
  935.             ;;
  936.             ifstatus)
  937.                 if is_iface_up $INTERFACE ; then
  938.                     message_if_not_run_from_rc "$INTERFACE is up"
  939.                     message_if_not_run_from_rc "$(ip addr show $INTERFACE)"
  940.                     while read a b c d e f g h i; do
  941.                         message "`printf "    %-9s IP address: %s" "$i" "$d"`"
  942.                     done < <(ip -o -4 addr show $INTERFACE)
  943.                     ifstatus-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  944.                     retcode=$R_SUCCESS
  945.                 else
  946.                     # message_if_not_run_from_rc "$INTERFACE is down"
  947.                     message "`printf "    %-9s is down" $INTERFACE`"
  948.                     retcode=$R_INACTIVE
  949.                 fi
  950.             ;;
  951.         esac
  952.     ;;
  953.     *)
  954.         # TODO: move this to ifup-static script ?
  955.         case $SCRIPTNAME in
  956.             ifup)
  957.                 retcode=$R_SUCCESS
  958.                 if [ -n "$MTU" ] ; then
  959.                     ip link set $INTERFACE mtu $MTU
  960.                     retcode_mtu=$?
  961.                 fi
  962.                 if ! ip link set up dev $INTERFACE \
  963.                         ${LLADDR:+address $LLADDR} $LINK_OPTIONS; then
  964.                     logerror "Cannot enable interface $INTERFACE."
  965.                     retcode=$R_NOTRUNNING
  966.                 else
  967.                     if [ -n "$MTU" ] ; then
  968.                         ip link set $INTERFACE mtu $MTU || retcode_mtu=$?
  969.                         if [ $retcode_mtu != 0 ] ; then
  970.                             logerror "Cannot set mtu of $MTU to interface $INTERFACE."
  971.                         fi
  972.                     fi
  973.                     ADDRCOUNT=0
  974.                     for IPVAR in ${!IPADDR*}; do
  975.                         INDEX=${IPVAR#IPADDR}
  976.                         if [ -n "$INDEX" ] ; then
  977.                             eval REMOTE_IPADDR=\$REMOTE_IPADDR$INDEX
  978.                             eval BROADCAST=\$BROADCAST$INDEX
  979.                             eval LABEL=\$LABEL$INDEX
  980.                             eval SCOPE=\$SCOPE$INDEX
  981.                             eval NETMASK=\$NETMASK$INDEX
  982.                             eval PREFIXLEN=\$PREFIXLEN$INDEX
  983.                             eval IP_OPTIONS=\$IP_OPTIONS$INDEX
  984.                         fi
  985.                         IPADDR=${!IPVAR}
  986.                         test -z "$IPADDR" && continue
  987.                         if [ -z "$PREFIXLEN" ] ; then
  988.                             PREFIXLEN=`mask2pfxlen $NETMASK`
  989.                         fi
  990.                         case $IPADDR in
  991.                             */*)
  992.                                 PREFIXLEN=${IPADDR#*/}
  993.                                 IPADDR=${IPADDR%/*}
  994.                                 ;;
  995.                             *) ;;         # IP=$IP${PREFIXLEN:+/$PREFIXLEN} ;;
  996.                         esac
  997.                         if [ -z "$NETMASK" ] ; then
  998.                             NETMASK=`pfxlen2mask $PREFIXLEN`
  999.                         fi
  1000.                         if [ -z "$BROADCAST" ]; then
  1001.                             BROADCAST=$DEFAULT_BROADCAST
  1002.                         fi
  1003.                         # Don't set broadcast for IPv6
  1004.                         case $IPADDR in
  1005.                             *:*)
  1006.                                 ISv6=yes
  1007.                                 BROADCAST='';;
  1008.                             *)
  1009.                                 ISv6=no;;
  1010.                         esac
  1011.  
  1012.                         # Make sure we have ipv6 support or skip this address
  1013.                         if [ "$ISv6" = "yes" ]; then
  1014.                             if test ! -d /proc/sys/net/ipv6 ; then
  1015.                                 if ! modprobe net-pf-10 2>/dev/null; then
  1016.                                     logerror "Missing IPv6 support." \
  1017.                                              "Ommitting address $IPADDR."
  1018.                                     continue
  1019.                                 fi
  1020.                             fi
  1021.                         fi
  1022.  
  1023.                         if [ "$RUN_FROM_RC" = yes ]; then
  1024.                             # show IP address etc.
  1025.                             case $INTERFACE in
  1026.                             # lo)    ;;
  1027.                             *)
  1028.                                 # if multiple addresses show one per line
  1029.                                 if [ "$ADDRCOUNT" -gt 0 -a -z "$LABEL" ]; then 
  1030.                                     message_n "              "  # 14 blanks
  1031.                                 else
  1032.                                     message_n "`printf "    %-9s " $INTERFACE${LABEL:+:$LABEL}`"
  1033.                                 fi
  1034.                                 if [ "$REMOTE_IPADDR" ]; then
  1035.                                     message_n "`printf "IP/Peer:    %s / %s  " $IPADDR $REMOTE_IPADDR`"
  1036.                                 # elif [ "$ISv6" = "yes" ]; then
  1037.                                 else
  1038.                                     message_n "`printf "IP address: %s/%s  " $IPADDR $PREFIXLEN`"
  1039.                                 # else
  1040.                                 #    message_n "`printf "IP/Netmask: %s / %s  " $IPADDR $NETMASK`"
  1041.                                 fi
  1042.                                 if [ "$INTERFACETYPE" == bond ] ; then
  1043.                                     message_n " as bonding master"
  1044.                                 fi
  1045.                                 message " "
  1046.                                 ;;
  1047.                             esac
  1048.                         fi
  1049.  
  1050.                         debug "Handling Index <$INDEX>:\n" \
  1051.                               "    IPADDR             = $IPADDR\n" \
  1052.                               "    PREFIXLEN          = $PREFIXLEN\n" \
  1053.                               "    CHECK_DUPLICATE_IP = $CHECK_DUPLICATE_IP"
  1054.                         if [ "$CHECK_DUPLICATE_IP"  = "yes" ] ; then
  1055.                             arping -q -c 2 -w 3 -D -I $INTERFACE $IPADDR \
  1056.                                 && CHECK_DUPLICATE_IP=no
  1057.                         fi
  1058.                         if [ "$CHECK_DUPLICATE_IP" = "yes" ] ; then
  1059.                             logerror "Error on setting up interface" \
  1060.                                      "$INTERFACE:$LABEL:\n" \
  1061.                                      "  address $IPADDR already in use.\n  Probably" \
  1062.                                      "there is another computer using that address."
  1063.                             retcode=$R_NOTRUNNING
  1064.                         else
  1065.                             # workaround for lo interface autoconfigured while "ip link set up"
  1066.                             # without an explicit broadcast address setting (bug #357021).
  1067.                             case "$INTERFACE" in
  1068.                             lo)
  1069.                               ip addr del $IPADDR${PREFIXLEN:+/$PREFIXLEN} dev $INTERFACE &>/dev/null
  1070.                             ;;
  1071.                             esac
  1072.                             MESSAGE=`\
  1073.                                 ip addr add dev $INTERFACE \
  1074.                                     "local" $IPADDR${PREFIXLEN:+/$PREFIXLEN} \
  1075.                                     ${REMOTE_IPADDR:+peer $REMOTE_IPADDR} \
  1076.                                     ${BROADCAST:+broadcast "$BROADCAST"} \
  1077.                                     ${LABEL:+label $INTERFACE:$LABEL} \
  1078.                                     ${SCOPE:+scope $SCOPE} \
  1079.                                     $IP_OPTIONS \
  1080.                                     2>&1 `
  1081.                             case $? in
  1082.                                 0) retcode=$R_SUCCESS ;;
  1083.                                 2)
  1084.                                     case "$MESSAGE" in
  1085.                                         # Address is already set.
  1086.                                         RTNET*File*exists*| \
  1087.                                         RTNET*No*buffer*space*available*)
  1088.                                             retcode=$R_SUCCESS ;;
  1089.                                         *) retcode=$R_NOTRUNNING ;;
  1090.                                     esac ;;
  1091.                                 *) retcode=$R_NOTRUNNING ;;
  1092.                             esac
  1093.                         fi
  1094.                         ADDRCOUNT=$(($ADDRCOUNT + 1))
  1095.                     done
  1096.                 fi
  1097.                 ifup-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1098.                 ;;
  1099.             ifdown)
  1100.                 case "$BOOTPROTO" in
  1101.                 dhcp*)
  1102.                     # already stopped in dhcp case before
  1103.                 ;;
  1104.                 *)
  1105.                     ifdown-dhcp $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1106.                 ;;
  1107.                 esac
  1108.                 ifdown-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1109.                 # Calling 'ip' if there is no interface (ifdown called from udev for
  1110.                 # remove event) would trigger automatic module loading (Bug 199456)
  1111.                 if [ -d /sys/class/net/$INTERFACE ] ; then
  1112.                     ip addr flush dev $INTERFACE &>/dev/null
  1113.                     ip link set dev $INTERFACE down &>/dev/null
  1114.                 fi
  1115.                 retcode=0 # $?
  1116.                 ;;
  1117.             ifstatus)
  1118.                 if is_iface_up $INTERFACE ; then
  1119.                     message_if_not_run_from_rc "$INTERFACE is up"
  1120.                     message_if_not_run_from_rc "$(ip addr show $INTERFACE)"
  1121.                     while read a b c d e f g h i; do
  1122.                         message "`printf "    %-9s IP address: %s" "$i" "$d"`"
  1123.                     done < <(ip -o -4 addr show $INTERFACE)
  1124.                     ifstatus-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1125.                     retcode=$R_SUCCESS
  1126.                 else
  1127.                     # message_if_not_run_from_rc "$INTERFACE is down"
  1128.                     message "`printf "    %-9s is down" $INTERFACE`"
  1129.                     retcode=$R_NOTRUNNING
  1130.                     case "$STARTMODE" in
  1131.                     manual|off) retcode=$R_INACTIVE ;;
  1132.                     esac
  1133.                 fi
  1134.                 ;;
  1135.         esac
  1136.         ;;
  1137. esac
  1138.  
  1139.  
  1140. ######################################################################
  1141. # call some default helper scripts
  1142. #
  1143.  
  1144. # call them only if we are not in the second run for dhcp
  1145. if [ "$DHCP" != yes ] ; then
  1146.  
  1147.     # we check connections and settings for wireless NICs when ifstatus
  1148.     if [ "$SCRIPTNAME" = ifstatus ] ; then
  1149.         scripts/${SCRIPTNAME}-wireless    $CONFIG $INTERFACE \
  1150.                                           ${OPTIONS:+-o $OPTIONS}
  1151.         scripts/${SCRIPTNAME}-connection  $CONFIG $INTERFACE \
  1152.                                           ${OPTIONS:+-o $OPTIONS}
  1153.         ret=$?
  1154.         test "$CHECK" = yes -a $ret != 0 && retcode=$ret
  1155.         DEP_IFACES=`get_depending_ifaces $INTERFACE`
  1156.         if [ "$?" = 0 -a "$NODEPS" != yes ] ; then
  1157.             message "`printf "    %-9s is still used from interfaces %s" \
  1158.                              $INTERFACE "$DEP_IFACES"`"
  1159.             #for DI in $DEP_IFACES; do
  1160.             #  ifstatus $DI -o $OPTIONS
  1161.             #done
  1162.         fi
  1163.         # check if setting up firewall is in progress
  1164.         if [ -f /var/lock/SuSEfirewall2.pid ] ; then
  1165.             message "Setting up firewall still in progress"
  1166.             retcode=$R_DHCP_BG
  1167.         fi
  1168.     fi
  1169.     
  1170.     if [ "$SCRIPTNAME" = ifdown ] ; then
  1171.         # after shutting down interfaces ifup-wireless
  1172.         # has to kill the wpa daemon
  1173.         scripts/${SCRIPTNAME}-wireless $CONFIG $INTERFACE \
  1174.         ${OPTIONS:+-o $OPTIONS}
  1175.  
  1176.         case "$INTERFACETYPE" in
  1177.         vlan)
  1178.             # Frob vlan interface, part II
  1179.             scripts/${SCRIPTNAME}-802.1q $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1180.             test "$?" -ne 0 && exit
  1181.         ;;
  1182.         ib|ibchild)
  1183.             # Frob ib interface
  1184.             scripts/${SCRIPTNAME}-infiniband $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1185.             test "$?" -ne 0 && exit
  1186.         ;;
  1187.         bond)
  1188.             # Frob bond interface, part II
  1189.             scripts/${SCRIPTNAME}-bonding $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1190.             test "$?" -ne 0 && exit
  1191.         ;;
  1192.         bridge)
  1193.             # Frob bridge interface, part II
  1194.             scripts/${SCRIPTNAME}-bridge $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1195.             test "$?" -ne 0 && exit
  1196.         ;;
  1197.         ipip|sit|gre|tun|tap)
  1198.             # Frob tunnel interface, part II
  1199.             scripts/${SCRIPTNAME}-tunnel $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1200.             test "$?" -ne 0 && exit
  1201.         ;;
  1202.         esac
  1203.     fi
  1204. fi
  1205.     
  1206. ######################################################################
  1207. # call optional and individual scripts
  1208. #
  1209.  
  1210. if [ "$SCRIPTNAME" = ifup \
  1211.      -a \( "${BOOTPROTO:0:4}" != dhcp -o "$DHCP" = yes \) ] ; then
  1212.  
  1213.     # start depending services
  1214.     scripts/${SCRIPTNAME}-services $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1215.  
  1216.     # execute global start scripts
  1217.     if [ "$GLOBAL_POST_UP_EXEC" = "yes" ]; then
  1218.         for SCRIPT in if-up.d/*; do
  1219.             [ -d $SCRIPT -o ! -x $SCRIPT ] && continue;
  1220.             # ignore backup files and leftovers from rpm
  1221.             echo $SCRIPT | grep -q '\(\.rpm\(save\|new\)$\)\|\(.~$\)' && continue;
  1222.             debug "executing additional global start script $SCRIPT"
  1223.             $SCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1224.         done
  1225.     fi
  1226.  
  1227.     # execute an individual poststart script if available
  1228.     # NOTE: 'eval echo' in the next line is necessary to expand settings
  1229.     # like POST_UP_SCRIPT="~root/bin/foo"
  1230.     for SCRIPT in `eval echo $POST_UP_SCRIPT scripts/$POST_UP_SCRIPT`; do
  1231.         if [ -x "$SCRIPT" -a ! -d "$SCRIPT" ] ; then
  1232.             debug "executing additional start script $SCRIPT"
  1233.             $SCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1234.         fi
  1235.     done
  1236.  
  1237. fi
  1238.  
  1239. # execute an individual poststop script if available
  1240. if [ "$SCRIPTNAME" = ifdown \
  1241.      -a \( "${BOOTPROTO:0:4}" != dhcp -o "$DHCP" != yes \) ] ; then
  1242.     # NOTE: 'eval echo' in the next line is necessary to expand settings
  1243.     # like POST_DOWN_SCRIPT="~root/bin/foo"
  1244.     for SCRIPT in `eval echo $POST_DOWN_SCRIPT scripts/$POST_DOWN_SCRIPT`; do
  1245.         if [ -x "$SCRIPT" -a ! -d "$SCRIPT" ] ; then
  1246.             debug "executing additional stop script $SCRIPT"
  1247.             $SCRIPT $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
  1248.         fi
  1249.     done
  1250. fi
  1251.  
  1252. # We have to respect the status of ifplugd for interfaces with
  1253. # STARTMODE=ifplugd. If ifplugd_retcode is set, then this value takes 
  1254. # priority over other reurn codes.
  1255. if [ -n "$ifplugd_retcode" -a "$ifplugd_retcode" != 99 ] ; then
  1256.     exithook $ifplugd_retcode
  1257. elif [ "$ifplugd_retcode" == 99 -a "$dhcpretcode" == $R_NOTRUNNING ] ; then
  1258.     message "`printf "    %-9s is probably not initialized completely" \
  1259.                      "$INTERFACE"`"
  1260.     exithook $R_DHCP_BG
  1261. elif [ "$dhcpretcode" != $R_SUCCESS ] ; then
  1262.     exithook $dhcpretcode
  1263. else
  1264.     if [ "$retcode" = 0 -a -n "$retcode_mtu" -a "$retcode_mtu" != 0 ] ; then
  1265.         exithook $R_PROPERTY_NOT_SET
  1266.     else
  1267.         exithook $retcode
  1268.     fi
  1269. fi
  1270.  
  1271.