freebsd-dev/etc/rc.d/pf
Doug Barton 801c438304 Prepare for the removal of set_rcvar() by changing the rcvar=
assignments to the literal values it would have returned.

The concept of set_rcvar() was nice in theory, but the forks
it creates are a drag on the startup process, which is especially
noticeable on slower systems, such as embedded ones.

During the discussion on freebsd-rc@ a preference was expressed for
using ${name}_enable instead of the literal values. However the
code portability concept doesn't really apply since there are so
many other places where the literal name has to be searched for
and replaced. Also, using the literal value is also a tiny bit
faster than dereferencing the variables, and every little bit helps.
2012-01-14 02:18:41 +00:00

73 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: pf
# REQUIRE: FILESYSTEMS netif pflog pfsync
# BEFORE: routing
# KEYWORD: nojail
. /etc/rc.subr
name="pf"
rcvar="pf_enable"
load_rc_config $name
start_cmd="pf_start"
stop_cmd="pf_stop"
check_cmd="pf_check"
reload_cmd="pf_reload"
resync_cmd="pf_resync"
status_cmd="pf_status"
extra_commands="check reload resync"
required_files="$pf_rules"
required_modules="pf"
pf_start()
{
check_startmsgs && echo -n 'Enabling pf'
$pf_program -F all > /dev/null 2>&1
$pf_program -f "$pf_rules" $pf_flags
if ! $pf_program -s info | grep -q "Enabled" ; then
$pf_program -eq
fi
check_startmsgs && echo '.'
}
pf_stop()
{
if $pf_program -s info | grep -q "Enabled" ; then
echo -n 'Disabling pf'
$pf_program -dq
echo '.'
fi
}
pf_check()
{
echo "Checking pf rules."
$pf_program -n -f "$pf_rules"
}
pf_reload()
{
echo "Reloading pf rules."
$pf_program -n -f "$pf_rules" || return 1
# Flush everything but existing state entries that way when
# rules are read in, it doesn't break established connections.
$pf_program -Fnat -Fqueue -Frules -FSources -Finfo -FTables -Fosfp > /dev/null 2>&1
$pf_program -f "$pf_rules" $pf_flags
}
pf_resync()
{
$pf_program -f "$pf_rules" $pf_flags
}
pf_status()
{
$pf_program -s info
}
run_rc_command "$1"