2004-03-23 23:30:15 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: pf
|
2005-10-02 21:12:42 +02:00
|
|
|
# REQUIRE: root mountcritlocal netif pflog pfsync
|
|
|
|
# BEFORE: routing
|
2004-10-07 15:55:26 +02:00
|
|
|
# KEYWORD: nojail
|
2004-03-23 23:30:15 +01:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="pf"
|
|
|
|
rcvar=`set_rcvar`
|
|
|
|
load_rc_config $name
|
|
|
|
start_precmd="pf_prestart"
|
|
|
|
start_cmd="pf_start"
|
|
|
|
stop_cmd="pf_stop"
|
2004-10-25 10:12:28 +02:00
|
|
|
check_cmd="pf_check"
|
2004-03-23 23:30:15 +01:00
|
|
|
reload_cmd="pf_reload"
|
|
|
|
resync_cmd="pf_resync"
|
|
|
|
status_cmd="pf_status"
|
2005-11-10 11:40:15 +01:00
|
|
|
extra_commands="check reload resync status"
|
2005-10-02 21:17:49 +02:00
|
|
|
required_files="$pf_rules"
|
2004-03-23 23:30:15 +01:00
|
|
|
|
|
|
|
pf_prestart()
|
|
|
|
{
|
|
|
|
# load pf kernel module if needed
|
2005-09-24 17:57:17 +02:00
|
|
|
if ! kldstat -q -m pf ; then
|
|
|
|
if kldload pf ; then
|
2004-03-23 23:30:15 +01:00
|
|
|
info 'pf module loaded.'
|
|
|
|
else
|
2005-10-02 21:17:49 +02:00
|
|
|
warn 'pf module failed to load.'
|
|
|
|
return 1
|
2004-03-23 23:30:15 +01:00
|
|
|
fi
|
|
|
|
fi
|
2005-10-02 21:17:49 +02:00
|
|
|
return 0
|
2004-03-23 23:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pf_start()
|
|
|
|
{
|
|
|
|
echo "Enabling pf."
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -Fall > /dev/null 2>&1
|
|
|
|
$pf_program -f "$pf_rules" $pf_flags
|
|
|
|
if ! $pf_program -s info | grep -q "Enabled" ; then
|
|
|
|
$pf_program -e
|
2004-06-23 03:42:06 +02:00
|
|
|
fi
|
2004-03-23 23:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pf_stop()
|
|
|
|
{
|
2005-10-02 21:17:49 +02:00
|
|
|
if $pf_program -s info | grep -q "Enabled" ; then
|
2004-03-23 23:30:15 +01:00
|
|
|
echo "Disabling pf."
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -d
|
2004-03-23 23:30:15 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2004-10-25 10:12:28 +02:00
|
|
|
pf_check()
|
|
|
|
{
|
|
|
|
echo "Checking pf rules."
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -n -f "$pf_rules"
|
2004-10-25 10:12:28 +02:00
|
|
|
}
|
|
|
|
|
2004-03-23 23:30:15 +01:00
|
|
|
pf_reload()
|
|
|
|
{
|
|
|
|
echo "Reloading pf rules."
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -n -f "$pf_rules" || return 1
|
2005-04-05 01:06:10 +02:00
|
|
|
# Flush everything but existing state entries that way when
|
|
|
|
# rules are read in, it doesn't break established connections.
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -Fnat -Fqueue -Frules -FSources -Finfo -FTables -Fosfp > /dev/null 2>&1
|
|
|
|
$pf_program -f "$pf_rules" $pf_flags
|
2004-03-23 23:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pf_resync()
|
|
|
|
{
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -f "$pf_rules" $pf_flags
|
2004-03-23 23:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pf_status()
|
|
|
|
{
|
2005-10-02 21:17:49 +02:00
|
|
|
$pf_program -s info
|
2004-03-23 23:30:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
run_rc_command "$1"
|