#!/bin/bash
# Copyright (c) 2002 SuSE Linux AG Nuernberg, Germany. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
# Network interface configuration
#
# Author: Michal Svec <msvec@suse.cz>
#         Christian Zoz <zoz@suse.de>
#         Mads Martin Joergensen <mmj@suse.de>
#         Bjoern Jacke
#
# $Id: ifup,v 1.64 2002/09/09 08:55:53 mmj Exp $
#

usage () {
	echo $@
	echo "usage: if{up,down,status} <config> [<interface>] [-o <options>]"
	echo "  In most cases config==interface, for details see man 8 ifup"
	echo "options are: [on]boot : we are currently booting (or shutting down)"
	echo "	           hotplug  : we are handling a hotplug event"
	echo "	           quiet    : supress normal output"
	echo "	           debug    : be verbose and don't use syslog"
	echo "	           rc       : we are called by a rc script"
	if [ "$SCRIPTNAME" = "ifup" ]; then
		echo "	           doalias  : if interface is real set up all aliases of it"
	fi
	if [ "$SCRIPTNAME" = "ifstatus" ]; then
		echo "	           check    : return R_BUSY (=$R_BUSY) if there are active"\
		     "connections on this interface"
	fi
	exit $R_USAGE
}

R_INTERNAL=1      # internal error, e.g. no config or missing scripts
cd /etc/sysconfig/network || exit $R_INTERNAL
test -f scripts/functions && . scripts/functions || exit $R_INTERNAL
test -f config && . config

######################################################################
# Commandline parsing
#
# if{up,down,status} config [interface] [-o options]
SCRIPTNAME=`basename $0`
debug $*
HWDESC=$1
case "$HWDESC" in ""|-h|*help*) usage; esac
shift
test "$1" != "-o" && INTERFACE=$1
shift
test "$1" = "-o" && shift
OPTIONS=$@
MODE=manual
while [ $# -gt 0 ]; do
	case $1 in
		boot|onboot) MODE=onboot ;;
		hotplug)     MODE=hotplug ;;
		rc)          export RUN_FROM_RC=yes ;;
		doalias)     DOALIAS=yes ;;
		check)       CHECK=yes ;;
		quiet)       BE_QUIET=yes ;;
		debug)       BE_QUIET=no
		             DEBUG=yes ;;
		*)           debug "unknown option $1 ignored" ;;
	esac
	shift
done


######################################################################
# analyse $INTERFACE    ([interface])   first run
#
# Save interface argument for proper error reporting
ARG_INTERFACE=$INTERFACE
# If $INTERFACE was given in the command line, we use this. If not we try to use
# the config name ($HWDESC) as interface.
test -z "$INTERFACE" && INTERFACE=$HWDESC
# Now determine the alias number and the master interface name, if $INTERFACE is
# an alias name.
IF_ALIAS=${INTERFACE#*:}
if [ "$IF_ALIAS" = "$INTERFACE" ] ; then
	IF_ALIAS=""
fi
INTERFACE=${INTERFACE%%:*}
# The interface must exist, otherwise we fail. But we will exit later, after
# STARTMODE check, because we want to return something like 'skipped', if
# current MODE and STARTMODE do not match. Return of 'no interface' should only
# happen, if the interface is configured to be set up in current MODE.
# See section 'analyse $INTERFACE ([interface]) second run'
if is_iface_available $INTERFACE ; then
	# Set the interface type (INTERFACE without number) to INTERFACETYPE.
        #read INTERFACETYPE b < <(IFS=1234567890; echo $INTERFACE)
	INTERFACETYPE=${INTERFACE%%[0-9]*}
else
	INTERFACE="nointerface"
fi

######################################################################
# analyse $HWDESC   (config)
#
# Save config argument for proper error reporting
ARG_HWDESC=$HWDESC
# Get the alias number from the hardware description and strip it
# from the hardware description
ALIAS=${HWDESC#*:}
if [ "$ALIAS" = "$HWDESC" ] ; then
	ALIAS=""
else
	HWDESC=${HWDESC%%:*}
fi

# ALIAS is used for finding a matching configuration (derived from $HWDESC)
# IF_ALIAS is used as interfacename extension (derived from $INTERFACE)
# If one of them is empty use the others value:
test -z "$IF_ALIAS" && IF_ALIAS=$ALIAS
test -z "$ALIAS" && ALIAS=$IF_ALIAS

# Seperate the fields from the hardware description
IFS=- read IFTYPE HWTYPE HWBUS HWID NIX < <(echo "$HWDESC")
case $IFTYPE in
	$HWDESC)
		HWTYPE=$IFTYPE
		IFTYPE=""
	;;
	eth|ppp|dsl|ippp|isdn|dummy|lo|plip|slip|tr)
	;;
	*)
		HWID=$HWBUS
		HWBUS=$HWTYPE
		HWTYPE=$IFTYPE
		IFTYPE=""
	;;
