#!/bin/sh
set -e

#
# Make sure below as your environment
#
PATH=${PATH:+$PATH:}/usr/local/sbin:/usr/sbin:/sbin
mip6d_conf=/usr/local/etc/mip6d-mn.conf
setkey_conf=/usr/local/etc/setkey.conf
#device used by mip6d.
dev=eth0

case "$1" in
    start)
	# disable to send RS from kernel.
	#echo 0 > /proc/sys/net/ipv6/conf/all/router_solicitations
	#echo 0 > /proc/sys/net/ipv6/conf/default/router_solicitations
	#echo 0 > /proc/sys/net/ipv6/conf/all/router_solicitation_interval
	#echo 0 > /proc/sys/net/ipv6/conf/default/router_solicitation_interval

  	# set IPsec configuration
	setkey -f $setkey_conf

	# bring up the interface which MN will use.
	ifconfig $DEV up

	# invoke mip6d
	mip6d -c $mip6d_conf
        echo "Starting MIPv6 MN."
	;;
    stop)
  	killall mip6d

  	ifconfig $DEV down

	# XXX: Deleting IPsec SAs can be here if you want.
	#

	# XXX: enable to send RS from kernel here if you want.
	#

        echo "Stopping MIPv6 MN."
	;;

    *)
	echo "Usage: ${0##*/} {start|stop}"
	exit 1
	;;
esac

exit 0
