#!/bin/sh
id=`/usr/sbin/modinfo | awk '/ipf/ { print $1 } ' -`
pid=`ps -e | awk '/ipmon/ { print $1 } ' -`
PATH=${PATH}:/sbin:/opt/ipf/bin
IPFILCONF=/etc/opt/ipf/ipf.conf
IPNATCONF=/etc/opt/ipf/ipnat.conf

case "$1" in
	start)
		if [ x"$pid" != x ] ; then
			kill -TERM $pid
		fi
		if [ x$id != x ] ; then
			modunload -i $id
		fi
		modload /usr/kernel/drv/ipf
		if [ -r ${IPFILCONF} ]; then
			ipf -IFa -f ${IPFILCONF}
			if [ $? != 0 ]; then
				echo "$0: load of ${IPFILCONF} into alternate set failed"
			else
				ipf -s
			fi
		fi
		if [ -r ${IPNATCONF} ]; then
			ipnat -CF -f ${IPNATCONF}
			if [ $? != 0 ]; then
				echo "$0: load of ${IPNATCONF} failed"
			fi
		fi
#		ipmon -s &
		;;

	stop)
		if [ x"$pid" != x ] ; then
			kill -TERM $pid
		fi
		if [ x$id != x ] ; then
			modunload -i $id
		fi
		;;

	reload)
		if [ -r ${IPFILCONF} ]; then
			ipf -I -Fa -f ${IPFILCONF}
			if [ $? != 0 ]; then
				echo "$0: reload of ${IPFILCONF} into alternate set failed"
			else
				ipf -s
			fi
		fi
		if [ -r ${IPNATCONF} ]; then
			ipnat -CF -f ${IPNATCONF}
			if [ $? != 0 ]; then
				echo "$0: reload of ${IPNATCONF} failed"
			fi
		fi
		;;

	*)
		echo "Usage: $0 (start|stop|reload)" >&2
		exit 1
		;;

esac
exit 0
