#!/bin/sh
# Network Interface Configuration System
# Copyright (c) 1996-2001 Red Hat, Inc. all rights reserved.
# Copyright (c) 2005-2006 PMC-Sierra, Inc. all rights reserved.
#
# This software may be freely redistributed under the terms of the GNU
# public license.
# 
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.

PATH=/sbin:/usr/sbin:/bin:/usr/bin
TEXTDOMAIN=initscripts
#set null for normal operation, set true to spit out lots of messages
DEBUG_NET=true

cd /etc/sysconfig/network-scripts
. /etc/sysconfig/network-scripts/network-functions
[ -f ../network ] && . ../network

CONFIG="bond0"

[ -z "${CONFIG}" ] && {
    exit 1
}

need_config ${CONFIG}

[ -f "${CONFIG}" ] || {
    echo $"$0: configuration for ${1} not found." >&2
    exit 1
}

# after source_config, I'll have all the things listed in ifcfg-* file
source_config

# Set the bonding mode
if [ "x$BONDINGMODE" = "x" ] ; then
    echo 1 > /sys/class/net/$DEVICE/bonding/mode
else
    echo $BONDINGMODE > /sys/class/net/$DEVICE/bonding/mode
fi

# master device for bonding
echo "This is a master device. Bringing link down and then up."
/sbin/ip link set ${DEVICE} down
/sbin/ip link set ${DEVICE} up

# Do enslaving here after setting the device parameters
echo "Bringing up master link for bond."
for device in `fgrep -l "MASTER=${DEVICE}" /etc/sysconfig/network-scripts/ifcfg-*` ; do
    /sbin/ifup ${device##*/}
done

#if we are using AoE, need to bind with bonded interface instead of slaves
if [ -c /dev/interfaces ] ; then
    echo "bond0" > /dev/interfaces
fi
    
echo "Restarting vblade service"
/etc/init.d/_vblade restart

exit 0