esac
test -z "$IFTYPE" && IFTYPE=$INTERFACETYPE

# Get the MAC Address from the interface, remove the ':' from it
# and create a list of substrings of it. The substrings always start
# at character 0 and have a decreasing length. The minimal length can be set in
# HWADDR_MIN_LENGTH in the general config file
HWADDR=`get_hwaddress $INTERFACE`
HWADDR=`(IFS=:; for a in $HWADDR; do echo -n $a; done)`
HWADDRESSES=""
declare -i n=${#HWADDR}
declare -i N=${HWADDR_MIN_LENGTH}
while [ $n -ge $N ] ; do
	HWADDRESSES="$HWADDRESSES ${HWADDR:0:$n}"
	n=$((n-1))
done
# to allow matching the HW address against the respective filename, written
# in upper OR lower case letters:
HWADDRESSES="$HWADDRESSES $(echo $HWADDRESSES | /bin/awk '{print toupper($0);}')"


# Now check if we have a file that matches (parts of) the MAC address,
# parts of the hardware description or the interface name
set -- ifcfg-*
if [ -z "$CONFIG" ]; then
	for a in $HWADDRESSES \
		${IFTYPE}-${HWTYPE}-${HWBUS}-${HWID} \
		${IFTYPE}-${HWTYPE}-${HWBUS} \
		${IFTYPE}-${HWTYPE} \
		${HWTYPE}-${HWBUS}-${HWID} \
		${HWTYPE}-${HWBUS} \
		${HWTYPE} \
		${INTERFACE} \
		${IFTYPE} ; do
		for b in ${@#ifcfg-}; do
			CONFIG="$a${ALIAS:+:$ALIAS}"
			test "$b" = "$CONFIG" && break 2
		done
		for b in ${@#ifcfg-}; do
			CONFIG="$a"
			test "$b" = "$CONFIG" && break 2
		done
		CONFIG=""
	done
fi

# to be deleted later
#debug "ALIAS = $ALIAS"
debug "CONFIG = $CONFIG        INTERFACE = $INTERFACE     ${IF_ALIAS:+IF_ALIAS = $IF_ALIAS}"
#debug "OPTIONS = $OPTIONS"
#debug "INTERFACE = $INTERFACE"
#debug "INTERFACETYPE = $INTERFACETYPE"
#debug "IF_ALIAS = $IF_ALIAS"


######################################################################
# source config
#
if [ ! -r "ifcfg-$CONFIG" ] ; then
	if [ "$SCRIPTNAME" != ifdown ] ; then
		logerror "No configuration found for $ARG_HWDESC $ARG_INTERFACE"
		exit $R_NOCONFIG
	fi
else
	. ifcfg-$CONFIG
fi


######################################################################
# check startmode (not for ifdown)
#
test "$STARTMODE" = "on" && STARTMODE=onboot
test "$STARTMODE" = "boot" && STARTMODE=onboot
test -z "$STARTMODE" && STARTMODE=manual
if [ "$SCRIPTNAME" != "ifdown" ] ; then
	case "$STARTMODE" in
		onboot|hotplug|manual) ;;
		off|ignore)
			debug STARTMODE is $STARTMODE -- ignoring this configuration ifcfg-$CONFIG
			exit $R_NOTCONFIGURED;
			;;
		*)
			logerror "Interface $INTERFACE has an invalid startmode\nset STARTMODE" \
			         "in ifcfg-$CONFIG to one of {onboot,hotplug,manual}"
			exit $R_NOTCONFIGURED ;;
	esac
	case $MODE in
		onboot|hotplug)
			if [ "$STARTMODE" != "$MODE" ] ; then
				debug  "STARTMODE '$STARTMODE' of configuration for '$CONFIG' does" \
				         "not match current MODE '$MODE'"
				exit $R_NOTCONFIGURED
			fi
		;;
		manual)
			# If we are called by a rc script we set up only ifaces with STARTMODE=
			# - onboot
			# - hotplug and which are currently plugged
			# - manual and which were already manually set up but stopped via a
			#   rc script
			# They are currently plugged or manually activated if there is an
			# interface name in temporary files $RUN_FILES_BASE*. The next code
			# section will try to read them if INTERFACE==rc_manual
			if [ "$RUN_FROM_RC" = yes -a "$STARTMODE" != onboot ] ; then
				INTERFACE=rc_manual
			fi
		;;
	esac
