#!/bin/bash
# Network Interface Configuration System
# Copyright (c) 1996-2005 Red Hat, 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.
#
# Example  ifcfg-vde0
#
# DEVICE=vde
# IPADDR=10.0.0.1
# NETMASK=255.0.0.0
# NETWORK=10.0.0.0
# BROADCAST=10.255.255.255
# ONBOOT=yes
# #PORT=/var/run/vde
# MODE=0755
# NUMPORTS=32
#
# TYPE=switch
# #TYPE=hub
# TAPDEV=tap0
# #GROUP=qemu


. /etc/init.d/functions

cd /etc/sysconfig/network-scripts
. network-functions

[ -f ../network ] && . ../network

CONFIG=${1}

need_config ${CONFIG}

source_config

if [ -n "$IPADDR" -a -n "$TAPDEV" ]
then
  expand_config  
fi

test -z "$PORT" && PORT="/var/run/$DEVNAME"
test -z "$TYPE" && TYPE="switch"
test -z "$MODE" && MODE=0755
test -z "$NUMPORTS" && NUMPORTS=32

PIDFILE="/var/run/$DEVNAME.pid"

HUBOPT=""
test "$TYPE" = "hub" && HUBOPT="--hub"

TAPOPT=""
test -n "$IPADDR" -a -n "$TAPDEV" && TAPOPT="--tap $TAPDEV"

GROUPOPT=""
test -n "$GROUP" && GROUPOPT="--group $GROUP"

vde_switch  --numports $NUMPORTS --mod $MODE --sock $PORT $HUBOPT --pidfile $PIDFILE $TAPOPT $GROUPOPT --daemon

if [ -n "$IPADDR" -a -n "$TAPDEV" ]
then
  sleep 1
  ifconfig $TAPDEV $IPADDR netmask $NETMASK broadcast $BROADCAST
fi
