1254721Semaste#!/bin/sh
2254721Semaste#
3254721Semaste# $FreeBSD$
4254721Semaste#
5254721Semaste
6254721Semaste# PROVIDE: ipfs
7254721Semaste# REQUIRE: ipnat
8254721Semaste# KEYWORD: nojail shutdown
9254721Semaste
10254721Semaste. /etc/rc.subr
11254721Semaste
12254721Semastename="ipfs"
13254721Semastercvar="ipfs_enable"
14254721Semastestart_cmd="ipfs_start"
15254721Semastestop_cmd="ipfs_stop"
16254721Semastestart_precmd="ipfs_prestart"
17254721Semaste
18254721Semasteipfs_prestart()
19254721Semaste{
20254721Semaste	# Do not continue if either ipnat or ipfilter is not enabled or
21254721Semaste	# if the ipfilter module is not loaded.
22254721Semaste	#
23254721Semaste	if ! checkyesno ipfilter_enable -o ! checkyesno ipnat_enable ; then
24254721Semaste		err 1  "${name} requires either ipfilter or ipnat enabled"
25254721Semaste	fi
26254721Semaste	if ! ${ipfilter_program:-/sbin/ipf} -V | grep -q 'Running: yes' >/dev/null 2>&1; then
27254721Semaste		err 1 "ipfilter module is not loaded"
28254721Semaste	fi
29254721Semaste	return 0
30254721Semaste}
31254721Semaste
32254721Semasteipfs_start()
33254721Semaste{
34254721Semaste	if [ -r /var/db/ipf/ipstate.ipf -a -r /var/db/ipf/ipnat.ipf ]; then
35254721Semaste		${ipfs_program} -R ${rc_flags}
36254721Semaste		rm -f /var/db/ipf/ipstate.ipf /var/db/ipf/ipnat.ipf
37254721Semaste	fi
38254721Semaste}
39254721Semaste
40254721Semasteipfs_stop()
41254721Semaste{
42254721Semaste	if [ ! -d /var/db/ipf ]; then
43254721Semaste		mkdir /var/db/ipf
44254721Semaste		chmod 700 /var/db/ipf
45254721Semaste		chown root:wheel /var/db/ipf
46254721Semaste	fi
47254721Semaste	${ipfs_program} -W ${rc_flags}
48254721Semaste}
49254721Semaste
50254721Semasteload_rc_config $name
51254721Semasterun_rc_command "$1"
52254721Semaste