fi

RUN_FILE=$RUN_FILES_BASE$CONFIG

######################################################################
# analyse $INTERFACE    ([interface])   second run
#
# Now we can return 'no interface' if $INTERFACE is set to 'nointerface'.
# See 'analyse $INTERFACE ([interface]) first run'
# But there may be an interface name for 'hotplug' or 'manual' devices in
# temporary files.
if [ "$INTERFACE" = "nointerface" -o "$INTERFACE" = "rc_manual" ]  ; then
	for INTERFACE in `cat $RUN_FILE 2>/dev/null`; do
		# take only the last entry
		debug "Interface from $RUN_FILE: $INTERFACE"
	done
fi
if ! is_iface_available $INTERFACE ; then
	case "$INTERFACE" in
		nointerface)
			case "$STARTMODE" in
				off|ignore)
					debug STARTMODE is $STARTMODE -- ignoring this configuration ifcfg-$CONFIG
					exit $R_NOTCONFIGURED;
					;;
			esac
			if [ -n "$ARG_INTERFACE" ] ; then # we were called with an interface
				logerror "interface '$ARG_INTERFACE' is not available"
				exit $R_NODEV
			else                              # we were called without an interface
				logerror "Could not get a valid interface name: -> skipped"
				exit $R_NODEV
			fi
			;;
		rc_manual) # a 'hotplug' or 'manual' configuration was not active before
			test "$SCRIPTNAME" = "ifup" &&
				logerror "Configuration '$CONFIG' has STARTMODE=$STARTMODE: -> skipped"\
				         "\n\tAs we are called from rcnetwork we do not set it up,"\
				         "because\n\tit was not set up manually or by hotplug before."
			exit $R_NOTCONFIGURED
			;;
		*) # there were hotplug events while network was down via rcnetwork
		   # therefore we have to clean up a little bit.
			logerror "interface $INTERFACE is not available anymore"
			for RF in $RUN_FILES_BASE*; do
				(	rm -f $RF;
					while read IFACE; do
						test "$IFACE" != "$INTERFACE" && \
							echo $IFACE >> $RF
					done
				) < $RF
			done
			exit $R_NOTCONFIGURED
			;;
	esac
fi


######################################################################
# check for master of alias (only for ifup)
#
if [ -n "$IF_ALIAS"                  \
     -a "$SCRIPTNAME"       = "ifup" \
     -a "$CHECK_FOR_MASTER" = yes    ] ; then
	if ! is_iface_up $INTERFACE ; then
		logerror "Master interface ($INTERFACE) for interface" \
		         "$INTERFACE:$IF_ALIAS is not up."
		exit $R_NOMASTER
	fi
fi


######################################################################
# bringing up/down the interface
#

