#!/bin/sh
set -e

#
# Make sure below as your environment
#
PATH=/usr/local/sbin:/usr/sbin:/sbin:${PATH}
mip6d_conf=/usr/local/etc/mip6d-ha.conf
setkey_conf=/usr/local/etc/setkey.conf
radvd_conf=/usr/local/etc/radvd.conf


case "$1" in
    start)
	# Router
	echo 1 >/proc/sys/net/ipv6/conf/all/forwarding
	# Proxy ND
	echo 1 >/proc/sys/net/ipv6/conf/all/proxy_ndp

  	# set IPsec configuration
	setkey -f $setkey_conf

	# invoke mip6d
	mip6d -c $mip6d_conf

	# For low performance systems, you can add sleep here
	# to make sure mip6d has started
	#

	# RD
	radvd -C $radvd_conf

        echo "Starting MIPv6 HA."
	;;
    stop)
	killall radvd
  	killall mip6d

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

	# XXX: Disabling router and/or Proxy ND can be here if you want.
	#

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

exit 0
