#!/bin/sh
id=`/usr/sbin/modinfo | grep ipf | awk ' { print $1 } ' -`
pid=`ps -e | grep ipmon | awk ' { 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
		[ -r ${IPFILCONF} ] && ipf -Fa -f ${IPFILCONF}
		[ -r ${IPNATCONF} ] && ipnat -CF -f ${IPNATCONF}
#		ipmon -sn &
		;;

	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
