xref: /freebsd/libexec/rc/rc.d/ipfs (revision 4c1a82cea504df7a79f5bd8f7d0a41cacccff16e)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: ipfs
7# REQUIRE: ipnat
8# KEYWORD: nojail shutdown
9
10. /etc/rc.subr
11
12name="ipfs"
13desc="Saves and restores information for NAT and state tables"
14rcvar="ipfs_enable"
15start_cmd="ipfs_start"
16stop_cmd="ipfs_stop"
17start_precmd="ipfs_prestart"
18
19ipfs_prestart()
20{
21	# Do not continue if either ipnat or ipfilter is not enabled or
22	# if the ipfilter module is not loaded.
23	#
24	if ! checkyesno ipfilter_enable -o ! checkyesno ipnat_enable ; then
25		err 1  "${name} requires either ipfilter or ipnat enabled"
26	fi
27	if ! ${ipfilter_program:-/sbin/ipf} -V | grep -q 'Running: yes' >/dev/null 2>&1; then
28		err 1 "ipfilter module is not loaded"
29	fi
30	return 0
31}
32
33ipfs_start()
34{
35	if [ -r /var/db/ipf/ipstate.ipf -a -r /var/db/ipf/ipnat.ipf ]; then
36		${ipfs_program} -R ${rc_flags}
37		rm -f /var/db/ipf/ipstate.ipf /var/db/ipf/ipnat.ipf
38	fi
39}
40
41ipfs_stop()
42{
43	if [ ! -d /var/db/ipf ]; then
44		mkdir /var/db/ipf
45		chmod 700 /var/db/ipf
46		chown root:wheel /var/db/ipf
47	fi
48	${ipfs_program} -W ${rc_flags}
49}
50
51load_rc_config $name
52run_rc_command "$1"
53