28f47a199c
Support loading a default pf ruleset in case of invalid pf.conf. If no pf rules are loaded pf will pass/allow all traffic, assuming the kernel is compiled without PF_DEFAULT_TO_DROP, as is the case in GENERIC. In other words: if there's a typo in the main pf_rules we would allow all traffic. The new default rules minimise the impact of this. If $pf_program (i.e. pfctl) fails to set $pf_fules and $pf_fallback_rules_enable is YES we will load $pf_fallback_rules_file if set, or $pf_fallback_rules. $pf_fallback_rules can include multiple rules, for example to permit traffic on a management interface. $pf_fallback_rules_enable defaults to "NO", preserving historic behaviour. man page changes by ceri@. PR: 256410 Reviewed by: donner, kp Sponsored by: semaphor.dk Differential Revision: https://reviews.freebsd.org/D30791
93 lines
1.6 KiB
Bash
Executable File
93 lines
1.6 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
|
|
# PROVIDE: pf
|
|
# REQUIRE: FILESYSTEMS netif pflog pfsync routing
|
|
# KEYWORD: nojailvnet
|
|
|
|
. /etc/rc.subr
|
|
|
|
name="pf"
|
|
desc="Packet filter"
|
|
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_fallback()
|
|
{
|
|
warn "Unable to load $pf_rules."
|
|
|
|
if ! checkyesno pf_fallback_rules_enable; then
|
|
return
|
|
fi
|
|
|
|
if [ -f $pf_fallback_rules_file ]; then
|
|
warn "Loading fallback rules file: $pf_fallback_rules_file"
|
|
$pf_program -f "$pf_fallback_rules_file" $pf_flags
|
|
else
|
|
warn "Loading fallback rules: $pf_fallback_rules"
|
|
echo $pf_fallback_rules | $pf_program -f - $pf_flags
|
|
fi
|
|
}
|
|
|
|
pf_start()
|
|
{
|
|
check_startmsgs && echo -n 'Enabling pf'
|
|
$pf_program -F all > /dev/null 2>&1
|
|
$pf_program -f "$pf_rules" $pf_flags || pf_fallback
|
|
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_flags
|
|
}
|
|
|
|
pf_reload()
|
|
{
|
|
echo "Reloading pf rules."
|
|
pf_resync
|
|
}
|
|
|
|
pf_resync()
|
|
{
|
|
$pf_program -n -f "$pf_rules" $pf_flags || return 1
|
|
$pf_program -f "$pf_rules" $pf_flags
|
|
}
|
|
|
|
pf_status()
|
|
{
|
|
if ! [ -c /dev/pf ] ; then
|
|
echo "pf.ko is not loaded"
|
|
return 1
|
|
else
|
|
$pf_program -s info
|
|
$pf_program -s Running >/dev/null
|
|
fi
|
|
}
|
|
|
|
run_rc_command "$1"
|