#!/bin/sh
#
# Startup script for multicast routing
#
# chkconfig: 35 80 20
# description: Multicast routing 
# processname: multicast
#

### BEGIN INIT INFO
# Provides:
# Required-Start: $network $syslog
# Required-Stop: 
# Default-Start: 3 5
# Default-Stop: 1 6
# Short-Description: Multicast routing
# Description: Multicast routing
### END INIT INFO

# Source function library.
if [ -x /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
fi

PROG="Multicast Routing"

# default will be eth0, can be overwritten in /etc/sysconfig/multicast
DEV=eth0
if [ -f /etc/sysconfig/multicast ]; then
. /etc/sysconfig/multicast
fi

RETVAL=0

# See how we were called.
start() {
    echo -n "Starting $PROG: "
    running=`route -n | grep 224.0.0.0 | wc -l`
    if [ $running == 0 ]; then
	    route add -net 224.0.0.0 netmask 240.0.0.0 dev $DEV 2> /dev/null
	    RETVAL=$?
	    [ $RETVAL == 0 ] && success || failure
    else
	    failure
    fi
    echo
}

stop() {
    echo -n "Stopping $PROG: "
    running=`route -n | grep 224.0.0.0 | wc -l`
    if [ $running == 1 ]; then
	    route del -net 224.0.0.0 netmask 240.0.0.0 dev $DEV 2> /dev/null
	    RETVAL=$?
	    [ $RETVAL == 0 ] && success || failure
    else
	    failure
    fi
    
    echo
}


# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  *)
        echo "Usage: $PROG {start|stop}"
        exit 1
esac

exit $RETVAL