# remember hotplug or manual interfaces if not called from a rc script. This is
# necessary to enable a restart also for hotplug devices, because rcnetwork
# does not know the interface names. So we have to know them ourselves.
if [ "$RUN_FROM_RC" != yes ] ; then
	if [ "$MODE" = hotplug -o "$MODE" = manual ] ; then
		case $SCRIPTNAME in
			ifup)
				# ppp and dsl devices are often set up without usage of ifup. Therefore
				# it is better not to store the interface names. Else we would sometimes
				# know them and sometimes not, which confuses the user. (Bug 14497)
				case "$INTERFACETYPE" in
					ppp|dsl) ;;
					*) echo $INTERFACE >> $RUN_FILE ;;
				esac
				;;
			ifdown)
				if [ -f $RUN_FILE ] ; then
					(	rm -f $RUN_FILE;
						while read IFACE; do
							test "$IFACE" != "$INTERFACE" && \
								echo $IFACE >> $RUN_FILE
						done
					) < $RUN_FILE
				fi
				;;
		esac
	fi
fi

# execute global down/stop scripts
if [ "$SCRIPTNAME" = ifdown -a "$GLOBAL_PRE_DOWN_EXEC" = "yes" ]; then
	for SCRIPT in if-down.d/*; do
		[ -d $SCRIPT -o ! -x $SCRIPT ] && continue;
		# ignore backup files and leftovers from rpm
		echo $SCRIPT | grep -q '\(\.rpm\(save\|new\)$\)\|\(.~$\)' && continue;
		debug "executing additional global stop script $SCRIPT"
		$SCRIPT $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} ${OPTIONS:+-o $OPTIONS}
	done
fi

# execute an individual stop script if available
if [ "$SCRIPTNAME" = ifdown ] ; then
	# NOTE: 'eval echo' in the next line is necessary to expand settings
	# like PRE_DOWN_SCRIPT="~root/bin/foo"
	for SCRIPT in `eval echo $PRE_DOWN_SCRIPT scripts/$PRE_DOWN_SCRIPT`; do
		if [ -x "$SCRIPT" -a ! -d "$SCRIPT" ] ; then
			debug "executing additional stop script $SCRIPT"
			$SCRIPT $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} ${OPTIONS:+-o $OPTIONS}
		fi
	done
fi

# perhaps we have to close some connections first when ifdown
if [ "$SCRIPTNAME" = ifdown ] ; then
	scripts/${SCRIPTNAME}-connection $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
	                                 ${OPTIONS:+-o $OPTIONS}
fi

# before setting up interfaces we have to configure wireless NICs
if [ "$SCRIPTNAME" = ifup ] ; then
	scripts/${SCRIPTNAME}-wireless $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
	                               ${OPTIONS:+-o $OPTIONS}
fi

# Frob vlan interface
if [ "$SCRIPTNAME" = ifup -a "$INTERFACETYPE" = vlan ]; then
	scripts/${SCRIPTNAME}-802.1q $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
					${OPTIONS:+-o $OPTIONS}
fi

# exec interface-type ifup if present
INTERFACESCRIPT="scripts/${SCRIPTNAME}-${INTERFACETYPE}"
if [ -x "$INTERFACESCRIPT" ] ; then
	exec $INTERFACESCRIPT $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
	                   ${OPTIONS:+-o $OPTIONS}
fi

# switch type
retcode=0
case "$BOOTPROTO" in
	bootp|BOOTP)
		${SCRIPTNAME}-bootp $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
		                    ${OPTIONS:+-o $OPTIONS}
	;;
	dhcp*|DHCP)
		${SCRIPTNAME}-dhcp $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
		                   ${OPTIONS:+-o $OPTIONS}
		retcode=$?
	;;
	*)
		case $SCRIPTNAME in
			ifup)
				retcode=$R_SUCCESS
				if ! ip link set up dev $INTERFACE ${MTU:+mtu $MTU} ${LLADDR:+address $LLADDR} $LINK_OPTIONS; then
					logerror "Cannot enable interface $INTERFACE."
					retcode=$R_NOTRUNNING
				else
					for IPVAR in ${!IPADDR*}; do
						INDEX=${IPVAR#IPADDR}
						if [ -n "$INDEX" ] ; then
							eval REMOTE_IPADDR=\$REMOTE_IPADDR$INDEX
							eval BROADCAST=\$BROADCAST$INDEX
							eval LABEL=\$LABEL$INDEX
							eval SCOPE=\$SCOPE$INDEX
							eval NETMASK=\$NETMASK$INDEX
							eval PREFIXLEN=\$PREFIXLEN$INDEX
							eval IP_OPTIONS=\$IP_OPTIONS$INDEX
						else
							LABEL=$IF_ALIAS
						fi
						IPADDR=${!IPVAR}
						test -z "$IPADDR" && continue
						if [ -z "$PREFIXLEN" ] ; then
							PREFIXLEN=`mask2pfxlen $NETMASK`
						fi
						case $IPADDR in
							*/*)
								PREFIXLEN=${IPADDR#*/}
								IPADDR=${IPADDR%/*}
								;;
							*) ;;         # IP=$IP${PREFIXLEN:+/$PREFIXLEN} ;;
						esac
						if [ -z "$NETMASK" ] ; then
							NETMASK=`pfxlen2mask $PREFIXLEN`
						fi
						if [ -z "$BROADCAST" ]; then
							BROADCAST=$DEFAULT_BROADCAST
						fi
						# Don't set broadcast for IPv6
						case $IPADDR in
							*:*)
								ISv6=yes
								BROADCAST='';;
							*)
								ISv6=no;;
						esac

						if [ "$RUN_FROM_RC" = yes ]; then
							# show IP address etc.
							case $INTERFACE in
							lo)	;;
							*) 	if [ "$REMOTE_IPADDR" ]; then
									message_n "`printf "IP/Peer:    %15s / %s  " $IPADDR $REMOTE_IPADDR`"
								elif [ "$ISv6" = "yes" ]; then
									message_n "`printf "IP/Prefix:  %15s / %s  " $IPADDR $PREFIXLEN`"
								else
									message_n "`printf "IP/Netmask: %15s / %s  " $IPADDR $NETMASK`"
								fi
								;;
							esac
						fi

						debug "Handling Index <$INDEX>:\n" \
						      "    IPADDR             = $IPADDR\n" \
						      "    PREFIXLEN          = $PREFIXLEN\n" \
						      "    CHECK_DUPLICATE_IP = $CHECK_DUPLICATE_IP"
						if [ "$CHECK_DUPLICATE_IP"  = "yes" ] ; then
							arping -q -c 2 -w 3 -D -I $INTERFACE $IPADDR \
							    && CHECK_DUPLICATE_IP=no
						fi
						if [ "$CHECK_DUPLICATE_IP" = "yes" ] ; then
							logerror "Error on setting up interface $INTERFACE:$LABEL:\n" \
							         "  address $IPADDR already in use.\n  Probably" \
							         "there is another computer using that address."
							retcode=$R_NOTRUNNING
						else
							MESSAGE=`\
								ip address add dev $INTERFACE \
								               "local" $IPADDR${PREFIXLEN:+/$PREFIXLEN} \
								               ${REMOTE_IPADDR:+peer $REMOTE_IPADDR} \
									       ${BROADCAST:+broadcast "$BROADCAST"} \
								               ${LABEL:+label $INTERFACE:$LABEL} \
								               ${SCOPE:+scope $SCOPE} \
								               $IP_OPTIONS \
								2>&1 `
							case $? in
								0) retcode=$R_SUCCESS ;;
								2)
									case "$MESSAGE" in
										RTNET*File*exists*) retcode=$R_SUCCESS ;;
										*) retcode=$R_NOTRUNNING ;;
									esac ;;
								*) retcode=$R_NOTRUNNING ;;
							esac
						fi
					done
				fi
				ifup-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
				;;
			ifdown)
				ifdown-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
				if [ -z "$IF_ALIAS" ] ; then
					ip address flush dev $INTERFACE &>/dev/null
					ip link set dev $INTERFACE down &>/dev/null
				else
					ip address flush dev $INTERFACE label $INTERFACE:$IF_ALIAS &>/dev/null
				fi
				retcode=0 # $?
				;;
			ifstatus)
				# !!! We have to change the check at least for aliases !!!
				# !!! They are always up, as soon as the master interface is up !!!
				if is_iface_up $INTERFACE ; then
					message_if_not_run_from_rc "$INTERFACE is up"
					message_if_not_run_from_rc && ip address show $INTERFACE \
					                           ${IF_ALIAS:+label $INTERFACE:$IF_ALIAS}
					ifstatus-route $CONFIG $INTERFACE ${OPTIONS:+-o $OPTIONS}
					retcode=$R_SUCCESS
				else
					message_if_not_run_from_rc "$INTERFACE is down"
					retcode=$R_NOTRUNNING
					test "$STARTMODE" = "manual" && retcode=$R_INACTIVE
				fi
				;;
		esac
		;;
esac

# IPv6 initialisation?
if [ "${NETWORKING_IPV6}" = "yes" ]; then
	scripts/${SCRIPTNAME}-ipv6 $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
	                           ${OPTIONS:+-o $OPTIONS}
fi

# we check connections and settings for wireless NICs when ifstatus
if [ "$SCRIPTNAME" = ifstatus ] ; then
	scripts/${SCRIPTNAME}-wireless   $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
	                                 ${OPTIONS:+-o $OPTIONS}
	scripts/${SCRIPTNAME}-connection $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
	                                 ${OPTIONS:+-o $OPTIONS}
	ret=$?
	test "$CHECK" = yes -a $ret != 0 && retcode=$ret
fi

# postinstallation stuff
#[ "$retcode" = 0 ] &&
#	scripts/${SCRIPTNAME}-post $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
#	                           ${OPTIONS:+-o $OPTIONS}
#retcode=$?

# execute global start scripts
if [ "$SCRIPTNAME" = ifup -a "$GLOBAL_POST_UP_EXEC" = "yes" ]; then
	for SCRIPT in if-up.d/*; do
		[ -d $SCRIPT -o ! -x $SCRIPT ] && continue;
		# ignore backup files and leftovers from rpm
		echo $SCRIPT | grep -q '\(\.rpm\(save\|new\)$\)\|\(.~$\)' && continue;
		debug "executing additional global start script $SCRIPT"
		$SCRIPT $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} ${OPTIONS:+-o $OPTIONS}
	done
fi

# execute an individual start script if available
if [ "$SCRIPTNAME" = ifup ] ; then
	# NOTE: 'eval echo' in the next line is necessary to expand settings
	# like PRE_DOWN_SCRIPT="~root/bin/foo"
	for SCRIPT in `eval echo $POST_UP_SCRIPT scripts/$POST_UP_SCRIPT`; do
		if [ -x "$SCRIPT" -a ! -d "$SCRIPT" ] ; then
			debug "executing additional start script $SCRIPT"
			$SCRIPT $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} ${OPTIONS:+-o $OPTIONS}
		fi
	done
fi

if [ -z "$ALIAS" -a "$DOALIAS" = "yes" -a "$SCRIPTNAME" != ifdown ] ; then
	for CONF in ifcfg-$CONFIG:* ; do
		case $CONF in
			*~*|*.*|*\*) ;; # drop backup files, rpm{save,new,orig} and catch the
			                # 'ifcfg-$CONFIG:\*' if there was no match
			*) ${SCRIPTNAME} ${CONF#ifcfg-} $INTERFACE ${OPTIONS:+-o $OPTIONS}
			   ret=$?; test $ret = 0 || retcode=$ret ;;
		esac
	done
fi

# Frob vlan interface, part II
if [ "$SCRIPTNAME" = ifdown -a "$INTERFACETYPE" = vlan ]; then
	scripts/${SCRIPTNAME}-802.1q $CONFIG $INTERFACE${IF_ALIAS:+:$IF_ALIAS} \
					${OPTIONS:+-o $OPTIONS}
fi

if [ "$RUN_FROM_RC" != yes -o "$MODE" != onboot ]; then
	if [ "$SCRIPTNAME" != ifstatus -a "$FIREWALL" = yes ]; then
		if chkconfig --check SuSEfirewall2_setup; then
			/sbin/SuSEfirewall2 start
		fi
	fi
fi

exit $retcode

