2004-04-02 19:25:27 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# PROVIDE: pflog
|
2012-09-11 05:04:59 +00:00
|
|
|
# REQUIRE: FILESYSTEMS netif FILESYSTEMS
|
2004-10-07 13:55:26 +00:00
|
|
|
# KEYWORD: nojail
|
2004-04-02 19:25:27 +00:00
|
|
|
|
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="pflog"
|
2012-01-14 02:18:41 +00:00
|
|
|
rcvar="pflog_enable"
|
2005-10-02 15:54:26 +00:00
|
|
|
command="/sbin/pflogd"
|
|
|
|
pidfile="/var/run/pflogd.pid"
|
2004-04-02 19:25:27 +00:00
|
|
|
start_precmd="pflog_prestart"
|
2005-10-02 15:54:26 +00:00
|
|
|
stop_postcmd="pflog_poststop"
|
|
|
|
extra_commands="reload resync"
|
|
|
|
|
|
|
|
# for backward compatibility
|
2004-04-02 19:25:27 +00:00
|
|
|
resync_cmd="pflog_resync"
|
|
|
|
|
|
|
|
pflog_prestart()
|
|
|
|
{
|
2006-12-31 10:37:18 +00:00
|
|
|
load_kld pflog || return 1
|
2004-04-02 19:25:27 +00:00
|
|
|
|
2013-11-13 03:50:31 +00:00
|
|
|
# set pflog_dev interface to up state
|
|
|
|
if ! ifconfig $pflog_dev up; then
|
|
|
|
warn "could not bring up $pflog_dev."
|
2004-04-02 19:25:27 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
# prepare the command line for pflogd
|
2013-11-13 03:50:31 +00:00
|
|
|
rc_flags="-f $pflog_logfile -i $pflog_dev $rc_flags"
|
2004-04-02 19:25:27 +00:00
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
# report we're ready to run pflogd
|
|
|
|
return 0
|
2004-04-02 19:25:27 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 03:50:31 +00:00
|
|
|
pflog_poststart() {
|
|
|
|
# Allow child pflogd to settle
|
|
|
|
sleep 0.10
|
|
|
|
# More elegant(?) method for getting a unique pid
|
|
|
|
if [ -f /var/run/pflogd.pid ]; then
|
|
|
|
mv /var/run/pflogd.pid $pidfile
|
|
|
|
else
|
|
|
|
warn "/var/run/pflogd.pid does not exist. Too fast."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
pflog_poststop()
|
2004-04-02 19:25:27 +00:00
|
|
|
{
|
2013-11-13 03:50:31 +00:00
|
|
|
if ! ifconfig $pflog_dev down; then
|
|
|
|
warn "could not bring down $pflog_dev."
|
2005-10-02 15:54:26 +00:00
|
|
|
return 1
|
2004-04-02 19:25:27 +00:00
|
|
|
fi
|
2013-11-13 03:50:31 +00:00
|
|
|
|
|
|
|
if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
|
|
|
|
rm $pidfile
|
|
|
|
fi
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
return 0
|
2004-04-02 19:25:27 +00:00
|
|
|
}
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
# for backward compatibility
|
|
|
|
pflog_resync()
|
2004-04-02 19:25:27 +00:00
|
|
|
{
|
2005-10-02 15:54:26 +00:00
|
|
|
run_rc_command reload
|
2004-04-02 19:25:27 +00:00
|
|
|
}
|
|
|
|
|
2005-10-02 15:54:26 +00:00
|
|
|
load_rc_config $name
|
2013-11-13 03:50:31 +00:00
|
|
|
|
|
|
|
# Check if spawning multiple pflogd
|
|
|
|
echo "Starting pflogd: $pflog_instances"
|
|
|
|
if [ "$pflog_instances" ] && [ -n "$pflog_instances" ]; then
|
|
|
|
start_postcmd="pflog_poststart"
|
|
|
|
# Interate through requested instances.
|
|
|
|
for i in $pflog_instances; do
|
|
|
|
# Set required variables
|
|
|
|
eval pflog_dev=\$pflog_${i}_dev
|
|
|
|
eval pflog_logfile=\$pflog_${i}_logfile
|
|
|
|
eval pflog_flags=\$pflog_${i}_flags
|
|
|
|
# Check that required vars have non-zero length, warn if not.
|
|
|
|
if [ -z $pflog_dev ]; then
|
|
|
|
warn "pflog_dev not set"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ -z $pflog_logfile ]; then
|
|
|
|
warn "pflog_logfile not set"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
# pflogd sets a pidfile, but the name is hardcoded. Concoct a
|
|
|
|
# unique pidfile name.
|
|
|
|
pidfile="/var/run/pflogd.$i.pid"
|
|
|
|
run_rc_command "$1"
|
|
|
|
done
|
|
|
|
else
|
|
|
|
# Typical case, spawn single instance only.
|
|
|
|
pflog_dev=${pflog_dev:-"pflog0"}
|
|
|
|
run_rc_command "$1"
|
|
|
|
fi
|