#!/bin/sh

# You don't usually need to touch this file at all, the full configuration
# of the bridge can be done in a standard way on /etc/network/interfaces.

# Have a look at /usr/share/doc/bridge-utils/README.Debian.gz if you want
# more info about the way on wich a bridge is set up on Debian.

if [ ! -x /usr/sbin/brctl ]
then
  exit 0
fi

case "$IF_BRIDGE_PORTS" in
    "")
	exit 0
	;;
    none)
	INTERFACES=""
	;;
    all)
	INTERFACES=`grep eth /proc/net/dev|sed 's/\(\ *\)\(eth[^:]*\)\(.*\)/\2/'`
	;;
    *)
	INTERFACES="$IF_BRIDGE_PORTS"
	;;
esac

brctl addbr $IFACE &&

for i in $INTERFACES
do
  brctl addif $IFACE $i && ifconfig $i 0.0.0.0 up
done

if [ "$IF_BRIDGE_AGEING" ]
then
  brctl setageing $IFACE $IF_BRIDGE_AGEING
fi

if [ "$IF_BRIDGE_BRIDGEPRIO" ]
then
  brctl setbridgeprio $IFACE $IF_BRIDGE_BRIDGEPRIO
fi

if [ "$IF_BRIDGE_FD" ]
then
  brctl setfd $IFACE $IF_BRIDGE_FD
fi

if [ "$IF_BRIDGE_GCINT" ]
then
  brctl setgcint $IFACE $IF_BRIDGE_GCINT
fi

if [ "$IF_BRIDGE_HELLO" ]
then
  brctl sethello $IFACE $IF_BRIDGE_HELLO
fi

if [ "$IF_BRIDGE_MAXAGE" ]
then
  brctl setmaxage $IFACE $IF_BRIDGE_MAXAGE
fi

if [ "$IF_BRIDGE_PATHCOST" ]
then
  brctl setpathcost $IFACE $IF_BRIDGE_PATHCOST
fi

if [ "$IF_BRIDGE_PORTPRIO" ]
then
  brctl setportprio $IFACE $IF_BRIDGE_PORTPRIO
fi

if [ "$IF_BRIDGE_STP" ]
then
  brctl stp $IFACE $IF_BRIDGE_STP
fi
